1 #ifndef __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__
2 #define __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__
5 * Copyright (c) 2014 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/actors/image-actor.h>
24 #include <dali/public-api/animation/animation.h>
25 #include <dali/public-api/object/property-notification.h>
28 #include <dali-toolkit/public-api/controls/scrollable/scroll-component-impl.h>
29 #include <dali-toolkit/public-api/controls/scrollable/scroll-connector.h>
30 #include <dali-toolkit/public-api/controls/scroll-bar/scroll-bar.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 ScrollComponentImpl
57 SCROLLBAR_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
58 SCROLLBAR_PROPERTY_END_INDEX = SCROLLBAR_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
62 typedef Toolkit::ScrollBar::ScrollPositionNotifiedSignalType ScrollPositionNotifiedSignalType;
67 * @copydoc Toolkit::ScrollBar::ScrollBar()
72 * @copydoc Toolkit::ScrollBar::~ScrollBar()
77 * @copydoc Toolkit::ScrollBar::New()
79 static Toolkit::ScrollBar New();
82 * @copydoc Toolkit::ScrollComponentImpl::OnScrollConnectorSet()
84 void OnScrollConnectorSet( Toolkit::ScrollConnector connector );
87 * @copydoc Toolkit::ScrollBar::SetIndicatorImage()
89 void SetIndicatorImage( Image image );
92 * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
94 Actor GetScrollIndicator();
97 * @copydoc Toolkit::ScrollBar::SetPositionNotifications()
99 void SetPositionNotifications( const std::vector<float>& positions );
102 * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
104 void SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy );
107 * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
109 Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy();
112 * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
114 void SetIndicatorFixedHeight( float height );
117 * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
119 float GetIndicatorFixedHeight();
122 * @copydoc Toolkit::ScrollBar::SetIndicatorShowDuration()
124 void SetIndicatorShowDuration( float durationSeconds );
127 * @copydoc Toolkit::ScrollBar::GetIndicatorShowDuration()
129 float GetIndicatorShowDuration();
132 * @copydoc Toolkit::ScrollBar::SetIndicatorHideDuration()
134 void SetIndicatorHideDuration( float durationSeconds );
137 * @copydoc Toolkit::ScrollBar::GetIndicatorHideDuration()
139 float GetIndicatorHideDuration();
142 * @copydoc Toolkit::ScrollBar::Show()
147 * @copydoc Toolkit::ScrollBar::Hide()
152 * Signal emitted after the SetScrollDomain() method has been called.
154 ScrollPositionNotifiedSignalType& ScrollPositionNotifiedSignal()
156 return mScrollPositionNotifiedSignal;
162 * Called when a property of an object of this type is set.
163 * @param[in] object The object whose property is set.
164 * @param[in] index The property index.
165 * @param[in] value The new property value.
167 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
170 * Called to retrieve a property of an object of this type.
171 * @param[in] object The object whose property is to be retrieved.
172 * @param[in] index The property index.
173 * @return The current value of the property.
175 static Property::Value GetProperty( BaseObject* object, Property::Index index );
177 private: // from Control
180 * @copydoc Toolkit::Control::OnInitialize
182 virtual void OnInitialize();
185 * @copydoc Toolkit::Control::OnPan
187 virtual void OnPan( PanGesture gesture );
190 * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& size )
192 virtual void OnControlSizeSet( const Vector3& size );
197 * Apply constraints for background and indicator.
198 * These constraints are based on values from the scroll connector.
200 void ApplyConstraints();
203 * Callback when the start & end position and size of the scrollable content are changed.
204 * @param[in] minPosition The minimum position.
205 * @param[in] maxPosition The maximum position.
206 * @param[in] contentSize The size of scrollable content.
208 void OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize);
211 * Callback when the current scroll position of the scrollable content goes above or
212 * below the values specified by SetPositionNotifications().
213 * @param[in] source the property notification that triggered this callback
215 void OnScrollPositionNotified(PropertyNotification& source);
218 * Process the pan gesture per predefined timeout until the gesture is finished.
219 * @return True if the timer should be kept running.
221 bool OnPanGestureProcessTick();
224 * Handle SetProperty for scroll indicator height policy.
225 * @param[in] propertyValue The new property value.
227 void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
231 Constrainable mScrollPositionObject; ///< From mScrollConnector
233 ImageActor mIndicator; ///< Image of scroll indicator.
234 Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
236 float mIndicatorShowDuration; ///< The duration of scroll indicator show animation
237 float mIndicatorHideDuration; ///< The duration of scroll indicator hide animation
239 float mScrollStart; ///< Scroll Start position (start of drag)
240 Vector3 mGestureDisplacement; ///< Gesture Displacement.
242 bool mIsPanning; ///< Whether the scroll bar is being panned.
243 float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture
245 Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy; ///< The height policy of scroll indicator (variable or fixed)
246 float mIndicatorFixedHeight; ///< The fixed height of scroll indicator
248 Timer mTimer; ///< The timer to process the pan gesture after the gesture is started.
250 Property::Index mPropertyIndicatorPosition; ///< Indicatore Position ("indicator-position")
252 PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes
254 ScrollPositionNotifiedSignalType mScrollPositionNotifiedSignal;
256 ActiveConstraint mIndicatorSizeConstraint;
257 ActiveConstraint mIndicatorPositionConstraint;
260 } // namespace Internal
262 // Helpers for public-api forwarding methods
264 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
266 DALI_ASSERT_ALWAYS(scrollBar);
268 Dali::RefObject& handle = scrollBar.GetImplementation();
270 return static_cast<Toolkit::Internal::ScrollBar&>(handle);
273 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
275 DALI_ASSERT_ALWAYS(scrollBar);
277 const Dali::RefObject& handle = scrollBar.GetImplementation();
279 return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
282 } // namespace Toolkit
286 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__