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() |
60 class DALI_IMPORT_API ItemView : public Scrollable
66 PROPERTY_START_INDEX = Toolkit::Scrollable::PROPERTY_END_INDEX + 1, ///< @since DALi 1.1.18
67 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, ///< Reserve property indices, @since DALi 1.1.18
69 ANIMATABLE_PROPERTY_START_INDEX = Toolkit::Scrollable::ANIMATABLE_PROPERTY_END_INDEX + 1,
70 ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_START_INDEX + 1000 ///< Reserve animatable property indices
74 * @brief An enumeration of properties belonging to the ScrollView class.
80 // Event side properties
81 MINIMUM_SWIPE_SPEED = PROPERTY_START_INDEX, ///< Property, name "minimumSwipeSpeed", @see SetMinimumSwipeSpeed(), type float, @since DALi 1.1.18
82 MINIMUM_SWIPE_DISTANCE, ///< Property, name "minimumSwipeDistance", @see SetMinimumSwipeDistance(), type float, @since DALi 1.1.18
83 WHEEL_SCROLL_DISTANCE_STEP, ///< Property, name "wheelScrollDistanceStep", @see SetWheelScrollDistanceStep(), type float, @since DALi 1.1.18
84 SNAP_TO_ITEM_ENABLED, ///< Property, name "snapToItemEnabled", @see SetAnchoring(), type bool, @since DALi 1.1.18
85 REFRESH_INTERVAL, ///< Property, name "refreshInterval", @see SetRefreshInterval(), type float, @since DALi 1.1.18
87 // Animatable properties
88 LAYOUT_POSITION = ANIMATABLE_PROPERTY_START_INDEX, ///< Property, name "layoutPosition", type float
89 SCROLL_SPEED, ///< Property, name "scrollSpeed", type float
90 OVERSHOOT, ///< Property, name "overshoot", type float
91 SCROLL_DIRECTION, ///< Property, name "scrollDirection", type Vector2
92 LAYOUT_ORIENTATION, ///< Property, name "layoutOrientation", type integer
93 SCROLL_CONTENT_SIZE ///< Property, name "scrollContentSize", type float
99 typedef Signal< void () > LayoutActivatedSignalType;
104 * @brief Create an uninitialized ItemView; this can be initialized with ItemView::New().
106 * Calling member functions with an uninitialized Dali::Object is not allowed.
111 * @brief Copy constructor.
113 ItemView( const ItemView& itemView );
116 * @brief Assignment operator.
118 ItemView& operator=( const ItemView& itemView );
123 * This is non-virtual since derived Handle types must not contain data or virtual methods.
128 * @brief Create an initialized ItemView.
130 * @param[in] factory The factory which provides ItemView with items.
131 * @return A handle to a newly allocated Dali resource.
133 static ItemView New(ItemFactory& factory);
136 * @brief Downcast an Object handle to ItemView.
138 * If handle points to a ItemView the downcast produces valid
139 * handle. If not the returned handle is left uninitialized.
141 * @param[in] handle Handle to an object
142 * @return handle to a ItemView or an uninitialized handle
144 static ItemView DownCast( BaseHandle handle );
147 * @brief Query the number of layouts.
149 * @return The number of layouts.
151 unsigned int GetLayoutCount() const;
154 * @brief Add a layout.
156 * @param[in] layout The layout.
158 void AddLayout(ItemLayout& layout);
161 * @brief Remove a layout.
163 * @pre layoutIndex is less than GetLayoutCount().
164 * @param[in] layoutIndex The index of one of the ItemView layouts.
166 void RemoveLayout(unsigned int layoutIndex);
169 * @brief Retrieve a layout.
171 * @pre layoutIndex is less than GetLayoutCount().
172 * @param[in] layoutIndex The index of the layout to retrieve.
175 ItemLayoutPtr GetLayout(unsigned int layoutIndex) const;
178 * @brief Retrieve the currently active layout, if any.
180 * @return The layout, or an uninitialized pointer if no layout is active.
182 ItemLayoutPtr GetActiveLayout() const;
185 * @brief Retrieve the current layout-position of an item in the ItemView.
187 * @param[in] itemId The item identifier.
188 * @return The current layout-position.
190 float GetCurrentLayoutPosition(ItemId itemId) const;
193 * @brief Activate one of the layouts; this will resize the ItemView
194 * & relayout actors within the ItemView.
196 * This is done by applying constraints from the new layout, and
197 * removing constraints from the previous layout.
199 * @pre layoutIndex is less than GetLayoutCount().
200 * @pre durationSeconds is greater or equal to zero.
201 * @param[in] layoutIndex The index of one of the ItemView layouts.
202 * @param[in] targetSize The target ItemView & layout size.
203 * @param[in] durationSeconds The time taken to relayout in seconds (zero for immediate).
205 void ActivateLayout(unsigned int layoutIndex, Vector3 targetSize, float durationSeconds);
208 * @brief Deactivate the current layout, if any.
210 * The constraints applied by the layout will be removed.
212 void DeactivateCurrentLayout();
215 * @brief Set the minimum swipe speed in pixels per second; A pan
216 * gesture must exceed this to trigger a swipe.
218 * @param[in] speed The minimum swipe speed
220 void SetMinimumSwipeSpeed(float speed);
223 * @brief Get the minimum swipe speed in pixels per second.
225 * @return The minimum swipe speed
227 float GetMinimumSwipeSpeed() const;
230 * @brief Set the minimum swipe distance in actor coordinates; A pan
231 * gesture must exceed this to trigger a swipe.
233 * @param[in] distance The minimum swipe distance.
235 void SetMinimumSwipeDistance(float distance);
238 * @brief Get the minimum swipe distance in actor coordinates.
240 * @return The minimum swipe distance
242 float GetMinimumSwipeDistance() const;
245 * @brief Set the step of scroll distance in actor coordinates for each wheel event received.
247 * @param[in] step The step of scroll distance(pixel).
249 void SetWheelScrollDistanceStep(float step);
252 * @brief Get the step of scroll distance in actor coordinates for each wheel event received.
254 * @return The step of scroll distance(pixel)
256 float GetWheelScrollDistanceStep() const;
259 * @brief Set whether to enable the animation for the layout to
260 * scroll to its anchor position after dragging or swiping.
262 * The anchor position is the position where all the items in the layout
263 * are aligned to their closest rounded layout positions in integer.
265 * @param[in] enabled Whether the anchor animation is enabled or not.
267 void SetAnchoring(bool enabled);
270 * @brief Get whether the anchor animation is enabled or not.
272 * @return Whether the anchor animation is enabled or not.
274 bool GetAnchoring() const;
277 * @brief Set the duration of the anchor animation in seconds.
279 * This is the time taken to reach the nearest anchor position after
280 * a drag or swipe gesture ends.
282 * @pre durationSeconds must be greater than zero.
283 * @param[in] durationSeconds The duration of the anchor animation in seconds.
285 void SetAnchoringDuration(float durationSeconds);
288 * @brief Get the duration of the anchor animation in seconds.
290 * @return The duration of the anchor animation
292 float GetAnchoringDuration() const;
295 * @brief Scroll the current layout to a particular item.
297 * @pre durationSeconds must be zero or greater; zero means the layout should scroll to the particular item instantly.
298 * If calling this with zero second of duration immediately after calling ActivateLayout, it might not work unless
299 * the duration of relayout animation for ActivateLayout is also set to be zero.
300 * @param[in] itemId The ID of an item in the layout.
301 * @param[in] durationSeconds How long the scrolling takes in seconds.
303 void ScrollToItem(ItemId itemId, float durationSeconds);
306 * @brief Set the interval between refreshes. When the layout-position of items is changed by this interval,
307 * new items are requested from ItemFactory.
309 * @param[in] intervalLayoutPositions The refresh interval in layout position.
311 void SetRefreshInterval(float intervalLayoutPositions);
314 * @brief Get the interval between refreshes in layout position.
316 * @return The refresh interval
318 float GetRefreshInterval() const;
321 * @brief Do a refresh of the item view.
326 * @brief Given the Item ID, this returns the accompanying actor.
328 * @param[in] itemId The Item ID of the actor required.
329 * @return The Actor corresponding to the Item ID.
331 Actor GetItem(ItemId itemId) const;
334 * @brief Returns the Item ID of the specified actor.
336 * @param[in] actor The actor whose Item ID is required.
337 * @return The Item ID of the item.
338 * @pre The actor should be an item of ItemView.
340 ItemId GetItemId(Actor actor) const;
343 * @brief Insert an item.
345 * A relayout will occur for the existing actors; for example if InsertItem(Item(2, ActorZ), 0) is called,
346 * the items with ID 2 or greater will be moved:
347 * Initial actors: After insert:
348 * ID 1 - ActorA ID 1 - ActorA
349 * ID 2 - ActorB ID 2 - ActorZ !
350 * ID 3 - ActorC ID 3 - ActorB
352 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
353 * @param[in] newItem The item to insert.
354 * @param[in] durationSeconds How long the relayout takes in seconds.
356 void InsertItem(Item newItem, float durationSeconds);
359 * @brief Insert a set of items; this is more efficient than calling InsertItem() repeatedly.
361 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
362 * @param[in] newItems The items to insert.
363 * @param[in] durationSeconds How long the relayout takes in seconds.
365 void InsertItems(const ItemContainer& newItems, float durationSeconds);
368 * @brief Removes an item with the given ID.
370 * A relayout will occur for the remaining actors; for example if RemoveItem(Item(2, ActorZ), 0) is called,
371 * the items with ID 3 or greater will be moved:
372 * Initial actors: After remove:
373 * ID 1 - ActorA ID 1 - ActorA
374 * ID 2 - ActorB ID 2 - ActorC (previously ID 3)
375 * ID 3 - ActorC ID 3 - ActorB (previously ID 4)
377 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
378 * @param[in] itemId The Item ID of the item to remove.
379 * @param[in] durationSeconds How long the relayout takes in seconds.
381 void RemoveItem(ItemId itemId, float durationSeconds);
384 * @brief Remove a set of items; this is more efficient than calling RemoveItem() repeatedly.
386 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
387 * @param[in] itemIds The IDs of the items to remove.
388 * @param[in] durationSeconds How long the relayout takes in seconds.
390 void RemoveItems(const ItemIdContainer& itemIds, float durationSeconds);
393 * @brief Replace an item.
395 * A relayout will occur for the replacement item only.
396 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
397 * @param[in] replacementItem The replacement for an existing item.
398 * @param[in] durationSeconds How long the relayout takes in seconds.
400 void ReplaceItem(Item replacementItem, float durationSeconds);
403 * @brief Replace a set of items.
405 * A relayout will occur for the replacement items only.
406 * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
407 * @param[in] replacementItems The replacements for a set of existing items.
408 * @param[in] durationSeconds How long the relayout takes in seconds.
410 void ReplaceItems(const ItemContainer& replacementItems, float durationSeconds);
413 * @brief Set the parent origin of the items
415 * A relayout will occur for all the items if the parent origin is different than the current one.
416 * @param[in] parentOrigin New parent origin position vector
418 void SetItemsParentOrigin( const Vector3& parentOrigin );
421 * @brief Get the parent origin of the items
423 * @return The current parent origin of the items
425 Vector3 GetItemsParentOrigin() const;
428 * @brief Set the anchor point of the items
430 * A relayout will occur for all the items if the anchor point is different than the current one.
431 * @param[in] anchorPoint New anchor point position vector
433 void SetItemsAnchorPoint( const Vector3& anchorPoint );
436 * @brief Get the anchor point of the items
438 * @return The current anchor point of the items
440 Vector3 GetItemsAnchorPoint() const;
443 * @brief Get the range of items that are currently in ItemView.
445 * @param[out] range The range of items.
447 void GetItemsRange(ItemRange& range);
452 * @brief Signal emitted when layout activation is finished.
454 * A callback of the following type may be connected:
456 * void YourCallbackName();
458 * @pre The Object has been initialized.
459 * @return The signal to connect to.
461 ItemView::LayoutActivatedSignalType& LayoutActivatedSignal();
463 public: // Not intended for application developers
466 * @brief Creates a handle using the Toolkit::Internal implementation.
468 * @param[in] implementation The Control implementation.
470 DALI_INTERNAL ItemView(Internal::ItemView& implementation);
473 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
475 * @param[in] internal A pointer to the internal CustomActor.
477 explicit DALI_INTERNAL ItemView( Dali::Internal::CustomActor* internal );
483 } // namespace Toolkit
487 #endif // __DALI_TOOLKIT_ITEM_VIEW_H__