Add move semantics to common and base Toolkit classes
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / scrollable / scrollable.h
1 #ifndef DALI_TOOLKIT_SCROLLABLE_H
2 #define DALI_TOOLKIT_SCROLLABLE_H
3
4 /*
5  * Copyright (c) 2020 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 class Scrollable;
33 }
34 /**
35  * @addtogroup dali_toolkit_controls_scrollable
36  * @{
37  */
38
39 /**
40  * @brief Base class for derived Scrollables that contains actors that can be scrolled manually
41  * (via touch) or automatically.
42  *
43  * Scrollables such as ScrollView and ItemView can be derived from this class.
44  *
45  * Signals
46  * | %Signal Name     | Method                       |
47  * |------------------|------------------------------|
48  * | scrollStarted    | @ref ScrollStartedSignal()   |
49  * | scrollCompleted  | @ref ScrollCompletedSignal() |
50  * | scrollUpdated    | @ref ScrollUpdatedSignal()   |
51  * @SINCE_1_0.0
52  */
53 class DALI_TOOLKIT_API Scrollable : public Control
54 {
55 public:
56
57   /**
58    * @brief Enumeration for the start and end property ranges for this control.
59    * @SINCE_1_0.0
60    */
61   enum PropertyRange
62   {
63     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0
64     PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000,             ///< Reserve property indices @SINCE_1_0.0
65
66     ANIMATABLE_PROPERTY_START_INDEX = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX,
67     ANIMATABLE_PROPERTY_END_INDEX =   ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1000              ///< Reserve animatable property indices @SINCE_1_0.0
68   };
69
70   /**
71    * @brief Enumeration for the instance of properties belonging to the Scrollable class.
72    * @SINCE_1_0.0
73    */
74   struct Property
75   {
76     /**
77      * @brief Enumeration for the instance of properties belonging to the Scrollable class.
78      * @SINCE_1_0.0
79      */
80     enum
81     {
82       // Event side properties
83       OVERSHOOT_EFFECT_COLOR = PROPERTY_START_INDEX, ///< Property, name "overshootEffectColor",      @see SetOvershootEffectColor(),    type Vector4 @SINCE_1_0.0
84       OVERSHOOT_ANIMATION_SPEED,                     ///< Property, name "overshootAnimationSpeed",   @see SetOvershootAnimationSpeed(), type float @SINCE_1_0.0
85       OVERSHOOT_ENABLED,                             ///< Property, name "overshootEnabled",          @see SetOvershootEnabled(),        type bool,    @SINCE_1_1.18
86       OVERSHOOT_SIZE,                                ///< Property, name "overshootSize",                                                type Vector2, @SINCE_1_1.31
87       SCROLL_TO_ALPHA_FUNCTION,                      ///< Property, name "scrollToAlphaFunction",                                        type int,     @SINCE_1_1.33
88
89       // Animatable properties
90       SCROLL_RELATIVE_POSITION = ANIMATABLE_PROPERTY_START_INDEX, ///< Property, name "scrollRelativePosition",   type Vector2 @SINCE_1_0.0
91       SCROLL_POSITION_MIN,                                        ///< Property, name "scrollPositionMin",        type Vector2 @SINCE_1_0.0
92       SCROLL_POSITION_MIN_X,                                      ///< Property, name "scrollPositionMinX",       type float @SINCE_1_0.0
93       SCROLL_POSITION_MIN_Y,                                      ///< Property, name "scrollPositionMinY",       type float @SINCE_1_0.0
94       SCROLL_POSITION_MAX,                                        ///< Property, name "scrollPositionMax",        type Vector2 @SINCE_1_0.0
95       SCROLL_POSITION_MAX_X,                                      ///< Property, name "scrollPositionMaxX",       type float @SINCE_1_0.0
96       SCROLL_POSITION_MAX_Y,                                      ///< Property, name "scrollPositionMaxY",       type float @SINCE_1_0.0
97       CAN_SCROLL_VERTICAL,                                        ///< Property, name "canScrollVertical",        type bool @SINCE_1_0.0
98       CAN_SCROLL_HORIZONTAL                                       ///< Property, name "canScrollHorizontal",      type bool @SINCE_1_0.0
99     };
100   };
101
102   // Typedefs
103
104   typedef Signal< void ( const Vector2& ) > ScrollStartedSignalType;   ///< ScrollStarted signal type @SINCE_1_0.0
105   typedef Signal< void ( const Vector2& ) > ScrollCompletedSignalType; ///< ScrollCompleted signal type @SINCE_1_0.0
106   typedef Signal< void ( const Vector2& ) > ScrollUpdatedSignalType;   ///< Scroll updated signal type @SINCE_1_0.0
107
108 public:
109
110   /**
111    * @brief Creates an uninitialized Scrollable handle.
112    * @SINCE_1_0.0
113    */
114   Scrollable();
115
116   /**
117    * @brief Copy constructor.
118    *
119    * Creates another handle that points to the same real object.
120    *
121    * @SINCE_1_0.0
122    * @param handle to copy from
123    */
124   Scrollable( const Scrollable& handle );
125
126   /**
127    * @brief Move constructor
128    * @SINCE_1_9.23
129    *
130    * @param[in] rhs A reference to the moved handle
131    */
132   Scrollable( Scrollable&& rhs );
133
134   /**
135    * @brief Assignment operator.
136    *
137    * Changes this handle to point to another real object.
138    * @SINCE_1_0.0
139    * @param[in] handle Handle to copy from
140    * @return A reference to this
141    */
142   Scrollable& operator=( const Scrollable& handle );
143
144   /**
145    * @brief Move assignment
146    * @SINCE_1_9.23
147    *
148    * @param[in] rhs A reference to the moved handle
149    * @return A reference to this
150    */
151   Scrollable& operator=( Scrollable&& rhs );
152
153   /**
154    * @brief Destructor.
155    *
156    * This is non-virtual since derived Handle types must not contain data or virtual methods.
157    * @SINCE_1_0.0
158    */
159   ~Scrollable();
160
161   /**
162    * @brief Downcasts a handle to Scrollable handle.
163    *
164    * If handle points to a Scrollable, the downcast produces valid handle.
165    * If not, the returned handle is left uninitialized.
166    *
167    * @SINCE_1_0.0
168    * @param[in] handle Handle to an object
169    * @return A handle to a Scrollable or an uninitialized handle
170    */
171   static Scrollable DownCast( BaseHandle handle );
172
173   /**
174    * @brief Checks if scroll overshoot has been enabled or not.
175    *
176    * @SINCE_1_0.0
177    * @return Whether the scroll overshoot is enabled
178    */
179   bool IsOvershootEnabled() const;
180
181   /**
182    * @brief Sets whether to enables or disable scroll overshoot.
183    *
184    * @SINCE_1_0.0
185    * @param[in] enable Whether to enable the scroll overshoot or not
186    */
187   void SetOvershootEnabled(bool enable);
188
189   /**
190    * @brief Sets the color of the overshoot effect.
191    *
192    * @SINCE_1_0.0
193    * @param[in] color The color of the overshoot effect
194    */
195   void SetOvershootEffectColor( const Vector4& color );
196
197   /**
198    * @brief Gets the color of the overshoot effect.
199    * @SINCE_1_0.0
200    * @return The color of the overshoot effect
201    */
202   Vector4 GetOvershootEffectColor() const;
203
204   /**
205    * @brief Sets the speed of overshoot animation in pixels per second.
206    *
207    * When the speed is not greater than 0, the overshoot is set instantly with no animation.
208    * @SINCE_1_0.0
209    * @param[in] pixelsPerSecond The speed of the overshoot animation
210    */
211   void SetOvershootAnimationSpeed( float pixelsPerSecond );
212
213   /**
214    * @brief Gets the speed of overshoot animation in pixels per second.
215    * @SINCE_1_0.0
216    * @return The speed of the overshoot animation
217    */
218   float GetOvershootAnimationSpeed() const;
219
220 public: // Signals
221
222   /**
223    * @brief Signal emitted when the Scrollable has moved (whether by touch or animation).
224    *
225    * A callback of the following type may be connected:
226    * @code
227    *   void YourCallbackName(const Vector2& currentScrollPosition);
228    * @endcode
229    * @SINCE_1_0.0
230    * @return The signal to connect to
231    * @pre The Object has been initialized.
232    */
233   ScrollStartedSignalType& ScrollStartedSignal();
234
235   /**
236    * @brief Signal emitted when the Scrollable has moved (whether by touch or animation).
237    *
238    * A callback of the following type may be connected:
239    * @code
240    *   void YourCallbackName(const Vector2& currentScrollPosition);
241    * @endcode
242    * @SINCE_1_0.0
243    * @return The signal to connect to
244    * @pre The Object has been initialized.
245    */
246   ScrollUpdatedSignalType& ScrollUpdatedSignal();
247
248   /**
249    * @brief Signal emitted when the Scrollable has completed movement (whether by touch or animation).
250    *
251    * A callback of the following type may be connected:
252    * @code
253    *   void YourCallbackName(const Vector2& currentScrollPosition);
254    * @endcode
255    * @SINCE_1_0.0
256    * @return The signal to connect to
257    * @pre The Object has been initialized.
258    */
259   ScrollCompletedSignalType& ScrollCompletedSignal();
260
261 public: // Not intended for application developers
262
263   /// @cond internal
264   /**
265    * @brief Creates a handle using the Toolkit::Internal implementation.
266    *
267    * @SINCE_1_0.0
268    * @param[in] implementation The Control implementation
269    */
270   DALI_INTERNAL Scrollable(Internal::Scrollable& implementation);
271
272   /**
273    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
274    *
275    * @SINCE_1_0.0
276    * @param[in] internal A pointer to the internal CustomActor
277    */
278   explicit DALI_INTERNAL Scrollable( Dali::Internal::CustomActor* internal );
279   /// @endcond
280 };
281
282 /**
283  * @}
284  */
285 } // namespace Toolkit
286
287 } // namespace Dali
288
289 #endif // DALI_TOOLKIT_SCROLLABLE_H