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 = ControlImpl::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::SetBackgroundImage()
83 void SetBackgroundImage( Image image, const Vector4& border );
86 * @copydoc Toolkit::ScrollBar::SetIndicatorImage()
88 void SetIndicatorImage( Image image );
91 * @copydoc Toolkit::ScrollBar::SetIndicatorImage()
93 void SetIndicatorImage( Image image, const Vector4& border );
96 * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
98 Actor GetScrollIndicator();
101 * @copydoc Toolkit::ScrollBar::SetPositionNotifications()
103 void SetPositionNotifications( const std::vector<float>& positions );
106 * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
108 void SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy );
111 * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
113 Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy();
116 * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
118 void SetIndicatorFixedHeight( float height );
121 * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
123 float GetIndicatorFixedHeight();
126 * @copydoc Toolkit::ScrollBar::Show()
131 * @copydoc Toolkit::ScrollBar::Hide()
136 * Signal emitted after the SetScrollDomain() method has been called.
138 ScrollPositionNotifiedSignalType& ScrollPositionNotifiedSignal()
140 return mScrollPositionNotifiedSignal;
146 * Called when a property of an object of this type is set.
147 * @param[in] object The object whose property is set.
148 * @param[in] index The property index.
149 * @param[in] value The new property value.
151 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
154 * Called to retrieve a property of an object of this type.
155 * @param[in] object The object whose property is to be retrieved.
156 * @param[in] index The property index.
157 * @return The current value of the property.
159 static Property::Value GetProperty( BaseObject* object, Property::Index index );
161 private: // from Control
164 * @copydoc Toolkit::Control::OnInitialize
166 virtual void OnInitialize();
169 * @copydoc Toolkit::Control::OnPan
171 virtual void OnPan( PanGesture gesture );
176 * Apply constraints for background and indicator.
177 * These constraints are based on values from the scroll connector.
179 void ApplyConstraints();
182 * Callback when the start & end position and size of the scrollable content are changed.
183 * @param[in] minPosition The minimum position.
184 * @param[in] maxPosition The maximum position.
185 * @param[in] contentSize The size of scrollable content.
187 void OnScrollDomainChanged(float minPosition, float maxPosition, float contentSize);
190 * Callback when the current scroll position of the scrollable content goes above or
191 * below the values specified by SetPositionNotifications().
192 * @param[in] source the property notification that triggered this callback
194 void OnScrollPositionNotified(PropertyNotification& source);
197 * Process the pan gesture per predefined timeout until the gesture is finished.
198 * @return True if the timer should be kept running.
200 bool OnPanGestureProcessTick();
203 * Handle SetProperty for scroll indicator height policy.
204 * @param[in] propertyValue The new property value.
206 void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
210 Constrainable mScrollPositionObject; ///< From mScrollConnector
212 ImageActor mBackground; ///< Background image of scroll bar.
213 ImageActor mIndicator; ///< Image of scroll indicator.
214 Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
216 float mScrollStart; ///< Scroll Start position (start of drag)
217 Vector3 mGestureDisplacement; ///< Gesture Displacement.
219 bool mIsPanning; ///< Whether the scroll bar is being panned.
220 float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture
222 Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy; ///< The height policy of scroll indicator (variable or fixed)
223 float mIndicatorFixedHeight; ///< The fixed height of scroll indicator
225 Timer mTimer; ///< The timer to process the pan gesture after the gesture is started.
227 Property::Index mPropertyIndicatorPosition; ///< Indicatore Position ("indicator-position")
229 PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes
231 ScrollPositionNotifiedSignalType mScrollPositionNotifiedSignal;
233 ActiveConstraint mIndicatorSizeConstraint;
234 ActiveConstraint mIndicatorPositionConstraint;
237 } // namespace Internal
239 // Helpers for public-api forwarding methods
241 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
243 DALI_ASSERT_ALWAYS(scrollBar);
245 Dali::RefObject& handle = scrollBar.GetImplementation();
247 return static_cast<Toolkit::Internal::ScrollBar&>(handle);
250 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
252 DALI_ASSERT_ALWAYS(scrollBar);
254 const Dali::RefObject& handle = scrollBar.GetImplementation();
256 return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
259 } // namespace Toolkit
263 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H__