1 #ifndef DALI_TOOLKIT_INTERNAL_SCROLLABLE_H
2 #define DALI_TOOLKIT_INTERNAL_SCROLLABLE_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/animation/alpha-function.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
37 typedef IntrusivePtr<Scrollable> ScrollablePtr;
40 * @copydoc Toolkit::Scrollable
42 class Scrollable : public Control
46 * @copydoc Dali::Toolkit::Scrollable::IsOvershootEnabled
48 bool IsOvershootEnabled() const;
51 * @copydoc Dali::Toolkit::Scrollable::SetOvershootEnabled
53 void SetOvershootEnabled(bool enable);
56 * Adds actor as an Overlay to Scrollable
57 * This method is called by Add-on UI components
58 * such as scroll bars, page indicators.
59 * @param[in] actor Actor to add as an overlay.
61 virtual void AddOverlay(Actor actor) = 0;
64 * Removes overlay actor from Scrollable
65 * This method is called by Add-on UI components
66 * such as scroll bars, page indicators.
67 * @param[in] actor Actor overlay to remove.
69 virtual void RemoveOverlay(Actor actor) = 0;
72 * Retrieves current scroll position.
73 * @returns The current scroll position.
75 virtual Vector2 GetCurrentScrollPosition() const = 0;
78 * Scrolls Scrollable to position specified (contents will scroll to this position)
79 * Position 0,0 is the origin. Increasing X scrolls contents left, while
80 * increasing Y scrolls contents up.
81 * @param[in] position The position to scroll to.
82 * @param[in] duration The duration of the animation in seconds
84 virtual void ScrollTo(const Vector2& position, float duration) = 0;
87 * Set the color of the overshoot effect.
88 * @parm[in] color The color of the overshoot effect
90 virtual void SetOvershootEffectColor(const Vector4& color) = 0;
93 * Retrieve the color of the overshoot effect.
94 * @return The color of the overshoot effect.
96 Vector4 GetOvershootEffectColor() const;
99 * @copydoc Dali::Toolkit::Scrollable::SetOvershootAnimationSpeed(float pixelsPerSecond)
101 void SetOvershootAnimationSpeed(float pixelsPerSecond);
104 * @copydoc Dali::Toolkit::Scrollable::GetOvershootAnimationSpeed()
106 float GetOvershootAnimationSpeed() const;
109 * @copydoc Dali::Toolkit::Scrollable::GetOvershootSize()
111 const Vector2& GetOvershootSize() const;
114 * Set the size of the overshoot effect.
115 * @parm[in] size The size of the overshoot effect
117 virtual void SetOvershootSize(const Vector2& size) = 0;
119 protected: // From Control
120 class ScrollableAccessible : public DevelControl::ControlAccessible
123 using DevelControl::ControlAccessible::ControlAccessible;
126 * @copydoc Dali::Accessibility::Component::IsScrollable()
128 bool IsScrollable() const override;
132 * @copydoc Control::OnInitialize
134 virtual void OnInitialize() override;
137 * @copydoc Toolkit::Internal::Control::CreateAccessibleObject()
139 DevelControl::ControlAccessible* CreateAccessibleObject() override;
143 * Temporary function to override EnableScrollOvershoot functionality for overshoot
144 * Only ScrollView needs to override this as HQ has not requested disable functionality in ItemView
145 * @param[in] enable true to enable, false to disable overshoot indicator
147 virtual void EnableScrollOvershoot(bool enable)
153 * @copydoc Dali::Toolkit::Scrollable::ScrollStartedSignal()
155 Toolkit::Scrollable::ScrollStartedSignalType& ScrollStartedSignal();
158 * @copydoc Dali::Toolkit::Scrollable::ScrollUpdatedSignal()
160 Toolkit::Scrollable::ScrollUpdatedSignalType& ScrollUpdatedSignal();
163 * @copydoc Dali::Toolkit::Scrollable::ScrollCompletedSignal()
165 Toolkit::Scrollable::ScrollCompletedSignalType& ScrollCompletedSignal();
168 * Connects a callback function with the object's signals.
169 * @param[in] object The object providing the signal.
170 * @param[in] tracker Used to disconnect the signal.
171 * @param[in] signalName The signal to connect to.
172 * @param[in] functor A newly allocated FunctorDelegate.
173 * @return True if the signal was connected.
174 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
176 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
181 * Called when a property of an object of this type is set.
182 * @param[in] object The object whose property is set.
183 * @param[in] index The property index.
184 * @param[in] value The new property value.
186 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
189 * Called to retrieve a property of an object of this type.
190 * @param[in] object The object whose property is to be retrieved.
191 * @param[in] index The property index.
192 * @return The current value of the property.
194 static Property::Value GetProperty(BaseObject* object, Property::Index index);
198 * Removed default constructor.
200 Scrollable() = delete;
203 * @brief Construct a new Scrollable.
205 * @param[in] behaviourFlags Flags to enable
207 Scrollable(ControlBehaviour behaviourFlags);
210 * A reference counted object may only be deleted by calling Unreference()
212 virtual ~Scrollable();
216 * Gets position property.
218 * @return The current position
220 Vector2 GetPropertyPosition() const;
224 Scrollable(const Scrollable&);
227 Scrollable& operator=(const Scrollable& rhs);
230 Vector4 mOvershootEffectColor; ///<The color of the overshoot bouncing effect
231 float mOvershootAnimationSpeed; ///<The speed of the overshoot animation (pixels per second)
232 Vector2 mOvershootSize; ///<The size of the overshoot effect
234 Dali::AlphaFunction::BuiltinFunction mScrollToAlphaFunction; ///< The ScrollTo() animations use this
236 Toolkit::Scrollable::ScrollStartedSignalType mScrollStartedSignal;
237 Toolkit::Scrollable::ScrollUpdatedSignalType mScrollUpdatedSignal;
238 Toolkit::Scrollable::ScrollCompletedSignalType mScrollCompletedSignal;
241 bool mOvershootEnabled : 1;
244 } // namespace Internal
246 // Helpers for public-api forwarding methods
248 inline Toolkit::Internal::Scrollable& GetImpl(Toolkit::Scrollable& scrollable)
250 DALI_ASSERT_ALWAYS(scrollable);
252 Dali::RefObject& handle = scrollable.GetImplementation();
254 return static_cast<Toolkit::Internal::Scrollable&>(handle);
257 inline const Toolkit::Internal::Scrollable& GetImpl(const Toolkit::Scrollable& scrollable)
259 DALI_ASSERT_ALWAYS(scrollable);
261 const Dali::RefObject& handle = scrollable.GetImplementation();
263 return static_cast<const Toolkit::Internal::Scrollable&>(handle);
266 } // namespace Toolkit
270 #endif // DALI_TOOLKIT_INTERNAL_SCROLLABLE_H