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