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