82be3ca416b1290ccfa7d341a4c2f5f723916206
[platform/core/uifw/dali-toolkit.git] / capi / dali-toolkit / public-api / controls / scrollable / item-view / grid-layout.h
1 #ifndef __DALI_TOOLKIT_GRID_LAYOUT_H__
2 #define __DALI_TOOLKIT_GRID_LAYOUT_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
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
10 //
11 //     http://floralicense.org/license/
12 //
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.
18 //
19
20 /**
21  * @addtogroup CAPI_DALI_TOOLKIT_ITEM_VIEW_MODULE
22  * @{
23  */
24
25 // INTERNAL INCLUDES
26 #include <dali/dali.h>
27
28 #include <dali-toolkit/public-api/controls/scrollable/item-view/item-layout.h>
29
30 namespace Dali DALI_IMPORT_API
31 {
32
33 namespace Toolkit
34 {
35
36 class GridLayout;
37
38 typedef IntrusivePtr<GridLayout> GridLayoutPtr; ///< Pointer to a Dali::Toolkit::GridLayout object
39
40 /**
41  * @brief An ItemView layout which arranges items in a grid.
42  */
43 class GridLayout : public ItemLayout
44 {
45 public:
46
47   /**
48    * @brief Function signature for a method to calculate the item size.
49    *
50    * @see SetItemSizeFunction()
51    */
52   typedef boost::function<Vector3 (unsigned int numberOfColumns, float layoutWidth, float sideMargin, float columnSpacing)> ItemSizeFunction;
53
54   /**
55    * @brief Create a new grid layout.
56    */
57   static GridLayoutPtr New();
58
59   /**
60    * @brief Virtual destructor.
61    */
62   virtual ~GridLayout();
63
64   /**
65    * @brief Set the number of columns in the layout.
66    *
67    * @param[in] columns The number of columns.
68    */
69   void SetNumberOfColumns(unsigned int columns);
70
71   /**
72    * @brief Get the number of columns in the layout.
73    *
74    * @return The number of columns.
75    */
76   unsigned int GetNumberOfColumns() const;
77
78   /**
79    * @brief Set the spacing between rows.
80    *
81    * @param[in] spacing The row spacing.
82    */
83   void SetRowSpacing(float spacing);
84
85   /**
86    * @brief Get the spacing between rows.
87    *
88    * @return The row spacing.
89    */
90   float GetRowSpacing() const;
91
92   /**
93    * @brief Set the spacing between columns.
94    *
95    * @param[in] spacing The row spacing.
96    */
97   void SetColumnSpacing(float spacing);
98
99   /**
100    * @brief Get the spacing between columns.
101    *
102    * @return The row spacing.
103    */
104   float GetColumnSpacing() const;
105
106   /**
107    * @brief Set the margin in the top of the layout.
108    *
109    * @param[in] margin The layout top margin.
110    */
111   void SetTopMargin(float margin);
112
113   /**
114    * @brief Get the margin in the top of the layout.
115    *
116    * @return The layout top margin.
117    */
118   float GetTopMargin() const;
119
120   /**
121    * @brief Set the margin in the bottom of the layout.
122    *
123    * @param[in] margin The layout bottom margin.
124    */
125   void SetBottomMargin(float margin);
126
127   /**
128    * @brief Get the margin in the bottom of the layout.
129    *
130    * @return The layout bottom margin.
131    */
132   float GetBottomMargin() const;
133
134   /**
135    * @brief Set the margin in the left and right of the layout.
136    *
137    * @param[in] margin The layout side margin.
138    */
139   void SetSideMargin(float margin);
140
141   /**
142    * @brief Get the margin in the left and right of the layout.
143    *
144    * @return The layout side margin.
145    */
146   float GetSideMargin() const;
147
148   /**
149    * @brief Set the gap of items in the Z axis in different columns.
150    *
151    * @param[in] gap The gap of items.
152    */
153   void SetZGap(float gap);
154
155   /**
156    * @brief Get the gap of items in the Z axis in different columns.
157    *
158    * @return The gap of items.
159    */
160   float GetZGap() const;
161
162   /**
163    * @brief Set the function used to calculate the item-size, for a given layout-size.
164    *
165    * @param[in] function The item-size function.
166    */
167   void SetItemSizeFunction(ItemSizeFunction function);
168
169   /**
170    * @brief Get the function used to calculate the item-size.
171    *
172    * @return The item-size function.
173    */
174   ItemSizeFunction GetItemSizeFunction() const;
175
176   /**
177    * @brief Set the factor used to customise the scroll speed while dragging and swiping the layout.
178    *
179    * @param[in] scrollSpeed The scroll speed factor.
180    */
181   void SetScrollSpeedFactor(float scrollSpeed);
182
183   /**
184    * @brief Set the maximum swipe speed in pixels per second.
185    *
186    * @param[in] speed The maximum swipe speed.
187    */
188   void SetMaximumSwipeSpeed(float speed);
189
190   /**
191    * @brief Set the duration of the flick animation in seconds.
192    *
193    * This is the time taken to animate each item to its next layout
194    * position (e.g. from 1.0 to 2.0) when a flick animation is
195    * triggered by a swipe gesture.
196    *
197    * @pre durationSeconds must be greater than zero.
198    * @param[in] durationSeconds The duration of flick animation in seconds.
199    */
200   void SetItemFlickAnimationDuration(float durationSeconds);
201
202   /**
203    * @copydoc ItemLayout::GetScrollSpeedFactor()
204    */
205   virtual float GetScrollSpeedFactor() const;
206
207   /**
208    * @copydoc ItemLayout::GetMaximumSwipeSpeed()
209    */
210   virtual float GetMaximumSwipeSpeed() const;
211
212   /**
213    * @copydoc ItemLayout::GetItemFlickAnimationDuration()
214    */
215   virtual float GetItemFlickAnimationDuration() const;
216
217   /**
218    * @copydoc ItemLayout::GetClosestOnScreenLayoutPosition()
219    */
220   virtual float GetClosestOnScreenLayoutPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize);
221
222   /**
223    * @copydoc ItemLayout::GetNextFocusItemID()
224    */
225   virtual int GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
226
227 private:
228
229   /**
230    * @copydoc ItemLayout::GetMinimumLayoutPosition()
231    */
232   virtual float GetMinimumLayoutPosition(unsigned int numberOfItems, Vector3 layoutSize) const;
233
234   /**
235    * @copydoc ItemLayout::GetClosestAnchorPosition()
236    */
237   virtual float GetClosestAnchorPosition(float layoutPosition) const;
238
239   /**
240    * @copydoc ItemLayout::GetItemScrollToPosition()
241    */
242   virtual float GetItemScrollToPosition(unsigned int itemId) const;
243
244   /**
245    * @copydoc ItemLayout::GetItemsWithinArea()
246    */
247   virtual ItemRange GetItemsWithinArea(float firstItemPosition, Vector3 layoutSize) const;
248
249   /**
250    * @copydoc ItemLayout::GetReserveItemCount()
251    */
252   virtual unsigned int GetReserveItemCount(Vector3 layoutSize) const;
253
254   /**
255    * @copydoc ItemLayout::GetItemSize()
256    */
257   virtual bool GetItemSize(unsigned int itemId, Vector3 layoutSize, Vector3& itemSize) const;
258
259   /**
260    * @copydoc ItemLayout::GetResizeAnimation()
261    */
262   virtual void GetResizeAnimation(Animation& animation, Actor actor, Vector3 size, float durationSeconds) const;
263
264   /**
265    * @copydoc ItemLayout::GetPositionConstraint()
266    */
267   virtual bool GetPositionConstraint(unsigned int itemId, ItemLayout::Vector3Function& constraint) const;
268
269   /**
270    * @copydoc ItemLayout::GetRotationConstraint()
271    */
272   virtual bool GetRotationConstraint(unsigned int itemId, ItemLayout::QuaternionFunction& constraint) const;
273
274   /**
275    * @copydoc ItemLayout::GetScaleConstraint()
276    */
277   virtual bool GetScaleConstraint(unsigned int itemId, ItemLayout::Vector3Function& constraint) const;
278
279   /**
280    * @copydoc ItemLayout::GetColorConstraint()
281    */
282   virtual bool GetColorConstraint(unsigned int itemId, ItemLayout::Vector4Function& constraint) const;
283
284   /**
285    * @copydoc ItemLayout::GetVisibilityConstraint()
286    */
287   virtual bool GetVisibilityConstraint(unsigned int itemId, ItemLayout::BoolFunction& constraint) const;
288
289   /**
290    * @copydoc ItemLayout::GetScrollDirection()
291    */
292   virtual Degree GetScrollDirection() const;
293
294 protected:
295
296   /**
297    * @brief Protected constructor; see also GridLayout::New().
298    */
299   GridLayout();
300
301 private:
302
303   struct Impl;
304   Impl* mImpl;
305 };
306
307 } // namespace Toolkit
308
309 } // namespace Dali
310
311 /**
312  * @}
313  */
314 #endif // __DALI_TOOLKIT_GRID_LAYOUT_H__