1 #ifndef __DALI_TOOLKIT_ITEM_VIEW_H__
2 #define __DALI_TOOLKIT_ITEM_VIEW_H__
5 * Copyright (c) 2018 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 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_TOOLKIT_API ItemView : public Scrollable
72 * @brief Enumeration for the start and end property ranges for this control.
77 PROPERTY_START_INDEX = Toolkit::Scrollable::PROPERTY_END_INDEX + 1, ///< @SINCE_1_1.18
78 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, ///< Reserve property indices, @SINCE_1_1.18
80 ANIMATABLE_PROPERTY_START_INDEX = Toolkit::Scrollable::ANIMATABLE_PROPERTY_END_INDEX + 1,
81 ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_START_INDEX + 1000 ///< Reserve animatable property indices @SINCE_1_0.0
85 * @brief Enumeration for the instance of properties belonging to the ScrollView class.
91 * @brief Enumeration for the instance of properties belonging to the ScrollView class.
96 ///////////////////////////////////////////////////////////////////////////////
97 // Event side (non-animatable) properties
98 ///////////////////////////////////////////////////////////////////////////////
101 * @brief The minimum swipe speed in pixels per second.
102 * @details Name "minimumSwipeSpeed", type Property::FLOAT.
104 * @see SetMinimumSwipeSpeed()
106 MINIMUM_SWIPE_SPEED = PROPERTY_START_INDEX,
109 * @brief The minimum swipe distance in actor coordinates.
110 * @details Name "minimumSwipeDistance", type Property::FLOAT.
112 * @see SetMinimumSwipeDistance()
114 MINIMUM_SWIPE_DISTANCE,
117 * @brief The step of scroll distance in actor coordinates for each wheel event received.
118 * @details Name "wheelScrollDistanceStep", type Property::FLOAT.
120 * @see SetWheelScrollDistanceStep()
122 WHEEL_SCROLL_DISTANCE_STEP,
125 * @brief Whether the animation for the layout to scroll to its anchor position after dragging or swiping is enabled.
126 * @details Name "snapToItemEnabled", type Property::BOOLEAN.
128 * @see SetAnchoring()
130 SNAP_TO_ITEM_ENABLED,
133 * @brief The interval between refreshes.
134 * @details Name "refreshInterval", type Property::FLOAT.
136 * @see SetRefreshInterval()
141 * @brief The layout used.
142 * @details Name "layout", type Property::ARRAY.
144 * @see Dali::Toolkit::DefaultItemLayoutProperty
148 ///////////////////////////////////////////////////////////////////////////////
149 // Animatable Properties
150 ///////////////////////////////////////////////////////////////////////////////
153 * @brief The current logical position within the layout.
154 * @details Name "layoutPosition", type Property::FLOAT.
157 LAYOUT_POSITION = ANIMATABLE_PROPERTY_START_INDEX,
160 * @brief The scrolling speed when playing the flick animation.
161 * @details Name "scrollSpeed", type Property::FLOAT.
167 * @brief The amount that we can scroll beyond the boundary.
168 * @details Name "overshoot", type Property::FLOAT.
174 * @brief The current scrolling direction.
175 * @details Name "scrollDirection", type Property::FLOAT.
181 * @brief The current orientation of the layout.
182 * @details Name "layoutOrientation", type Property::INTEGER.
188 * @brief The size of the content.
189 * @details Name "scrollContentSize", type Property::FLOAT.
198 typedef Signal< void () > LayoutActivatedSignalType;
203 * @brief Creates an uninitialized ItemView; this can be initialized with ItemView::New().
205 * Calling member functions with an uninitialized Dali::Object is not allowed.
211 * @brief Copy constructor.
213 * @param[in] itemView Handle to an object
215 ItemView( const ItemView& itemView );
218 * @brief Assignment operator.
220 * @param[in] itemView Handle to an object
221 * @return A reference to this
223 ItemView& operator=( const ItemView& itemView );
228 * This is non-virtual since derived Handle types must not contain data or virtual methods.
234 * @brief Creates an initialized ItemView.
237 * @param[in] factory The factory which provides ItemView with items
238 * @return A handle to a newly allocated Dali resource
240 static ItemView New(ItemFactory& factory);
243 * @brief Downcasts a handle to ItemView handle.
245 * If handle points to a ItemView, the downcast produces valid handle.
246 * If not, the returned handle is left uninitialized.
249 * @param[in] handle Handle to an object
250 * @return A handle to a ItemView or an uninitialized handle
252 static ItemView DownCast( BaseHandle handle );
255 * @brief Queries the number of layouts.
258 * @return The number of layouts
260 unsigned int GetLayoutCount() const;
263 * @brief Adds a layout.
266 * @param[in] layout The layout
268 void AddLayout(ItemLayout& layout);
271 * @brief Removes a layout.
274 * @param[in] layoutIndex The index of one of the ItemView layouts
275 * @pre layoutIndex is less than GetLayoutCount().
277 void RemoveLayout(unsigned int layoutIndex);
280 * @brief Retrieves a layout.
283 * @param[in] layoutIndex The index of the layout to retrieve
285 * @pre layoutIndex is less than GetLayoutCount().
287 ItemLayoutPtr GetLayout(unsigned int layoutIndex) const;
290 * @brief Retrieves the currently active layout, if any.
293 * @return The layout, or an uninitialized pointer if no layout is active
295 ItemLayoutPtr GetActiveLayout() const;
298 * @brief Retrieves the current layout-position of an item in the ItemView.
301 * @param[in] itemId The item identifier
302 * @return The current layout-position
304 float GetCurrentLayoutPosition(ItemId itemId) const;
307 * @brief Activates one of the layouts; this will resize the ItemView
308 * & relayout actors within the ItemView.
310 * This is done by applying constraints from the new layout, and
311 * removing constraints from the previous layout.
314 * @param[in] layoutIndex The index of one of the ItemView layouts
315 * @param[in] targetSize The target ItemView & layout size
316 * @param[in] durationSeconds The time taken to relayout in seconds (zero for immediate)
317 * @pre layoutIndex is less than GetLayoutCount().
318 * @pre durationSeconds is greater or equal to zero.
320 void ActivateLayout(unsigned int layoutIndex, Vector3 targetSize, float durationSeconds);
323 * @brief Deactivates the current layout, if any.
325 * The constraints applied by the layout will be removed.
328 void DeactivateCurrentLayout();
331 * @brief Sets the minimum swipe speed in pixels per second;
332 * A pan gesture must exceed this to trigger a swipe.
335 * @param[in] speed The minimum swipe speed
337 void SetMinimumSwipeSpeed(float speed);
340 * @brief Gets the minimum swipe speed in pixels per second.
343 * @return The minimum swipe speed
345 float GetMinimumSwipeSpeed() const;
348 * @brief Sets the minimum swipe distance in actor coordinates;
349 * A pan gesture must exceed this to trigger a swipe.
352 * @param[in] distance The minimum swipe distance
354 void SetMinimumSwipeDistance(float distance);
357 * @brief Gets the minimum swipe distance in actor coordinates.
360 * @return The minimum swipe distance
362 float GetMinimumSwipeDistance() const;
365 * @brief Set the step of scroll distance in actor coordinates for each wheel event received.
368 * @param[in] step The step of scroll distance(pixel).
370 void SetWheelScrollDistanceStep(float step);
373 * @brief Get the step of scroll distance in actor coordinates for each wheel event received.
376 * @return The step of scroll distance(pixel)
378 float GetWheelScrollDistanceStep() const;
381 * @brief Set whether to enable the animation for the layout to
382 * scroll to its anchor position after dragging or swiping.
384 * The anchor position is the position where all the items in the layout
385 * are aligned to their closest rounded layout positions in integer.
388 * @param[in] enabled Whether the anchor animation is enabled or not.
390 void SetAnchoring(bool enabled);
393 * @brief Get whether the anchor animation is enabled or not.
396 * @return Whether the anchor animation is enabled or not.
398 bool GetAnchoring() const;
401 * @brief Set the duration of the anchor animation in seconds.
403 * This is the time taken to reach the nearest anchor position after
404 * a drag or swipe gesture ends.
407 * @param[in] durationSeconds The duration of the anchor animation in seconds.
408 * @pre durationSeconds must be greater than zero.
410 void SetAnchoringDuration(float durationSeconds);
413 * @brief Get the duration of the anchor animation in seconds.
416 * @return The duration of the anchor animation
418 float GetAnchoringDuration() const;
421 * @brief Scroll the current layout to a particular item.
424 * @param[in] itemId The ID of an item in the layout.
425 * @param[in] durationSeconds How long the scrolling takes in seconds.
426 * @pre durationSeconds must be zero or greater; zero means the layout should scroll to the particular item instantly.
427 * If calling this with zero second of duration immediately after calling ActivateLayout, it might not work unless
428 * the duration of relayout animation for ActivateLayout is also set to be zero.
430 void ScrollToItem(ItemId itemId, float durationSeconds);
433 * @brief Set the interval between refreshes.
435 * When the layout-position of items is changed by this interval,
436 * new items are requested from ItemFactory.
439 * @param[in] intervalLayoutPositions The refresh interval in layout position.
441 void SetRefreshInterval(float intervalLayoutPositions);
444 * @brief Get the interval between refreshes in layout position.
447 * @return The refresh interval
449 float GetRefreshInterval() const;
452 * @brief Do a refresh of the item view.
458 * @brief Given the Item ID, this returns the accompanying actor.
461 * @param[in] itemId The Item ID of the actor required.
462 * @return The Actor corresponding to the Item ID.
464 Actor GetItem(ItemId itemId) const;
467 * @brief Returns the Item ID of the specified actor.
470 * @param[in] actor The actor whose Item ID is required.
471 * @return The Item ID of the item.
472 * @pre The actor should be an item of ItemView.
474 ItemId GetItemId(Actor actor) const;
477 * @brief Insert an item.
479 * A relayout will occur for the existing actors; for example if InsertItem(Item(2, ActorZ), 0) is called,
480 * the items with ID 2 or greater will be moved:
481 * Initial actors: After insert:
482 * ID 1 - ActorA ID 1 - ActorA
483 * ID 2 - ActorB ID 2 - ActorZ !
484 * ID 3 - ActorC ID 3 - ActorB
487 * @param[in] newItem The item to insert.
488 * @param[in] durationSeconds How long the relayout takes in seconds.
489 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
491 void InsertItem(Item newItem, float durationSeconds);
494 * @brief Insert a set of items; this is more efficient than calling InsertItem() repeatedly.
497 * @param[in] newItems The items to insert.
498 * @param[in] durationSeconds How long the relayout takes in seconds.
499 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
501 void InsertItems(const ItemContainer& newItems, float durationSeconds);
504 * @brief Removes an item with the given ID.
506 * A relayout will occur for the remaining actors; for example if RemoveItem(Item(2, ActorZ), 0) is called,
507 * the items with ID 3 or greater will be moved:
508 * | Initial actors: | After remove: |
509 * |:------------------ |:-------------- |
510 * | ID 1 - ActorA | ID 1 - ActorA |
511 * | ID 2 - ActorB | ID 2 - ActorC (previously ID 3) |
512 * | ID 3 - ActorC | ID 3 - ActorB (previously ID 4) |
513 * | ID 4 - ActorD | |
515 * @param[in] itemId The Item ID of the item to remove.
516 * @param[in] durationSeconds How long the relayout takes in seconds.
517 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
519 void RemoveItem(ItemId itemId, float durationSeconds);
522 * @brief Remove a set of items; this is more efficient than calling RemoveItem() repeatedly.
525 * @param[in] itemIds The IDs of the items to remove.
526 * @param[in] durationSeconds How long the relayout takes in seconds.
527 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
529 void RemoveItems(const ItemIdContainer& itemIds, float durationSeconds);
532 * @brief Replace an item.
534 * A relayout will occur for the replacement item only.
536 * @param[in] replacementItem The replacement for an existing item.
537 * @param[in] durationSeconds How long the relayout takes in seconds.
538 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
540 void ReplaceItem(Item replacementItem, float durationSeconds);
543 * @brief Replace a set of items.
545 * A relayout will occur for the replacement items only.
547 * @param[in] replacementItems The replacements for a set of existing items.
548 * @param[in] durationSeconds How long the relayout takes in seconds.
549 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
551 void ReplaceItems(const ItemContainer& replacementItems, float durationSeconds);
554 * @brief Set the parent origin of the items.
556 * A relayout will occur for all the items if the parent origin is different than the current one.
558 * @param[in] parentOrigin New parent origin position vector
560 void SetItemsParentOrigin( const Vector3& parentOrigin );
563 * @brief Get the parent origin of the items.
566 * @return The current parent origin of the items
568 Vector3 GetItemsParentOrigin() const;
571 * @brief Set the anchor point of the items.
573 * A relayout will occur for all the items if the anchor point is different than the current one.
575 * @param[in] anchorPoint New anchor point position vector
577 void SetItemsAnchorPoint( const Vector3& anchorPoint );
580 * @brief Get the anchor point of the items.
583 * @return The current anchor point of the items
585 Vector3 GetItemsAnchorPoint() const;
588 * @brief Get the range of items that are currently in ItemView.
591 * @param[out] range The range of items.
593 void GetItemsRange(ItemRange& range);
598 * @brief Signal emitted when layout activation is finished.
600 * A callback of the following type may be connected:
602 * void YourCallbackName();
605 * @return The signal to connect to.
606 * @pre The Object has been initialized.
608 ItemView::LayoutActivatedSignalType& LayoutActivatedSignal();
610 public: // Not intended for application developers
614 * @brief Creates a handle using the Toolkit::Internal implementation.
617 * @param[in] implementation The Control implementation.
619 DALI_INTERNAL ItemView(Internal::ItemView& implementation);
622 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
625 * @param[in] internal A pointer to the internal CustomActor.
627 explicit DALI_INTERNAL ItemView( Dali::Internal::CustomActor* internal );
634 } // namespace Toolkit
638 #endif // __DALI_TOOLKIT_ITEM_VIEW_H__