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