1 #ifndef __DALI_TOOLKIT_ITEM_LAYOUT_H__
2 #define __DALI_TOOLKIT_ITEM_LAYOUT_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.
22 #include <dali/public-api/animation/alpha-function.h>
23 #include <dali/public-api/object/property-key.h>
24 #include <dali/public-api/object/property-map.h>
27 #include <dali-toolkit/public-api/enums.h>
28 #include <dali-toolkit/public-api/controls/control.h>
36 * @addtogroup dali_toolkit_controls_item_view
42 typedef IntrusivePtr<ItemLayout> ItemLayoutPtr; ///< Pointer to a Dali::Toolkit::ItemLayout object @SINCE_1_0.0
45 * @brief A support class for managing ranges of items.
51 * @brief Creates a range of item identifiers.
54 * @param[in] beginItem The first item within the range
55 * @param[in] endItem The past-the-end item
57 ItemRange(unsigned int beginItem, unsigned int endItem)
64 * @brief Copy Constructor.
67 * @param[in] copy ItemRange we should copy from
69 ItemRange(const ItemRange& copy)
76 * @brief Assignment operator.
79 * @param[in] range The Range to assign from
80 * @return The updated range
82 ItemRange& operator=(const ItemRange& range)
93 * @brief Tests whether an item is within the range.
96 * @param[in] itemId The item identifier
97 * @return true if the item is within the range
99 bool Within(unsigned int itemId)
101 return itemId >= begin &&
106 * @brief Creates the intersection of two ranges.
109 * @param[in] second The second range
110 * @return The intersection
112 ItemRange Intersection(const ItemRange& second)
114 ItemRange intersection(0u, 0u);
116 // If the ranges intersect
117 if ( (begin < second.end && end > second.begin) ||
118 (second.begin < end && second.end > begin) )
120 intersection.begin = std::max(begin, second.begin);
121 intersection.end = std::min(end, second.end);
127 unsigned int begin; ///< The start of the range
128 unsigned int end; ///< The end of the range
132 * @brief An ItemLayout describes the constraints which are imposed on items in the layout.
134 * - Potentially visible items are represented by Actors, created for ItemView by the ItemFactory.
135 * - Constraints are applied after ItemView activates a layout.
137 * An ItemLayout also describes the direction of input gestures, used to scroll through the layout.
138 * Whilst scrolling, the layout provides a range of items that are within a layout-area (3D bounding volume).
141 class DALI_TOOLKIT_API ItemLayout : public RefObject
145 class Extension; ///< Forward declare future extension interface
148 * @brief Virtual destructor.
151 virtual ~ItemLayout();
154 * @brief Set the orientation of the layout.
157 * @param[in] orientation The orientation of the layout.
159 void SetOrientation(ControlOrientation::Type orientation);
162 * @brief Query the orientation of the layout.
165 * @return the orientation of the layout.
167 ControlOrientation::Type GetOrientation() const;
170 * @brief Apply the layout Properties.
172 * @param[in] properties The properties the layout.
174 void SetLayoutProperties(const Property::Map& properties);
177 * @brief Get the layout Properties.
179 * @return the property of the layout.
181 Property::Map GetLayoutProperties();
184 * @brief Retrieve the target size of an item in the layout.
186 * This will return the default size for the layout unless overridden by calling SetItemSize().
189 * @param[in] itemId The ID of an item in the layout.
190 * @param[in] layoutSize The layout size
191 * @param[out] itemSize The target size of an item.
192 * @note layout-position is not provided as a parameter, since applying size constraints is not recommended.
193 * Animating to target-sizes is preferable, since this allows controls to perform layouting without constraints.
195 void GetItemSize( unsigned int itemId, const Vector3& layoutSize, Vector3& itemSize ) const;
198 * @brief Overrides the default size for the layout.
201 * @param[in] itemSize The size of each item.
203 void SetItemSize( const Vector3& itemSize );
206 * @brief Query the minimum valid layout position; this is a negative value.
208 * When scrolling, the first item will move within the range 0 to GetMinimumLayoutPosition().
210 * @param[in] numberOfItems The current number of items in the layout.
211 * @param[in] layoutSize The size of the layout area.
212 * @return The minimum layout position.
214 virtual float GetMinimumLayoutPosition(unsigned int numberOfItems, Vector3 layoutSize) const = 0;
217 * @brief Query the closest anchor position for the given layout position.
219 * This anchor position is the position where all the items in the layout are aligned to
220 * their rounded layout positions in integer.
222 * @param[in] layoutPosition The layout position.
223 * @return The closest anchor position for the given layout position.
225 virtual float GetClosestAnchorPosition(float layoutPosition) const = 0;
228 * @brief Query the layout position for the first item in the layout to move to when the layout
229 * needs to scroll to a particular item.
232 * @param[in] itemId The ID of an item in the layout.
233 * @return The layout position for the first item in the layout to move to.
235 virtual float GetItemScrollToPosition(unsigned int itemId) const = 0;
238 * @brief Query the items within a given layout-area.
241 * @param[in] firstItemPosition The layout-position of the first item in the layout.
242 * @param[in] layoutSize The size of the layout area.
243 * @return The ID of the first & last visible item.
245 virtual ItemRange GetItemsWithinArea(float firstItemPosition, Vector3 layoutSize) const = 0;
248 * @brief Get the closest layout position to bring an item onto the screen.
250 * If the item is already fully on the screen this function will
251 * return the current layout position.
253 * This function is used by systems such as KeyboardFocusManager to
254 * bring the next focusable item into view and all layout
255 * implementations should provide their own version of this function
256 * to ensure proper functionality of internal toolkit systems.
259 * @param[in] itemID id of the item to bring within the viewable screen area
260 * @param[in] currentLayoutPosition the current layout position of the item view instance
261 * @param[in] layoutSize the current size of the item view instance
262 * @return The layout position
264 virtual float GetClosestOnScreenLayoutPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize);
267 * @brief Query the number of items that should be reserved, for scrolling purposes.
270 * @param[in] layoutSize The size of the layout area.
271 * @return The number of extra items. ItemView will populate itself with actors within the layout-area
272 * (see GetItemsWithinArea), plus this number of additional items on either-side.
274 virtual unsigned int GetReserveItemCount(Vector3 layoutSize) const = 0;
277 * @brief Retrieve the default size of an item in the layout.
280 * @param[in] itemId The ID of an item in the layout.
281 * @param[in] layoutSize The layout size
282 * @param[out] itemSize The target size of an item.
283 * @note layout-position is not provided as a parameter, since applying size constraints is not recommended.
284 * Animating to target-sizes is preferable, since this allows controls to perform layouting without constraints.
286 virtual void GetDefaultItemSize( unsigned int itemId, const Vector3& layoutSize, Vector3& itemSize ) const = 0;
289 * @brief Query the scroll direction of the layout.
291 * When an input gesture follows this direction, the layout-position of items will be increased.
292 * If the input gesture points in the opposite direction, then the layout-positions will decrease.
294 * @return The scroll direction in degrees.
296 virtual Degree GetScrollDirection() const = 0;
299 * @brief Query the scroll speed factor of the layout while dragging.
301 * This factor is used by the layout to customise its scroll speed while dragging.
302 * The factor will be multiplied with the scroll distance of how many pixels in actor coordinate,
303 * and the layout position of the actors in ItemView will be moved by this result.
304 * For example, when the speed factor is 0.01, if the scroll distance is 100 pixels, the layout
305 * position of actors will be moved by 1.
306 * Therefore, the bigger the factor is, the faster the scroll speed will be.
309 * @return The scroll speed factor of the layout.
311 virtual float GetScrollSpeedFactor() const = 0;
314 * @brief Query the maximum swipe speed in pixels per second.
316 * Swipe gestures will be clamped when exceeding this speed limit.
318 * @return speed The maximum swipe speed.
320 virtual float GetMaximumSwipeSpeed() const = 0;
323 * @brief Get the duration of the flick animation in second.
325 * This is the time taken to animate each
326 * item to its next layout position (e.g. from 1.0 to 2.0) when a flick animation is triggered
327 * by a swipe gesture.
329 * @return The duration of the flick animation.
331 virtual float GetItemFlickAnimationDuration() const = 0;
334 * @brief Gets the id of the next item for KeyboardFocusManager to focus on depending on the inputted item ID.
337 * @param[in] itemID The current focused item
338 * @param[in] maxItems The maximum number of items in the list
339 * @param[in] direction The directional key pressed on the keyboard
340 * @param[in] loopEnabled Whether the KeyboardFocusManager is set to wrap around between first and last item
341 * @return The next item ID.
343 virtual int GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled);
346 * @brief Query the flick speed factor of the layout while swipping.
348 * This factor is used by the layout to customise its scroll speed while swiping.
349 * The factor will be multiplied with the scroll distance of how many pixels in actor coordinate,
350 * and the layout position of the actors in ItemView will be moved by this result.
351 * For example, when the speed factor is 0.01, if the scroll distance is 100 pixels, the layout
352 * position of actors will be moved by 1.
353 * Therefore, the bigger the factor is, the faster the flick speed will be.
356 * @return The scroll speed factor of the layout.
358 virtual float GetFlickSpeedFactor() const;
361 * @brief Applies constraints defined by the layout to an actor.
363 * @param[in] actor The actor to constrain.
364 * @param[in] itemId The ID of the item represented by the actor.
365 * @param[in] layoutSize The current size of the item view instance.
366 * @param[in] itemViewActor The item view instance which requests the application of constraints.
368 virtual void ApplyConstraints( Actor& actor, const int itemId, const Vector3& layoutSize, const Actor& itemViewActor ) = 0;
371 * @brief Gets the position of a given item
374 * @param[in] itemID The id of the item we want to get its position
375 * @param[in] currentLayoutPosition The current layout position of the item view instance
376 * @param[in] layoutSize The current size of the item view instance
377 * @return The item position (x,y,z)
379 virtual Vector3 GetItemPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize) const = 0;
382 * @brief Retrieve the extension for this layout.
385 * @return The extension if available, NULL otherwise
387 virtual Extension* GetExtension()
395 * @brief Create a new ItemLayout; Only derived versions are instantiatable.
403 * @brief Don't allow copy constructor
406 ItemLayout( const ItemLayout& handle );
409 * @brief Don't allow copy operator
412 ItemLayout& operator=( const ItemLayout& handle );
423 } // namespace Toolkit
427 #endif // __DALI_TOOLKIT_ITEM_LAYOUT_H__