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-toolkit/public-api/controls/scrollable/scroll-component-impl.h>
23 #include <dali-toolkit/public-api/controls/scrollable/scroll-connector.h>
24 #include <dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h>
37 typedef IntrusivePtr<ScrollBar> ScrollBarPtr;
40 * ScrollBar is a UI component that can be added to the scrollable controls
41 * indicating the current scroll position of the scrollable content.
43 class ScrollBar : public ScrollComponentImpl
51 SCROLLBAR_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
52 SCROLLBAR_PROPERTY_END_INDEX = SCROLLBAR_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
56 typedef Toolkit::ScrollBar::ScrollPositionNotifiedSignalType ScrollPositionNotifiedSignalType;
61 * @copydoc Toolkit::ScrollBar::ScrollBar()
66 * @copydoc Toolkit::ScrollBar::~ScrollBar()
71 * @copydoc Toolkit::ScrollBar::New()
73 static Toolkit::ScrollBar New();
76 * @copydoc Toolkit::ScrollComponentImpl::OnScrollConnectorSet()
78 void OnScrollConnectorSet( Toolkit::ScrollConnector connector );
81 * @copydoc Toolkit::ScrollBar::SetIndicatorImage()
83 void SetIndicatorImage( Image image );
86 * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
88 Actor GetScrollIndicator();
91 * @copydoc Toolkit::ScrollBar::SetPositionNotifications()
93 void SetPositionNotifications( const std::vector<float>& positions );
96 * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
98 void SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy );
101 * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
103 Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy();
106 * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
108 void SetIndicatorFixedHeight( float height );
111 * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
113 float GetIndicatorFixedHeight();
116 * @copydoc Toolkit::ScrollBar::SetIndicatorShowDuration()
118 void SetIndicatorShowDuration( float durationSeconds );
121 * @copydoc Toolkit::ScrollBar::GetIndicatorShowDuration()
123 float GetIndicatorShowDuration();
126 * @copydoc Toolkit::ScrollBar::SetIndicatorHideDuration()
128 void SetIndicatorHideDuration( float durationSeconds );
131 * @copydoc Toolkit::ScrollBar::GetIndicatorHideDuration()
133 float GetIndicatorHideDuration();
136 * @copydoc Toolkit::ScrollBar::Show()
141 * @copydoc Toolkit::ScrollBar::Hide()
146 * Signal emitted after the SetScrollDomain() method has been called.
148 ScrollPositionNotifiedSignalType& ScrollPositionNotifiedSignal()
150 return mScrollPositionNotifiedSignal;
156 * Called when a property of an object of this type is set.
157 * @param[in] object The object whose property is set.
158 * @param[in] index The property index.
159 * @param[in] value The new property value.
161 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
164 * Called to retrieve a property of an object of this type.
165 * @param[in] object The object whose property is to be retrieved.
166 * @param[in] index The property index.
167 * @return The current value of the property.
169 static Property::Value GetProperty( BaseObject* object, Property::Index index );
171 private: // from Control
174 * @copydoc Toolkit::Control::OnInitialize
176 virtual void OnInitialize();
179 * @copydoc Toolkit::Control::OnPan
181 virtual void OnPan( PanGesture gesture );
186 * Apply constraints for background and indicator.
187 * These constraints are based on values from the scroll connector.
189 void ApplyConstraints();
192 * Callback when the start & end position and size of the scrollable content are changed.
193 * @param[in] minPosition The minimum position.
194 * @param[in] maxPosition The maximum position.
195 * @param[in] contentSize The size of scrollable content.
197 void OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize);
200 * Callback when the current scroll position of the scrollable content goes above or
201 * below the values specified by SetPositionNotifications().
202 * @param[in] source the property notification that triggered this callback
204 void OnScrollPositionNotified(PropertyNotification& source);
207 * Process the pan gesture per predefined timeout until the gesture is finished.
208 * @return True if the timer should be kept running.
210 bool OnPanGestureProcessTick();
213 * Handle SetProperty for scroll indicator height policy.
214 * @param[in] propertyValue The new property value.
216 void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
220 Constrainable mScrollPositionObject; ///< From mScrollConnector
222 ImageActor mBackground; ///< Background image of scroll bar.
223 ImageActor mIndicator; ///< Image of scroll indicator.
224 Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
226 float mIndicatorShowDuration; ///< The duration of scroll indicator show animation
227 float mIndicatorHideDuration; ///< The duration of scroll indicator hide animation
229 float mScrollStart; ///< Scroll Start position (start of drag)
230 Vector3 mGestureDisplacement; ///< Gesture Displacement.
232 bool mIsPanning; ///< Whether the scroll bar is being panned.
233 float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture
235 Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy; ///< The height policy of scroll indicator (variable or fixed)
236 float mIndicatorFixedHeight; ///< The fixed height of scroll indicator
238 Timer mTimer; ///< The timer to process the pan gesture after the gesture is started.
240 Property::Index mPropertyIndicatorPosition; ///< Indicatore Position ("indicator-position")
242 PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes
244 ScrollPositionNotifiedSignalType mScrollPositionNotifiedSignal;
246 ActiveConstraint mIndicatorSizeConstraint;
247 ActiveConstraint mIndicatorPositionConstraint;
250 } // namespace Internal
252 // Helpers for public-api forwarding methods
254 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
256 DALI_ASSERT_ALWAYS(scrollBar);
258 Dali::RefObject& handle = scrollBar.GetImplementation();
260 return static_cast<Toolkit::Internal::ScrollBar&>(handle);
263 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
265 DALI_ASSERT_ALWAYS(scrollBar);
267 const Dali::RefObject& handle = scrollBar.GetImplementation();
269 return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
272 } // namespace Toolkit
276 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__