1 #ifndef __DALI_TOOLKIT_ITEM_LAYOUT_H__
2 #define __DALI_TOOLKIT_ITEM_LAYOUT_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.
22 #include <dali/public-api/animation/alpha-function.h>
25 #include <dali-toolkit/public-api/enums.h>
26 #include <dali-toolkit/public-api/controls/control.h>
36 typedef IntrusivePtr<ItemLayout> ItemLayoutPtr; ///< Pointer to a Dali::Toolkit::ItemLayout object
39 * @brief A support class for managing ranges of items.
44 * @brief Create a range of item identifiers.
46 * @param[in] beginItem The first item within the range.
47 * @param[in] endItem The past-the-end item.
49 ItemRange(unsigned int beginItem, unsigned int endItem)
56 * @brief Copy Constructor.
58 * @param[in] copy ItemRange we should copy from.
60 ItemRange(const ItemRange& copy)
67 * @brief Assignment operator.
69 * @param[in] range The Range to assign from.
70 * @return The updated range.
72 ItemRange& operator=(const ItemRange& range)
80 * @brief Test whether an item is within the range.
82 * @param[in] itemId The item identifier.
83 * @return True if the item is within the range.
85 bool Within(unsigned int itemId)
87 return itemId >= begin &&
92 * @brief Create the intersection of two ranges.
94 * @param[in] second The second range.
95 * @return The intersection.
97 ItemRange Intersection(const ItemRange& second)
99 ItemRange intersection(0u, 0u);
101 // If the ranges intersect
102 if ( (begin < second.end && end > second.begin) ||
103 (second.begin < end && second.end > begin) )
105 intersection.begin = std::max(begin, second.begin);
106 intersection.end = std::min(end, second.end);
112 unsigned int begin; ///< The start of the range
113 unsigned int end; ///< The end of the range
117 * @brief An ItemLayout describes the constraints which are imposed on items in the layout.
119 * - Potentially visible items are represented by Actors, created for ItemView by the ItemFactory.
120 * - Constraints are applied after ItemView activates a layout.
122 * An ItemLayout also describes the direction of input gestures, used to scroll through the layout.
123 * Whilst scrolling, the layout provides a range of items that are within a layout-area (3D bounding volume).
125 class DALI_IMPORT_API ItemLayout : public RefObject
129 class Extension; ///< Forward declare future extension interface
132 * @brief Virtual destructor.
134 DALI_IMPORT_API virtual ~ItemLayout();
137 * @brief Set the orientation of the layout.
139 * @param[in] orientation The orientation of the layout.
141 DALI_IMPORT_API void SetOrientation(ControlOrientation::Type orientation);
144 * @brief Query the orientation of the layout.
146 * @return the orientation of the layout.
148 DALI_IMPORT_API ControlOrientation::Type GetOrientation() const;
151 * @brief Retrieve the target size of an item in the layout.
153 * This will return the default size for the layout unless overridden by calling SetItemSize().
155 * @note layout-position is not provided as a parameter, since applying size constraints is not recommended.
156 * Animating to target-sizes is preferable, since this allows controls to perform layouting without constraints.
157 * @param[in] itemId The ID of an item in the layout.
158 * @param[in] layoutSize The layout size
159 * @param[out] itemSize The target size of an item.
161 DALI_IMPORT_API void GetItemSize( unsigned int itemId, const Vector3& layoutSize, Vector3& itemSize ) const;
164 * @brief Overrides the default size for the layout.
166 * @param[in] itemSize The size of each item.
168 DALI_IMPORT_API void SetItemSize( const Vector3& itemSize );
171 * @brief Query the minimum valid layout position; this is a negative value.
173 * When scrolling, the first item will move within the range 0 to GetMinimumLayoutPosition().
174 * @param[in] numberOfItems The current number of items in the layout.
175 * @param[in] layoutSize The size of the layout area.
176 * @return The minimum layout position.
178 virtual float GetMinimumLayoutPosition(unsigned int numberOfItems, Vector3 layoutSize) const = 0;
181 * @brief Query the closest anchor position for the given layout position.
183 * This anchor position is the position where all the items in the layout are aligned to
184 * their rounded layout positions in integer.
185 * @param[in] layoutPosition The layout position.
186 * @return The closest anchor position for the given layout position.
188 virtual float GetClosestAnchorPosition(float layoutPosition) const = 0;
191 * @brief Query the layout position for the first item in the layout to move to when the layout
192 * needs to scroll to a particular item.
194 * @param[in] itemId The ID of an item in the layout.
195 * @return The layout position for the first item in the layout to move to.
197 virtual float GetItemScrollToPosition(unsigned int itemId) const = 0;
200 * @brief Query the items within a given layout-area.
202 * @param[in] firstItemPosition The layout-position of the first item in the layout.
203 * @param[in] layoutSize The size of the layout area.
204 * @return The ID of the first & last visible item.
206 virtual ItemRange GetItemsWithinArea(float firstItemPosition, Vector3 layoutSize) const = 0;
209 * @brief Get the closest layout position to bring an item onto the screen.
211 * If the item is already fully on the screen this function will
212 * return the current layout position.
214 * This function is used by systems such as KeyboardFocusManager to
215 * bring the next focusable item into view and all layout
216 * implementations should provide their own version of this function
217 * to ensure proper functionality of internal toolkit systems.
219 * @param[in] itemID id of the item to bring within the viewable screen area
220 * @param[in] currentLayoutPosition the current layout position of the item view instance
221 * @param[in] layoutSize the current size of the item view instance
222 * @return The layout position
224 DALI_IMPORT_API virtual float GetClosestOnScreenLayoutPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize);
227 * @brief Query the number of items that should be reserved, for scrolling purposes.
229 * @param[in] layoutSize The size of the layout area.
230 * @return The number of extra items. ItemView will populate itself with actors within the layout-area
231 * (see GetItemsWithinArea), plus this number of additional items on either-side.
233 virtual unsigned int GetReserveItemCount(Vector3 layoutSize) const = 0;
236 * @brief Retrieve the default size of an item in the layout.
238 * @note layout-position is not provided as a parameter, since applying size constraints is not recommended.
239 * Animating to target-sizes is preferable, since this allows controls to perform layouting without constraints.
240 * @param[in] itemId The ID of an item in the layout.
241 * @param[in] layoutSize The layout size
242 * @param[out] itemSize The target size of an item.
244 virtual void GetDefaultItemSize( unsigned int itemId, const Vector3& layoutSize, Vector3& itemSize ) const = 0;
247 * @brief Retrieve the resize animation in the layout.
249 * @note This allows the layout to provide its own resize animation.
250 * @param[in] animation The resize animation, not owned by the layout
251 * @param[in] actor The actor to animate
252 * @param [in] size The target size.
253 * @param [in] durationSeconds The duration of the resizing.
255 virtual void GetResizeAnimation(Animation& animation, Actor actor, Vector3 size, float durationSeconds) const = 0;
258 * @brief Query the scroll direction of the layout.
260 * When an input gesture follows this direction, the layout-position of items will be increased.
261 * If the input gesture points in the opposite direction, then the layout-positions will decrease.
262 * @return The scroll direction in degrees.
264 virtual Degree GetScrollDirection() const = 0;
267 * @brief Query the scroll speed factor of the layout while dragging.
269 * This factor is used by the layout to customise its scroll speed while dragging.
270 * The factor will be multiplied with the scroll distance of how many pixels in actor coordinate,
271 * and the layout position of the actors in ItemView will be moved by this result.
272 * For example, when the speed factor is 0.01, if the scroll distance is 100 pixels, the layout
273 * position of actors will be moved by 1.
274 * Therefore, the bigger the factor is, the faster the scroll speed will be.
276 * @return The scroll speed factor of the layout.
278 virtual float GetScrollSpeedFactor() const = 0;
281 * @brief Query the maximum swipe speed in pixels per second.
283 * Swipe gestures will be clamped when exceeding this speed limit.
284 * @return speed The maximum swipe speed.
286 virtual float GetMaximumSwipeSpeed() const = 0;
289 * @brief Get the duration of the flick animation in second.
291 * This is the time taken to animate each
292 * item to its next layout position (e.g. from 1.0 to 2.0) when a flick animation is triggered
293 * by a swipe gesture.
294 * @return The duration of the flick animation.
296 virtual float GetItemFlickAnimationDuration() const = 0;
299 * @brief Gets the id of the next item for KeyboardFocusManager to focus on depending on the inputted item ID.
301 * @param[in] itemID The current focused item
302 * @param[in] maxItems The maximum number of items in the list
303 * @param[in] direction The directional key pressed on the keyboard
304 * @param[in] loopEnabled Whether the KeyboardFocusManager is set to wrap around between first and last item
305 * @return The next item ID.
307 DALI_IMPORT_API virtual int GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
310 * @brief Query the flick speed factor of the layout while swipping.
312 * This factor is used by the layout to customise its scroll speed while swiping.
313 * The factor will be multiplied with the scroll distance of how many pixels in actor coordinate,
314 * and the layout position of the actors in ItemView will be moved by this result.
315 * For example, when the speed factor is 0.01, if the scroll distance is 100 pixels, the layout
316 * position of actors will be moved by 1.
317 * Therefore, the bigger the factor is, the faster the flick speed will be.
319 * @return The scroll speed factor of the layout.
321 DALI_IMPORT_API virtual float GetFlickSpeedFactor() const;
324 * @brief Applies constraints defined by the layout to an actor.
326 * @param[in] actor The actor to constrain.
327 * @param[in] itemId The ID of the item represented by the actor.
328 * @param[in] layoutSize the current size of the item view instance.
329 * @param[in] itemViewActor The item view instance which requests the application of constraints.
331 DALI_IMPORT_API virtual void ApplyConstraints( Actor& actor, const int itemId, const Vector3& layoutSize, const Actor& itemViewActor ) = 0;
334 * @brief Gets the position of a given item
336 * @param[in] itemID id of the item we want to get its position
337 * @param[in] currentLayoutPosition the current layout position of the item view instance
338 * @param[in] layoutSize the current size of the item view instance
339 * @return The item position (x,y,z)
341 DALI_IMPORT_API virtual Vector3 GetItemPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize) const = 0;
344 * Retrieve the extension for this layout.
346 * @return The extension if available, NULL otherwise
348 virtual Extension* GetExtension()
356 * @brief Create a new ItemLayout; Only derived versions are instantiatable.
358 DALI_IMPORT_API ItemLayout();
366 } // namespace Toolkit
370 #endif // __DALI_TOOLKIT_ITEM_LAYOUT_H__