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;
160 * Connects a callback function with the object's signals.
161 * @param[in] object The object providing the signal.
162 * @param[in] tracker Used to disconnect the signal.
163 * @param[in] signalName The signal to connect to.
164 * @param[in] functor A newly allocated FunctorDelegate.
165 * @return True if the signal was connected.
166 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
168 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
173 * Called when a property of an object of this type is set.
174 * @param[in] object The object whose property is set.
175 * @param[in] index The property index.
176 * @param[in] value The new property value.
178 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
181 * Called to retrieve a property of an object of this type.
182 * @param[in] object The object whose property is to be retrieved.
183 * @param[in] index The property index.
184 * @return The current value of the property.
186 static Property::Value GetProperty( BaseObject* object, Property::Index index );
188 private: // from Control
191 * @copydoc Toolkit::Control::OnInitialize
193 virtual void OnInitialize();
196 * @copydoc Toolkit::Control::OnPan
198 virtual void OnPan( PanGesture gesture );
201 * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& size )
203 virtual void OnControlSizeSet( const Vector3& size );
208 * Apply constraints for background and indicator.
209 * These constraints are based on values from the scroll connector.
211 void ApplyConstraints();
214 * Callback when the start & end position and size of the scrollable content are changed.
215 * @param[in] minPosition The minimum position.
216 * @param[in] maxPosition The maximum position.
217 * @param[in] contentSize The size of scrollable content.
219 void OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize);
222 * Callback when the current scroll position of the scrollable content goes above or
223 * below the values specified by SetPositionNotifications().
224 * @param[in] source the property notification that triggered this callback
226 void OnScrollPositionNotified(PropertyNotification& source);
229 * Process the pan gesture per predefined timeout until the gesture is finished.
230 * @return True if the timer should be kept running.
232 bool OnPanGestureProcessTick();
235 * Handle SetProperty for scroll indicator height policy.
236 * @param[in] propertyValue The new property value.
238 void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
242 Constrainable mScrollPositionObject; ///< From mScrollConnector
244 ImageActor mIndicator; ///< Image of scroll indicator.
245 Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
247 float mIndicatorShowDuration; ///< The duration of scroll indicator show animation
248 float mIndicatorHideDuration; ///< The duration of scroll indicator hide animation
250 float mScrollStart; ///< Scroll Start position (start of drag)
251 Vector3 mGestureDisplacement; ///< Gesture Displacement.
253 bool mIsPanning; ///< Whether the scroll bar is being panned.
254 float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture
256 Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy; ///< The height policy of scroll indicator (variable or fixed)
257 float mIndicatorFixedHeight; ///< The fixed height of scroll indicator
259 Timer mTimer; ///< The timer to process the pan gesture after the gesture is started.
261 Property::Index mPropertyIndicatorPosition; ///< Indicatore Position ("indicator-position")
263 PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes
265 ScrollPositionNotifiedSignalType mScrollPositionNotifiedSignal;
267 ActiveConstraint mIndicatorSizeConstraint;
268 ActiveConstraint mIndicatorPositionConstraint;
271 } // namespace Internal
273 // Helpers for public-api forwarding methods
275 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
277 DALI_ASSERT_ALWAYS(scrollBar);
279 Dali::RefObject& handle = scrollBar.GetImplementation();
281 return static_cast<Toolkit::Internal::ScrollBar&>(handle);
284 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
286 DALI_ASSERT_ALWAYS(scrollBar);
288 const Dali::RefObject& handle = scrollBar.GetImplementation();
290 return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
293 } // namespace Toolkit
297 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__