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