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 Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali-toolkit/public-api/controls/scrollable/scroll-component-impl.h>
22 #include <dali-toolkit/public-api/controls/scrollable/scroll-connector.h>
23 #include <dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h>
36 typedef IntrusivePtr<ScrollBar> ScrollBarPtr;
39 * ScrollBar is a UI component that can be added to the scrollable controls
40 * indicating the current scroll position of the scrollable content.
42 class ScrollBar : public ScrollComponentImpl
50 SCROLLBAR_PROPERTY_START_INDEX = ControlImpl::CONTROL_PROPERTY_END_INDEX + 1,
51 SCROLLBAR_PROPERTY_END_INDEX = SCROLLBAR_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
55 typedef Toolkit::ScrollBar::ScrollPositionNotifiedSignalType ScrollPositionNotifiedSignalType;
60 * @copydoc Toolkit::ScrollBar::ScrollBar()
65 * @copydoc Toolkit::ScrollBar::~ScrollBar()
70 * @copydoc Toolkit::ScrollBar::New()
72 static Toolkit::ScrollBar New();
75 * @copydoc Toolkit::ScrollComponentImpl::OnScrollConnectorSet()
77 void OnScrollConnectorSet( Toolkit::ScrollConnector connector );
80 * @copydoc Toolkit::ScrollBar::SetBackgroundImage()
82 void SetBackgroundImage( Image image, const Vector4& border );
85 * @copydoc Toolkit::ScrollBar::SetIndicatorImage()
87 void SetIndicatorImage( Image image, const Vector4& border );
90 * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
92 Actor GetScrollIndicator();
95 * @copydoc Toolkit::ScrollBar::SetPositionNotifications()
97 void SetPositionNotifications( const std::vector<float>& positions );
100 * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
102 void SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy );
105 * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
107 Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy();
110 * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
112 void SetIndicatorFixedHeight( float height );
115 * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
117 float GetIndicatorFixedHeight();
120 * @copydoc Toolkit::ScrollBar::Show()
125 * @copydoc Toolkit::ScrollBar::Hide()
130 * Signal emitted after the SetScrollDomain() method has been called.
132 ScrollPositionNotifiedSignalType& ScrollPositionNotifiedSignal()
134 return mScrollPositionNotifiedSignal;
140 * Called when a property of an object of this type is set.
141 * @param[in] object The object whose property is set.
142 * @param[in] index The property index.
143 * @param[in] value The new property value.
145 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
148 * Called to retrieve a property of an object of this type.
149 * @param[in] object The object whose property is to be retrieved.
150 * @param[in] index The property index.
151 * @return The current value of the property.
153 static Property::Value GetProperty( BaseObject* object, Property::Index index );
155 private: // from ControlImpl
158 * @copydoc Toolkit::Control::OnInitialize
160 virtual void OnInitialize();
163 * @copydoc Toolkit::Control::OnPan
165 virtual void OnPan( PanGesture gesture );
170 * Apply constraints for background and indicator.
171 * These constraints are based on values from the scroll connector.
173 void ApplyConstraints();
176 * Callback when the start & end position and size of the scrollable content are changed.
177 * @param[in] minPosition The minimum position.
178 * @param[in] maxPosition The maximum position.
179 * @param[in] contentSize The size of scrollable content.
181 void OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize);
184 * Callback when the current scroll position of the scrollable content goes above or
185 * below the values specified by SetPositionNotifications().
186 * @param[in] source the property notification that triggered this callback
188 void OnScrollPositionNotified(PropertyNotification& source);
191 * Process the pan gesture per predefined timeout until the gesture is finished.
192 * @return True if the timer should be kept running.
194 bool OnPanGestureProcessTick();
197 * Handle SetProperty for scroll indicator height policy.
198 * @param[in] propertyValue The new property value.
200 void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
204 Constrainable mScrollPositionObject; ///< From mScrollConnector
206 ImageActor mBackground; ///< Background image of scroll bar.
207 ImageActor mIndicator; ///< Image of scroll indicator.
208 Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
210 float mScrollStart; ///< Scroll Start position (start of drag)
211 Vector3 mGestureDisplacement; ///< Gesture Displacement.
213 bool mIsPanning; ///< Whether the scroll bar is being panned.
214 float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture
216 Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy; ///< The height policy of scroll indicator (variable or fixed)
217 float mIndicatorFixedHeight; ///< The fixed height of scroll indicator
219 Timer mTimer; ///< The timer to process the pan gesture after the gesture is started.
221 Property::Index mPropertyIndicatorPosition; ///< Indicatore Position ("indicator-position")
223 PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes
225 ScrollPositionNotifiedSignalType mScrollPositionNotifiedSignal;
227 ActiveConstraint mIndicatorSizeConstraint;
228 ActiveConstraint mIndicatorPositionConstraint;
231 } // namespace Internal
233 // Helpers for public-api forwarding methods
235 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
237 DALI_ASSERT_ALWAYS(scrollBar);
239 Dali::RefObject& handle = scrollBar.GetImplementation();
241 return static_cast<Toolkit::Internal::ScrollBar&>(handle);
244 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
246 DALI_ASSERT_ALWAYS(scrollBar);
248 const Dali::RefObject& handle = scrollBar.GetImplementation();
250 return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
253 } // namespace Toolkit
257 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__