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 );
192 * Apply constraints for background and indicator.
193 * These constraints are based on values from the scroll connector.
195 void ApplyConstraints();
198 * Callback when the start & end position and size of the scrollable content are changed.
199 * @param[in] minPosition The minimum position.
200 * @param[in] maxPosition The maximum position.
201 * @param[in] contentSize The size of scrollable content.
203 void OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize);
206 * Callback when the current scroll position of the scrollable content goes above or
207 * below the values specified by SetPositionNotifications().
208 * @param[in] source the property notification that triggered this callback
210 void OnScrollPositionNotified(PropertyNotification& source);
213 * Process the pan gesture per predefined timeout until the gesture is finished.
214 * @return True if the timer should be kept running.
216 bool OnPanGestureProcessTick();
219 * Handle SetProperty for scroll indicator height policy.
220 * @param[in] propertyValue The new property value.
222 void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
226 Constrainable mScrollPositionObject; ///< From mScrollConnector
228 ImageActor mBackground; ///< Background image of scroll bar.
229 ImageActor mIndicator; ///< Image of scroll indicator.
230 Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
232 float mIndicatorShowDuration; ///< The duration of scroll indicator show animation
233 float mIndicatorHideDuration; ///< The duration of scroll indicator hide animation
235 float mScrollStart; ///< Scroll Start position (start of drag)
236 Vector3 mGestureDisplacement; ///< Gesture Displacement.
238 bool mIsPanning; ///< Whether the scroll bar is being panned.
239 float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture
241 Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy; ///< The height policy of scroll indicator (variable or fixed)
242 float mIndicatorFixedHeight; ///< The fixed height of scroll indicator
244 Timer mTimer; ///< The timer to process the pan gesture after the gesture is started.
246 Property::Index mPropertyIndicatorPosition; ///< Indicatore Position ("indicator-position")
248 PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes
250 ScrollPositionNotifiedSignalType mScrollPositionNotifiedSignal;
252 ActiveConstraint mIndicatorSizeConstraint;
253 ActiveConstraint mIndicatorPositionConstraint;
256 } // namespace Internal
258 // Helpers for public-api forwarding methods
260 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
262 DALI_ASSERT_ALWAYS(scrollBar);
264 Dali::RefObject& handle = scrollBar.GetImplementation();
266 return static_cast<Toolkit::Internal::ScrollBar&>(handle);
269 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
271 DALI_ASSERT_ALWAYS(scrollBar);
273 const Dali::RefObject& handle = scrollBar.GetImplementation();
275 return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
278 } // namespace Toolkit
282 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__