{
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
{
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
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
{
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)
{
}
void ScrollBar::ApplyConstraints()
{
- mIndicator.RemoveConstraints();
+ if( mScrollConnector )
+ {
+ Actor self = Self();
- Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
- ParentSource( Actor::SIZE ),
- IndicatorSizeConstraint( mScrollConnector.GetContentLength() ) );
- mIndicator.ApplyConstraint( constraint );
+ Constraint constraint;
- constraint = Constraint::New<Vector3>( 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<Vector3>( Actor::SIZE,
+ ParentSource( Actor::SIZE ),
+ IndicatorSizeConstraint( mScrollConnector.GetContentLength() ) );
+ mIndicatorSizeConstraint = mIndicator.ApplyConstraint( constraint );
+ }
+
+ if(mIndicatorPositionConstraint)
+ {
+ self.RemoveConstraint(mIndicatorPositionConstraint);
+ }
- constraint = Constraint::New<Vector3>(Actor::SIZE,
- ParentSource(Actor::SIZE),
- EqualToConstraint());
- mBackground.ApplyConstraint(constraint);
+ constraint = Constraint::New<Vector3>( 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<Vector3>(Actor::SIZE,
+ ParentSource(Actor::SIZE),
+ EqualToConstraint());
+ mBackground.ApplyConstraint(constraint);
+ }
}
}
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<std::string>() );
+ 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<float>());
+ 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
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:
void SetPositionNotifications( const std::vector<float>& 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();
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
/**
*/
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
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)
*
* @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();
void SetPositionNotifications( const std::vector<float>& 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();