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::Control::OnPan
216 void OnPan(const PanGesture& gesture) override;
219 * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
221 void OnSizeSet(const Vector3& size) override;
225 * Create the default indicator actor.
227 void CreateDefaultIndicatorActor();
230 * Apply constraints for background and indicator.
231 * These constraints are based on values from the scroll connector.
233 void ApplyConstraints();
236 * Callback when the current scroll position of the scrollable content goes above or
237 * below the values specified by SetScrollPositionIntervals().
238 * @param[in] source the property notification that triggered this callback
240 void OnScrollPositionIntervalReached(PropertyNotification& source);
243 * Process the pan gesture per predefined timeout until the gesture is finished.
244 * @return True if the timer should be kept running.
246 bool OnPanGestureProcessTick();
249 * Handle SetProperty for scroll direction.
250 * @param[in] propertyValue The new property value.
252 void OnScrollDirectionPropertySet(Property::Value propertyValue);
255 * Handle SetProperty for scroll indicator height policy.
256 * @param[in] propertyValue The new property value.
258 void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
263 * It initializes ScrollBar members.
265 ScrollBar(Toolkit::ScrollBar::Direction direction);
268 * A reference counted object may only be deleted by calling Unreference()
270 virtual ~ScrollBar();
273 Actor mIndicator; ///< Image of scroll indicator.
274 float mIndicatorShowAlpha; ///< The alpha value when the indicator is fully shown
275 Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
277 Toolkit::ScrollBar::Direction mDirection; ///< The direction of scroll bar (vertical or horizontal)
279 WeakHandle<Handle> mScrollableObject; ///< Object to be scrolled
281 Property::Index mPropertyScrollPosition = 0; ///< Index of scroll position property owned by the object to be scrolled
282 Property::Index mPropertyMinScrollPosition = 0; ///< Index of minimum scroll position property owned by the object to be scrolled
283 Property::Index mPropertyMaxScrollPosition = 1; ///< Index of maximum scroll position property owned by the object to be scrolled
284 Property::Index mPropertyScrollContentSize; ///< Index of scroll content size property owned by the object to be scrolled
286 float mIndicatorShowDuration; ///< The duration of scroll indicator show animation
287 float mIndicatorHideDuration; ///< The duration of scroll indicator hide animation
288 float mTransientIndicatorDuration; ///< The duration before hiding transient indicator
290 float mScrollStart; ///< Scroll Start position (start of drag)
291 Vector2 mGestureDisplacement; ///< Gesture Displacement.
293 float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture
295 Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy; ///< The height policy of scroll indicator (variable or fixed)
296 float mIndicatorFixedHeight; ///< The fixed height of scroll indicator
297 float mIndicatorMinimumHeight; ///< The minimum height for a variable size indicator
298 float mIndicatorStartPadding; ///< The padding at the start of the indicator
299 float mIndicatorEndPadding; ///< The padding at the end of the indicator
301 Timer mContractDelayTimer; ///< Timer guarantee contract delay time.
302 Timer mPanProcessTimer; ///< The timer to process the pan gesture after the gesture is started.
304 Dali::Vector<float> mScrollPositionIntervals; ///< List of values to receive notification for when the current scroll position goes above or below them
305 PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes
307 PanFinishedSignalType mPanFinishedSignal;
308 ScrollPositionIntervalReachedSignalType mScrollPositionIntervalReachedSignal;
310 Constraint mIndicatorPositionConstraint;
311 Constraint mIndicatorSizeConstraint;
313 bool mIsPanning : 1; ///< Whether the scroll bar is being panned.
314 bool mIndicatorFirstShow : 1; ///< True if the indicator has never been shown
317 struct AccessibleImpl : public DevelControl::ControlAccessible,
318 public virtual Dali::Accessibility::Value
320 using DevelControl::ControlAccessible::ControlAccessible;
322 double GetMinimum() const override;
323 double GetCurrent() const override;
324 double GetMaximum() const override;
325 bool SetCurrent(double) override;
326 double GetMinimumIncrement() const override;
330 } // namespace Internal
332 // Helpers for public-api forwarding methods
334 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
336 DALI_ASSERT_ALWAYS(scrollBar);
338 Dali::RefObject& handle = scrollBar.GetImplementation();
340 return static_cast<Toolkit::Internal::ScrollBar&>(handle);
343 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
345 DALI_ASSERT_ALWAYS(scrollBar);
347 const Dali::RefObject& handle = scrollBar.GetImplementation();
349 return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
352 } // namespace Toolkit
356 #endif // DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H