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