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/active-constraint.h>
25 #include <dali/public-api/animation/animation.h>
26 #include <dali/public-api/object/property-notification.h>
29 #include <dali-toolkit/public-api/controls/scrollable/scroll-component-impl.h>
30 #include <dali-toolkit/public-api/controls/scrollable/scroll-connector.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 ScrollComponentImpl
58 SCROLLBAR_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
59 SCROLLBAR_PROPERTY_END_INDEX = SCROLLBAR_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
63 typedef Toolkit::ScrollBar::ScrollPositionNotifiedSignalType ScrollPositionNotifiedSignalType;
68 * @copydoc Toolkit::ScrollBar::ScrollBar()
73 * @copydoc Toolkit::ScrollBar::~ScrollBar()
78 * @copydoc Toolkit::ScrollBar::New()
80 static Toolkit::ScrollBar New();
83 * @copydoc Toolkit::ScrollComponentImpl::OnScrollConnectorSet()
85 void OnScrollConnectorSet( Toolkit::ScrollConnector connector );
88 * @copydoc Toolkit::ScrollBar::SetIndicatorImage()
90 void SetIndicatorImage( Image image );
93 * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
95 Actor GetScrollIndicator();
98 * @copydoc Toolkit::ScrollBar::SetPositionNotifications()
100 void SetPositionNotifications( const std::vector<float>& positions );
103 * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
105 void SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy );
108 * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
110 Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy();
113 * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
115 void SetIndicatorFixedHeight( float height );
118 * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
120 float GetIndicatorFixedHeight();
123 * @copydoc Toolkit::ScrollBar::SetIndicatorShowDuration()
125 void SetIndicatorShowDuration( float durationSeconds );
128 * @copydoc Toolkit::ScrollBar::GetIndicatorShowDuration()
130 float GetIndicatorShowDuration();
133 * @copydoc Toolkit::ScrollBar::SetIndicatorHideDuration()
135 void SetIndicatorHideDuration( float durationSeconds );
138 * @copydoc Toolkit::ScrollBar::GetIndicatorHideDuration()
140 float GetIndicatorHideDuration();
143 * @copydoc Toolkit::ScrollBar::Show()
148 * @copydoc Toolkit::ScrollBar::Hide()
153 * Signal emitted after the SetScrollDomain() method has been called.
155 ScrollPositionNotifiedSignalType& ScrollPositionNotifiedSignal()
157 return mScrollPositionNotifiedSignal;
161 * Connects a callback function with the object's signals.
162 * @param[in] object The object providing the signal.
163 * @param[in] tracker Used to disconnect the signal.
164 * @param[in] signalName The signal to connect to.
165 * @param[in] functor A newly allocated FunctorDelegate.
166 * @return True if the signal was connected.
167 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
169 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
174 * Called when a property of an object of this type is set.
175 * @param[in] object The object whose property is set.
176 * @param[in] index The property index.
177 * @param[in] value The new property value.
179 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
182 * Called to retrieve a property of an object of this type.
183 * @param[in] object The object whose property is to be retrieved.
184 * @param[in] index The property index.
185 * @return The current value of the property.
187 static Property::Value GetProperty( BaseObject* object, Property::Index index );
189 private: // from Control
192 * @copydoc Toolkit::Control::OnInitialize
194 virtual void OnInitialize();
197 * @copydoc Toolkit::Control::OnPan
199 virtual void OnPan( PanGesture gesture );
202 * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& size )
204 virtual void OnControlSizeSet( const Vector3& size );
209 * Apply constraints for background and indicator.
210 * These constraints are based on values from the scroll connector.
212 void ApplyConstraints();
215 * Callback when the start & end position and size of the scrollable content are changed.
216 * @param[in] minPosition The minimum position.
217 * @param[in] maxPosition The maximum position.
218 * @param[in] contentSize The size of scrollable content.
220 void OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize);
223 * Callback when the current scroll position of the scrollable content goes above or
224 * below the values specified by SetPositionNotifications().
225 * @param[in] source the property notification that triggered this callback
227 void OnScrollPositionNotified(PropertyNotification& source);
230 * Process the pan gesture per predefined timeout until the gesture is finished.
231 * @return True if the timer should be kept running.
233 bool OnPanGestureProcessTick();
236 * Handle SetProperty for scroll indicator height policy.
237 * @param[in] propertyValue The new property value.
239 void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
243 Handle mScrollPositionObject; ///< From mScrollConnector
245 ImageActor mIndicator; ///< Image of scroll indicator.
246 Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
248 float mIndicatorShowDuration; ///< The duration of scroll indicator show animation
249 float mIndicatorHideDuration; ///< The duration of scroll indicator hide animation
251 float mScrollStart; ///< Scroll Start position (start of drag)
252 Vector3 mGestureDisplacement; ///< Gesture Displacement.
254 bool mIsPanning; ///< Whether the scroll bar is being panned.
255 float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture
257 Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy; ///< The height policy of scroll indicator (variable or fixed)
258 float mIndicatorFixedHeight; ///< The fixed height of scroll indicator
260 Timer mTimer; ///< The timer to process the pan gesture after the gesture is started.
262 Property::Index mPropertyIndicatorPosition; ///< Indicatore Position ("indicator-position")
264 PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes
266 ScrollPositionNotifiedSignalType mScrollPositionNotifiedSignal;
268 ActiveConstraint mIndicatorSizeConstraint;
269 ActiveConstraint mIndicatorPositionConstraint;
272 } // namespace Internal
274 // Helpers for public-api forwarding methods
276 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
278 DALI_ASSERT_ALWAYS(scrollBar);
280 Dali::RefObject& handle = scrollBar.GetImplementation();
282 return static_cast<Toolkit::Internal::ScrollBar&>(handle);
285 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
287 DALI_ASSERT_ALWAYS(scrollBar);
289 const Dali::RefObject& handle = scrollBar.GetImplementation();
291 return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
294 } // namespace Toolkit
298 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__