1 #ifndef __DALI_TOOLKIT_ITEM_VIEW_H__
2 #define __DALI_TOOLKIT_ITEM_VIEW_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 // http://floralicense.org/license/
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.
21 * @addtogroup CAPI_DALI_FRAMEWORK
26 #include <dali/dali.h>
28 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
30 namespace Dali DALI_IMPORT_API
36 namespace Internal DALI_INTERNAL
41 class ScrollConnector;
45 typedef IntrusivePtr<ItemLayout> ItemLayoutPtr;
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.
52 class ItemView : public Scrollable
57 * Create an uninitialized ItemView; this can be initialized with ItemView::New()
58 * Calling member functions with an uninitialized Dali::Object is not allowed.
65 ItemView( const ItemView& itemView );
68 * Assignment operator.
70 ItemView& operator=( const ItemView& itemView );
74 * Dali::Object derived classes typically do not contain member data.
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.
83 static ItemView New(ItemFactory& factory);
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
91 static ItemView DownCast( BaseHandle handle );
94 * Retrieve a scroll-connector; this can be used to connect scroll components e.g. scroll bars.
95 * @return The connector.
97 ScrollConnector GetScrollConnector() const;
100 * Query the number of layouts.
101 * @return The number of layouts.
103 unsigned int GetLayoutCount() const;
107 * @param[in] layout The layout.
109 void AddLayout(ItemLayout& layout);
113 * @pre layoutIndex is less than GetLayoutCount().
114 * @param[in] layoutIndex The index of one of the ItemView layouts.
116 void RemoveLayout(unsigned int layoutIndex);
120 * @pre layoutIndex is less than GetLayoutCount().
123 ItemLayoutPtr GetLayout(unsigned int layoutIndex) const;
126 * Retrieve the currently active layout, if any.
127 * @return The layout, or an uninitialized pointer if no layout is active.
129 ItemLayoutPtr GetActiveLayout() const;
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.
136 float GetCurrentLayoutPosition(unsigned int itemId) const;
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).
147 void ActivateLayout(unsigned int layoutIndex, Vector3 targetSize, float durationSeconds);
150 * Deactivate the current layout, if any.
151 * The constraints applied by the layout will be removed.
153 void DeactivateCurrentLayout();
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
159 void SetMinimumSwipeSpeed(float speed);
162 * Get the minimum swipe speed in pixels per second.
163 * @return The minimum swipe speed
165 float GetMinimumSwipeSpeed() const;
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.
171 void SetMinimumSwipeDistance(float distance);
174 * Get the minimum swipe distance in actor coordinates.
175 * @return The minimum swipe distance
177 float GetMinimumSwipeDistance() const;
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).
183 void SetMouseWheelScrollDistanceStep(float step);
186 * Get the step of scroll distance in actor coordinates for each mouse wheel event received.
187 * @return The step of scroll distance(pixel)
189 float GetMouseWheelScrollDistanceStep() const;
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.
197 void SetAnchoring(bool enabled);
200 * Get whether the anchor animation is enabled or not
201 * @return Whether the anchor animation is enabled or not.
203 bool GetAnchoring() const;
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.
211 void SetAnchoringDuration(float durationSeconds);
214 * Get the duration of the anchor animation in seconds
215 * @return The duration of the anchor animation
217 float GetAnchoringDuration() const;
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.
227 void ScrollToItem(unsigned int itemId, float durationSeconds);
230 * Set the interval between refreshes, during which new items are requested from ItemFactory.
231 * @param[in] intervalMilliseconds The refresh interval in milliseconds.
233 void SetRefreshInterval(unsigned int intervalMilliseconds);
236 * Get the interval between refreshes in milliseconds.
237 * @return The refresh interval
239 unsigned int GetRefreshInterval() const;
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.
246 Actor GetItem(unsigned int itemId) const;
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.
254 unsigned int GetItemId(Actor actor) const;
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.
263 void RemoveItem(unsigned int itemId, float durationSeconds);
265 public: // Not intended for application developers
268 * Creates a handle using the Toolkit::Internal implementation.
269 * @param[in] implementation The Control implementation.
271 ItemView(Internal::ItemView& implementation);
274 * Allows the creation of this Control from an Internal::CustomActor pointer.
275 * @param[in] internal A pointer to the internal CustomActor.
277 ItemView( Dali::Internal::CustomActor* internal );
280 } // namespace Toolkit
287 #endif // __DALI_TOOLKIT_ITEM_VIEW_H__