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