1 #ifndef __DALI_TOOLKIT_ITEM_LAYOUT_H__
2 #define __DALI_TOOLKIT_ITEM_LAYOUT_H__
5 * Copyright (c) 2014 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 * @addtogroup CAPI_DALI_TOOLKIT_ITEM_VIEW_MODULE
27 #include <dali/dali.h>
28 #include <dali-toolkit/public-api/enums.h>
29 #include <dali-toolkit/public-api/controls/control.h>
31 namespace Dali DALI_IMPORT_API
39 typedef IntrusivePtr<ItemLayout> ItemLayoutPtr; ///< Pointer to a Dali::Toolkit::ItemLayout object
41 typedef std::vector<ItemLayoutPtr> ItemLayoutContainer; ///< Container of Dali::Toolkit::ItemLayout objects
42 typedef ItemLayoutContainer::iterator ItemLayoutIter; ///< Iterator for Dali::Toolkit::ItemLayoutContainer
43 typedef ItemLayoutContainer::const_iterator ItemLayoutConstIter; ///< Const Iterator for Dali::Toolkit::ItemLayoutContainer
47 * @brief A support class for managing ranges of items.
52 * @brief Create 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.
66 * @param[in] copy ItemRange we should copy from.
68 ItemRange(const ItemRange& copy)
75 * @brief Assignment operator.
77 * @param[in] range The Range to assign from.
78 * @return The updated range.
80 ItemRange& operator=(const ItemRange& range)
88 * @brief Test whether an item is within the range.
90 * @param[in] itemId The item identifier.
91 * @return True if the item is within the range.
93 bool Within(unsigned int itemId)
95 return itemId >= begin &&
100 * @brief Create the intersection of two ranges.
102 * @param[in] second The second range.
103 * @return The intersection.
105 ItemRange Intersection(const ItemRange& second)
107 ItemRange intersection(0u, 0u);
109 // If the ranges intersect
110 if ( (begin < second.end && end > second.begin) ||
111 (second.begin < end && second.end > begin) )
113 intersection.begin = std::max(begin, second.begin);
114 intersection.end = std::min(end, second.end);
120 unsigned int begin; ///< The start of the range
121 unsigned int end; ///< The end of the range
125 * @brief An ItemLayout describes the constraints which are imposed on items in the layout.
127 * - Potentially visible items are represented by Actors, created for ItemView by the ItemFactory.
128 * - Constraints are applied after ItemView activates a layout.
130 * An ItemLayout also describes the direction of input gestures, used to scroll through the layout.
131 * Whilst scrolling, the layout provides a range of items that are within a layout-area (3D bounding volume).
133 class ItemLayout : public RefObject
137 /// @brief Function signature of a boolean constraint
138 typedef boost::function<bool (const bool& current, const float& layoutPosition, const float& scrollSpeed, const Vector3& layoutSize)> BoolFunction;
140 /// @brief Function signature of a Vector3 constraint
141 typedef boost::function<Vector3 (const Vector3& current, const float& layoutPosition, const float& scrollSpeed, const Vector3& layoutSize)> Vector3Function;
143 /// @brief Function signature of a Vector4 constraint
144 typedef boost::function<Vector4 (const Vector4& current, const float& layoutPosition, const float& scrollSpeed, const Vector3& layoutSize)> Vector4Function;
146 /// @brief Function signature of a Quaternion constraint
147 typedef boost::function<Quaternion (const Quaternion& current, const float& layoutPosition, const float& scrollSpeed, const Vector3& layoutSize)> QuaternionFunction;
150 * @brief Virtual destructor.
152 virtual ~ItemLayout();
155 * @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.
164 * @return the orientation of the layout.
166 ControlOrientation::Type GetOrientation() const;
169 * @brief Query the minimum valid layout position; this is a negative value.
171 * When scrolling, the first item will move within the range 0 to GetMinimumLayoutPosition().
172 * @param[in] numberOfItems The current number of items in the layout.
173 * @param[in] layoutSize The size of the layout area.
174 * @return The minimum layout position.
176 virtual float GetMinimumLayoutPosition(unsigned int numberOfItems, Vector3 layoutSize) const = 0;
179 * @brief Query the closest anchor position for the given layout position.
181 * This anchor position is the position where all the items in the layout are aligned to
182 * their rounded layout positions in integer.
183 * @param[in] layoutPosition The layout position.
184 * @return The closest anchor position for the given layout position.
186 virtual float GetClosestAnchorPosition(float layoutPosition) const = 0;
189 * @brief Query the layout position for the first item in the layout to move to when the layout
190 * needs to scroll to a particular item.
192 * @param[in] itemId The ID of an item in the layout.
193 * @return The layout position for the first item in the layout to move to.
195 virtual float GetItemScrollToPosition(unsigned int itemId) const = 0;
198 * @brief Query the items within a given layout-area.
200 * @param[in] firstItemPosition The layout-position of the first item in the layout.
201 * @param[in] layoutSize The size of the layout area.
202 * @return The ID of the first & last visible item.
204 virtual ItemRange GetItemsWithinArea(float firstItemPosition, Vector3 layoutSize) const = 0;
207 * @brief Get the closest layout position to bring an item onto the screen.
209 * If the item is already fully on the screen this function will
210 * return the current layout position.
212 * This function is used by systems such as KeyboardFocusManager to
213 * bring the next focusable item into view and all layout
214 * implementations should provide their own version of this function
215 * to ensure proper functionality of internal toolkit systems.
217 * @param[in] itemID id of the item to bring within the viewable screen area
218 * @param[in] currentLayoutPosition the current layout position of the item view instance
219 * @param[in] layoutSize the current size of the item view instance
220 * @return The layout position
222 virtual float GetClosestOnScreenLayoutPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize);
225 * @brief Query the number of items that should be reserved, for scrolling purposes.
227 * @param[in] layoutSize The size of the layout area.
228 * @return The number of extra items. ItemView will populate itself with actors within the layout-area
229 * (see GetItemsWithinArea), plus this number of additional items on either-side.
231 virtual unsigned int GetReserveItemCount(Vector3 layoutSize) const = 0;
234 * @brief Retrieve the target size of an item in the layout.
236 * @note layout-position is not provided as a parameter, since applying size constraints is not recommended.
237 * Animating to target-sizes is preferable, since this allows controls to perform layouting without constraints.
238 * @param[in] itemId The ID of an item in the layout.
239 * @param[in] layoutSize The layout size
240 * @param[out] itemSize The target size of an item, or an uninitialized value.
241 * @return Whether the item size is available or not
243 virtual bool GetItemSize(unsigned int itemId, Vector3 layoutSize, Vector3& itemSize) const = 0;
246 * @brief Retrieve the resize animation in the layout.
248 * @note This allows the layout to provide its own resize animation.
249 * @param[in] animation The resize animation, not owned by the layout
250 * @param[in] actor The actor to animate
251 * @param [in] size The target size.
252 * @param [in] durationSeconds The duration of the resizing.
254 virtual void GetResizeAnimation(Animation& animation, Actor actor, Vector3 size, float durationSeconds) const = 0;
257 * @brief Retrieve the position constraint function of an item in the layout.
259 * The constraint will be applied when the item is created or the layout is activated.
260 * @param[in] itemId The ID of an item in the layout.
261 * @param[out] constraint The position constraint function of an item, or an uninitialized function pointer.
262 * @return Whether the position constraint function of an item is available or not
264 virtual bool GetPositionConstraint(unsigned int itemId, Vector3Function& constraint) const = 0;
267 * @brief Retrieve the rotation constraint function of an item in the layout.
269 * The constraint will be applied when the item is created or the layout is activated.
270 * @param[in] itemId The ID of an item in the layout.
271 * @param[out] constraint The rotation constraint function of an item, or an uninitialized function pointer.
272 * @return Whether the rotation constraint function of an item is available or not
274 virtual bool GetRotationConstraint(unsigned int itemId, QuaternionFunction& constraint) const = 0;
277 * @brief Retrieve the scale constraint function of an item in the layout.
279 * The constraint will be applied when the item is created or the layout is activated.
280 * @param[in] itemId The ID of an item in the layout.
281 * @param[out] constraint The scale constraint function of an item, or an uninitialized function pointer.
282 * @return Whether the scale constraint function of an item is available or not
284 virtual bool GetScaleConstraint(unsigned int itemId, Vector3Function& constraint) const = 0;
287 * @brief Retrieve the color constraint function of an item in the layout.
289 * The constraint will be applied when the item is created or the layout is activated.
290 * @param[in] itemId The ID of an item in the layout.
291 * @param[out] constraint The color constraint function of an item, or an uninitialized function pointer.
292 * @return Whether the color constraint function of an item is available or not
294 virtual bool GetColorConstraint(unsigned int itemId, Vector4Function& constraint) const = 0;
297 * @brief Retrieve the visibility constraint function of an item in the layout.
299 * The constraint will be applied when the item is created or the layout is activated.
300 * @param[in] itemId The ID of an item in the layout.
301 * @param[out] constraint The visibility constraint function of an item, or an uninitialized function pointer.
302 * @return Whether the visibility constraint function of an item is available or not
304 virtual bool GetVisibilityConstraint(unsigned int itemId, BoolFunction& constraint) const = 0;
307 * @brief Query the scroll direction of the layout.
309 * When an input gesture follows this direction, the layout-position of items will be increased.
310 * If the input gesture points in the opposite direction, then the layout-positions will decrease.
311 * @return The scroll direction in degrees.
313 virtual Degree GetScrollDirection() const = 0;
316 * @brief Tells scroll components how to interpolate our logical scroll position as a screen x/y direction.
318 * Application developer wants to use -ve y, +ve x as up direction and +ve y, -ve x as down direction scroll values in a
319 * vertical scroll type effect (SpiralLayout). This means that scroll bar/overshoot indicator should be affected by y-axis.
320 * Returning (0.0f, 0.0f) for x and (0.0f, -1.0f) for y tells us that we need to use the y scroll value to move the scroll bar
321 * along y axis with y scroll of 0 starting at bottom (due to -1.0f on y), a value of (0.0f, 1.0f) on x axis mask would mean using y scroll value to move scroll bar along x axis
323 * This function is used by numerous objects such as scroll indicators and scroll overshoot indicators and all
324 * layout implementations should provide their own version of this function to ensure proper functionality of
325 * internal toolkit systems.
327 * @param[out] scrollHint Vector2 describing how x and y scroll values should be used for x-axis scrolling
329 virtual void GetXAxisScrollHint(Vector2& scrollHint) const;
332 * @brief Tells scroll components how to interpolate our logical scroll position as a screen x/y direction.
334 * Application developer wants to use -ve y, +ve x as up direction and +ve y, -ve x as down direction scroll values in a
335 * vertical scroll type effect (SpiralLayout). This means that scroll bar/overshoot indicator should be affected by y-axis.
336 * Returning (0.0f, 0.0f) for x and (0.0f, -1.0f) for y tells us that we need to use the y scroll value to move the scroll bar
337 * along y axis with y scroll of 0 starting at bottom (due to -1.0f on y), a value of (0.0f, 1.0f) on x axis mask would mean using y scroll value to move scroll bar along x axis
339 * This function is used by numerous objects such as scroll indicators and scroll overshoot indicators and all
340 * layout implementations should provide their own version of this function to ensure proper functionality of
341 * internal toolkit systems.
343 * @param[out] scrollHint Vector2 describing how x and y scroll values should be used for y-axis scrolling
345 virtual void GetYAxisScrollHint(Vector2& scrollHint) const;
348 * @brief Query the scroll speed factor of the layout while dragging.
350 * This factor is used by the layout to customise its scroll speed while dragging.
351 * The factor will be multiplied with the scroll distance of how many pixels in actor coordinate,
352 * and the layout position of the actors in ItemView will be moved by this result.
353 * For example, when the speed factor is 0.01, if the scroll distance is 100 pixels, the layout
354 * position of actors will be moved by 1.
355 * Therefore, the bigger the factor is, the faster the scroll speed will be.
357 * @return The scroll speed factor of the layout.
359 virtual float GetScrollSpeedFactor() const = 0;
362 * @brief Query the maximum swipe speed in pixels per second.
364 * Swipe gestures will be clamped when exceeding this speed limit.
365 * @return speed The maximum swipe speed.
367 virtual float GetMaximumSwipeSpeed() const = 0;
370 * @brief Get the duration of the flick animation in second.
372 * This is the time taken to animate each
373 * item to its next layout position (e.g. from 1.0 to 2.0) when a flick animation is triggered
374 * by a swipe gesture.
375 * @return The duration of the flick animation.
377 virtual float GetItemFlickAnimationDuration() const = 0;
380 * @brief Gets the id of the next item for KeyboardFocusManager to focus on depending on the inputted item ID.
382 * @param[in] itemID The current focused item
383 * @param[in] maxItems The maximum number of items in the list
384 * @param[in] direction The directional key pressed on the keyboard
385 * @param[in] loopEnabled Whether the KeyboardFocusManager is set to wrap around between first and last item
386 * @return The next item ID.
388 virtual int GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
391 * @brief Query the flick speed factor of the layout while swipping.
393 * This factor is used by the layout to customise its scroll speed while swiping.
394 * The factor will be multiplied with the scroll distance of how many pixels in actor coordinate,
395 * and the layout position of the actors in ItemView will be moved by this result.
396 * For example, when the speed factor is 0.01, if the scroll distance is 100 pixels, the layout
397 * position of actors will be moved by 1.
398 * Therefore, the bigger the factor is, the faster the flick speed will be.
400 * @return The scroll speed factor of the layout.
402 virtual float GetFlickSpeedFactor() const;
405 * @brief Applies constraints defined by the layout to an actor.
407 * @param[in] actor The actor to constrain.
408 * @param[in] itemId The ID of the item represented by the actor.
409 * @param[in] durationSeconds The time taken to fully constrain the actors.
410 * @param[in] scrollPositionObject The object which provides the layout position property.
411 * @param[in] itemViewActor The item view instance which requests the application of constraints.
413 virtual void ApplyConstraints( Actor& actor, const int itemId, const float durationSeconds, Constrainable scrollPositionObject, const Actor& itemViewActor );
416 * @brief Gets the position of a given item
418 * @param[in] itemID id of the item we want to get its position
419 * @param[in] currentLayoutPosition the current layout position of the item view instance
420 * @param[in] layoutSize the current size of the item view instance
421 * @return The item position (x,y,z)
423 virtual Vector3 GetItemPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize) const;
426 * @brief Set the alpha function used when applying constraints
428 * @param[in] func The alpha function to use.
430 void SetAlphaFunction(AlphaFunction func);
433 * @brief Retrieve the alpha function used when applying constraints
435 * @return The alpha function.
437 AlphaFunction GetAlphaFunction() const;
442 * @brief Create a new ItemLayout; Only derived versions are instantiatable.
448 ControlOrientation::Type mOrientation; ///< the orientation of the layout.
449 AlphaFunction mAlphaFunction; ///<Alpha function to be applied when removing/adding constraints
452 } // namespace Toolkit
459 #endif // __DALI_TOOLKIT_ITEM_LAYOUT_H__