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/control-devel.h>
31 #include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
32 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
33 #include <dali-toolkit/public-api/controls/control-impl.h>
43 typedef IntrusivePtr<ScrollBar> ScrollBarPtr;
46 * ScrollBar is a UI component that can be added to the scrollable controls
47 * indicating the current scroll position of the scrollable content.
49 class ScrollBar : public Control
53 typedef Toolkit::ScrollBar::PanFinishedSignalType PanFinishedSignalType;
54 typedef Toolkit::ScrollBar::ScrollPositionIntervalReachedSignalType ScrollPositionIntervalReachedSignalType;
58 * @copydoc Toolkit::ScrollBar::New()
60 static Toolkit::ScrollBar New(Toolkit::ScrollBar::Direction direction);
63 * @copydoc Toolkit::ScrollBar::SetScrollPropertySource()
65 void SetScrollPropertySource(Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize);
68 * @copydoc Toolkit::ScrollBar::SetScrollIndicator()
70 void SetScrollIndicator(Actor indicator);
73 * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
75 Actor GetScrollIndicator();
78 * @copydoc Toolkit::ScrollBar::SetScrollPositionIntervals()
80 void SetScrollPositionIntervals(const Dali::Vector<float>& positions);
83 * @copydoc Toolkit::ScrollBar::GetScrollPositionIntervals()
85 Dali::Vector<float> GetScrollPositionIntervals() const;
88 * @copydoc Toolkit::ScrollBar::SetScrollDirection()
90 void SetScrollDirection(Toolkit::ScrollBar::Direction direction);
93 * @copydoc Toolkit::ScrollBar::GetScrollDirection()
95 Toolkit::ScrollBar::Direction GetScrollDirection() const;
98 * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
100 void SetIndicatorHeightPolicy(Toolkit::ScrollBar::IndicatorHeightPolicy policy);
103 * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
105 Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy() const;
108 * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
110 void SetIndicatorFixedHeight(float height);
113 * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
115 float GetIndicatorFixedHeight() const;
118 * @copydoc Toolkit::ScrollBar::SetIndicatorShowDuration()
120 void SetIndicatorShowDuration(float durationSeconds);
123 * @copydoc Toolkit::ScrollBar::GetIndicatorShowDuration()
125 float GetIndicatorShowDuration() const;
128 * @copydoc Toolkit::ScrollBar::SetIndicatorHideDuration()
130 void SetIndicatorHideDuration(float durationSeconds);
133 * @copydoc Toolkit::ScrollBar::GetIndicatorHideDuration()
135 float GetIndicatorHideDuration() const;
138 * @copydoc Toolkit::ScrollBar::ShowIndicator()
140 void ShowIndicator();
143 * @copydoc Toolkit::ScrollBar::HideIndicator()
145 void HideIndicator();
148 * @brief Shows indicator until the transient duration has expired
150 void ShowTransientIndicator();
153 * @copydoc Toolkit::ScrollBar::PanFinishedSignal()
155 PanFinishedSignalType& PanFinishedSignal()
157 return mPanFinishedSignal;
161 * @copydoc Toolkit::ScrollBar::ScrollPositionIntervalReachedSignal()
163 ScrollPositionIntervalReachedSignalType& ScrollPositionIntervalReachedSignal()
165 return mScrollPositionIntervalReachedSignal;
169 * Connects a callback function with the object's signals.
170 * @param[in] object The object providing the signal.
171 * @param[in] tracker Used to disconnect the signal.
172 * @param[in] signalName The signal to connect to.
173 * @param[in] functor A newly allocated FunctorDelegate.
174 * @return True if the signal was connected.
175 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
177 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
182 * Called when a property of an object of this type is set.
183 * @param[in] object The object whose property is set.
184 * @param[in] index The property index.
185 * @param[in] value The new property value.
187 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
190 * Called to retrieve a property of an object of this type.
191 * @param[in] object The object whose property is to be retrieved.
192 * @param[in] index The property index.
193 * @return The current value of the property.
195 static Property::Value GetProperty(BaseObject* object, Property::Index index);
198 * Performs actions as requested using the action name.
199 * @param[in] object The object on which to perform the action.
200 * @param[in] actionName The action to perform.
201 * @param[in] attributes The attributes with which to perfrom this action.
202 * @return true if action has been accepted by this control
204 static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
206 private: // from Control
208 * @copydoc Toolkit::Control::OnInitialize
210 void OnInitialize() override;
213 * @copydoc Toolkit::Control::OnPan
215 void OnPan(const PanGesture& gesture) override;
218 * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
220 void OnSizeSet(const Vector3& size) override;
224 * Create the default indicator actor.
226 void CreateDefaultIndicatorActor();
229 * Apply constraints for background and indicator.
230 * These constraints are based on values from the scroll connector.
232 void ApplyConstraints();
235 * Callback when the current scroll position of the scrollable content goes above or
236 * below the values specified by SetScrollPositionIntervals().
237 * @param[in] source the property notification that triggered this callback
239 void OnScrollPositionIntervalReached(PropertyNotification& source);
242 * Process the pan gesture per predefined timeout until the gesture is finished.
243 * @return True if the timer should be kept running.
245 bool OnPanGestureProcessTick();
248 * Handle SetProperty for scroll direction.
249 * @param[in] propertyValue The new property value.
251 void OnScrollDirectionPropertySet(Property::Value propertyValue);
254 * Handle SetProperty for scroll indicator height policy.
255 * @param[in] propertyValue The new property value.
257 void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
262 * It initializes ScrollBar members.
264 ScrollBar(Toolkit::ScrollBar::Direction direction);
267 * A reference counted object may only be deleted by calling Unreference()
269 virtual ~ScrollBar();
272 Actor mIndicator; ///< Image of scroll indicator.
273 float mIndicatorShowAlpha; ///< The alpha value when the indicator is fully shown
274 Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
276 Toolkit::ScrollBar::Direction mDirection; ///< The direction of scroll bar (vertical or horizontal)
278 WeakHandle<Handle> mScrollableObject; ///< Object to be scrolled
280 Property::Index mPropertyScrollPosition = 0; ///< Index of scroll position property owned by the object to be scrolled
281 Property::Index mPropertyMinScrollPosition = 0; ///< Index of minimum scroll position property owned by the object to be scrolled
282 Property::Index mPropertyMaxScrollPosition = 1; ///< Index of maximum scroll position property owned by the object to be scrolled
283 Property::Index mPropertyScrollContentSize; ///< Index of scroll content size property owned by the object to be scrolled
285 float mIndicatorShowDuration; ///< The duration of scroll indicator show animation
286 float mIndicatorHideDuration; ///< The duration of scroll indicator hide animation
287 float mTransientIndicatorDuration; ///< The duration before hiding transient indicator
289 float mScrollStart; ///< Scroll Start position (start of drag)
290 Vector2 mGestureDisplacement; ///< Gesture Displacement.
292 float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture
294 Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy; ///< The height policy of scroll indicator (variable or fixed)
295 float mIndicatorFixedHeight; ///< The fixed height of scroll indicator
296 float mIndicatorMinimumHeight; ///< The minimum height for a variable size indicator
297 float mIndicatorStartPadding; ///< The padding at the start of the indicator
298 float mIndicatorEndPadding; ///< The padding at the end of the indicator
300 Timer mContractDelayTimer; ///< Timer guarantee contract delay time.
301 Timer mPanProcessTimer; ///< The timer to process the pan gesture after the gesture is started.
303 Dali::Vector<float> mScrollPositionIntervals; ///< List of values to receive notification for when the current scroll position goes above or below them
304 PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes
306 PanFinishedSignalType mPanFinishedSignal;
307 ScrollPositionIntervalReachedSignalType mScrollPositionIntervalReachedSignal;
309 Constraint mIndicatorPositionConstraint;
310 Constraint mIndicatorSizeConstraint;
312 bool mIsPanning : 1; ///< Whether the scroll bar is being panned.
313 bool mIndicatorFirstShow : 1; ///< True if the indicator has never been shown
316 struct AccessibleImpl : public DevelControl::AccessibleImpl,
317 public virtual Dali::Accessibility::Value
319 using DevelControl::AccessibleImpl::AccessibleImpl;
320 double GetMinimum() override;
321 double GetCurrent() override;
322 double GetMaximum() override;
323 bool SetCurrent(double) override;
324 double GetMinimumIncrement() override;
328 } // namespace Internal
330 // Helpers for public-api forwarding methods
332 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
334 DALI_ASSERT_ALWAYS(scrollBar);
336 Dali::RefObject& handle = scrollBar.GetImplementation();
338 return static_cast<Toolkit::Internal::ScrollBar&>(handle);
341 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
343 DALI_ASSERT_ALWAYS(scrollBar);
345 const Dali::RefObject& handle = scrollBar.GetImplementation();
347 return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
350 } // namespace Toolkit
354 #endif // DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H