1 #ifndef __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__
2 #define __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__
5 * Copyright (c) 2016 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/devel-api/object/weak-handle.h>
30 #include <dali-toolkit/public-api/controls/control-impl.h>
31 #include <dali-toolkit/public-api/controls/scroll-bar/scroll-bar.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
56 typedef Toolkit::ScrollBar::PanFinishedSignalType PanFinishedSignalType;
57 typedef Toolkit::ScrollBar::ScrollPositionIntervalReachedSignalType ScrollPositionIntervalReachedSignalType;
62 * @copydoc Toolkit::ScrollBar::New()
64 static Toolkit::ScrollBar New(Toolkit::ScrollBar::Direction direction);
67 * @copydoc Toolkit::ScrollBar::SetScrollPropertySource()
69 void SetScrollPropertySource( Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize );
72 * @copydoc Toolkit::ScrollBar::SetScrollIndicator()
74 void SetScrollIndicator( Actor indicator );
77 * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
79 Actor GetScrollIndicator();
82 * @copydoc Toolkit::ScrollBar::SetScrollPositionIntervals()
84 void SetScrollPositionIntervals( const Dali::Vector<float>& positions );
87 * @copydoc Toolkit::ScrollBar::GetScrollPositionIntervals()
89 Dali::Vector<float> GetScrollPositionIntervals() const;
92 * @copydoc Toolkit::ScrollBar::SetScrollDirection()
94 void SetScrollDirection( Toolkit::ScrollBar::Direction direction );
97 * @copydoc Toolkit::ScrollBar::GetScrollDirection()
99 Toolkit::ScrollBar::Direction GetScrollDirection() const;
102 * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
104 void SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy );
107 * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
109 Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy() const;
112 * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
114 void SetIndicatorFixedHeight( float height );
117 * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
119 float GetIndicatorFixedHeight() const;
122 * @copydoc Toolkit::ScrollBar::SetIndicatorShowDuration()
124 void SetIndicatorShowDuration( float durationSeconds );
127 * @copydoc Toolkit::ScrollBar::GetIndicatorShowDuration()
129 float GetIndicatorShowDuration() const;
132 * @copydoc Toolkit::ScrollBar::SetIndicatorHideDuration()
134 void SetIndicatorHideDuration( float durationSeconds );
137 * @copydoc Toolkit::ScrollBar::GetIndicatorHideDuration()
139 float GetIndicatorHideDuration() const;
142 * @copydoc Toolkit::ScrollBar::ShowIndicator()
144 void ShowIndicator();
147 * @copydoc Toolkit::ScrollBar::HideIndicator()
149 void HideIndicator();
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 );
196 private: // from Control
199 * @copydoc Toolkit::Control::OnInitialize
201 virtual void OnInitialize();
204 * @copydoc Toolkit::Control::OnPan
206 virtual void OnPan( const PanGesture& gesture );
209 * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
211 virtual void OnSizeSet( const Vector3& size );
216 * Create the default indicator actor.
218 void CreateDefaultIndicatorActor();
221 * Apply constraints for background and indicator.
222 * These constraints are based on values from the scroll connector.
224 void ApplyConstraints();
227 * Callback when the current scroll position of the scrollable content goes above or
228 * below the values specified by SetScrollPositionIntervals().
229 * @param[in] source the property notification that triggered this callback
231 void OnScrollPositionIntervalReached(PropertyNotification& source);
234 * Process the pan gesture per predefined timeout until the gesture is finished.
235 * @return True if the timer should be kept running.
237 bool OnPanGestureProcessTick();
240 * Handle SetProperty for scroll direction.
241 * @param[in] propertyValue The new property value.
243 void OnScrollDirectionPropertySet(Property::Value propertyValue);
246 * Handle SetProperty for scroll indicator height policy.
247 * @param[in] propertyValue The new property value.
249 void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
255 * It initializes ScrollBar members.
257 ScrollBar( Toolkit::ScrollBar::Direction direction );
260 * A reference counted object may only be deleted by calling Unreference()
262 virtual ~ScrollBar();
266 Actor mIndicator; ///< Image of scroll indicator.
267 float mIndicatorShowAlpha; ///< The alpha value when the indicator is fully shown
268 Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
270 Toolkit::ScrollBar::Direction mDirection; ///< The direction of scroll bar (vertical or horizontal)
272 WeakHandleBase mScrollableObject; ///< Object to be scrolled
274 Property::Index mPropertyScrollPosition; ///< Index of scroll position property owned by the object to be scrolled
275 Property::Index mPropertyMinScrollPosition; ///< Index of minimum scroll position property owned by the object to be scrolled
276 Property::Index mPropertyMaxScrollPosition; ///< Index of maximum scroll position property owned by the object to be scrolled
277 Property::Index mPropertyScrollContentSize; ///< Index of scroll content size property owned by the object to be scrolled
279 float mIndicatorShowDuration; ///< The duration of scroll indicator show animation
280 float mIndicatorHideDuration; ///< The duration of scroll indicator hide animation
282 float mScrollStart; ///< Scroll Start position (start of drag)
283 Vector3 mGestureDisplacement; ///< Gesture Displacement.
285 float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture
287 Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy; ///< The height policy of scroll indicator (variable or fixed)
288 float mIndicatorFixedHeight; ///< The fixed height of scroll indicator
289 float mIndicatorMinimumHeight; ///< The minimum height for a variable size indicator
290 float mIndicatorStartPadding; ///< The padding at the start of the indicator
291 float mIndicatorEndPadding; ///< The padding at the end of the indicator
293 Timer mContractDelayTimer; ///< Timer guarantee contract delay time.
294 Timer mPanProcessTimer; ///< The timer to process the pan gesture after the gesture is started.
296 Dali::Vector<float> mScrollPositionIntervals; ///< List of values to receive notification for when the current scroll position goes above or below them
297 PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes
299 PanFinishedSignalType mPanFinishedSignal;
300 ScrollPositionIntervalReachedSignalType mScrollPositionIntervalReachedSignal;
302 Constraint mIndicatorPositionConstraint;
303 Constraint mIndicatorSizeConstraint;
304 Constraint mScrollPositionInCurrentAxisConstraint;
306 bool mIsPanning : 1; ///< Whether the scroll bar is being panned.
307 bool mIndicatorFirstShow : 1; ///< True if the indicator has never been shown
310 } // namespace Internal
312 // Helpers for public-api forwarding methods
314 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
316 DALI_ASSERT_ALWAYS(scrollBar);
318 Dali::RefObject& handle = scrollBar.GetImplementation();
320 return static_cast<Toolkit::Internal::ScrollBar&>(handle);
323 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
325 DALI_ASSERT_ALWAYS(scrollBar);
327 const Dali::RefObject& handle = scrollBar.GetImplementation();
329 return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
332 } // namespace Toolkit
336 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__