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