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
72 * @brief 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 An enumeration of properties belonging to the ScrollView class.
92 // Event side properties
93 MINIMUM_SWIPE_SPEED = PROPERTY_START_INDEX, ///< Property, name "minimumSwipeSpeed", @see SetMinimumSwipeSpeed(), type float, @SINCE_1_1.18
94 MINIMUM_SWIPE_DISTANCE, ///< Property, name "minimumSwipeDistance", @see SetMinimumSwipeDistance(), type float, @SINCE_1_1.18
95 WHEEL_SCROLL_DISTANCE_STEP, ///< Property, name "wheelScrollDistanceStep", @see SetWheelScrollDistanceStep(), type float, @SINCE_1_1.18
96 SNAP_TO_ITEM_ENABLED, ///< Property, name "snapToItemEnabled", @see SetAnchoring(), type bool, @SINCE_1_1.18
97 REFRESH_INTERVAL, ///< Property, name "refreshInterval", @see SetRefreshInterval(), type float, @SINCE_1_1.18
99 // Animatable properties
100 LAYOUT_POSITION = ANIMATABLE_PROPERTY_START_INDEX, ///< Property, name "layoutPosition", type float @SINCE_1_0.0
101 SCROLL_SPEED, ///< Property, name "scrollSpeed", type float @SINCE_1_0.0
102 OVERSHOOT, ///< Property, name "overshoot", type float @SINCE_1_0.0
103 SCROLL_DIRECTION, ///< Property, name "scrollDirection", type Vector2 @SINCE_1_0.0
104 LAYOUT_ORIENTATION, ///< Property, name "layoutOrientation", type integer @SINCE_1_0.0
105 SCROLL_CONTENT_SIZE ///< Property, name "scrollContentSize", type float @SINCE_1_0.0
111 typedef Signal< void () > LayoutActivatedSignalType;
116 * @brief Create an uninitialized ItemView; this can be initialized with ItemView::New().
118 * Calling member functions with an uninitialized Dali::Object is not allowed.
124 * @brief Copy constructor.
126 * @param[in] itemView Handle to an object
128 ItemView( const ItemView& itemView );
131 * @brief Assignment operator.
133 * @param[in] itemView Handle to an object
134 * @return A reference to this
136 ItemView& operator=( const ItemView& itemView );
141 * This is non-virtual since derived Handle types must not contain data or virtual methods.
147 * @brief Create an initialized ItemView.
150 * @param[in] factory The factory which provides ItemView with items.
151 * @return A handle to a newly allocated Dali resource.
153 static ItemView New(ItemFactory& factory);
156 * @brief Downcast a handle to ItemView handle.
158 * If handle points to a ItemView the downcast produces valid
159 * handle. If not the returned handle is left uninitialized.
162 * @param[in] handle Handle to an object
163 * @return A handle to a ItemView or an uninitialized handle
165 static ItemView DownCast( BaseHandle handle );
168 * @brief Query the number of layouts.
171 * @return The number of layouts.
173 unsigned int GetLayoutCount() const;
176 * @brief Add a layout.
179 * @param[in] layout The layout.
181 void AddLayout(ItemLayout& layout);
184 * @brief Remove a layout.
187 * @param[in] layoutIndex The index of one of the ItemView layouts.
188 * @pre layoutIndex is less than GetLayoutCount().
190 void RemoveLayout(unsigned int layoutIndex);
193 * @brief Retrieve a layout.
196 * @param[in] layoutIndex The index of the layout to retrieve.
198 * @pre layoutIndex is less than GetLayoutCount().
200 ItemLayoutPtr GetLayout(unsigned int layoutIndex) const;
203 * @brief Retrieve the currently active layout, if any.
206 * @return The layout, or an uninitialized pointer if no layout is active.
208 ItemLayoutPtr GetActiveLayout() const;
211 * @brief Retrieve the current layout-position of an item in the ItemView.
214 * @param[in] itemId The item identifier.
215 * @return The current layout-position.
217 float GetCurrentLayoutPosition(ItemId itemId) const;
220 * @brief Activate one of the layouts; this will resize the ItemView
221 * & relayout actors within the ItemView.
223 * This is done by applying constraints from the new layout, and
224 * removing constraints from the previous layout.
227 * @param[in] layoutIndex The index of one of the ItemView layouts.
228 * @param[in] targetSize The target ItemView & layout size.
229 * @param[in] durationSeconds The time taken to relayout in seconds (zero for immediate).
230 * @pre layoutIndex is less than GetLayoutCount().
231 * @pre durationSeconds is greater or equal to zero.
233 void ActivateLayout(unsigned int layoutIndex, Vector3 targetSize, float durationSeconds);
236 * @brief Deactivate the current layout, if any.
238 * The constraints applied by the layout will be removed.
241 void DeactivateCurrentLayout();
244 * @brief Set the minimum swipe speed in pixels per second; A pan
245 * gesture must exceed this to trigger a swipe.
248 * @param[in] speed The minimum swipe speed
250 void SetMinimumSwipeSpeed(float speed);
253 * @brief Get the minimum swipe speed in pixels per second.
256 * @return The minimum swipe speed
258 float GetMinimumSwipeSpeed() const;
261 * @brief Set the minimum swipe distance in actor coordinates; A pan
262 * gesture must exceed this to trigger a swipe.
265 * @param[in] distance The minimum swipe distance.
267 void SetMinimumSwipeDistance(float distance);
270 * @brief Get the minimum swipe distance in actor coordinates.
273 * @return The minimum swipe distance
275 float GetMinimumSwipeDistance() const;
278 * @brief Set the step of scroll distance in actor coordinates for each wheel event received.
281 * @param[in] step The step of scroll distance(pixel).
283 void SetWheelScrollDistanceStep(float step);
286 * @brief Get the step of scroll distance in actor coordinates for each wheel event received.
289 * @return The step of scroll distance(pixel)
291 float GetWheelScrollDistanceStep() const;
294 * @brief Set whether to enable the animation for the layout to
295 * scroll to its anchor position after dragging or swiping.
297 * The anchor position is the position where all the items in the layout
298 * are aligned to their closest rounded layout positions in integer.
301 * @param[in] enabled Whether the anchor animation is enabled or not.
303 void SetAnchoring(bool enabled);
306 * @brief Get whether the anchor animation is enabled or not.
309 * @return Whether the anchor animation is enabled or not.
311 bool GetAnchoring() const;
314 * @brief Set the duration of the anchor animation in seconds.
316 * This is the time taken to reach the nearest anchor position after
317 * a drag or swipe gesture ends.
320 * @param[in] durationSeconds The duration of the anchor animation in seconds.
321 * @pre durationSeconds must be greater than zero.
323 void SetAnchoringDuration(float durationSeconds);
326 * @brief Get the duration of the anchor animation in seconds.
329 * @return The duration of the anchor animation
331 float GetAnchoringDuration() const;
334 * @brief Scroll the current layout to a particular item.
337 * @param[in] itemId The ID of an item in the layout.
338 * @param[in] durationSeconds How long the scrolling takes in seconds.
339 * @pre durationSeconds must be zero or greater; zero means the layout should scroll to the particular item instantly.
340 * If calling this with zero second of duration immediately after calling ActivateLayout, it might not work unless
341 * the duration of relayout animation for ActivateLayout is also set to be zero.
343 void ScrollToItem(ItemId itemId, float durationSeconds);
346 * @brief Set the interval between refreshes.
348 * When the layout-position of items is changed by this interval,
349 * new items are requested from ItemFactory.
352 * @param[in] intervalLayoutPositions The refresh interval in layout position.
354 void SetRefreshInterval(float intervalLayoutPositions);
357 * @brief Get the interval between refreshes in layout position.
360 * @return The refresh interval
362 float GetRefreshInterval() const;
365 * @brief Do a refresh of the item view.
371 * @brief Given the Item ID, this returns the accompanying actor.
374 * @param[in] itemId The Item ID of the actor required.
375 * @return The Actor corresponding to the Item ID.
377 Actor GetItem(ItemId itemId) const;
380 * @brief Returns the Item ID of the specified actor.
383 * @param[in] actor The actor whose Item ID is required.
384 * @return The Item ID of the item.
385 * @pre The actor should be an item of ItemView.
387 ItemId GetItemId(Actor actor) const;
390 * @brief Insert an item.
392 * A relayout will occur for the existing actors; for example if InsertItem(Item(2, ActorZ), 0) is called,
393 * the items with ID 2 or greater will be moved:
394 * Initial actors: After insert:
395 * ID 1 - ActorA ID 1 - ActorA
396 * ID 2 - ActorB ID 2 - ActorZ !
397 * ID 3 - ActorC ID 3 - ActorB
400 * @param[in] newItem The item to insert.
401 * @param[in] durationSeconds How long the relayout takes in seconds.
402 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
404 void InsertItem(Item newItem, float durationSeconds);
407 * @brief Insert a set of items; this is more efficient than calling InsertItem() repeatedly.
410 * @param[in] newItems The items to insert.
411 * @param[in] durationSeconds How long the relayout takes in seconds.
412 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
414 void InsertItems(const ItemContainer& newItems, float durationSeconds);
417 * @brief Removes an item with the given ID.
419 * A relayout will occur for the remaining actors; for example if RemoveItem(Item(2, ActorZ), 0) is called,
420 * the items with ID 3 or greater will be moved:
421 * Initial actors: After remove:
422 * ID 1 - ActorA ID 1 - ActorA
423 * ID 2 - ActorB ID 2 - ActorC (previously ID 3)
424 * ID 3 - ActorC ID 3 - ActorB (previously ID 4)
427 * @param[in] itemId The Item ID of the item to remove.
428 * @param[in] durationSeconds How long the relayout takes in seconds.
429 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
431 void RemoveItem(ItemId itemId, float durationSeconds);
434 * @brief Remove a set of items; this is more efficient than calling RemoveItem() repeatedly.
437 * @param[in] itemIds The IDs of the items to remove.
438 * @param[in] durationSeconds How long the relayout takes in seconds.
439 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
441 void RemoveItems(const ItemIdContainer& itemIds, float durationSeconds);
444 * @brief Replace an item.
446 * A relayout will occur for the replacement item only.
448 * @param[in] replacementItem The replacement for an existing item.
449 * @param[in] durationSeconds How long the relayout takes in seconds.
450 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
452 void ReplaceItem(Item replacementItem, float durationSeconds);
455 * @brief Replace a set of items.
457 * A relayout will occur for the replacement items only.
459 * @param[in] replacementItems The replacements for a set of existing items.
460 * @param[in] durationSeconds How long the relayout takes in seconds.
461 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
463 void ReplaceItems(const ItemContainer& replacementItems, float durationSeconds);
466 * @brief Set the parent origin of the items.
468 * A relayout will occur for all the items if the parent origin is different than the current one.
470 * @param[in] parentOrigin New parent origin position vector
472 void SetItemsParentOrigin( const Vector3& parentOrigin );
475 * @brief Get the parent origin of the items.
478 * @return The current parent origin of the items
480 Vector3 GetItemsParentOrigin() const;
483 * @brief Set the anchor point of the items.
485 * A relayout will occur for all the items if the anchor point is different than the current one.
487 * @param[in] anchorPoint New anchor point position vector
489 void SetItemsAnchorPoint( const Vector3& anchorPoint );
492 * @brief Get the anchor point of the items.
495 * @return The current anchor point of the items
497 Vector3 GetItemsAnchorPoint() const;
500 * @brief Get the range of items that are currently in ItemView.
503 * @param[out] range The range of items.
505 void GetItemsRange(ItemRange& range);
510 * @brief Signal emitted when layout activation is finished.
512 * A callback of the following type may be connected:
514 * void YourCallbackName();
517 * @return The signal to connect to.
518 * @pre The Object has been initialized.
520 ItemView::LayoutActivatedSignalType& LayoutActivatedSignal();
522 public: // Not intended for application developers
526 * @brief Creates a handle using the Toolkit::Internal implementation.
529 * @param[in] implementation The Control implementation.
531 DALI_INTERNAL ItemView(Internal::ItemView& implementation);
534 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
537 * @param[in] internal A pointer to the internal CustomActor.
539 explicit DALI_INTERNAL ItemView( Dali::Internal::CustomActor* internal );
546 } // namespace Toolkit
550 #endif // __DALI_TOOLKIT_ITEM_VIEW_H__