DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedBackgroundVisual", MAP, SELECTED_BACKGROUND_VISUAL )
DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledUnselectedBackgroundVisual", MAP, DISABLED_UNSELECTED_BACKGROUND_VISUAL )
DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledSelectedBackgroundVisual", MAP, DISABLED_SELECTED_BACKGROUND_VISUAL )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "labelStrutLength", INTEGER, LABEL_STRUT_LENGTH )
DALI_PROPERTY_REGISTRATION( Toolkit, Button, "labelRelativeAlignment", STRING, LABEL_RELATIVE_ALIGNMENT )
// Signals:
Button::Button()
: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
mAutoRepeatingTimer(),
- mForeGroundToLabelStrutLength( 0.0f ),
mTextLabelAlignment( END ),
mAutoRepeating( false ),
mTogglableButton( false ),
void Button::PerformFunctionOnVisualsInState( void(Button::*functionPtr)( Property::Index visualIndex), State state )
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::PerformFunctionOnVisualsInState BACKROUND visual(%d) for state (%d)\n", GET_VISUAL_INDEX_FOR_STATE[state][BACKGROUND], state );
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::PerformFunctionOnVisualsInState FOREGROUND visuals(%d) for state (%d)\n", GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND], state );
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::PerformFunctionOnVisualsInState BACKROUND visual(%d) for state (%d)\n",
+ GET_VISUAL_INDEX_FOR_STATE[state][BACKGROUND], state );
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::PerformFunctionOnVisualsInState FOREGROUND visuals(%d) for state (%d)\n",
+ GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND], state );
(this->*functionPtr)( GET_VISUAL_INDEX_FOR_STATE[state][BACKGROUND] );
(this->*functionPtr)( GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND] );
if ( Self().OnStage() )
{
- // Clear existing animation and remove visual being transitioned out before starting a new transition of visuals. ClearTransitionAnimation();
OnStateChange( mButtonState ); // Notify derived buttons
- //// When animations enabled PerformFunctionOnVisualsInState( &Button::TransitionButtonVisualOut, mPreviousButtonState );
PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState );
- // When animations enabled then call PerformFunctionOnVisualsInState( &Button::TransitionButtonVisualIn, mButtonState );
- // then StartTransitionAnimation();
- // and ClearTransitionAnimation();
+ // If animation supported then visual removal should be performed after any transition animation has completed.
PerformFunctionOnVisualsInState( &Button::OnButtonVisualRemoval, mPreviousButtonState ); // Derived button can override OnButtonVisualRemoval
}
return mTogglableButton && selected;
}
-void Button::SetAnimationTime( float animationTime )
-{
- mAnimationTime = animationTime;
-}
-
-float Button::GetAnimationTime() const
-{
- return mAnimationTime;
-}
-
void Button::SetLabelText( const std::string& label )
{
Property::Map labelProperty;
}
}
- // Notify derived button classes of the change.
- OnLabelSet( false );
-
RelayoutRequest();
}
-void Button::SetLabelStrutLength( unsigned int length )
-{
- mForeGroundToLabelStrutLength = length;
-}
-
void Button::SetLabelAlignment( Button::Align labelAlignment)
{
mTextLabelAlignment = labelAlignment;
RelayoutRequest();
}
-float Button::GetLabelStrutLength()
-{
- return mForeGroundToLabelStrutLength;
-}
-
Button::Align Button::GetLabelAlignment()
{
return mTextLabelAlignment;
}
}
-const Vector4 Button::GetUnselectedColor() const
-{
- return mUnselectedColor;
-}
-
-const Vector4 Button::GetSelectedColor() const
-{
- return mSelectedColor;
-}
-
-// Legacy code whilst Color can be set by direct Property setting ( deprecated ) instead of setting a Visual
-void Button::SetColor( const Vector4& color, Property::Index visualIndex )
-{
- if ( visualIndex == Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL )
- {
- mSelectedColor = color;
- }
- else
- {
- mUnselectedColor = color;
- }
-
- Property::Map map;
- map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR;
- map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
-
- CreateVisualsForComponent( visualIndex, map, DepthIndex::BACKGROUND );
-}
-
bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
{
bool ret = false;
if( !mClickActionPerforming )
{
mClickActionPerforming = true;
- OnButtonDown();
+ ButtonDown();
if ( !mTogglableButton )
{
mButtonPressedState = DEPRESSED;
}
- OnButtonUp();
+ ButtonUp();
mClickActionPerforming = false;
return true;
return false;
}
-void Button::OnButtonDown()
+void Button::ButtonDown()
{
if( mTogglableButton )
{
mPressedSignal.Emit( handle );
}
-void Button::OnButtonUp()
+void Button::ButtonUp()
{
if( DEPRESSED == mButtonPressedState )
{
- if( mTogglableButton )
+ bool validButtonAction = false;
+
+ if( mTogglableButton ) // Button up will change state
{
- if ( TOGGLE_DEPRESSED != mButtonPressedState )
- {
- SetSelected( !IsSelected() );
- mButtonPressedState = UNPRESSED;
- }
+ OnToggleReleased(); // Derived toggle buttons can override this to provide custom behaviour
}
else
{
- Released();
+ Released(); // Button up will result in unselected state
if( mAutoRepeating )
{
mAutoRepeatingTimer.Reset();
}
+ validButtonAction = true;
}
- // The clicked and released signals should be emitted regardless of toggle mode.
- Toolkit::Button handle( GetOwner() );
- mReleasedSignal.Emit( handle );
- mClickedSignal.Emit( handle );
+ if ( validButtonAction )
+ {
+ // The clicked and released signals should be emitted regardless of toggle mode.
+ Toolkit::Button handle( GetOwner() );
+ mReleasedSignal.Emit( handle );
+ mClickedSignal.Emit( handle );
+ }
}
}
+bool Button::OnToggleReleased()
+{
+ SetSelected( !IsSelected() );
+ mButtonPressedState = UNPRESSED;
+ return true;
+}
+
+
void Button::OnTouchPointLeave()
{
if( DEPRESSED == mButtonPressedState )
{
case PointState::DOWN:
{
- OnButtonDown();
+ ButtonDown();
break;
}
case PointState::UP:
{
- OnButtonUp();
+ ButtonUp();
break;
}
case PointState::INTERRUPTED:
{
DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout targetSize(%f,%f) ptr(%p) state[%d]\n", size.width, size.height, this, mButtonState );
- PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState );
-
- ResizePolicy::Type widthResizePolicy = Self().GetResizePolicy( Dimension::WIDTH );
- ResizePolicy::Type heightResizePolicy = Self().GetResizePolicy( Dimension::HEIGHT );
-
- DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout resize policy: width:%d height:%d\n", heightResizePolicy, widthResizePolicy);
-
Toolkit::Visual::Base currentVisual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[mButtonState][FOREGROUND] );
Toolkit::Visual::Base currentBackGroundVisual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[mButtonState][BACKGROUND] );
if( mButtonState == UNSELECTED_STATE )
{
- ClearTransitionAnimation();
ChangeState( SELECTED_STATE );
OnPressed(); // Notifies the derived class the button has been pressed.
}
if( mButtonState == SELECTED_STATE && !mTogglableButton )
{
- ClearTransitionAnimation();
ChangeState( UNSELECTED_STATE );
OnReleased(); // // Notifies the derived class the button has been released.
}
mButtonPressedState = UNPRESSED;
}
-Button::PressState Button::GetPressedState()
-{
- return mButtonPressedState;
-}
-
-Button::State Button::GetButtonState()
-{
- return mButtonState;
-}
-
void Button::SelectRequiredVisual( Property::Index visualIndex )
{
DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SelectRequiredVisual index(%d) state(%d)\n", visualIndex, mButtonState );
EnableVisual( visualIndex, true );
}
-void Button::TransitionButtonVisualOut( Property::Index visualIndex )
-{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::TransitionButtonVisualOut index(%d)\n", visualIndex);
-
- // PrepareForTranstionOut and OnTransitionOut needs to be called on visual instead of Actor once animating is possible
-}
-
-void Button::TransitionButtonVisualIn( Property::Index visualIndex )
-{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::TransitionButtonVisualIn index(%d)\n", visualIndex );
-}
-
-void Button::OnTransitionIn( Actor actor )
-{
- PerformFunctionOnVisualsInState( &Button::OnButtonVisualRemoval, mPreviousButtonState ); // Derived button can override OnButtonVisualRemoval
-}
-
void Button::RemoveVisual( Property::Index visualIndex )
{
// Use OnButtonVisualRemoval if want button developer to have the option to override removal.
RemoveVisual( visualIndex );
}
-void Button::StartTransitionAnimation()
-{
- if( mTransitionAnimation )
- {
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::StartTransitionAnimation progress(%f) duration(%f) state(%d) \n",
- mTransitionAnimation.GetCurrentProgress(), mTransitionAnimation.GetDuration(),
- mTransitionAnimation.GetState());
- mTransitionAnimation.Play();
- }
-}
-
-void Button::ClearTransitionAnimation()
-{
- if( mTransitionAnimation )
- {
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ClearTransitionAnimation progress(%f) duration(%f) state(%d) \n",
- mTransitionAnimation.GetCurrentProgress(), mTransitionAnimation.GetDuration(),
- mTransitionAnimation.GetState());
- mTransitionAnimation.Clear();
- mTransitionAnimation.Reset();
- }
-}
-
-Dali::Animation Button::GetTransitionAnimation()
-{
- if( !mTransitionAnimation )
- {
- mTransitionAnimation = Dali::Animation::New( GetAnimationTime() );
- mTransitionAnimation.FinishedSignal().Connect( this, &Button::TransitionAnimationFinished );
- }
-
- return mTransitionAnimation;
-}
-
-void Button::TransitionAnimationFinished( Dali::Animation& source )
-{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::TransitionAnimationFinished\n" );
- ClearTransitionAnimation();
- PerformFunctionOnVisualsInState( &Button::OnButtonVisualRemoval, mPreviousButtonState ); // Derived button can override OnButtonVisualRemoval
-}
-
void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
{
Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
break;
}
- case Toolkit::Button::Property::LABEL_STRUT_LENGTH:
- {
- GetImplementation( button ).SetLabelStrutLength( value.Get< int >() );
- break;
- }
-
case Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT:
{
Button::Align labelAlignment(END);
////////////////////////////////////////////////////////////////////////
// Legacy functions from Tizen 2.4 and 3.0
+// Legacy code needed whilst Color can be set by direct Property setting ( deprecated ) instead of setting a Visual
+void Button::SetColor( const Vector4& color, Property::Index visualIndex )
+{
+ if ( visualIndex == Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL )
+ {
+ mSelectedColor = color;
+ }
+ else
+ {
+ mUnselectedColor = color;
+ }
+
+ Property::Map map;
+ map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR;
+ map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
+
+ CreateVisualsForComponent( visualIndex, map, DepthIndex::BACKGROUND );
+}
+
+const Vector4 Button::GetUnselectedColor() const
+{
+ return mUnselectedColor;
+}
+
+const Vector4 Button::GetSelectedColor() const
+{
+ return mSelectedColor;
+}
+
+void Button::SetAnimationTime( float animationTime )
+{
+ // Used by depreciated API
+ mAnimationTime = animationTime;
+}
+
+float Button::GetAnimationTime() const
+{
+ // Used by depreciated API
+ return mAnimationTime;
+}
+
void Button::SetLabel( Actor label )
{
if ( label )
/**
* Button press state which is not the same as the actual button's state.
- * A button can be DEPRESSED but the until released the button state may have not changed,
- * For example DEPRESSING a toggle button that is already in the SELECTED state will not change the button state untill released.
+ * For example An UNSELECTED button can be DEPRESSED, but until released, the actual button state doesn't change to SELECTED
*/
enum PressState
{
bool DoClickAction( const Property::Map& attributes );
/**
- * This method is called when the label is set.
- * @param[in] noPadding Used to bypass padding if the label is to be treated generically.
- */
- virtual void OnLabelSet( bool noPadding ) {}
-
- /**
- * This method is called when the unselected button image is set
- */
- virtual void OnUnselectedImageSet() {}
-
- /**
- * This method is called when the selected image is set
- */
- virtual void OnSelectedImageSet() {}
-
- /**
- * This method is called when the background image is set
- */
- virtual void OnBackgroundImageSet() {}
-
- /**
- * This method is called when the selected background image is set
- */
- virtual void OnSelectedBackgroundImageSet() {}
-
- /**
- * This method is called when the disabled button image is set
- */
- virtual void OnDisabledImageSet() {}
-
- /**
- * This method is called when the disabled selected image is set
- */
- virtual void OnDisabledSelectedImageSet() {}
-
- /**
- * This method is called when the disabled background image is set
- */
- virtual void OnDisabledBackgroundImageSet() {}
-
- /**
- * This method is called the button is down.
- * Could be reimplemented in subclasses to provide specific behaviour.
- */
- virtual void OnButtonDown();
-
- /**
- * This method is called when the button is up.
+ * This method is called when the button is a Toggle button and released
* Could be reimplemented in subclasses to provide specific behaviour.
+ * @return bool returns true if state changed.
*/
- virtual void OnButtonUp();
+ virtual bool OnToggleReleased();
/**
* This method is called when touch leaves the boundary of the button or several touch points are received.
void Pressed();
/**
+ * This method is called the button is down.
+ */
+ void ButtonDown();
+
+ /**
+ * This method is called when the button is up.
+ */
+ void ButtonUp();
+
+ /**
* Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer.
*/
bool AutoRepeatingSlot();
void PerformFunctionOnVisualsInState( void(Button::*functionPtr)( Property::Index visualIndex), State state );
/**
- * Transition the visual in or out using the set animation
- * @param[in] state State to transition in or out
- */
- void SetVisualsForTransition( State state );
-
- /**
* Changes the button state when an action occurs on it
* @param[in] requestedState the state to change to
*/
Padding GetForegroundPadding();
/**
- * @brief Get the pressed state of the button
- * @return ButtonPressedState the state the button is in
- */
- PressState GetPressedState();
-
- /**
- * @brief Get the state of the button
- * @return PaintState the state the button is in
- */
- State GetButtonState();
-
- /**
* @brief Setup the button components for example foregrounds and background
* @param[in] index the index of the visual to set
* @param[in] value the value to set on the component
Dali::Animation GetTransitionAnimation();
/**
- * @brief Set distance between label and foreground/icon, if both present
- * @param[in] length length of strut
- */
- void SetLabelStrutLength( unsigned int length );
-
- /**
* @brief Set the position of the label relative to foreground/icon, if both present
* @param[in] labelAlignment given alignment setting
*/
void SetLabelAlignment( Align labelAlignment);
/**
- * @brief Get set distance between label and foreground/icon visual
- * @return length of strut
- */
- float GetLabelStrutLength();
-
- /**
* @brief Get set alignment of label in relation to foreground/icon
* @return Set alignment value
*/
Align GetLabelAlignment();
/**
- * Prepares the actor to be transitioned in.
- * @param[in] actor The actor that will be transitioned in.
- */
- virtual void PrepareForTransitionIn( Actor actor ) {}
-
- /**
- * Prepares the actor to be transitioned in.
- * @param[in] actor The actor that will be transitioned out.
- */
- virtual void PrepareForTransitionOut( Actor actor ) {}
-
- /**
- * Transitions the actor in, allowing derived classes to configure
- * the GetTransitionAnimation() animation ready.
- * Button is in charge of calling Dali::Animation::Play and so derived classes
- * only need to add the animation.
- */
- virtual void OnTransitionIn( Actor actor );
-
- /**
- * Transitions the actor out, allowing derived classes to configure
- * the GetTransitionAnimation() animation ready.
- * Button is in charge of calling Dali::Animation::Play and so derived classes
- * only need to add the animation.
- */
- virtual void OnTransitionOut( Actor actor ) {}
-
- /**
* Removes the visual from the button (un-staged)
* If the derived button does not want the visual removed then use this virtual function to
* define the required behaviour.
private:
/**
- * Starts the transition animation.
- * Button::TransitionFinished is called when the animation finishes.
- */
- void StartTransitionAnimation();
-
- /**
- * This method stops and clears animations
- */
- void ClearTransitionAnimation();
-
- /**
- * Called when the transition animation finishes.
- */
- void TransitionAnimationFinished( Dali::Animation& source );
-
- /**
- * Transition button visual using an animation before removal from Stage
- */
- void TransitionButtonVisualOut( Property::Index visualIndex );
-
- /**
- * Transition button visual using an animation before adding to Stage
- */
- void TransitionButtonVisualIn( Property::Index visualIndex );
-
- /**
* Removes the visual from the button and prepares it to be transitioned out
* @param[in] visualIndex the visual to remove
*/
Padding mLabelPadding; ///< The padding around the label (if present).
Padding mForegroundPadding; ///< The padding around the foreground/icon visual (if present).
- unsigned int mForeGroundToLabelStrutLength; ///< Distance between foreground/icon and label.
Align mTextLabelAlignment; ///< Position of text label in relation to foreground/icon when both are present.
- Animation mTransitionAnimation; ///< Used in the state transitions.
-
TapGestureDetector mTapDetector;
Vector4 mUnselectedColor;