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