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 Flora License, Version 1.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://floralicense.org/license/
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.
21 * @addtogroup CAPI_DALI_FRAMEWORK
26 #include <dali/dali.h>
27 #include <dali-toolkit/public-api/enums.h>
28 #include <dali-toolkit/public-api/controls/control.h>
30 namespace Dali DALI_IMPORT_API
38 typedef IntrusivePtr<ItemLayout> ItemLayoutPtr;
40 typedef std::vector<ItemLayoutPtr> ItemLayoutContainer;
41 typedef ItemLayoutContainer::iterator ItemLayoutIter;
42 typedef ItemLayoutContainer::const_iterator ItemLayoutConstIter;
47 * Create a range of item identifiers.
48 * @param[in] beginItem The first item within the range.
49 * @param[in] endItem The past-the-end item.
51 ItemRange(unsigned int beginItem, unsigned int endItem)
59 * @param[in] copy ItemRange we should copy from.
61 ItemRange(const ItemRange& copy)
68 * Assignment operator.
69 * @param[in] range The Range to assign from.
70 * @return The updated range.
72 ItemRange& operator=(const ItemRange& range)
80 * Test whether an item is within the range.
81 * @param[in] itemId The item identifier.
82 * @return True if the item is within the range.
84 bool Within(unsigned int itemId)
86 return itemId >= begin &&
91 * Create the intersection of two ranges.
92 * @param[in] second The second range.
93 * @return The intersection.
95 ItemRange Intersection(const ItemRange& second)
97 ItemRange intersection(0u, 0u);
99 // If the ranges intersect
100 if ( (begin < second.end && end > second.begin) ||
101 (second.begin < end && second.end > begin) )
103 intersection.begin = std::max(begin, second.begin);
104 intersection.end = std::min(end, second.end);
115 * An ItemLayout describes the constraints, which are imposed on items in the layout.
116 * - Potentially visible items are represented by Actors, created for ItemView by the ItemFactory.
117 * - Constraints are applied after ItemView activates a layout.
119 * An ItemLayout also describes the direction of input gestures, used to scroll through the layout.
120 * Whilst scrolling, the layout provides a range of items that are within a layout-area (3D bounding volume).
122 class ItemLayout : public RefObject
126 typedef boost::function<bool (const bool& current, const float& layoutPosition, const float& scrollSpeed, const Vector3& layoutSize)> BoolFunction;
127 typedef boost::function<Vector3 (const Vector3& current, const float& layoutPosition, const float& scrollSpeed, const Vector3& layoutSize)> Vector3Function;
128 typedef boost::function<Vector4 (const Vector4& current, const float& layoutPosition, const float& scrollSpeed, const Vector3& layoutSize)> Vector4Function;
129 typedef boost::function<Quaternion (const Quaternion& current, const float& layoutPosition, const float& scrollSpeed, const Vector3& layoutSize)> QuaternionFunction;
132 * Virtual destructor.
134 virtual ~ItemLayout();
137 * Set the orientation of the layout.
138 * @param[in] orientation The orientation of the layout.
140 void SetOrientation(ControlOrientation::Type orientation);
143 * Query the orientation of the layout.
144 * @return the orientation of the layout.
146 ControlOrientation::Type GetOrientation() const;
149 * Query the minimum valid layout position; this is a negative value.
150 * When scrolling, the first item will move within the range 0 to GetMinimumLayoutPosition().
151 * @param[in] numberOfItems The current number of items in the layout.
152 * @param[in] layoutSize The size of the layout area.
153 * @return The minimum layout position.
155 virtual float GetMinimumLayoutPosition(unsigned int numberOfItems, Vector3 layoutSize) const = 0;
158 * Query the closest anchor position for the given layout position.
159 * This anchor position is the position where all the items in the layout are aligned to
160 * their rounded layout positions in integer.
161 * @param[in] layoutPosition The layout position.
162 * @return The closest anchor position for the given layout position.
164 virtual float GetClosestAnchorPosition(float layoutPosition) const = 0;
167 * Query the layout position for the first item in the layout to move to when the layout
168 * needs to scroll to a particular item.
169 * @param[in] itemId The ID of an item in the layout.
170 * @return The layout position for the first item in the layout to move to.
172 virtual float GetItemScrollToPosition(unsigned int itemId) const = 0;
175 * Query the items within a given layout-area.
176 * @param[in] firstItemPosition The layout-position of the first item in the layout.
177 * @param[in] layoutSize The size of the layout area.
178 * @return The ID of the first & last visible item.
180 virtual ItemRange GetItemsWithinArea(float firstItemPosition, Vector3 layoutSize) const = 0;
183 * Get the closest layout position to bring an item onto the screen. If the item is already fully on the screen
184 * this function will return the current layout position.
186 * This function is used by systems such as KeyboardFocusManager to bring the next focusable item into view and all
187 * layout implementations should provide their own version of this function to ensure proper functionality of
188 * internal toolkit systems.
190 * @param[in] itemID id of the item to bring within the viewable screen area
191 * @param[in] currentLayoutPosition the current layout position of the item view instance
192 * @param[in] layoutSize the current size of the item view instance
194 virtual float GetClosestOnScreenLayoutPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize);
197 * Query the number of items that should be reserved, for scrolling purposes.
198 * @param[in] layoutSize The size of the layout area.
199 * @return The number of extra items. ItemView will populate itself with actors within the layout-area
200 * (see GetItemsWithinArea), plus this number of additional items on either-side.
202 virtual unsigned int GetReserveItemCount(Vector3 layoutSize) const = 0;
205 * Retrieve the target size of an item in the layout.
206 * @note layout-position is not provided as a parameter, since applying size constraints is not recommended.
207 * Animating to target-sizes is preferable, since this allows controls to perform layouting without constraints.
208 * @param[in] itemId The ID of an item in the layout.
209 * @param[in] layoutSize The layout size
210 * @param[out] itemSize The target size of an item, or an uninitialized value.
211 * @return Whether the item size is available or not
213 virtual bool GetItemSize(unsigned int itemId, Vector3 layoutSize, Vector3& itemSize) const = 0;
216 * Retrieve the resize animation in the layout.
217 * @note This allows the layout to provide its own resize animation.
218 * @param[in] animation The resize animation, not owned by the layout
219 * @param[in] actor The actor to animate
220 * @param [in] size The target size.
221 * @param [in] durationSeconds The duration of the resizing.
223 virtual void GetResizeAnimation(Animation& animation, Actor actor, Vector3 size, float durationSeconds) const = 0;
226 * Retrieve the position constraint function of an item in the layout.
227 * The constraint will be applied when the item is created or the layout is activated.
228 * @param[in] itemId The ID of an item in the layout.
229 * @param[out] constraint The position constraint function of an item, or an uninitialized function pointer.
230 * @return Whether the position constraint function of an item is available or not
232 virtual bool GetPositionConstraint(unsigned int itemId, Vector3Function& constraint) const = 0;
235 * Retrieve the rotation constraint function of an item in the layout.
236 * The constraint will be applied when the item is created or the layout is activated.
237 * @param[in] itemId The ID of an item in the layout.
238 * @param[out] constraint The rotation constraint function of an item, or an uninitialized function pointer.
239 * @return Whether the rotation constraint function of an item is available or not
241 virtual bool GetRotationConstraint(unsigned int itemId, QuaternionFunction& constraint) const = 0;
244 * Retrieve the scale constraint function of an item in the layout.
245 * The constraint will be applied when the item is created or the layout is activated.
246 * @param[in] itemId The ID of an item in the layout.
247 * @param[out] constraint The scale constraint function of an item, or an uninitialized function pointer.
248 * @return Whether the scale constraint function of an item is available or not
250 virtual bool GetScaleConstraint(unsigned int itemId, Vector3Function& constraint) const = 0;
253 * Retrieve the color constraint function of an item in the layout.
254 * The constraint will be applied when the item is created or the layout is activated.
255 * @param[in] itemId The ID of an item in the layout.
256 * @param[out] constraint The color constraint function of an item, or an uninitialized function pointer.
257 * @return Whether the color constraint function of an item is available or not
259 virtual bool GetColorConstraint(unsigned int itemId, Vector4Function& constraint) const = 0;
262 * Retrieve the visibility constraint function of an item in the layout.
263 * The constraint will be applied when the item is created or the layout is activated.
264 * @param[in] itemId The ID of an item in the layout.
265 * @param[out] constraint The visibility constraint function of an item, or an uninitialized function pointer.
266 * @return Whether the visibility constraint function of an item is available or not
268 virtual bool GetVisibilityConstraint(unsigned int itemId, BoolFunction& constraint) const = 0;
271 * Query the scroll direction of the layout.
272 * When an input gesture follows this direction, the layout-position of items will be increased.
273 * If the input gesture points in the opposite direction, then the layout-positions will decrease.
274 * @return The scroll direction in degrees.
276 virtual Degree GetScrollDirection() const = 0;
279 * Tells scroll components how to interpolate our logical scroll position as a screen x/y direction
281 * Application developer wants to use -ve y, +ve x as up direction and +ve y, -ve x as down direction scroll values in a
282 * vertical scroll type effect (SpiralLayout). This means that scroll bar/overshoot indicator should be affected by y-axis.
283 * 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
284 * 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
286 * This function is used by numerous objects such as scroll indicators and scroll overshoot indicators and all
287 * layout implementations should provide their own version of this function to ensure proper functionality of
288 * internal toolkit systems.
290 * @param[out] scrollHint Vector2 describing how x and y scroll values should be used for x-axis scrolling
292 virtual void GetXAxisScrollHint(Vector2& scrollHint) const;
295 * Tells scroll components how to interpolate our logical scroll position as a screen x/y direction
297 * Application developer wants to use -ve y, +ve x as up direction and +ve y, -ve x as down direction scroll values in a
298 * vertical scroll type effect (SpiralLayout). This means that scroll bar/overshoot indicator should be affected by y-axis.
299 * 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
300 * 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
302 * This function is used by numerous objects such as scroll indicators and scroll overshoot indicators and all
303 * layout implementations should provide their own version of this function to ensure proper functionality of
304 * internal toolkit systems.
306 * @param[out] scrollHint Vector2 describing how x and y scroll values should be used for y-axis scrolling
308 virtual void GetYAxisScrollHint(Vector2& scrollHint) const;
311 * Query the scroll speed factor of the layout.
312 * This factor is used by the layout to customise its scroll speed while dragging and 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 scroll speed will be.
319 * @return The scroll speed factor of the layout.
321 virtual float GetScrollSpeedFactor() const = 0;
324 * Query the maximum swipe speed in pixels per second.
325 * Swipe gestures will be clamped when exceeding this speed limit.
326 * @return speed The maximum swipe speed.
328 virtual float GetMaximumSwipeSpeed() const = 0;
331 * Get the duration of the flick animation in second. This is the time taken to animate each
332 * item to its next layout position (e.g. from 1.0 to 2.0) when a flick animation is triggered
333 * by a swipe gesture.
334 * @return The duration of the flick animation.
336 virtual float GetItemFlickAnimationDuration() const = 0;
339 * Gets the id of the next item for KeyboardFocusManager to focus on depending on the inputted item ID
341 * @param[in] itemID The current focused item
342 * @param[in] maxItems The maximum number of items in the list
343 * @param[in] direction The directional key pressed on the keyboard
344 * @param[in] loopEnabled Whether the KeyboardFocusManager is set to wrap around between first and last item
346 virtual int GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
351 * Create a new ItemLayout; Only derived versions are instantiatable.
357 ControlOrientation::Type mOrientation;
360 } // namespace Toolkit
367 #endif // __DALI_TOOLKIT_ITEM_LAYOUT_H__