1 #ifndef DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H
2 #define DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H
5 * Copyright (c) 2020 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/constraint.h>
24 #include <dali/public-api/animation/animation.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/public-api/controls/control-impl.h>
31 #include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
32 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
45 typedef IntrusivePtr<ScrollBar> ScrollBarPtr;
48 * ScrollBar is a UI component that can be added to the scrollable controls
49 * indicating the current scroll position of the scrollable content.
51 class ScrollBar : public Control
57 typedef Toolkit::ScrollBar::PanFinishedSignalType PanFinishedSignalType;
58 typedef Toolkit::ScrollBar::ScrollPositionIntervalReachedSignalType ScrollPositionIntervalReachedSignalType;
63 * @copydoc Toolkit::ScrollBar::New()
65 static Toolkit::ScrollBar New(Toolkit::ScrollBar::Direction direction);
68 * @copydoc Toolkit::ScrollBar::SetScrollPropertySource()
70 void SetScrollPropertySource( Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize );
73 * @copydoc Toolkit::ScrollBar::SetScrollIndicator()
75 void SetScrollIndicator( Actor indicator );
78 * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
80 Actor GetScrollIndicator();
83 * @copydoc Toolkit::ScrollBar::SetScrollPositionIntervals()
85 void SetScrollPositionIntervals( const Dali::Vector<float>& positions );
88 * @copydoc Toolkit::ScrollBar::GetScrollPositionIntervals()
90 Dali::Vector<float> GetScrollPositionIntervals() const;
93 * @copydoc Toolkit::ScrollBar::SetScrollDirection()
95 void SetScrollDirection( Toolkit::ScrollBar::Direction direction );
98 * @copydoc Toolkit::ScrollBar::GetScrollDirection()
100 Toolkit::ScrollBar::Direction GetScrollDirection() const;
103 * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
105 void SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy );
108 * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
110 Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy() const;
113 * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
115 void SetIndicatorFixedHeight( float height );
118 * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
120 float GetIndicatorFixedHeight() const;
123 * @copydoc Toolkit::ScrollBar::SetIndicatorShowDuration()
125 void SetIndicatorShowDuration( float durationSeconds );
128 * @copydoc Toolkit::ScrollBar::GetIndicatorShowDuration()
130 float GetIndicatorShowDuration() const;
133 * @copydoc Toolkit::ScrollBar::SetIndicatorHideDuration()
135 void SetIndicatorHideDuration( float durationSeconds );
138 * @copydoc Toolkit::ScrollBar::GetIndicatorHideDuration()
140 float GetIndicatorHideDuration() const;
143 * @copydoc Toolkit::ScrollBar::ShowIndicator()
145 void ShowIndicator();
148 * @copydoc Toolkit::ScrollBar::HideIndicator()
150 void HideIndicator();
153 * @brief Shows indicator until the transient duration has expired
155 void ShowTransientIndicator();
158 * @copydoc Toolkit::ScrollBar::PanFinishedSignal()
160 PanFinishedSignalType& PanFinishedSignal()
162 return mPanFinishedSignal;
166 * @copydoc Toolkit::ScrollBar::ScrollPositionIntervalReachedSignal()
168 ScrollPositionIntervalReachedSignalType& ScrollPositionIntervalReachedSignal()
170 return mScrollPositionIntervalReachedSignal;
174 * Connects a callback function with the object's signals.
175 * @param[in] object The object providing the signal.
176 * @param[in] tracker Used to disconnect the signal.
177 * @param[in] signalName The signal to connect to.
178 * @param[in] functor A newly allocated FunctorDelegate.
179 * @return True if the signal was connected.
180 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
182 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
187 * Called when a property of an object of this type is set.
188 * @param[in] object The object whose property is set.
189 * @param[in] index The property index.
190 * @param[in] value The new property value.
192 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
195 * Called to retrieve a property of an object of this type.
196 * @param[in] object The object whose property is to be retrieved.
197 * @param[in] index The property index.
198 * @return The current value of the property.
200 static Property::Value GetProperty( BaseObject* object, Property::Index index );
203 * Performs actions as requested using the action name.
204 * @param[in] object The object on which to perform the action.
205 * @param[in] actionName The action to perform.
206 * @param[in] attributes The attributes with which to perfrom this action.
207 * @return true if action has been accepted by this control
209 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes );
211 private: // from Control
214 * @copydoc Toolkit::Control::OnInitialize
216 void OnInitialize() 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;
231 * Create the default indicator actor.
233 void CreateDefaultIndicatorActor();
236 * Apply constraints for background and indicator.
237 * These constraints are based on values from the scroll connector.
239 void ApplyConstraints();
242 * Callback when the current scroll position of the scrollable content goes above or
243 * below the values specified by SetScrollPositionIntervals().
244 * @param[in] source the property notification that triggered this callback
246 void OnScrollPositionIntervalReached(PropertyNotification& source);
249 * Process the pan gesture per predefined timeout until the gesture is finished.
250 * @return True if the timer should be kept running.
252 bool OnPanGestureProcessTick();
255 * Handle SetProperty for scroll direction.
256 * @param[in] propertyValue The new property value.
258 void OnScrollDirectionPropertySet(Property::Value propertyValue);
261 * Handle SetProperty for scroll indicator height policy.
262 * @param[in] propertyValue The new property value.
264 void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
270 * It initializes ScrollBar members.
272 ScrollBar( Toolkit::ScrollBar::Direction direction );
275 * A reference counted object may only be deleted by calling Unreference()
277 virtual ~ScrollBar();
281 Actor mIndicator; ///< Image of scroll indicator.
282 float mIndicatorShowAlpha; ///< The alpha value when the indicator is fully shown
283 Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
285 Toolkit::ScrollBar::Direction mDirection; ///< The direction of scroll bar (vertical or horizontal)
287 WeakHandle<Handle> mScrollableObject; ///< Object to be scrolled
289 Property::Index mPropertyScrollPosition = 0; ///< Index of scroll position property owned by the object to be scrolled
290 Property::Index mPropertyMinScrollPosition = 0; ///< Index of minimum scroll position property owned by the object to be scrolled
291 Property::Index mPropertyMaxScrollPosition = 1; ///< Index of maximum scroll position property owned by the object to be scrolled
292 Property::Index mPropertyScrollContentSize; ///< Index of scroll content size property owned by the object to be scrolled
294 float mIndicatorShowDuration; ///< The duration of scroll indicator show animation
295 float mIndicatorHideDuration; ///< The duration of scroll indicator hide animation
296 float mTransientIndicatorDuration; ///< The duration before hiding transient indicator
298 float mScrollStart; ///< Scroll Start position (start of drag)
299 Vector2 mGestureDisplacement; ///< Gesture Displacement.
301 float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture
303 Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy; ///< The height policy of scroll indicator (variable or fixed)
304 float mIndicatorFixedHeight; ///< The fixed height of scroll indicator
305 float mIndicatorMinimumHeight; ///< The minimum height for a variable size indicator
306 float mIndicatorStartPadding; ///< The padding at the start of the indicator
307 float mIndicatorEndPadding; ///< The padding at the end of the indicator
309 Timer mContractDelayTimer; ///< Timer guarantee contract delay time.
310 Timer mPanProcessTimer; ///< The timer to process the pan gesture after the gesture is started.
312 Dali::Vector<float> mScrollPositionIntervals; ///< List of values to receive notification for when the current scroll position goes above or below them
313 PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes
315 PanFinishedSignalType mPanFinishedSignal;
316 ScrollPositionIntervalReachedSignalType mScrollPositionIntervalReachedSignal;
318 Constraint mIndicatorPositionConstraint;
319 Constraint mIndicatorSizeConstraint;
321 bool mIsPanning : 1; ///< Whether the scroll bar is being panned.
322 bool mIndicatorFirstShow : 1; ///< True if the indicator has never been shown
325 struct AccessibleImpl : public Control::Impl::AccessibleImpl,
326 public virtual Dali::Accessibility::Value
328 using Control::Impl::AccessibleImpl::AccessibleImpl;
329 double GetMinimum() override;
330 double GetCurrent() override;
331 double GetMaximum() override;
332 bool SetCurrent( double ) override;
333 double GetMinimumIncrement() override;
337 } // namespace Internal
339 // Helpers for public-api forwarding methods
341 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
343 DALI_ASSERT_ALWAYS(scrollBar);
345 Dali::RefObject& handle = scrollBar.GetImplementation();
347 return static_cast<Toolkit::Internal::ScrollBar&>(handle);
350 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
352 DALI_ASSERT_ALWAYS(scrollBar);
354 const Dali::RefObject& handle = scrollBar.GetImplementation();
356 return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
359 } // namespace Toolkit
363 #endif // DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H