From: Richard Huang Date: Mon, 19 May 2014 16:41:00 +0000 (+0100) Subject: Added new API to set fixed height for the scroll bar X-Git-Tag: dali-2014-wk21-release~8 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=916eb39585dea4dae019b739376ee493e8fdcc63 Added new API to set fixed height for the scroll bar [problem] When fast scroll is enabled, the height of the scroll bar should be fixed. [cause] The height of scroll bar is dynamically changed according to the length of scroll content. There is no API to set fixed height for the scroll bar. [solution] Implemented new API to set fixed height for the scroll bar, so that the the height of the scroll bar will keep the same regardless of the length of scroll content. --- diff --git a/base/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp b/base/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp index 21582a0..91a49df 100755 --- a/base/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp +++ b/base/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp @@ -23,11 +23,13 @@ namespace { const char* DEFAULT_INDICATOR_IMAGE_PATH = DALI_IMAGE_DIR "popup_scroll.png"; -const Vector4 DEFAULT_INDICATOR_NINE_PATCH_BORDER(0.0f, 12.0f, 14.0f, 14.0f); +const Vector4 DEFAULT_INDICATOR_NINE_PATCH_BORDER(4.0f, 9.0f, 7.0f, 11.0f); +const float MINIMUM_INDICATOR_HEIGHT(20.0f); // The minimum indicator height for the nine patch border const float DEFAULT_SLIDER_DEPTH(1.0f); const float INDICATOR_SHOW_TIME(0.5f); const float INDICATOR_HIDE_TIME(0.5f); const float DEFAULT_PAN_GESTURE_PROCESS_TIME(16.7f); // 16.7 milliseconds, i.e. one frame +const float DEFAULT_INDICATOR_FIXED_HEIGHT(80.0f); /** * Indicator size constraint @@ -54,7 +56,7 @@ struct IndicatorSizeConstraint { const Vector3& parentSize = parentSizeProperty.GetVector3(); float height = mContentSize > parentSize.height ? parentSize.height * ( parentSize.height / mContentSize ) : parentSize.height * ( (parentSize.height - mContentSize * 0.5f) / parentSize.height); - return Vector3( parentSize.width, height, parentSize.depth ); + return Vector3( parentSize.width, std::max(MINIMUM_INDICATOR_HEIGHT, height), parentSize.depth ); } float mContentSize; ///< The size of scrollable content @@ -110,6 +112,9 @@ namespace Dali namespace Toolkit { +const Property::Index ScrollBar::PROPERTY_INDICATOR_HEIGHT_POLICY( Internal::ScrollBar::SCROLLBAR_PROPERTY_START_INDEX ); +const Property::Index ScrollBar::PROPERTY_INDICATOR_FIXED_HEIGHT( Internal::ScrollBar::SCROLLBAR_PROPERTY_START_INDEX + 1 ); + namespace Internal { @@ -118,19 +123,25 @@ namespace using namespace Dali; +const char* INDICATOR_HEIGHT_POLICY_NAME[] = {"Variable", "Fixed"}; + BaseHandle Create() { - return BaseHandle(); + return Toolkit::ScrollBar::New(); } -TypeRegistration mType( typeid(Toolkit::ScrollBar), typeid(Toolkit::Control), Create ); +TypeRegistration typeRegistration( typeid(Toolkit::ScrollBar), typeid(Toolkit::ScrollComponent), Create ); +PropertyRegistration property1( typeRegistration, "indicator-height-policy", Toolkit::ScrollBar::PROPERTY_INDICATOR_HEIGHT_POLICY, Property::STRING, &ScrollBar::SetProperty, &ScrollBar::GetProperty ); +PropertyRegistration property2( typeRegistration, "indicator-fixed-height", Toolkit::ScrollBar::PROPERTY_INDICATOR_FIXED_HEIGHT, Property::FLOAT, &ScrollBar::SetProperty, &ScrollBar::GetProperty ); } ScrollBar::ScrollBar() : mScrollStart(0.0f), mIsPanning(false), - mCurrentScrollPosition(0.0f) + mCurrentScrollPosition(0.0f), + mIndicatorHeightPolicy(Toolkit::ScrollBar::Variable), + mIndicatorFixedHeight(DEFAULT_INDICATOR_FIXED_HEIGHT) { } @@ -206,28 +217,51 @@ Actor ScrollBar::GetScrollIndicator() void ScrollBar::ApplyConstraints() { - mIndicator.RemoveConstraints(); + if( mScrollConnector ) + { + Actor self = Self(); - Constraint constraint = Constraint::New( Actor::SIZE, - ParentSource( Actor::SIZE ), - IndicatorSizeConstraint( mScrollConnector.GetContentLength() ) ); - mIndicator.ApplyConstraint( constraint ); + Constraint constraint; - constraint = Constraint::New( Actor::POSITION, - LocalSource( Actor::SIZE ), - ParentSource( Actor::SIZE ), - Source( mScrollPositionObject, Toolkit::ScrollConnector::SCROLL_POSITION ), - IndicatorPositionConstraint( mScrollConnector.GetMinLimit(), mScrollConnector.GetMaxLimit() ) ); - mIndicator.ApplyConstraint( constraint ); + if(mIndicatorSizeConstraint) + { + self.RemoveConstraint(mIndicatorSizeConstraint); + } - if( mBackground ) - { - mBackground.RemoveConstraints(); + // Set indicator height according to the indicator's height policy + if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed) + { + mIndicator.SetSize(Self().GetCurrentSize().width, mIndicatorFixedHeight); + } + else + { + constraint = Constraint::New( Actor::SIZE, + ParentSource( Actor::SIZE ), + IndicatorSizeConstraint( mScrollConnector.GetContentLength() ) ); + mIndicatorSizeConstraint = mIndicator.ApplyConstraint( constraint ); + } + + if(mIndicatorPositionConstraint) + { + self.RemoveConstraint(mIndicatorPositionConstraint); + } - constraint = Constraint::New(Actor::SIZE, - ParentSource(Actor::SIZE), - EqualToConstraint()); - mBackground.ApplyConstraint(constraint); + constraint = Constraint::New( Actor::POSITION, + LocalSource( Actor::SIZE ), + ParentSource( Actor::SIZE ), + Source( mScrollPositionObject, Toolkit::ScrollConnector::SCROLL_POSITION ), + IndicatorPositionConstraint( mScrollConnector.GetMinLimit(), mScrollConnector.GetMaxLimit() ) ); + mIndicatorPositionConstraint = mIndicator.ApplyConstraint( constraint ); + + if( mBackground ) + { + mBackground.RemoveConstraints(); + + constraint = Constraint::New(Actor::SIZE, + ParentSource(Actor::SIZE), + EqualToConstraint()); + mBackground.ApplyConstraint(constraint); + } } } @@ -359,6 +393,94 @@ void ScrollBar::OnScrollDomainChanged(float minPosition, float maxPosition, floa ApplyConstraints(); } +void ScrollBar::SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy ) +{ + mIndicatorHeightPolicy = policy; + ApplyConstraints(); +} + +Toolkit::ScrollBar::IndicatorHeightPolicy ScrollBar::GetIndicatorHeightPolicy() +{ + return mIndicatorHeightPolicy; +} + +void ScrollBar::SetIndicatorFixedHeight( float height ) +{ + mIndicatorFixedHeight = height; + ApplyConstraints(); +} + +float ScrollBar::GetIndicatorFixedHeight() +{ + return mIndicatorFixedHeight; +} + +void ScrollBar::OnIndicatorHeightPolicyPropertySet( Property::Value propertyValue ) +{ + std::string policyName( propertyValue.Get() ); + if(policyName == "Variable") + { + SetIndicatorHeightPolicy(Toolkit::ScrollBar::Variable); + } + else if(policyName == "Fixed") + { + SetIndicatorHeightPolicy(Toolkit::ScrollBar::Fixed); + } + else + { + DALI_ASSERT_ALWAYS( !"ScrollBar::OnIndicatorHeightPolicyPropertySet(). Invalid Property value." ); + } +} + +void ScrollBar::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +{ + Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( Dali::BaseHandle( object ) ); + + if( scrollBar ) + { + ScrollBar& scrollBarImpl( GetImpl( scrollBar ) ); + switch( index ) + { + case Toolkit::ScrollBar::PROPERTY_INDICATOR_HEIGHT_POLICY: + { + scrollBarImpl.OnIndicatorHeightPolicyPropertySet( value ); + break; + } + case Toolkit::ScrollBar::PROPERTY_INDICATOR_FIXED_HEIGHT: + { + scrollBarImpl.SetIndicatorFixedHeight(value.Get()); + break; + } + } + } +} + +Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index index ) +{ + Property::Value value; + + Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( Dali::BaseHandle( object ) ); + + if( scrollBar ) + { + ScrollBar& scrollBarImpl( GetImpl( scrollBar ) ); + switch( index ) + { + case Toolkit::ScrollBar::PROPERTY_INDICATOR_HEIGHT_POLICY: + { + value = INDICATOR_HEIGHT_POLICY_NAME[ scrollBarImpl.GetIndicatorHeightPolicy() ]; + break; + } + case Toolkit::ScrollBar::PROPERTY_INDICATOR_FIXED_HEIGHT: + { + value = scrollBarImpl.GetIndicatorFixedHeight(); + break; + } + } + } + return value; +} + Toolkit::ScrollBar ScrollBar::New() { // Create the implementation, temporarily owned by this handle on stack diff --git a/base/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.h b/base/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.h index 909e4fe..db26273 100755 --- a/base/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.h +++ b/base/dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.h @@ -44,6 +44,14 @@ class ScrollBar : public ScrollComponentImpl public: + // Properties + enum + { + SCROLLBAR_PROPERTY_START_INDEX = ControlImpl::CONTROL_PROPERTY_END_INDEX + 1, + SCROLLBAR_PROPERTY_END_INDEX = SCROLLBAR_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices + }; + + // Signals typedef Toolkit::ScrollBar::ScrollPositionNotifiedSignalType ScrollPositionNotifiedSignalType; public: @@ -89,6 +97,26 @@ public: void SetPositionNotifications( const std::vector& positions ); /** + * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy() + */ + void SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy ); + + /** + * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy() + */ + Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy(); + + /** + * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight() + */ + void SetIndicatorFixedHeight( float height ); + + /** + * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight() + */ + float GetIndicatorFixedHeight(); + + /** * @copydoc Toolkit::ScrollBar::Show() */ void Show(); @@ -106,6 +134,24 @@ public: return mScrollPositionNotifiedSignal; } + // Properties + + /** + * Called when a property of an object of this type is set. + * @param[in] object The object whose property is set. + * @param[in] index The property index. + * @param[in] value The new property value. + */ + static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ); + + /** + * Called to retrieve a property of an object of this type. + * @param[in] object The object whose property is to be retrieved. + * @param[in] index The property index. + * @return The current value of the property. + */ + static Property::Value GetProperty( BaseObject* object, Property::Index index ); + private: // from ControlImpl /** @@ -147,27 +193,39 @@ private: */ bool OnPanGestureProcessTick(); + /** + * Handle SetProperty for scroll indicator height policy. + * @param[in] propertyValue The new property value. + */ + void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue); + private: - Constrainable mScrollPositionObject; ///< From mScrollConnector + Constrainable mScrollPositionObject; ///< From mScrollConnector + + ImageActor mBackground; ///< Background image of scroll bar. + ImageActor mIndicator; ///< Image of scroll indicator. + Animation mAnimation; ///< Scroll indicator Show/Hide Animation. - ImageActor mBackground; ///< Background image of scroll bar. - ImageActor mIndicator; ///< Image of scroll indicator. - Animation mAnimation; ///< Scroll indicator Show/Hide Animation. + float mScrollStart; ///< Scroll Start position (start of drag) + Vector3 mGestureDisplacement; ///< Gesture Displacement. - float mScrollStart; ///< Scroll Start position (start of drag) - Vector3 mGestureDisplacement; ///< Gesture Displacement. + bool mIsPanning; ///< Whether the scroll bar is being panned. + float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture - bool mIsPanning; ///< Whether the scroll bar is being panned. - float mCurrentScrollPosition; ///< The current scroll position updated by the pan gesture + Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy; ///< The height policy of scroll indicator (variable or fixed) + float mIndicatorFixedHeight; ///< The fixed height of scroll indicator - Timer mTimer; ///< The timer to process the pan gesture after the gesture is started. + Timer mTimer; ///< The timer to process the pan gesture after the gesture is started. - Property::Index mPropertyIndicatorPosition; ///< Indicatore Position ("indicator-position") + Property::Index mPropertyIndicatorPosition; ///< Indicatore Position ("indicator-position") - PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes + PropertyNotification mPositionNotification; ///< Stores the property notification used for scroll position changes ScrollPositionNotifiedSignalType mScrollPositionNotifiedSignal; + + ActiveConstraint mIndicatorSizeConstraint; + ActiveConstraint mIndicatorPositionConstraint; }; } // namespace Internal diff --git a/base/dali-toolkit/public-api/controls/scroll-bar/scroll-bar.cpp b/base/dali-toolkit/public-api/controls/scroll-bar/scroll-bar.cpp index b0279de..94eb45e 100755 --- a/base/dali-toolkit/public-api/controls/scroll-bar/scroll-bar.cpp +++ b/base/dali-toolkit/public-api/controls/scroll-bar/scroll-bar.cpp @@ -88,6 +88,26 @@ void ScrollBar::SetPositionNotifications( const std::vector& positions ) GetImpl(*this).SetPositionNotifications(positions); } +void ScrollBar::SetIndicatorHeightPolicy( ScrollBar::IndicatorHeightPolicy policy ) +{ + GetImpl(*this).SetIndicatorHeightPolicy(policy); +} + +ScrollBar::IndicatorHeightPolicy ScrollBar::GetIndicatorHeightPolicy() +{ + return GetImpl(*this).GetIndicatorHeightPolicy(); +} + +void ScrollBar::SetIndicatorFixedHeight( float height ) +{ + GetImpl(*this).SetIndicatorFixedHeight(height); +} + +float ScrollBar::GetIndicatorFixedHeight() +{ + return GetImpl(*this).GetIndicatorFixedHeight(); +} + void ScrollBar::Show() { GetImpl(*this).Show(); diff --git a/capi/dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h b/capi/dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h index 12aa98b..d48304d 100755 --- a/capi/dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h +++ b/capi/dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h @@ -49,9 +49,22 @@ public: static const char* const SCROLL_POSITION_NOTIFIED_SIGNAL_NAME; ///< "scroll-position-notified" signal name typedef SignalV2< void ( float ) > ScrollPositionNotifiedSignalType; + // Properties + static const Property::Index PROPERTY_INDICATOR_HEIGHT_POLICY; ///< name "indicator-height-policy", type STRING + static const Property::Index PROPERTY_INDICATOR_FIXED_HEIGHT; ///< name "indicator-fixed-height", type FLOAT + public: /** + * @brief Indicator height policy. + */ + enum IndicatorHeightPolicy + { + Variable = 0, ///< Variable height changed dynamically according to the length of scroll content + Fixed ///< Fixed height regardless of the length of scroll content + }; + + /** * @brief Create an uninitialized ScrollBar; this can be initialized with ScrollBar::New() * Calling member functions with an uninitialized Dali::Object is not allowed. * or horizontally (false) @@ -120,7 +133,7 @@ public: * * @pre The scroll bar actor has been initialised. * - * The indicator indicates the current scroll position of the scrollable content. + * @return The indicator indicates the current scroll position of the scrollable content. */ Actor GetScrollIndicator(); @@ -135,6 +148,40 @@ public: void SetPositionNotifications( const std::vector& positions ); /** + * @brief Sets the height policy of scroll indicator to have either variable or fixed height. + * + * @pre The scroll bar actor has been initialised. + * + * @param[in] policy The height policy of scroll indicator + */ + void SetIndicatorHeightPolicy( IndicatorHeightPolicy policy ); + + /** + * @brief Gets the height policy of scroll indicator. + * + * @return The height policy of scroll indicator + */ + IndicatorHeightPolicy GetIndicatorHeightPolicy(); + + /** + * @brief Sets the fixed height of scroll indicator. + * Normally the height of scroll indicator is changed dynamically according to the length of scroll content. + * However, when the height policy of scroll indicator is set to be fixed, the height will keep fixed + * regardless of the length of scroll content. + * + * @pre The scroll bar actor has been initialised. + * + * @param[in] height The fixed height of the scroll indicator + */ + void SetIndicatorFixedHeight( float height ); + + /** + * @brief Gets the fix height of scroll indicator. + * @return The fixed height of the scroll indicator + */ + float GetIndicatorFixedHeight(); + + /** * @brief Shows the scroll indicator */ void Show();