1 #ifndef __DALI_TOOLKIT_ITEM_VIEW_H__
2 #define __DALI_TOOLKIT_ITEM_VIEW_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
25 #include <dali-toolkit/public-api/controls/scrollable/item-view/item-view-declarations.h>
33 namespace Internal DALI_INTERNAL
38 * @addtogroup dali_toolkit_controls_item_view
46 typedef IntrusivePtr<ItemLayout> ItemLayoutPtr;
49 * @brief 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.
55 * | %Signal Name | Method |
56 * |---------------------------------|--------------------------------------------|
57 * | layoutActivated | @ref LayoutActivatedSignal() |
61 * | %Action Name | Attributes | Description |
62 * |---------------|-------------------------|-------------------------------------------------|
63 * | stopScrolling | Doesn't have attributes | Stops the scroll animation. See @ref DoAction() |
67 class DALI_IMPORT_API ItemView : public Scrollable
73 PROPERTY_START_INDEX = Toolkit::Scrollable::PROPERTY_END_INDEX + 1, ///< @SINCE_1_1.18
74 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, ///< Reserve property indices, @SINCE_1_1.18
76 ANIMATABLE_PROPERTY_START_INDEX = Toolkit::Scrollable::ANIMATABLE_PROPERTY_END_INDEX + 1,
77 ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_START_INDEX + 1000 ///< Reserve animatable property indices @SINCE_1_0.0
81 * @brief An enumeration of properties belonging to the ScrollView class.
88 // Event side properties
89 MINIMUM_SWIPE_SPEED = PROPERTY_START_INDEX, ///< Property, name "minimumSwipeSpeed", @see SetMinimumSwipeSpeed(), type float, @SINCE_1_1.18
90 MINIMUM_SWIPE_DISTANCE, ///< Property, name "minimumSwipeDistance", @see SetMinimumSwipeDistance(), type float, @SINCE_1_1.18
91 WHEEL_SCROLL_DISTANCE_STEP, ///< Property, name "wheelScrollDistanceStep", @see SetWheelScrollDistanceStep(), type float, @SINCE_1_1.18
92 SNAP_TO_ITEM_ENABLED, ///< Property, name "snapToItemEnabled", @see SetAnchoring(), type bool, @SINCE_1_1.18
93 REFRESH_INTERVAL, ///< Property, name "refreshInterval", @see SetRefreshInterval(), type float, @SINCE_1_1.18
95 // Animatable properties
96 LAYOUT_POSITION = ANIMATABLE_PROPERTY_START_INDEX, ///< Property, name "layoutPosition", type float @SINCE_1_0.0
97 SCROLL_SPEED, ///< Property, name "scrollSpeed", type float @SINCE_1_0.0
98 OVERSHOOT, ///< Property, name "overshoot", type float @SINCE_1_0.0
99 SCROLL_DIRECTION, ///< Property, name "scrollDirection", type Vector2 @SINCE_1_0.0
100 LAYOUT_ORIENTATION, ///< Property, name "layoutOrientation", type integer @SINCE_1_0.0
101 SCROLL_CONTENT_SIZE ///< Property, name "scrollContentSize", type float @SINCE_1_0.0
107 typedef Signal< void () > LayoutActivatedSignalType;
112 * @brief Create an uninitialized ItemView; this can be initialized with ItemView::New().
114 * Calling member functions with an uninitialized Dali::Object is not allowed.
120 * @brief Copy constructor.
123 ItemView( const ItemView& itemView );
126 * @brief Assignment operator.
129 ItemView& operator=( const ItemView& itemView );
134 * This is non-virtual since derived Handle types must not contain data or virtual methods.
140 * @brief Create an initialized ItemView.
143 * @param[in] factory The factory which provides ItemView with items.
144 * @return A handle to a newly allocated Dali resource.
146 static ItemView New(ItemFactory& factory);
149 * @brief Downcast a handle to ItemView handle.
151 * If handle points to a ItemView the downcast produces valid
152 * handle. If not the returned handle is left uninitialized.
155 * @param[in] handle Handle to an object
156 * @return A handle to a ItemView or an uninitialized handle
158 static ItemView DownCast( BaseHandle handle );
161 * @brief Query the number of layouts.
164 * @return The number of layouts.
166 unsigned int GetLayoutCount() const;
169 * @brief Add a layout.
172 * @param[in] layout The layout.
174 void AddLayout(ItemLayout& layout);
177 * @brief Remove a layout.
180 * @param[in] layoutIndex The index of one of the ItemView layouts.
181 * @pre layoutIndex is less than GetLayoutCount().
183 void RemoveLayout(unsigned int layoutIndex);
186 * @brief Retrieve a layout.
189 * @param[in] layoutIndex The index of the layout to retrieve.
191 * @pre layoutIndex is less than GetLayoutCount().
193 ItemLayoutPtr GetLayout(unsigned int layoutIndex) const;
196 * @brief Retrieve the currently active layout, if any.
199 * @return The layout, or an uninitialized pointer if no layout is active.
201 ItemLayoutPtr GetActiveLayout() const;
204 * @brief Retrieve the current layout-position of an item in the ItemView.
207 * @param[in] itemId The item identifier.
208 * @return The current layout-position.
210 float GetCurrentLayoutPosition(ItemId itemId) const;
213 * @brief Activate one of the layouts; this will resize the ItemView
214 * & relayout actors within the ItemView.
216 * This is done by applying constraints from the new layout, and
217 * removing constraints from the previous layout.
220 * @param[in] layoutIndex The index of one of the ItemView layouts.
221 * @param[in] targetSize The target ItemView & layout size.
222 * @param[in] durationSeconds The time taken to relayout in seconds (zero for immediate).
223 * @pre layoutIndex is less than GetLayoutCount().
224 * @pre durationSeconds is greater or equal to zero.
226 void ActivateLayout(unsigned int layoutIndex, Vector3 targetSize, float durationSeconds);
229 * @brief Deactivate the current layout, if any.
231 * The constraints applied by the layout will be removed.
234 void DeactivateCurrentLayout();
237 * @brief Set the minimum swipe speed in pixels per second; A pan
238 * gesture must exceed this to trigger a swipe.
241 * @param[in] speed The minimum swipe speed
243 void SetMinimumSwipeSpeed(float speed);
246 * @brief Get the minimum swipe speed in pixels per second.
249 * @return The minimum swipe speed
251 float GetMinimumSwipeSpeed() const;
254 * @brief Set the minimum swipe distance in actor coordinates; A pan
255 * gesture must exceed this to trigger a swipe.
258 * @param[in] distance The minimum swipe distance.
260 void SetMinimumSwipeDistance(float distance);
263 * @brief Get the minimum swipe distance in actor coordinates.
266 * @return The minimum swipe distance
268 float GetMinimumSwipeDistance() const;
271 * @brief Set the step of scroll distance in actor coordinates for each wheel event received.
274 * @param[in] step The step of scroll distance(pixel).
276 void SetWheelScrollDistanceStep(float step);
279 * @brief Get the step of scroll distance in actor coordinates for each wheel event received.
282 * @return The step of scroll distance(pixel)
284 float GetWheelScrollDistanceStep() const;
287 * @brief Set whether to enable the animation for the layout to
288 * scroll to its anchor position after dragging or swiping.
290 * The anchor position is the position where all the items in the layout
291 * are aligned to their closest rounded layout positions in integer.
294 * @param[in] enabled Whether the anchor animation is enabled or not.
296 void SetAnchoring(bool enabled);
299 * @brief Get whether the anchor animation is enabled or not.
302 * @return Whether the anchor animation is enabled or not.
304 bool GetAnchoring() const;
307 * @brief Set the duration of the anchor animation in seconds.
309 * This is the time taken to reach the nearest anchor position after
310 * a drag or swipe gesture ends.
313 * @param[in] durationSeconds The duration of the anchor animation in seconds.
314 * @pre durationSeconds must be greater than zero.
316 void SetAnchoringDuration(float durationSeconds);
319 * @brief Get the duration of the anchor animation in seconds.
322 * @return The duration of the anchor animation
324 float GetAnchoringDuration() const;
327 * @brief Scroll the current layout to a particular item.
330 * @param[in] itemId The ID of an item in the layout.
331 * @param[in] durationSeconds How long the scrolling takes in seconds.
332 * @pre durationSeconds must be zero or greater; zero means the layout should scroll to the particular item instantly.
333 * If calling this with zero second of duration immediately after calling ActivateLayout, it might not work unless
334 * the duration of relayout animation for ActivateLayout is also set to be zero.
336 void ScrollToItem(ItemId itemId, float durationSeconds);
339 * @brief Set the interval between refreshes.
341 * When the layout-position of items is changed by this interval,
342 * new items are requested from ItemFactory.
345 * @param[in] intervalLayoutPositions The refresh interval in layout position.
347 void SetRefreshInterval(float intervalLayoutPositions);
350 * @brief Get the interval between refreshes in layout position.
353 * @return The refresh interval
355 float GetRefreshInterval() const;
358 * @brief Do a refresh of the item view.
364 * @brief Given the Item ID, this returns the accompanying actor.
367 * @param[in] itemId The Item ID of the actor required.
368 * @return The Actor corresponding to the Item ID.
370 Actor GetItem(ItemId itemId) const;
373 * @brief Returns the Item ID of the specified actor.
376 * @param[in] actor The actor whose Item ID is required.
377 * @return The Item ID of the item.
378 * @pre The actor should be an item of ItemView.
380 ItemId GetItemId(Actor actor) const;
383 * @brief Insert an item.
385 * A relayout will occur for the existing actors; for example if InsertItem(Item(2, ActorZ), 0) is called,
386 * the items with ID 2 or greater will be moved:
387 * Initial actors: After insert:
388 * ID 1 - ActorA ID 1 - ActorA
389 * ID 2 - ActorB ID 2 - ActorZ !
390 * ID 3 - ActorC ID 3 - ActorB
393 * @param[in] newItem The item to insert.
394 * @param[in] durationSeconds How long the relayout takes in seconds.
395 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
397 void InsertItem(Item newItem, float durationSeconds);
400 * @brief Insert a set of items; this is more efficient than calling InsertItem() repeatedly.
403 * @param[in] newItems The items to insert.
404 * @param[in] durationSeconds How long the relayout takes in seconds.
405 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
407 void InsertItems(const ItemContainer& newItems, float durationSeconds);
410 * @brief Removes an item with the given ID.
412 * A relayout will occur for the remaining actors; for example if RemoveItem(Item(2, ActorZ), 0) is called,
413 * the items with ID 3 or greater will be moved:
414 * Initial actors: After remove:
415 * ID 1 - ActorA ID 1 - ActorA
416 * ID 2 - ActorB ID 2 - ActorC (previously ID 3)
417 * ID 3 - ActorC ID 3 - ActorB (previously ID 4)
420 * @param[in] itemId The Item ID of the item to remove.
421 * @param[in] durationSeconds How long the relayout takes in seconds.
422 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
424 void RemoveItem(ItemId itemId, float durationSeconds);
427 * @brief Remove a set of items; this is more efficient than calling RemoveItem() repeatedly.
430 * @param[in] itemIds The IDs of the items to remove.
431 * @param[in] durationSeconds How long the relayout takes in seconds.
432 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
434 void RemoveItems(const ItemIdContainer& itemIds, float durationSeconds);
437 * @brief Replace an item.
439 * A relayout will occur for the replacement item only.
441 * @param[in] replacementItem The replacement for an existing item.
442 * @param[in] durationSeconds How long the relayout takes in seconds.
443 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
445 void ReplaceItem(Item replacementItem, float durationSeconds);
448 * @brief Replace a set of items.
450 * A relayout will occur for the replacement items only.
452 * @param[in] replacementItems The replacements for a set of existing items.
453 * @param[in] durationSeconds How long the relayout takes in seconds.
454 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
456 void ReplaceItems(const ItemContainer& replacementItems, float durationSeconds);
459 * @brief Set the parent origin of the items.
461 * A relayout will occur for all the items if the parent origin is different than the current one.
463 * @param[in] parentOrigin New parent origin position vector
465 void SetItemsParentOrigin( const Vector3& parentOrigin );
468 * @brief Get the parent origin of the items.
471 * @return The current parent origin of the items
473 Vector3 GetItemsParentOrigin() const;
476 * @brief Set the anchor point of the items.
478 * A relayout will occur for all the items if the anchor point is different than the current one.
480 * @param[in] anchorPoint New anchor point position vector
482 void SetItemsAnchorPoint( const Vector3& anchorPoint );
485 * @brief Get the anchor point of the items.
488 * @return The current anchor point of the items
490 Vector3 GetItemsAnchorPoint() const;
493 * @brief Get the range of items that are currently in ItemView.
496 * @param[out] range The range of items.
498 void GetItemsRange(ItemRange& range);
503 * @brief Signal emitted when layout activation is finished.
505 * A callback of the following type may be connected:
507 * void YourCallbackName();
510 * @return The signal to connect to.
511 * @pre The Object has been initialized.
513 ItemView::LayoutActivatedSignalType& LayoutActivatedSignal();
515 public: // Not intended for application developers
519 * @brief Creates a handle using the Toolkit::Internal implementation.
522 * @param[in] implementation The Control implementation.
524 DALI_INTERNAL ItemView(Internal::ItemView& implementation);
527 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
530 * @param[in] internal A pointer to the internal CustomActor.
532 explicit DALI_INTERNAL ItemView( Dali::Internal::CustomActor* internal );
539 } // namespace Toolkit
543 #endif // __DALI_TOOLKIT_ITEM_VIEW_H__