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