fc24681ccb2db96aaa00e86c2985322b046efed2
[platform/core/uifw/dali-toolkit.git] / capi / dali-toolkit / public-api / controls / scrollable / item-view / item-view.h
1 #ifndef __DALI_TOOLKIT_ITEM_VIEW_H__
2 #define __DALI_TOOLKIT_ITEM_VIEW_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/scrollable.h>
29
30 namespace Dali DALI_IMPORT_API
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal DALI_INTERNAL
37 {
38 class ItemView;
39 }
40
41 class ScrollConnector;
42 class ItemFactory;
43 class ItemLayout;
44
45 typedef IntrusivePtr<ItemLayout> ItemLayoutPtr;
46
47 /**
48  * ItemView is a scrollable layout container.
49  * Multiple ItemLayouts may be provided, to determine the logical position of each item a layout.
50  * Actors are provided from an external ItemFactory, to display the currently visible items.
51  */
52 class ItemView : public Scrollable
53 {
54 public:
55
56   /**
57    * Create an uninitialized ItemView; this can be initialized with ItemView::New()
58    * Calling member functions with an uninitialized Dali::Object is not allowed.
59    */
60   ItemView();
61
62   /**
63    * Copy constructor.
64    */
65   ItemView( const ItemView& itemView );
66
67   /**
68    * Assignment operator.
69    */
70   ItemView& operator=( const ItemView& itemView );
71
72   /**
73    * Virtual destructor.
74    * Dali::Object derived classes typically do not contain member data.
75    */
76   virtual ~ItemView();
77
78   /**
79    * Create an initialized ItemView.
80    * @param[in] factory The factory which provides ItemView with items.
81    * @return A handle to a newly allocated Dali resource.
82    */
83   static ItemView New(ItemFactory& factory);
84
85   /**
86    * Downcast an Object handle to ItemView. If handle points to a ItemView the
87    * downcast produces valid handle. If not the returned handle is left uninitialized.
88    * @param[in] handle Handle to an object
89    * @return handle to a ItemView or an uninitialized handle
90    */
91   static ItemView DownCast( BaseHandle handle );
92
93   /**
94    * Retrieve a scroll-connector; this can be used to connect scroll components e.g. scroll bars.
95    * @return The connector.
96    */
97   ScrollConnector GetScrollConnector() const;
98
99   /**
100    * Query the number of layouts.
101    * @return The number of layouts.
102    */
103   unsigned int GetLayoutCount() const;
104
105   /**
106    * Add a layout.
107    * @param[in] layout The layout.
108    */
109   void AddLayout(ItemLayout& layout);
110
111   /**
112    * Remove a layout.
113    * @pre layoutIndex is less than GetLayoutCount().
114    * @param[in] layoutIndex The index of one of the ItemView layouts.
115    */
116   void RemoveLayout(unsigned int layoutIndex);
117
118   /**
119    * Retrieve a layout.
120    * @pre layoutIndex is less than GetLayoutCount().
121    * @return The layout
122    */
123   ItemLayoutPtr GetLayout(unsigned int layoutIndex) const;
124
125   /**
126    * Retrieve the currently active layout, if any.
127    * @return The layout, or an uninitialized pointer if no layout is active.
128    */
129   ItemLayoutPtr GetActiveLayout() const;
130
131   /**
132    * Retrieve the current layout-position of an item in the ItemView.
133    * @param[in] itemId The item identifier.
134    * @return The current layout-position.
135    */
136   float GetCurrentLayoutPosition(unsigned int itemId) const;
137
138   /**
139    * Activate one of the layouts; this will resize the ItemView & relayout actors within the ItemView.
140    * This is done by applying constraints from the new layout, and removing constraints from the previous layout.
141    * @pre layoutIndex is less than GetLayoutCount().
142    * @pre durationSeconds is greater or equal to zero.
143    * @param[in] layoutIndex The index of one of the ItemView layouts.
144    * @param[in] targetSize The target ItemView & layout size.
145    * @param[in] durationSeconds The time taken to relayout in seconds (zero for immediate).
146    */
147   void ActivateLayout(unsigned int layoutIndex, Vector3 targetSize, float durationSeconds);
148
149   /**
150    * Deactivate the current layout, if any.
151    * The constraints applied by the layout will be removed.
152    */
153   void DeactivateCurrentLayout();
154
155   /**
156    * Set the minimum swipe speed in pixels per second; A pan gesture must exceed this to trigger a swipe.
157    * @param[in] speed The minimum swipe speed
158    */
159   void SetMinimumSwipeSpeed(float speed);
160
161   /**
162    * Get the minimum swipe speed in pixels per second.
163    * @return The minimum swipe speed
164    */
165   float GetMinimumSwipeSpeed() const;
166
167   /**
168    * Set the minimum swipe distance in actor coordinates; A pan gesture must exceed this to trigger a swipe.
169    * @param[in] distance The minimum swipe distance.
170    */
171   void SetMinimumSwipeDistance(float distance);
172
173   /**
174    * Get the minimum swipe distance in actor coordinates.
175    * @return The minimum swipe distance
176    */
177   float GetMinimumSwipeDistance() const;
178
179   /**
180    * Set the step of scroll distance in actor coordinates for each mouse wheel event received.
181    * @param[in] step The step of scroll distance(pixel).
182    */
183   void SetMouseWheelScrollDistanceStep(float step);
184
185   /**
186    * Get the step of scroll distance in actor coordinates for each mouse wheel event received.
187    * @return The step of scroll distance(pixel)
188    */
189   float GetMouseWheelScrollDistanceStep() const;
190
191   /**
192    * Set whether to enable the animation for the layout to scroll to its anchor position after
193    * dragging or swiping. The anchor position is the position where all the items in the layout
194    * are aligned to their closest rounded layout positions in integer.
195    * @param[in] enabled Whether the anchor animation is enabled or not.
196    */
197   void SetAnchoring(bool enabled);
198
199   /**
200    * Get whether the anchor animation is enabled or not
201    * @return Whether the anchor animation is enabled or not.
202    */
203   bool GetAnchoring() const;
204
205   /**
206    * Set the duration of the anchor animation in seconds. This is the time taken to reach the nearest
207    * anchor position after a drag or swipe gesture ends.
208    * @pre durationSeconds must be greater than zero.
209    * @param[in] durationSeconds The duration of the anchor animation in seconds.
210    */
211   void SetAnchoringDuration(float durationSeconds);
212
213   /**
214    * Get the duration of the anchor animation in seconds
215    * @return The duration of the anchor animation
216    */
217   float GetAnchoringDuration() const;
218
219   /**
220    * Scroll the current layout to a particular item.
221    * @pre durationSeconds must be zero or greater; zero means the layout should scroll to the particular item instantly.
222    * If calling this with zero second of duration immediately after calling ActivateLayout, it might not work unless
223    * the duration of relayout animation for ActivateLayout is also set to be zero.
224    * @param[in] itemId The ID of an item in the layout.
225    * @param[in] durationSeconds How long the scrolling takes in seconds.
226    */
227   void ScrollToItem(unsigned int itemId, float durationSeconds);
228
229   /**
230    * Set the interval between refreshes, during which new items are requested from ItemFactory.
231    * @param[in] intervalMilliseconds The refresh interval in milliseconds.
232    */
233   void SetRefreshInterval(unsigned int intervalMilliseconds);
234
235   /**
236    * Get the interval between refreshes in milliseconds.
237    * @return  The refresh interval
238    */
239   unsigned int GetRefreshInterval() const;
240
241   /**
242    * Given the Item ID, this returns the accompanying actor.
243    * @param[in] itemId The Item ID of the actor required.
244    * @return The Actor corresponding to the Item ID.
245    */
246   Actor GetItem(unsigned int itemId) const;
247
248   /**
249    * Returns the Item ID of the specified actor.
250    * @param[in] actor The actor whose Item ID is required.
251    * @return The Item ID of the item.
252    * @pre The actor should be an item of ItemView.
253    */
254   unsigned int GetItemId(Actor actor) const;
255
256   /**
257    * Removes an item with the given ID.
258    * @pre durationSeconds must be zero or greater; zero means when the item is deleted the remaining items
259    * will finish the relayout instantly.
260    * @param[in] itemId The Item ID of the item to remove.
261    * @param[in] durationSeconds How long the realyout takes in seconds after the item is deleted.
262    */
263   void RemoveItem(unsigned int itemId, float durationSeconds);
264
265 public: // Not intended for application developers
266
267   /**
268    * Creates a handle using the Toolkit::Internal implementation.
269    * @param[in]  implementation  The Control implementation.
270    */
271   ItemView(Internal::ItemView& implementation);
272
273   /**
274    * Allows the creation of this Control from an Internal::CustomActor pointer.
275    * @param[in]  internal  A pointer to the internal CustomActor.
276    */
277   ItemView( Dali::Internal::CustomActor* internal );
278 };
279
280 } // namespace Toolkit
281
282 } // namespace Dali
283
284 /**
285  * @}
286  */
287 #endif // __DALI_TOOLKIT_ITEM_VIEW_H__