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