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