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