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