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