Merge remote-tracking branch 'origin/tizen' into devel/new_mesh
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / scrollable / item-view / item-view.h
1 #ifndef __DALI_TOOLKIT_ITEM_VIEW_H__
2 #define __DALI_TOOLKIT_ITEM_VIEW_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22
23 // INTERNAL INCLUDES
24 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
25 #include <dali-toolkit/public-api/controls/scrollable/item-view/item-view-declarations.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Internal DALI_INTERNAL
34 {
35 class ItemView;
36 }
37
38 class ScrollConnector;
39 class ItemFactory;
40 class ItemLayout;
41 struct ItemRange;
42
43 typedef IntrusivePtr<ItemLayout> ItemLayoutPtr;
44
45 /**
46  * @brief ItemView is a scrollable layout container.
47  *
48  * Multiple ItemLayouts may be provided, to determine the logical position of each item a layout.
49  * Actors are provided from an external ItemFactory, to display the currently visible items.
50  */
51 class DALI_IMPORT_API ItemView : public Scrollable
52 {
53 public:
54
55   /**
56    * @brief Create an uninitialized ItemView; this can be initialized with ItemView::New().
57    *
58    * Calling member functions with an uninitialized Dali::Object is not allowed.
59    */
60   ItemView();
61
62   /**
63    * @brief Copy constructor.
64    */
65   ItemView( const ItemView& itemView );
66
67   /**
68    * @brief Assignment operator.
69    */
70   ItemView& operator=( const ItemView& itemView );
71
72   /**
73    * @brief Destructor
74    *
75    * This is non-virtual since derived Handle types must not contain data or virtual methods.
76    */
77   ~ItemView();
78
79   /**
80    * @brief Create an initialized ItemView.
81    *
82    * @param[in] factory The factory which provides ItemView with items.
83    * @return A handle to a newly allocated Dali resource.
84    */
85   static ItemView New(ItemFactory& factory);
86
87   /**
88    * @brief Downcast an Object handle to ItemView.
89    *
90    * If handle points to a ItemView the downcast produces valid
91    * handle. If not the returned handle is left uninitialized.
92    *
93    * @param[in] handle Handle to an object
94    * @return handle to a ItemView or an uninitialized handle
95    */
96   static ItemView DownCast( BaseHandle handle );
97
98   /**
99    * @brief Retrieve a scroll-connector; this can be used to connect scroll components e.g. scroll bars.
100    *
101    * @return The connector.
102    */
103   ScrollConnector GetScrollConnector() const;
104
105   /**
106    * @brief Query the number of layouts.
107    *
108    * @return The number of layouts.
109    */
110   unsigned int GetLayoutCount() const;
111
112   /**
113    * @brief Add a layout.
114    *
115    * @param[in] layout The layout.
116    */
117   void AddLayout(ItemLayout& layout);
118
119   /**
120    * @brief Remove a layout.
121    *
122    * @pre layoutIndex is less than GetLayoutCount().
123    * @param[in] layoutIndex The index of one of the ItemView layouts.
124    */
125   void RemoveLayout(unsigned int layoutIndex);
126
127   /**
128    * @brief Retrieve a layout.
129    *
130    * @pre layoutIndex is less than GetLayoutCount().
131    * @param[in] layoutIndex The index of the layout to retrieve.
132    * @return The layout
133    */
134   ItemLayoutPtr GetLayout(unsigned int layoutIndex) const;
135
136   /**
137    * @brief Retrieve the currently active layout, if any.
138    *
139    * @return The layout, or an uninitialized pointer if no layout is active.
140    */
141   ItemLayoutPtr GetActiveLayout() const;
142
143   /**
144    * @brief Retrieve the current layout-position of an item in the ItemView.
145    *
146    * @param[in] itemId The item identifier.
147    * @return The current layout-position.
148    */
149   float GetCurrentLayoutPosition(ItemId itemId) const;
150
151   /**
152    * @brief Activate one of the layouts; this will resize the ItemView
153    * & relayout actors within the ItemView.
154    *
155    * This is done by applying constraints from the new layout, and
156    * removing constraints from the previous layout.
157    *
158    * @pre layoutIndex is less than GetLayoutCount().
159    * @pre durationSeconds is greater or equal to zero.
160    * @param[in] layoutIndex The index of one of the ItemView layouts.
161    * @param[in] targetSize The target ItemView & layout size.
162    * @param[in] durationSeconds The time taken to relayout in seconds (zero for immediate).
163    */
164   void ActivateLayout(unsigned int layoutIndex, Vector3 targetSize, float durationSeconds);
165
166   /**
167    * @brief Deactivate the current layout, if any.
168    *
169    * The constraints applied by the layout will be removed.
170    */
171   void DeactivateCurrentLayout();
172
173   /**
174    * @brief Set the minimum swipe speed in pixels per second; A pan
175    * gesture must exceed this to trigger a swipe.
176    *
177    * @param[in] speed The minimum swipe speed
178    */
179   void SetMinimumSwipeSpeed(float speed);
180
181   /**
182    * @brief Get the minimum swipe speed in pixels per second.
183    *
184    * @return The minimum swipe speed
185    */
186   float GetMinimumSwipeSpeed() const;
187
188   /**
189    * @brief Set the minimum swipe distance in actor coordinates; A pan
190    * gesture must exceed this to trigger a swipe.
191    *
192    * @param[in] distance The minimum swipe distance.
193    */
194   void SetMinimumSwipeDistance(float distance);
195
196   /**
197    * @brief Get the minimum swipe distance in actor coordinates.
198    *
199    * @return The minimum swipe distance
200    */
201   float GetMinimumSwipeDistance() const;
202
203   /**
204    * @brief Set the step of scroll distance in actor coordinates for each mouse wheel event received.
205    *
206    * @param[in] step The step of scroll distance(pixel).
207    */
208   void SetMouseWheelScrollDistanceStep(float step);
209
210   /**
211    * @brief Get the step of scroll distance in actor coordinates for each mouse wheel event received.
212    *
213    * @return The step of scroll distance(pixel)
214    */
215   float GetMouseWheelScrollDistanceStep() const;
216
217   /**
218    * @brief Set whether to enable the animation for the layout to
219    * scroll to its anchor position after dragging or swiping.
220    *
221    * The anchor position is the position where all the items in the layout
222    * are aligned to their closest rounded layout positions in integer.
223    *
224    * @param[in] enabled Whether the anchor animation is enabled or not.
225    */
226   void SetAnchoring(bool enabled);
227
228   /**
229    * @brief Get whether the anchor animation is enabled or not.
230    *
231    * @return Whether the anchor animation is enabled or not.
232    */
233   bool GetAnchoring() const;
234
235   /**
236    * @brief Set the duration of the anchor animation in seconds.
237    *
238    * This is the time taken to reach the nearest anchor position after
239    * a drag or swipe gesture ends.
240    *
241    * @pre durationSeconds must be greater than zero.
242    * @param[in] durationSeconds The duration of the anchor animation in seconds.
243    */
244   void SetAnchoringDuration(float durationSeconds);
245
246   /**
247    * @brief Get the duration of the anchor animation in seconds.
248    *
249    * @return The duration of the anchor animation
250    */
251   float GetAnchoringDuration() const;
252
253   /**
254    * @brief Scroll the current layout to a particular item.
255    *
256    * @pre durationSeconds must be zero or greater; zero means the layout should scroll to the particular item instantly.
257    * If calling this with zero second of duration immediately after calling ActivateLayout, it might not work unless
258    * the duration of relayout animation for ActivateLayout is also set to be zero.
259    * @param[in] itemId The ID of an item in the layout.
260    * @param[in] durationSeconds How long the scrolling takes in seconds.
261    */
262   void ScrollToItem(ItemId itemId, float durationSeconds);
263
264   /**
265    * @brief Set the interval between refreshes. When the layout-position of items is changed by this interval,
266    * new items are requested from ItemFactory.
267    *
268    * @param[in] intervalLayoutPositions The refresh interval in layout position.
269    */
270   void SetRefreshInterval(float intervalLayoutPositions);
271
272   /**
273    * @brief Get the interval between refreshes in layout position.
274    *
275    * @return  The refresh interval
276    */
277   float GetRefreshInterval() const;
278
279   /**
280    * @brief Do a refresh of the item view.
281    */
282   void Refresh();
283
284   /**
285    * @brief Given the Item ID, this returns the accompanying actor.
286    *
287    * @param[in] itemId The Item ID of the actor required.
288    * @return The Actor corresponding to the Item ID.
289    */
290   Actor GetItem(ItemId itemId) const;
291
292   /**
293    * @brief Returns the Item ID of the specified actor.
294    *
295    * @param[in] actor The actor whose Item ID is required.
296    * @return The Item ID of the item.
297    * @pre The actor should be an item of ItemView.
298    */
299   ItemId GetItemId(Actor actor) const;
300
301   /**
302    * @brief Insert an item.
303    *
304    * A relayout will occur for the existing actors; for example if InsertItem(Item(2, ActorZ), 0) is called,
305    * the items with ID 2 or greater will be moved:
306    *   Initial actors:     After insert:
307    *     ID 1 - ActorA       ID 1 - ActorA
308    *     ID 2 - ActorB       ID 2 - ActorZ !
309    *     ID 3 - ActorC       ID 3 - ActorB
310    *                         ID 4 - ActorC
311    * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
312    * @param[in] newItem The item to insert.
313    * @param[in] durationSeconds How long the relayout takes in seconds.
314    */
315   void InsertItem(Item newItem, float durationSeconds);
316
317   /**
318    * @brief Insert a set of items; this is more efficient than calling InsertItem() repeatedly.
319    *
320    * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
321    * @param[in] newItems The items to insert.
322    * @param[in] durationSeconds How long the relayout takes in seconds.
323    */
324   void InsertItems(const ItemContainer& newItems, float durationSeconds);
325
326   /**
327    * @brief Removes an item with the given ID.
328    *
329    * A relayout will occur for the remaining actors; for example if RemoveItem(Item(2, ActorZ), 0) is called,
330    * the items with ID 3 or greater will be moved:
331    *   Initial actors:     After remove:
332    *     ID 1 - ActorA       ID 1 - ActorA
333    *     ID 2 - ActorB       ID 2 - ActorC (previously ID 3)
334    *     ID 3 - ActorC       ID 3 - ActorB (previously ID 4)
335    *     ID 4 - ActorD
336    * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
337    * @param[in] itemId The Item ID of the item to remove.
338    * @param[in] durationSeconds How long the relayout takes in seconds.
339    */
340   void RemoveItem(ItemId itemId, float durationSeconds);
341
342   /**
343    * @brief Remove a set of items; this is more efficient than calling RemoveItem() repeatedly.
344    *
345    * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
346    * @param[in] itemIds The IDs of the items to remove.
347    * @param[in] durationSeconds How long the relayout takes in seconds.
348    */
349   void RemoveItems(const ItemIdContainer& itemIds, float durationSeconds);
350
351   /**
352    * @brief Replace an item.
353    *
354    * A relayout will occur for the replacement item only.
355    * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
356    * @param[in] replacementItem The replacement for an existing item.
357    * @param[in] durationSeconds How long the relayout takes in seconds.
358    */
359   void ReplaceItem(Item replacementItem, float durationSeconds);
360
361   /**
362    * @brief Replace a set of items.
363    *
364    * A relayout will occur for the replacement items only.
365    * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
366    * @param[in] replacementItems The replacements for a set of existing items.
367    * @param[in] durationSeconds How long the relayout takes in seconds.
368    */
369   void ReplaceItems(const ItemContainer& replacementItems, float durationSeconds);
370
371   /**
372    * @brief Set the parent origin of the items
373    *
374    * A relayout will occur for all the items if the parent origin is different than the current one.
375    * @param[in] parentOrigin New parent origin position vector
376    */
377   void SetItemsParentOrigin( const Vector3& parentOrigin );
378
379   /**
380    * @brief Get the parent origin of the items
381    *
382    * @return The current parent origin of the items
383    */
384   Vector3 GetItemsParentOrigin() const;
385
386   /**
387    * @brief Set the anchor point of the items
388    *
389    * A relayout will occur for all the items if the anchor point is different than the current one.
390    * @param[in] anchorPoint New anchor point position vector
391    */
392   void SetItemsAnchorPoint( const Vector3& anchorPoint );
393
394   /**
395    * @brief Get the anchor point of the items
396    *
397    * @return The current anchor point of the items
398    */
399   Vector3 GetItemsAnchorPoint() const;
400
401   /**
402    * @brief Get the range of items that are currently in ItemView.
403    *
404    * @param[out] range The range of items.
405    */
406   void GetItemsRange(ItemRange& range);
407
408 public: // Not intended for application developers
409
410   /**
411    * @brief Creates a handle using the Toolkit::Internal implementation.
412    *
413    * @param[in]  implementation  The Control implementation.
414    */
415   DALI_INTERNAL ItemView(Internal::ItemView& implementation);
416
417   /**
418    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
419    *
420    * @param[in]  internal  A pointer to the internal CustomActor.
421    */
422   explicit DALI_INTERNAL ItemView( Dali::Internal::CustomActor* internal );
423 };
424
425 } // namespace Toolkit
426
427 } // namespace Dali
428
429 #endif // __DALI_TOOLKIT_ITEM_VIEW_H__