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