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