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/public-api/adaptor-framework/timer.h>
23 #include <dali/public-api/animation/animation.h>
24 #include <dali/public-api/animation/constraint.h>
25 #include <dali/public-api/common/dali-vector.h>
26 #include <dali/public-api/object/property-notification.h>
27 #include <dali/public-api/object/weak-handle.h>
30 #include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
31 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
32 #include <dali-toolkit/public-api/controls/control-impl.h>
42 typedef IntrusivePtr<ScrollBar> ScrollBarPtr;
45 * ScrollBar is a UI component that can be added to the scrollable controls
46 * indicating the current scroll position of the scrollable content.
48 class ScrollBar : public Control
52 typedef Toolkit::ScrollBar::PanFinishedSignalType PanFinishedSignalType;
53 typedef Toolkit::ScrollBar::ScrollPositionIntervalReachedSignalType ScrollPositionIntervalReachedSignalType;
57 * @copydoc Toolkit::ScrollBar::New()
59 static Toolkit::ScrollBar New(Toolkit::ScrollBar::Direction direction);
62 * @copydoc Toolkit::ScrollBar::SetScrollPropertySource()
64 void SetScrollPropertySource(Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize);
67 * @copydoc Toolkit::ScrollBar::SetScrollIndicator()
69 void SetScrollIndicator(Actor indicator);
72 * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
74 Actor GetScrollIndicator();
77 * @copydoc Toolkit::ScrollBar::SetScrollPositionIntervals()
79 void SetScrollPositionIntervals(const Dali::Vector<float>& positions);
82 * @copydoc Toolkit::ScrollBar::GetScrollPositionIntervals()
84 Dali::Vector<float> GetScrollPositionIntervals() const;
87 * @copydoc Toolkit::ScrollBar::SetScrollDirection()
89 void SetScrollDirection(Toolkit::ScrollBar::Direction direction);
92 * @copydoc Toolkit::ScrollBar::GetScrollDirection()
94 Toolkit::ScrollBar::Direction GetScrollDirection() const;
97 * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
99 void SetIndicatorHeightPolicy(Toolkit::ScrollBar::IndicatorHeightPolicy policy);
102 * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
104 Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy() const;
107 * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
109 void SetIndicatorFixedHeight(float height);
112 * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
114 float GetIndicatorFixedHeight() const;
117 * @copydoc Toolkit::ScrollBar::SetIndicatorShowDuration()
119 void SetIndicatorShowDuration(float durationSeconds);
122 * @copydoc Toolkit::ScrollBar::GetIndicatorShowDuration()
124 float GetIndicatorShowDuration() const;
127 * @copydoc Toolkit::ScrollBar::SetIndicatorHideDuration()
129 void SetIndicatorHideDuration(float durationSeconds);
132 * @copydoc Toolkit::ScrollBar::GetIndicatorHideDuration()
134 float GetIndicatorHideDuration() const;
137 * @copydoc Toolkit::ScrollBar::ShowIndicator()
139 void ShowIndicator();
142 * @copydoc Toolkit::ScrollBar::HideIndicator()
144 void HideIndicator();
147 * @brief Shows indicator until the transient duration has expired
149 void ShowTransientIndicator();
152 * @copydoc Toolkit::ScrollBar::PanFinishedSignal()
154 PanFinishedSignalType& PanFinishedSignal()
156 return mPanFinishedSignal;
160 * @copydoc Toolkit::ScrollBar::ScrollPositionIntervalReachedSignal()
162 ScrollPositionIntervalReachedSignalType& ScrollPositionIntervalReachedSignal()
164 return mScrollPositionIntervalReachedSignal;
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);
197 * Performs actions as requested using the action name.
198 * @param[in] object The object on which to perform the action.
199 * @param[in] actionName The action to perform.
200 * @param[in] attributes The attributes with which to perfrom this action.
201 * @return true if action has been accepted by this control
203 static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
205 private: // from Control
207 * @copydoc Toolkit::Control::OnInitialize
209 void OnInitialize() override;
212 * @copydoc Toolkit::Control::OnPan
214 void OnPan(const PanGesture& gesture) override;
217 * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
219 void OnSizeSet(const Vector3& size) override;
223 * Create the default indicator actor.
225 void CreateDefaultIndicatorActor();
228 * Apply constraints for background and indicator.
229 * These constraints are based on values from the scroll connector.
231 void ApplyConstraints();
234 * Callback when the current scroll position of the scrollable content goes above or
235 * below the values specified by SetScrollPositionIntervals().
236 * @param[in] source the property notification that triggered this callback
238 void OnScrollPositionIntervalReached(PropertyNotification& source);
241 * Process the pan gesture per predefined timeout until the gesture is finished.
242 * @return True if the timer should be kept running.
244 bool OnPanGestureProcessTick();
247 * Handle SetProperty for scroll direction.
248 * @param[in] propertyValue The new property value.
250 void OnScrollDirectionPropertySet(Property::Value propertyValue);
253 * Handle SetProperty for scroll indicator height policy.
254 * @param[in] propertyValue The new property value.
256 void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
261 * It initializes ScrollBar members.
263 ScrollBar(Toolkit::ScrollBar::Direction direction);
266 * A reference counted object may only be deleted by calling Unreference()
268 virtual ~ScrollBar();
271 Actor mIndicator; ///< Image of scroll indicator.
272 float mIndicatorShowAlpha; ///< The alpha value when the indicator is fully shown
273 Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
275 Toolkit::ScrollBar::Direction mDirection; ///< The direction of scroll bar (vertical or horizontal)
277 WeakHandle<Handle> mScrollableObject; ///< Object to be scrolled
279 Property::Index mPropertyScrollPosition = 0; ///< Index of scroll position property owned by the object to be scrolled
280 Property::Index mPropertyMinScrollPosition = 0; ///< Index of minimum scroll position property owned by the object to be scrolled
281 Property::Index mPropertyMaxScrollPosition = 1; ///< Index of maximum scroll position property owned by the object to be scrolled
282 Property::Index mPropertyScrollContentSize; ///< Index of scroll content size property owned by the object to be scrolled
284 float mIndicatorShowDuration; ///< The duration of scroll indicator show animation
285 float mIndicatorHideDuration; ///< The duration of scroll indicator hide animation
286 float mTransientIndicatorDuration; ///< The duration before hiding transient indicator
288 float mScrollStart; ///< Scroll Start position (start of drag)
289 Vector2 mGestureDisplacement; ///< Gesture Displacement.
291 float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture
293 Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy; ///< The height policy of scroll indicator (variable or fixed)
294 float mIndicatorFixedHeight; ///< The fixed height of scroll indicator
295 float mIndicatorMinimumHeight; ///< The minimum height for a variable size indicator
296 float mIndicatorStartPadding; ///< The padding at the start of the indicator
297 float mIndicatorEndPadding; ///< The padding at the end of the indicator
299 Timer mContractDelayTimer; ///< Timer guarantee contract delay time.
300 Timer mPanProcessTimer; ///< The timer to process the pan gesture after the gesture is started.
302 Dali::Vector<float> mScrollPositionIntervals; ///< List of values to receive notification for when the current scroll position goes above or below them
303 PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes
305 PanFinishedSignalType mPanFinishedSignal;
306 ScrollPositionIntervalReachedSignalType mScrollPositionIntervalReachedSignal;
308 Constraint mIndicatorPositionConstraint;
309 Constraint mIndicatorSizeConstraint;
311 bool mIsPanning : 1; ///< Whether the scroll bar is being panned.
312 bool mIndicatorFirstShow : 1; ///< True if the indicator has never been shown
315 struct AccessibleImpl : public Control::Impl::AccessibleImpl,
316 public virtual Dali::Accessibility::Value
318 using Control::Impl::AccessibleImpl::AccessibleImpl;
319 double GetMinimum() override;
320 double GetCurrent() override;
321 double GetMaximum() override;
322 bool SetCurrent(double) override;
323 double GetMinimumIncrement() override;
327 } // namespace Internal
329 // Helpers for public-api forwarding methods
331 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
333 DALI_ASSERT_ALWAYS(scrollBar);
335 Dali::RefObject& handle = scrollBar.GetImplementation();
337 return static_cast<Toolkit::Internal::ScrollBar&>(handle);
340 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
342 DALI_ASSERT_ALWAYS(scrollBar);
344 const Dali::RefObject& handle = scrollBar.GetImplementation();
346 return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
349 } // namespace Toolkit
353 #endif // DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H