1 #ifndef __DALI_TOOLKIT_ITEM_VIEW_H__
2 #define __DALI_TOOLKIT_ITEM_VIEW_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 // http://floralicense.org/license/
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.
21 * @addtogroup CAPI_DALI_TOOLKIT_ITEM_VIEW_MODULE
26 #include <dali/dali.h>
29 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
30 #include <dali-toolkit/public-api/controls/scrollable/item-view/item-view-declarations.h>
32 namespace Dali DALI_IMPORT_API
38 namespace Internal DALI_INTERNAL
43 class ScrollConnector;
47 typedef IntrusivePtr<ItemLayout> ItemLayoutPtr;
50 * @brief ItemView is a scrollable layout container.
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.
55 class ItemView : public Scrollable
60 * @brief Create an uninitialized ItemView; this can be initialized with ItemView::New().
62 * Calling member functions with an uninitialized Dali::Object is not allowed.
67 * @brief Copy constructor.
69 ItemView( const ItemView& itemView );
72 * @brief Assignment operator.
74 ItemView& operator=( const ItemView& itemView );
77 * @brief Virtual destructor.
79 * Dali::Object derived classes typically do not contain member data.
84 * @brief Create an initialized ItemView.
86 * @param[in] factory The factory which provides ItemView with items.
87 * @return A handle to a newly allocated Dali resource.
89 static ItemView New(ItemFactory& factory);
92 * @brief Downcast an Object handle to ItemView.
94 * If handle points to a ItemView the downcast produces valid
95 * handle. If not the returned handle is left uninitialized.
97 * @param[in] handle Handle to an object
98 * @return handle to a ItemView or an uninitialized handle
100 static ItemView DownCast( BaseHandle handle );
103 * @brief Retrieve a scroll-connector; this can be used to connect scroll components e.g. scroll bars.
105 * @return The connector.
107 ScrollConnector GetScrollConnector() const;
110 * @brief Query the number of layouts.
112 * @return The number of layouts.
114 unsigned int GetLayoutCount() const;
117 * @brief Add a layout.
119 * @param[in] layout The layout.
121 void AddLayout(ItemLayout& layout);
124 * @brief Remove a layout.
126 * @pre layoutIndex is less than GetLayoutCount().
127 * @param[in] layoutIndex The index of one of the ItemView layouts.
129 void RemoveLayout(unsigned int layoutIndex);
132 * @brief Retrieve a layout.
134 * @pre layoutIndex is less than GetLayoutCount().
135 * @param[in] layoutIndex The index of the layout to retrieve.
138 ItemLayoutPtr GetLayout(unsigned int layoutIndex) const;
141 * @brief Retrieve the currently active layout, if any.
143 * @return The layout, or an uninitialized pointer if no layout is active.
145 ItemLayoutPtr GetActiveLayout() const;
148 * @brief Retrieve the current layout-position of an item in the ItemView.
150 * @param[in] itemId The item identifier.
151 * @return The current layout-position.
153 float GetCurrentLayoutPosition(ItemId itemId) const;
156 * @brief Activate one of the layouts; this will resize the ItemView
157 * & relayout actors within the ItemView.
159 * This is done by applying constraints from the new layout, and
160 * removing constraints from the previous layout.
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).
168 void ActivateLayout(unsigned int layoutIndex, Vector3 targetSize, float durationSeconds);
171 * @brief Deactivate the current layout, if any.
173 * The constraints applied by the layout will be removed.
175 void DeactivateCurrentLayout();
178 * @brief Set the minimum swipe speed in pixels per second; A pan
179 * gesture must exceed this to trigger a swipe.
181 * @param[in] speed The minimum swipe speed
183 void SetMinimumSwipeSpeed(float speed);
186 * @brief Get the minimum swipe speed in pixels per second.
188 * @return The minimum swipe speed
190 float GetMinimumSwipeSpeed() const;
193 * @brief Set the minimum swipe distance in actor coordinates; A pan
194 * gesture must exceed this to trigger a swipe.
196 * @param[in] distance The minimum swipe distance.
198 void SetMinimumSwipeDistance(float distance);
201 * @brief Get the minimum swipe distance in actor coordinates.
203 * @return The minimum swipe distance
205 float GetMinimumSwipeDistance() const;
208 * @brief Set the step of scroll distance in actor coordinates for each mouse wheel event received.
210 * @param[in] step The step of scroll distance(pixel).
212 void SetMouseWheelScrollDistanceStep(float step);
215 * @brief Get the step of scroll distance in actor coordinates for each mouse wheel event received.
217 * @return The step of scroll distance(pixel)
219 float GetMouseWheelScrollDistanceStep() const;
222 * @brief Set whether to enable the animation for the layout to
223 * scroll to its anchor position after dragging or swiping.
225 * The anchor position is the position where all the items in the layout
226 * are aligned to their closest rounded layout positions in integer.
228 * @param[in] enabled Whether the anchor animation is enabled or not.
230 void SetAnchoring(bool enabled);
233 * @brief Get whether the anchor animation is enabled or not.
235 * @return Whether the anchor animation is enabled or not.
237 bool GetAnchoring() const;
240 * @brief Set the duration of the anchor animation in seconds.
242 * This is the time taken to reach the nearest anchor position after
243 * a drag or swipe gesture ends.
245 * @pre durationSeconds must be greater than zero.
246 * @param[in] durationSeconds The duration of the anchor animation in seconds.
248 void SetAnchoringDuration(float durationSeconds);
251 * @brief Get the duration of the anchor animation in seconds.
253 * @return The duration of the anchor animation
255 float GetAnchoringDuration() const;
258 * @brief Scroll the current layout to a particular item.
260 * @pre durationSeconds must be zero or greater; zero means the layout should scroll to the particular item instantly.
261 * If calling this with zero second of duration immediately after calling ActivateLayout, it might not work unless
262 * the duration of relayout animation for ActivateLayout is also set to be zero.
263 * @param[in] itemId The ID of an item in the layout.
264 * @param[in] durationSeconds How long the scrolling takes in seconds.
266 void ScrollToItem(ItemId itemId, float durationSeconds);
269 * @brief Set the interval between refreshes, during which new items are requested from ItemFactory.
271 * @param[in] intervalMilliseconds The refresh interval in milliseconds.
273 void SetRefreshInterval(unsigned int intervalMilliseconds);
276 * @brief Get the interval between refreshes in milliseconds.
278 * @return The refresh interval
280 unsigned int GetRefreshInterval() const;
283 * @brief Given the Item ID, this returns the accompanying actor.
285 * @param[in] itemId The Item ID of the actor required.
286 * @return The Actor corresponding to the Item ID.
288 Actor GetItem(ItemId itemId) const;
291 * @brief Returns the Item ID of the specified actor.
293 * @param[in] actor The actor whose Item ID is required.
294 * @return The Item ID of the item.
295 * @pre The actor should be an item of ItemView.
297 ItemId GetItemId(Actor actor) const;
300 * @brief Insert an item.
302 * A relayout will occur for the existing actors; for example if InsertItem(Item(2, ActorZ), 0) is called,
303 * the items with ID 2 or greater will be moved:
304 * Initial actors: After insert:
305 * ID 1 - ActorA ID 1 - ActorA
306 * ID 2 - ActorB ID 2 - ActorZ !
307 * ID 3 - ActorC ID 3 - ActorB
309 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
310 * @param[in] newItem The item to insert.
311 * @param[in] durationSeconds How long the relayout takes in seconds.
313 void InsertItem(Item newItem, float durationSeconds);
316 * @brief Insert a set of items; this is more efficient than calling InsertItem() repeatedly.
318 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
319 * @param[in] newItems The items to insert.
320 * @param[in] durationSeconds How long the relayout takes in seconds.
322 void InsertItems(const ItemContainer& newItems, float durationSeconds);
325 * @brief Removes an item with the given ID.
327 * A relayout will occur for the remaining actors; for example if RemoveItem(Item(2, ActorZ), 0) is called,
328 * the items with ID 3 or greater will be moved:
329 * Initial actors: After remove:
330 * ID 1 - ActorA ID 1 - ActorA
331 * ID 2 - ActorB ID 2 - ActorC (previously ID 3)
332 * ID 3 - ActorC ID 3 - ActorB (previously ID 4)
334 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
335 * @param[in] itemId The Item ID of the item to remove.
336 * @param[in] durationSeconds How long the relayout takes in seconds.
338 void RemoveItem(ItemId itemId, float durationSeconds);
341 * @brief Remove a set of items; this is more efficient than calling RemoveItem() repeatedly.
343 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
344 * @param[in] itemIds The IDs of the items to remove.
345 * @param[in] durationSeconds How long the relayout takes in seconds.
347 void RemoveItems(const ItemIdContainer& itemIds, float durationSeconds);
350 * @brief Replace an item.
352 * A relayout will occur for the replacement item only.
353 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
354 * @param[in] replacementItem The replacement for an existing item.
355 * @param[in] durationSeconds How long the relayout takes in seconds.
357 void ReplaceItem(Item replacementItem, float durationSeconds);
360 * @brief Replace a set of items.
362 * A relayout will occur for the replacement items only.
363 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
364 * @param[in] replacementItems The replacements for a set of existing items.
365 * @param[in] durationSeconds How long the relayout takes in seconds.
367 void ReplaceItems(const ItemContainer& replacementItems, float durationSeconds);
369 public: // Not intended for application developers
372 * @brief Creates a handle using the Toolkit::Internal implementation.
374 * @param[in] implementation The Control implementation.
376 ItemView(Internal::ItemView& implementation);
379 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
381 * @param[in] internal A pointer to the internal CustomActor.
383 ItemView( Dali::Internal::CustomActor* internal );
386 } // namespace Toolkit
393 #endif // __DALI_TOOLKIT_ITEM_VIEW_H__