1 #ifndef DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H
2 #define DALI_TOOLKIT_INTERNAL_SCROLL_BAR_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/devel-api/atspi-interfaces/value.h>
23 #include <dali/public-api/adaptor-framework/timer.h>
24 #include <dali/public-api/animation/animation.h>
25 #include <dali/public-api/animation/constraint.h>
26 #include <dali/public-api/common/dali-vector.h>
27 #include <dali/public-api/object/property-notification.h>
28 #include <dali/public-api/object/weak-handle.h>
31 #include <dali-toolkit/devel-api/controls/control-devel.h>
32 #include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
33 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
34 #include <dali-toolkit/public-api/controls/control-impl.h>
44 typedef IntrusivePtr<ScrollBar> ScrollBarPtr;
47 * ScrollBar is a UI component that can be added to the scrollable controls
48 * indicating the current scroll position of the scrollable content.
50 class ScrollBar : public Control
54 typedef Toolkit::ScrollBar::PanFinishedSignalType PanFinishedSignalType;
55 typedef Toolkit::ScrollBar::ScrollPositionIntervalReachedSignalType ScrollPositionIntervalReachedSignalType;
59 * @copydoc Toolkit::ScrollBar::New()
61 static Toolkit::ScrollBar New(Toolkit::ScrollBar::Direction direction);
64 * @copydoc Toolkit::ScrollBar::SetScrollPropertySource()
66 void SetScrollPropertySource(Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize);
69 * @copydoc Toolkit::ScrollBar::SetScrollIndicator()
71 void SetScrollIndicator(Actor indicator);
74 * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
76 Actor GetScrollIndicator();
79 * @copydoc Toolkit::ScrollBar::SetScrollPositionIntervals()
81 void SetScrollPositionIntervals(const Dali::Vector<float>& positions);
84 * @copydoc Toolkit::ScrollBar::GetScrollPositionIntervals()
86 Dali::Vector<float> GetScrollPositionIntervals() const;
89 * @copydoc Toolkit::ScrollBar::SetScrollDirection()
91 void SetScrollDirection(Toolkit::ScrollBar::Direction direction);
94 * @copydoc Toolkit::ScrollBar::GetScrollDirection()
96 Toolkit::ScrollBar::Direction GetScrollDirection() const;
99 * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
101 void SetIndicatorHeightPolicy(Toolkit::ScrollBar::IndicatorHeightPolicy policy);
104 * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
106 Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy() const;
109 * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
111 void SetIndicatorFixedHeight(float height);
114 * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
116 float GetIndicatorFixedHeight() const;
119 * @copydoc Toolkit::ScrollBar::SetIndicatorShowDuration()
121 void SetIndicatorShowDuration(float durationSeconds);
124 * @copydoc Toolkit::ScrollBar::GetIndicatorShowDuration()
126 float GetIndicatorShowDuration() const;
129 * @copydoc Toolkit::ScrollBar::SetIndicatorHideDuration()
131 void SetIndicatorHideDuration(float durationSeconds);
134 * @copydoc Toolkit::ScrollBar::GetIndicatorHideDuration()
136 float GetIndicatorHideDuration() const;
139 * @copydoc Toolkit::ScrollBar::ShowIndicator()
141 void ShowIndicator();
144 * @copydoc Toolkit::ScrollBar::HideIndicator()
146 void HideIndicator();
149 * @brief Shows indicator until the transient duration has expired
151 void ShowTransientIndicator();
154 * @copydoc Toolkit::ScrollBar::PanFinishedSignal()
156 PanFinishedSignalType& PanFinishedSignal()
158 return mPanFinishedSignal;
162 * @copydoc Toolkit::ScrollBar::ScrollPositionIntervalReachedSignal()
164 ScrollPositionIntervalReachedSignalType& ScrollPositionIntervalReachedSignal()
166 return mScrollPositionIntervalReachedSignal;
170 * Connects a callback function with the object's signals.
171 * @param[in] object The object providing the signal.
172 * @param[in] tracker Used to disconnect the signal.
173 * @param[in] signalName The signal to connect to.
174 * @param[in] functor A newly allocated FunctorDelegate.
175 * @return True if the signal was connected.
176 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
178 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
183 * Called when a property of an object of this type is set.
184 * @param[in] object The object whose property is set.
185 * @param[in] index The property index.
186 * @param[in] value The new property value.
188 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
191 * Called to retrieve a property of an object of this type.
192 * @param[in] object The object whose property is to be retrieved.
193 * @param[in] index The property index.
194 * @return The current value of the property.
196 static Property::Value GetProperty(BaseObject* object, Property::Index index);
199 * Performs actions as requested using the action name.
200 * @param[in] object The object on which to perform the action.
201 * @param[in] actionName The action to perform.
202 * @param[in] attributes The attributes with which to perfrom this action.
203 * @return true if action has been accepted by this control
205 static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
207 private: // from Control
209 * @copydoc Toolkit::Control::OnInitialize
211 void OnInitialize() override;
214 * @copydoc Toolkit::Internal::Control::CreateAccessibleObject()
216 DevelControl::ControlAccessible* CreateAccessibleObject() override;
219 * @copydoc Toolkit::Control::OnPan
221 void OnPan(const PanGesture& gesture) override;
224 * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
226 void OnSizeSet(const Vector3& size) override;
230 * Create the default indicator actor.
232 void CreateDefaultIndicatorActor();
235 * Apply constraints for background and indicator.
236 * These constraints are based on values from the scroll connector.
238 void ApplyConstraints();
241 * Callback when the current scroll position of the scrollable content goes above or
242 * below the values specified by SetScrollPositionIntervals().
243 * @param[in] source the property notification that triggered this callback
245 void OnScrollPositionIntervalReached(PropertyNotification& source);
248 * Process the pan gesture per predefined timeout until the gesture is finished.
249 * @return True if the timer should be kept running.
251 bool OnPanGestureProcessTick();
254 * Handle SetProperty for scroll direction.
255 * @param[in] propertyValue The new property value.
257 void OnScrollDirectionPropertySet(Property::Value propertyValue);
260 * Handle SetProperty for scroll indicator height policy.
261 * @param[in] propertyValue The new property value.
263 void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
268 * It initializes ScrollBar members.
270 ScrollBar(Toolkit::ScrollBar::Direction direction);
273 * A reference counted object may only be deleted by calling Unreference()
275 virtual ~ScrollBar();
278 Actor mIndicator; ///< Image of scroll indicator.
279 float mIndicatorShowAlpha; ///< The alpha value when the indicator is fully shown
280 Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
282 Toolkit::ScrollBar::Direction mDirection; ///< The direction of scroll bar (vertical or horizontal)
284 WeakHandle<Handle> mScrollableObject; ///< Object to be scrolled
286 Property::Index mPropertyScrollPosition = 0; ///< Index of scroll position property owned by the object to be scrolled
287 Property::Index mPropertyMinScrollPosition = 0; ///< Index of minimum scroll position property owned by the object to be scrolled
288 Property::Index mPropertyMaxScrollPosition = 1; ///< Index of maximum scroll position property owned by the object to be scrolled
289 Property::Index mPropertyScrollContentSize; ///< Index of scroll content size property owned by the object to be scrolled
291 float mIndicatorShowDuration; ///< The duration of scroll indicator show animation
292 float mIndicatorHideDuration; ///< The duration of scroll indicator hide animation
293 float mTransientIndicatorDuration; ///< The duration before hiding transient indicator
295 float mScrollStart; ///< Scroll Start position (start of drag)
296 Vector2 mGestureDisplacement; ///< Gesture Displacement.
298 float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture
300 Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy; ///< The height policy of scroll indicator (variable or fixed)
301 float mIndicatorFixedHeight; ///< The fixed height of scroll indicator
302 float mIndicatorMinimumHeight; ///< The minimum height for a variable size indicator
303 float mIndicatorStartPadding; ///< The padding at the start of the indicator
304 float mIndicatorEndPadding; ///< The padding at the end of the indicator
306 Timer mContractDelayTimer; ///< Timer guarantee contract delay time.
307 Timer mPanProcessTimer; ///< The timer to process the pan gesture after the gesture is started.
309 Dali::Vector<float> mScrollPositionIntervals; ///< List of values to receive notification for when the current scroll position goes above or below them
310 PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes
312 PanFinishedSignalType mPanFinishedSignal;
313 ScrollPositionIntervalReachedSignalType mScrollPositionIntervalReachedSignal;
315 Constraint mIndicatorPositionConstraint;
316 Constraint mIndicatorSizeConstraint;
318 bool mIsPanning : 1; ///< Whether the scroll bar is being panned.
319 bool mIndicatorFirstShow : 1; ///< True if the indicator has never been shown
322 class ScrollBarAccessible : public DevelControl::ControlAccessible,
323 public virtual Dali::Accessibility::Value
326 using DevelControl::ControlAccessible::ControlAccessible;
329 * @copydoc Dali::Accessibility::Value::GetMinimum()
331 double GetMinimum() const override;
334 * @copydoc Dali::Accessibility::Value::GetCurrent()
336 double GetCurrent() const override;
339 * @copydoc Dali::Accessibility::Value::GetMaximum()
341 double GetMaximum() const override;
344 * @copydoc Dali::Accessibility::Value::SetCurrent()
346 bool SetCurrent(double) override;
349 * @copydoc Dali::Accessibility::Value::GetMinimumIncrement()
351 double GetMinimumIncrement() const override;
355 } // namespace Internal
357 // Helpers for public-api forwarding methods
359 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
361 DALI_ASSERT_ALWAYS(scrollBar);
363 Dali::RefObject& handle = scrollBar.GetImplementation();
365 return static_cast<Toolkit::Internal::ScrollBar&>(handle);
368 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
370 DALI_ASSERT_ALWAYS(scrollBar);
372 const Dali::RefObject& handle = scrollBar.GetImplementation();
374 return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
377 } // namespace Toolkit
381 #endif // DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H