1 #ifndef __DALI_TOOLKIT_GRID_LAYOUT_H__
2 #define __DALI_TOOLKIT_GRID_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 #include <dali/dali.h>
24 #include <dali-toolkit/public-api/controls/scrollable/item-view/item-layout.h>
26 namespace Dali DALI_IMPORT_API
34 typedef IntrusivePtr<GridLayout> GridLayoutPtr; ///< Pointer to a Dali::Toolkit::GridLayout object
37 * @brief An ItemView layout which arranges items in a grid.
39 class GridLayout : public ItemLayout
44 * @brief Function signature for a method to calculate the item size.
46 * @see SetItemSizeFunction()
48 typedef boost::function<Vector3 (unsigned int numberOfColumns, float layoutWidth, float sideMargin, float columnSpacing)> ItemSizeFunction;
51 * @brief Create a new grid layout.
53 static GridLayoutPtr New();
56 * @brief Virtual destructor.
58 virtual ~GridLayout();
61 * @brief Set the number of columns in the layout.
63 * @param[in] columns The number of columns.
65 void SetNumberOfColumns(unsigned int columns);
68 * @brief Get the number of columns in the layout.
70 * @return The number of columns.
72 unsigned int GetNumberOfColumns() const;
75 * @brief Set the spacing between rows.
77 * @param[in] spacing The row spacing.
79 void SetRowSpacing(float spacing);
82 * @brief Get the spacing between rows.
84 * @return The row spacing.
86 float GetRowSpacing() const;
89 * @brief Set the spacing between columns.
91 * @param[in] spacing The row spacing.
93 void SetColumnSpacing(float spacing);
96 * @brief Get the spacing between columns.
98 * @return The row spacing.
100 float GetColumnSpacing() const;
103 * @brief Set the margin in the top of the layout.
105 * @param[in] margin The layout top margin.
107 void SetTopMargin(float margin);
110 * @brief Get the margin in the top of the layout.
112 * @return The layout top margin.
114 float GetTopMargin() const;
117 * @brief Set the margin in the bottom of the layout.
119 * @param[in] margin The layout bottom margin.
121 void SetBottomMargin(float margin);
124 * @brief Get the margin in the bottom of the layout.
126 * @return The layout bottom margin.
128 float GetBottomMargin() const;
131 * @brief Set the margin in the left and right of the layout.
133 * @param[in] margin The layout side margin.
135 void SetSideMargin(float margin);
138 * @brief Get the margin in the left and right of the layout.
140 * @return The layout side margin.
142 float GetSideMargin() const;
145 * @brief Set the gap of items in the Z axis in different columns.
147 * @param[in] gap The gap of items.
149 void SetZGap(float gap);
152 * @brief Get the gap of items in the Z axis in different columns.
154 * @return The gap of items.
156 float GetZGap() const;
159 * @brief Set the function used to calculate the item-size, for a given layout-size.
161 * @param[in] function The item-size function.
163 void SetItemSizeFunction(ItemSizeFunction function);
166 * @brief Get the function used to calculate the item-size.
168 * @return The item-size function.
170 ItemSizeFunction GetItemSizeFunction() const;
173 * @brief Set the factor used to customise the scroll speed while dragging and swiping the layout.
175 * @param[in] scrollSpeed The scroll speed factor.
177 void SetScrollSpeedFactor(float scrollSpeed);
180 * @brief Set the maximum swipe speed in pixels per second.
182 * @param[in] speed The maximum swipe speed.
184 void SetMaximumSwipeSpeed(float speed);
187 * @brief Set the duration of the flick animation in seconds.
189 * This is the time taken to animate each item to its next layout
190 * position (e.g. from 1.0 to 2.0) when a flick animation is
191 * triggered by a swipe gesture.
193 * @pre durationSeconds must be greater than zero.
194 * @param[in] durationSeconds The duration of flick animation in seconds.
196 void SetItemFlickAnimationDuration(float durationSeconds);
199 * @copydoc ItemLayout::GetScrollSpeedFactor()
201 virtual float GetScrollSpeedFactor() const;
204 * @copydoc ItemLayout::GetMaximumSwipeSpeed()
206 virtual float GetMaximumSwipeSpeed() const;
209 * @copydoc ItemLayout::GetItemFlickAnimationDuration()
211 virtual float GetItemFlickAnimationDuration() const;
214 * @copydoc ItemLayout::GetClosestOnScreenLayoutPosition()
216 virtual float GetClosestOnScreenLayoutPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize);
219 * @copydoc ItemLayout::GetNextFocusItemID()
221 virtual int GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
226 * @copydoc ItemLayout::GetMinimumLayoutPosition()
228 virtual float GetMinimumLayoutPosition(unsigned int numberOfItems, Vector3 layoutSize) const;
231 * @copydoc ItemLayout::GetClosestAnchorPosition()
233 virtual float GetClosestAnchorPosition(float layoutPosition) const;
236 * @copydoc ItemLayout::GetItemScrollToPosition()
238 virtual float GetItemScrollToPosition(unsigned int itemId) const;
241 * @copydoc ItemLayout::GetItemsWithinArea()
243 virtual ItemRange GetItemsWithinArea(float firstItemPosition, Vector3 layoutSize) const;
246 * @copydoc ItemLayout::GetReserveItemCount()
248 virtual unsigned int GetReserveItemCount(Vector3 layoutSize) const;
251 * @copydoc ItemLayout::GetItemSize()
253 virtual bool GetItemSize(unsigned int itemId, Vector3 layoutSize, Vector3& itemSize) const;
256 * @copydoc ItemLayout::GetResizeAnimation()
258 virtual void GetResizeAnimation(Animation& animation, Actor actor, Vector3 size, float durationSeconds) const;
261 * @copydoc ItemLayout::GetPositionConstraint()
263 virtual bool GetPositionConstraint(unsigned int itemId, ItemLayout::Vector3Function& constraint) const;
266 * @copydoc ItemLayout::GetRotationConstraint()
268 virtual bool GetRotationConstraint(unsigned int itemId, ItemLayout::QuaternionFunction& constraint) const;
271 * @copydoc ItemLayout::GetScaleConstraint()
273 virtual bool GetScaleConstraint(unsigned int itemId, ItemLayout::Vector3Function& constraint) const;
276 * @copydoc ItemLayout::GetColorConstraint()
278 virtual bool GetColorConstraint(unsigned int itemId, ItemLayout::Vector4Function& constraint) const;
281 * @copydoc ItemLayout::GetVisibilityConstraint()
283 virtual bool GetVisibilityConstraint(unsigned int itemId, ItemLayout::BoolFunction& constraint) const;
286 * @copydoc ItemLayout::GetScrollDirection()
288 virtual Degree GetScrollDirection() const;
293 * @brief Protected constructor; see also GridLayout::New().
303 } // namespace Toolkit
307 #endif // __DALI_TOOLKIT_GRID_LAYOUT_H__