Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / public-api / controls / scrollable / item-view / spiral-layout.h
1 #ifndef __DALI_TOOLKIT_SPIRAL_LAYOUT_H__
2 #define __DALI_TOOLKIT_SPIRAL_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 SpiralLayout;
33
34 typedef IntrusivePtr<SpiralLayout> SpiralLayoutPtr;
35
36 /**
37  * An ItemView layout which arranges items in a spiral.
38  */
39 class SpiralLayout : public ItemLayout
40 {
41 public:
42
43   typedef boost::function<Vector3 (const Vector3& layoutSize)> ItemSizeFunction;
44   typedef boost::function<float   (const Vector3& layoutSize)> SpiralRadiusFunction;
45
46   /**
47    * Create a new spiral layout
48    */
49   static SpiralLayoutPtr New();
50
51   /**
52    * Virtual destructor.
53    */
54   virtual ~SpiralLayout();
55
56   /**
57    * Set the function used to calculate the item-size, for a given layout-size.
58    * @param[in] function The item-size function.
59    */
60   void SetItemSizeFunction(ItemSizeFunction function);
61
62   /**
63    * Get the function used to calculate the item-size
64    * @return The item-size function.
65    */
66   ItemSizeFunction GetItemSizeFunction() const;
67
68   /**
69    * Set spacing angle between items.
70    * @param[in] itemSpacing The angle in radians.
71    */
72   void SetItemSpacing(Radian itemSpacing);
73
74   /**
75    * Get spacing angle between items.
76    * @return The angle in radians.
77    */
78   Radian GetItemSpacing() const;
79
80   /**
81    * Set the vertical distance for one revolution of the spiral.
82    * @param[in] distance The revolution distance.
83    */
84   void SetRevolutionDistance(float distance);
85
86   /**
87    * Get the vertical distance for one revolution of the spiral.
88    * @return The revolution distance.
89    */
90   float GetRevolutionDistance() const;
91
92   /**
93    * Set the function used to calculate the spiral radius, for a given layout-size.
94    * @param[in] function The spiral-radius function.
95    */
96   void SetSpiralRadiusFunction(SpiralRadiusFunction function);
97
98   /**
99    * Get the function used to calculate the spiral radius.
100    * @return The spiral-radius function.
101    */
102   SpiralRadiusFunction GetSpiralRadiusFunction() const;
103
104   /**
105    * Set the alignment of the top-item, when at the beginning of the spiral (with a first-item layout-position of zero).
106    * A value of 0 indicates that the top-item is centered in the middle of the layout. A value of -0.5 or 0.5 indicates
107    * that the top-item is centred at the top or bottom of the layout respectively.
108    * @param[in] alignment The top-item alignment.
109    */
110   void SetTopItemAlignment(float alignment);
111
112   /**
113    * Get the alignment of the top-item, when at the beginning of the spiral
114    * @return The top-item alignment.
115    */
116   float GetTopItemAlignment() const;
117
118   /**
119    * Set the factor used to customise the scroll speed while dragging and swiping the layout.
120    * @param[in] scrollSpeed The scroll speed factor.
121    */
122   void SetScrollSpeedFactor(float scrollSpeed);
123
124   /**
125    * Set the maximum swipe speed in pixels per second.
126    * @param[in] speed The maximum swipe speed.
127    */
128   void SetMaximumSwipeSpeed(float speed);
129
130   /**
131    * Set the duration of the flick animation in second. This is the time taken to animate each
132    * item to its next layout position (e.g. from 1.0 to 2.0) when a flick animation is triggered
133    * by a swipe gesture.
134    * @pre durationSeconds must be greater than zero.
135    * @param[in] durationSeconds The duration of flick animation in seconds.
136    */
137   void SetItemFlickAnimationDuration(float durationSeconds);
138
139   /**
140    * @copydoc ItemLayout::GetScrollSpeedFactor()
141    */
142   virtual float GetScrollSpeedFactor() const;
143
144   /**
145    * @copydoc ItemLayout::GetMaximumSwipeSpeed()
146    */
147   virtual float GetMaximumSwipeSpeed() const;
148
149   /**
150    * @copydoc ItemLayout::GetItemFlickAnimationDuration()
151    */
152   virtual float GetItemFlickAnimationDuration() const;
153
154   /**
155    * @copydoc ItemLayout::GetClosestOnScreenLayoutPosition()
156    */
157   virtual float GetClosestOnScreenLayoutPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize);
158
159 private:
160
161   /**
162    * @copydoc ItemLayout::GetMinimumLayoutPosition()
163    */
164   virtual float GetMinimumLayoutPosition(unsigned int numberOfItems, Vector3 layoutSize) const;
165
166   /**
167    * @copydoc ItemLayout::GetClosestAnchorPosition()
168    */
169   virtual float GetClosestAnchorPosition(float layoutPosition) const;
170
171   /**
172    * @copydoc ItemLayout::GetItemScrollToPosition()
173    */
174   virtual float GetItemScrollToPosition(unsigned int itemId) const;
175
176   /**
177    * @copydoc ItemLayout::GetItemsWithinArea()
178    */
179   virtual ItemRange GetItemsWithinArea(float firstItemPosition, Vector3 layoutSize) const;
180
181   /**
182    * @copydoc ItemLayout::GetReserveItemCount()
183    */
184   virtual unsigned int GetReserveItemCount(Vector3 layoutSize) const;
185
186   /**
187    * @copydoc ItemLayout::GetItemSize()
188    */
189   virtual bool GetItemSize(unsigned int itemId, Vector3 layoutSize, Vector3& itemSize) const;
190
191   /**
192    * @copydoc ItemLayout::GetResizeAnimation()
193    */
194   virtual void GetResizeAnimation(Animation& animation, Actor actor, Vector3 size, float durationSeconds) const;
195
196   /**
197    * @copydoc ItemLayout::GetPositionConstraint()
198    */
199   virtual bool GetPositionConstraint(unsigned int itemId, ItemLayout::Vector3Function& constraint) const;
200
201   /**
202    * @copydoc ItemLayout::GetRotationConstraint()
203    */
204   virtual bool GetRotationConstraint(unsigned int itemId, ItemLayout::QuaternionFunction& constraint) const;
205
206   /**
207    * @copydoc ItemLayout::GetScaleConstraint()
208    */
209   virtual bool GetScaleConstraint(unsigned int itemId, ItemLayout::Vector3Function& constraint) const;
210
211   /**
212    * @copydoc ItemLayout::GetColorConstraint()
213    */
214   virtual bool GetColorConstraint(unsigned int itemId, ItemLayout::Vector4Function& constraint) const;
215
216   /**
217    * @copydoc ItemLayout::GetVisibilityConstraint()
218    */
219   virtual bool GetVisibilityConstraint(unsigned int itemId, ItemLayout::BoolFunction& constraint) const;
220
221   /**
222    * @copydoc ItemLayout::GetScrollDirection()
223    */
224   virtual Degree GetScrollDirection() const;
225
226 protected:
227
228   /**
229    * Protected constructor; see also SpiralLayout::New()
230    */
231   SpiralLayout();
232
233 private:
234
235   struct Impl;
236   Impl* mImpl;
237 };
238
239 } // namespace Toolkit
240
241 } // namespace Dali
242
243 #endif // __DALI_TOOLKIT_SPIRAL_LAYOUT_H__