3bd0adc616893402125627c4d3ec648388021aec
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / scroll-bar / scroll-bar.h
1 #ifndef __DALI_TOOLKIT_SCROLL_BAR_H__
2 #define __DALI_TOOLKIT_SCROLL_BAR_H__
3
4 /*
5  * Copyright (c) 2016 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-toolkit/public-api/controls/control.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Internal DALI_INTERNAL
31 {
32 // Forward declarations
33
34 class ScrollBar;
35 }
36 /**
37  * @addtogroup dali_toolkit_controls_scroll_bar
38  * @{
39  */
40
41 /**
42  * @brief ScrollBar is a UI component that can be linked to the scrollable objects
43  * indicating the current scroll position of the scrollable object.
44  *
45  * Signals
46  * | %Signal Name                  | Method                                     |
47  * |-------------------------------|--------------------------------------------|
48  * | panFinished                   | @ref PanFinishedSignal()                   |
49  * | scrollPositionIntervalReached | @ref ScrollPositionIntervalReachedSignal() |
50  * @SINCE_1_0.0
51  */
52 class DALI_IMPORT_API ScrollBar : public Control
53 {
54 public:
55
56   // Properties
57
58   /**
59    * @brief Enumeration for the start and end property ranges for this control.
60    * @SINCE_1_0.0
61    */
62   enum PropertyRange
63   {
64     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0
65     PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000              ///< Reserve property indices @SINCE_1_0.0
66   };
67
68   /**
69    * @brief Enumeration for the instance of properties belonging to the ScrollBar class.
70    * @SINCE_1_0.0
71    */
72   struct Property
73   {
74     /**
75      * @brief Enumeration for the instance of properties belonging to the ScrollBar class.
76      * @SINCE_1_0.0
77      */
78     enum
79     {
80       /**
81        * @brief name "scrollDirection", type std::string.
82        * @SINCE_1_0.0
83        * @see SetScrollDirection()
84        */
85       SCROLL_DIRECTION = PROPERTY_START_INDEX,
86       /**
87        * @brief name "indicatorHeightPolicy", type std::string.
88        * @SINCE_1_0.0
89        * @see SetIndicatorHeightPolicy()
90        */
91       INDICATOR_HEIGHT_POLICY,
92       /**
93        * @brief name "indicatorFixedHeight", type float.
94        * @SINCE_1_0.0
95        * @see SetIndicatorFixedHeight()
96        */
97       INDICATOR_FIXED_HEIGHT,
98       /**
99        * @brief name "indicatorShowDuration", type float.
100        * @SINCE_1_0.0
101        * @see SetIndicatorShowDuration()
102        */
103       INDICATOR_SHOW_DURATION,
104       /**
105        * @brief name "indicatorHideDuration", type float.
106        * @SINCE_1_0.0
107        * @see SetIndicatorHideDuration()
108        */
109       INDICATOR_HIDE_DURATION,
110       /**
111        * @brief name "scrollPositionIntervals", type Property::Array.
112        * @SINCE_1_0.0
113        * @see SetScrollPositionIntervals()
114        */
115       SCROLL_POSITION_INTERVALS,
116       /**
117        * @brief name "indicatorMinimumHeight", type float.
118        * The minimum height for a variable size indicator.
119        * @SINCE_1_1.36
120        */
121       INDICATOR_MINIMUM_HEIGHT,
122       /**
123        * @brief name "indicatorStartPadding", type float.
124        * The padding at the start of the indicator. For example, the top if scrollDirection is Vertical.
125        * @SINCE_1_1.36
126        */
127       INDICATOR_START_PADDING,
128       /**
129        * @brief name "indicatorEndPadding", type float.
130        * The padding at the end of the indicator. For example, the bottom if scrollDirection is Vertical.
131        * @SINCE_1_1.36
132        */
133       INDICATOR_END_PADDING
134     };
135   };
136
137   // Signals
138
139   typedef Signal< void () > PanFinishedSignalType;
140   typedef Signal< void ( float ) > ScrollPositionIntervalReachedSignalType;
141
142 public:
143
144   /**
145    * @brief Direction.
146    * @SINCE_1_0.0
147    */
148   enum Direction
149   {
150     Vertical = 0,   ///< Scroll in the vertical direction @SINCE_1_0.0
151     Horizontal      ///< Scroll in the horizontal direction @SINCE_1_0.0
152   };
153
154   /**
155    * @brief Indicator height policy.
156    * @SINCE_1_0.0
157    */
158   enum IndicatorHeightPolicy
159   {
160     Variable = 0,  ///< Variable height changed dynamically according to the length of scroll content @SINCE_1_0.0
161     Fixed          ///< Fixed height regardless of the length of scroll content @SINCE_1_0.0
162   };
163
164   /**
165    * @brief Creates an uninitialized ScrollBar; this can be initialized with ScrollBar::New()
166    * Calling member functions with an uninitialized Dali::Object is not allowed.
167    * @SINCE_1_0.0
168    */
169   ScrollBar();
170
171   /**
172    * @brief Copy constructor.
173    * @SINCE_1_0.0
174    * @param[in] scrollBar Handle to an object
175    */
176   ScrollBar( const ScrollBar& scrollBar );
177
178   /**
179    * @brief Assignment operator.
180    * @SINCE_1_0.0
181    * @param[in] scrollBar Handle to an object
182    * @return A reference to this
183    */
184   ScrollBar& operator=( const ScrollBar& scrollBar );
185
186   /**
187    * @brief Destructor.
188    *
189    * This is non-virtual since derived Handle types must not contain data or virtual methods.
190    * @SINCE_1_0.0
191    */
192   ~ScrollBar();
193
194   /**
195    * @brief Creates an initialized ScrollBar.
196    * @SINCE_1_0.0
197    * @param[in] direction The direction of scroll bar (either vertically or horizontally)
198    * @return A pointer to the created ScrollBar
199    */
200   static ScrollBar New(Direction direction = Vertical);
201
202   /**
203    * @brief Downcasts a handle to ScrollBar handle.
204    *
205    * If handle points to a ScrollBar, the downcast produces valid handle.
206    * If not, the returned handle is left uninitialized.
207    * @SINCE_1_0.0
208    * @param[in] handle Handle to an object
209    * @return Handle to a ScrollBar or an uninitialized handle
210    */
211   static ScrollBar DownCast( BaseHandle handle );
212
213   /**
214    * @brief Sets the source of the scroll position properties.
215    *
216    * @SINCE_1_0.0
217    * @param[in] handle The handle of the object owing the scroll properties
218    * @param[in] propertyScrollPosition The index of the scroll position property (The scroll position, type float)
219    * @param[in] propertyMinScrollPosition The index of the minimum scroll position property (The minimum scroll position, type float)
220    * @param[in] propertyMaxScrollPosition The index of the maximum scroll position property (The maximum scroll position, type float)
221    * @param[in] propertyScrollContentSize The index of the scroll content size property (The size of the scrollable content in actor coordinates, type float)
222    * @pre The handle to the object owing the scroll properties has been initialised and the property index must be valid.
223    */
224   void SetScrollPropertySource( Handle handle, Dali::Property::Index propertyScrollPosition, Dali::Property::Index propertyMinScrollPosition, Dali::Property::Index propertyMaxScrollPosition, Dali::Property::Index propertyScrollContentSize );
225
226   /**
227    * @brief Sets the indicator of scroll bar.
228    *
229    * @SINCE_1_0.0
230    * @param[in] indicator The indicator that moves to indicate the current scroll position
231    * @pre The scroll bar actor has been initialized.
232    */
233   void SetScrollIndicator( Actor indicator );
234
235   /**
236    * @brief Gets the indicator of scroll bar.
237    *
238    * @SINCE_1_0.0
239    * @return The indicator indicates the current scroll position of the scrollable content
240    * @pre The scroll bar actor has been initialized.
241    */
242   Actor GetScrollIndicator();
243
244   /**
245    * @brief Sets the list of values to get notification when the current scroll position of the scrollable
246    * object goes above or below any of these values.
247    *
248    * @SINCE_1_0.0
249    * @param[in] positions List of values to receive notifications for when the current scroll position crosses them
250    * @pre The scroll bar actor has been initialized.
251    */
252   void SetScrollPositionIntervals( const Dali::Vector<float>& positions );
253
254   /**
255    * @brief Gets the list of values to receive notifications when the current scroll position of the scrollable
256    * object goes above or below any of these values.
257    *
258    * @SINCE_1_0.0
259    * @return The list of values to receive notifications for when the current scroll position crosses them
260    * @pre The scroll bar actor has been initialized.
261    *
262    */
263   Dali::Vector<float> GetScrollPositionIntervals() const;
264
265   /**
266    * @brief Sets the direction of scroll bar to scroll either vertically or horizontally.
267    *
268    * @SINCE_1_0.0
269    * @param[in] direction The direction of scroll bar (either vertically or horizontally)
270    * @pre The scroll bar actor has been initialized.
271    */
272   void SetScrollDirection( Direction direction );
273
274   /**
275    * @brief Gets the direction of scroll bar.
276    *
277    * @SINCE_1_0.0
278    * @return The direction of scroll bar
279    */
280   Direction GetScrollDirection() const;
281
282   /**
283    * @brief Sets the height policy of scroll indicator to have either variable or fixed height.
284    *
285    * @SINCE_1_0.0
286    * @param[in] policy The height policy of scroll indicator
287    * @pre The scroll bar actor has been initialized.
288    */
289   void SetIndicatorHeightPolicy( IndicatorHeightPolicy policy );
290
291   /**
292    * @brief Gets the height policy of scroll indicator.
293    *
294    * @SINCE_1_0.0
295    * @return The height policy of scroll indicator
296    */
297   IndicatorHeightPolicy GetIndicatorHeightPolicy() const;
298
299   /**
300    * @brief Sets the fixed height of scroll indicator.
301    *
302    * Normally the height of scroll indicator is changed dynamically according to the length of scroll content.
303    * However, when the height policy of scroll indicator is set to be fixed, the height will be kept fixed
304    * regardless of the length of scroll content.
305    *
306    * @SINCE_1_0.0
307    * @param[in] height The fixed height of the scroll indicator
308    * @pre The scroll bar actor has been initialized.
309    *
310    */
311   void SetIndicatorFixedHeight( float height );
312
313   /**
314    * @brief Gets the fix height of scroll indicator.
315    * @SINCE_1_0.0
316    * @return The fixed height of the scroll indicator
317    */
318   float GetIndicatorFixedHeight() const;
319
320   /**
321    * @brief Sets the duration in seconds for the scroll indicator to become fully visible.
322    *
323    * @SINCE_1_0.0
324    * @param[in] durationSeconds The duration for the scroll indicator to become fully visible
325    * @pre The scroll bar actor has been initialised; durationSeconds must be zero or greater; zero means the indicator will be shown instantly.
326    *
327    */
328   void SetIndicatorShowDuration( float durationSeconds );
329
330   /**
331    * @brief Gets the duration in seconds for the scroll indicator to become fully visible.
332    * @SINCE_1_0.0
333    * @return The duration for the scroll indicator to become fully visible
334    */
335   float GetIndicatorShowDuration() const;
336
337   /**
338    * @brief Sets the duration in seconds for the scroll indicator to become fully invisible.
339    *
340    * @SINCE_1_0.0
341    * @param[in] durationSeconds The duration for the scroll indicator to become fully invisible
342    * @pre The scroll bar actor has been initialised; durationSeconds must be zero or greater; zero means the indicator will be hidden instantly.
343    *
344    */
345   void SetIndicatorHideDuration( float durationSeconds );
346
347   /**
348    * @brief Gets the duration in seconds for the scroll indicator to become fully invisible.
349    * @SINCE_1_0.0
350    * @return The duration for the scroll indicator to become fully invisible
351    */
352   float GetIndicatorHideDuration() const;
353
354   /**
355    * @brief Shows the scroll indicator.
356    * @SINCE_1_0.0
357    */
358   void ShowIndicator();
359
360   /**
361    * @brief Hides the scroll indicator.
362    * @SINCE_1_0.0
363    */
364   void HideIndicator();
365
366 public: // Signals
367
368   /**
369    * @brief Signal emitted when panning is finished on the scroll indicator.
370    *
371    * Signal only emitted when the source of the scroll position properties are set.
372    *
373    * A callback of the following type may be connected:
374    * @code
375    *   void YourCallbackName();
376    * @endcode
377    * @SINCE_1_0.0
378    * @return The signal to connect to
379    * @pre The Object has been initialized.
380    */
381   ScrollBar::PanFinishedSignalType& PanFinishedSignal();
382
383   /**
384    * @brief Signal emitted when the current scroll position of the scrollable content
385    * goes above or below the values specified by SCROLL_POSITION_INTERVALS property.
386    *
387    * Signal only emitted when the source of the scroll position properties are set.
388    *
389    * A callback of the following type may be connected:
390    * @code
391    *   void YourCallbackName(float currentScrollPosition);
392    * @endcode
393    * @SINCE_1_0.0
394    * @return The signal to connect to
395    * @pre The Object has been initialized.
396    */
397   ScrollBar::ScrollPositionIntervalReachedSignalType& ScrollPositionIntervalReachedSignal();
398
399 public: // Not intended for application developers
400
401   /// @cond internal
402   /**
403    * @brief Creates a handle using the Toolkit::Internal implementation.
404    * @SINCE_1_0.0
405    * @param[in] implementation The Control implementation
406    */
407   DALI_INTERNAL ScrollBar( Internal::ScrollBar& implementation );
408
409   /**
410    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
411    * @SINCE_1_0.0
412    * @param[in] internal A pointer to the internal CustomActor
413    */
414   explicit DALI_INTERNAL ScrollBar( Dali::Internal::CustomActor* internal );
415   /// @endcond
416 };
417
418 /**
419  * @}
420  */
421 } // namespace Toolkit
422
423 } // namespace Dali
424
425 #endif // __DALI_TOOLKIT_SCROLL_BAR_H__