// EXTERNAL INCLUDES
#include <cstring> // for strcmp
+#include <dali/devel-api/scripting/enum-helper.h>
+#include <dali/integration-api/debug.h>
#include <dali/public-api/events/touch-data.h>
#include <dali/public-api/images/resource-image.h>
#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/size-negotiation/relayout-container.h>
#include <dali/devel-api/scripting/scripting.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
#include <dali-toolkit/public-api/controls/image-view/image-view.h>
#include <dali-toolkit/public-api/visuals/color-visual-properties.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
+#include <dali-toolkit/public-api/visuals/image-visual-properties.h>
+#include <dali-toolkit/devel-api/align-enums.h>
+#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
#include <dali-toolkit/devel-api/visual-factory/devel-visual-properties.h>
#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
-/**
- * Button states and contents
- * (3) mSelectedContent
- * (2) mUnselectedContent (2) mSelectedBackgroundContent
- * (1) mBackgroundContent (1) mBackgroundContent
- * < unselected > ----------------------- < selected >
- * | OnSelect() |
- * | OnDisabled() | OnDisabled()
- * | |
- * < disabled > < disabled-selected >
- * (2) mDisabledContent (2) mDisabledSelectedContent
- * (1) mDisabledBackgroundContent (1) mDisabledBackgroundContent
- *
- * The drawing order of child actors is as follows.
- *
- * Top mLabel
- * | mUnselectedContent / mSelectedContent / mDisabledContent / mDisabledSelectedContent
- * | mSelectedBackgroundContent
- * Bottom mBackgroundContent / mDisabledBackgroundContent
- *
- * Some of contents may be missed.
- * And 2 images - fade-in image and fade-out image - in the same layer can be shown during the transition animation. Fade-in image should be above fade-out image.
- */
+#if defined(DEBUG_ENABLED)
+ Debug::Filter* gLogButtonFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_BUTTON_CONTROL");
+#endif
namespace Dali
{
}
// Setup properties, signals and actions using the type-registry.
-DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Button, Toolkit::Control, Create );
-
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled", BOOLEAN, DISABLED )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "autoRepeating", BOOLEAN, AUTO_REPEATING )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initialAutoRepeatingDelay", FLOAT, INITIAL_AUTO_REPEATING_DELAY )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "nextAutoRepeatingDelay", FLOAT, NEXT_AUTO_REPEATING_DELAY )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "togglable", BOOLEAN, TOGGLABLE )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected", BOOLEAN, SELECTED )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedStateImage", STRING, UNSELECTED_STATE_IMAGE )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedStateImage", STRING, SELECTED_STATE_IMAGE )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledStateImage", STRING, DISABLED_STATE_IMAGE )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedColor", VECTOR4, UNSELECTED_COLOR )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedColor", VECTOR4, SELECTED_COLOR )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label", MAP, LABEL )
-
-// Deprecated properties:
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "labelText", STRING, LABEL_TEXT )
+DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Button, Toolkit::Control, Create )
+
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled", BOOLEAN, DISABLED )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "autoRepeating", BOOLEAN, AUTO_REPEATING )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initialAutoRepeatingDelay", FLOAT, INITIAL_AUTO_REPEATING_DELAY )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "nextAutoRepeatingDelay", FLOAT, NEXT_AUTO_REPEATING_DELAY )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "togglable", BOOLEAN, TOGGLABLE )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected", BOOLEAN, SELECTED )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedStateImage", MAP, UNSELECTED_STATE_IMAGE ) // Deprecated property
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedStateImage", MAP, SELECTED_STATE_IMAGE ) // Deprecated property
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledStateImage", MAP, DISABLED_STATE_IMAGE ) // Deprecated property
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedColor", VECTOR4, UNSELECTED_COLOR ) // Deprecated property
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedColor", VECTOR4, SELECTED_COLOR ) // Deprecated property
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label", MAP, LABEL )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "labelText", STRING, LABEL_TEXT ) // Deprecated property
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedVisual", MAP, UNSELECTED_VISUAL )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedVisual", MAP, SELECTED_VISUAL )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledSelectedVisual", MAP, DISABLED_SELECTED_VISUAL )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledUnselectedVisual", MAP, DISABLED_UNSELECTED_VISUAL )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedBackgroundVisual", MAP, UNSELECTED_BACKGROUND_VISUAL )
+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, "labelRelativeAlignment", STRING, LABEL_RELATIVE_ALIGNMENT )
// Signals:
DALI_SIGNAL_REGISTRATION( Toolkit, Button, "pressed", SIGNAL_PRESSED )
DALI_TYPE_REGISTRATION_END()
-const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
-const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
+DALI_ENUM_TO_STRING_TABLE_BEGIN( ALIGNMENT )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, BEGIN )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, END )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, TOP )
+DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, BOTTOM )
+DALI_ENUM_TO_STRING_TABLE_END( ALIGNMENT )
+
+const Scripting::StringEnum ALIGNMENT_STRING_TABLE[] =
+{
+ { "BEGIN", Button::BEGIN },
+ { "END", Button::END },
+ { "TOP", Button::TOP },
+ { "BOTTOM", Button::BOTTOM },
+};
+
+const unsigned int ALIGNMENT_STRING_TABLE_COUNT = sizeof( ALIGNMENT_STRING_TABLE ) / sizeof( ALIGNMENT_STRING_TABLE[0] );
+
+const Property::Index GET_VISUAL_INDEX_FOR_STATE[][Button::STATE_COUNT] =
+{
+ { Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::UNSELECTED_VISUAL },
+ { Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::SELECTED_VISUAL },
+ { Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL },
+ { Toolkit::Button::Property::DISABLED_SELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::DISABLED_SELECTED_VISUAL }
+};
} // unnamed namespace
Button::Button()
: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
mAutoRepeatingTimer(),
- mUnselectedColor( Color::WHITE ), // The natural colors of the specified images will be used by default.
- mSelectedColor( Color::WHITE ),
- mDisabled( false ),
+ mTextLabelAlignment( END ),
mAutoRepeating( false ),
mTogglableButton( false ),
- mSelected( false ),
- mInitialAutoRepeatingDelay( INITIAL_AUTOREPEATING_DELAY ),
- mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ),
+ mInitialAutoRepeatingDelay( 0.0f ),
+ mNextAutoRepeatingDelay( 0.0f ),
mAnimationTime( 0.0f ),
- mClickActionPerforming( false ),
- mState( ButtonUp ),
- mPaintState( UnselectedState )
+ mButtonPressedState( UNPRESSED ),
+ mButtonState( UNSELECTED_STATE ),
+ mPreviousButtonState( mButtonState ),
+ mClickActionPerforming( false )
{
}
{
}
-void Button::SetDisabled( bool disabled )
-{
- if( disabled == mDisabled )
- {
- return;
- }
-
- StopTransitionAnimation();
-
- mDisabled = disabled;
-
- // Notifies the derived class the button has been disabled.
- OnDisabled();
-
- switch( mPaintState )
- {
- case UnselectedState:
- {
- //Layer Order
- //(3) mDisabledContent (Inserted)
- //(4) mUnselectedContent
- //(2) mDisabledBackgroundContent (Inserted)
- //(1) mBackgroundContent
-
- AddButtonImage( mBackgroundContent );
- TransitionButtonImage( mDisabledBackgroundContent );
- AddButtonImage( mUnselectedContent );
- TransitionButtonImage( mDisabledContent );
-
- AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
- ReAddLabel();
-
- TransitionOut( mDecoration[ SELECTED_DECORATION ] );
- TransitionOut( mUnselectedContent );
- TransitionOut( mSelectedContent );
- TransitionOut( mBackgroundContent );
- TransitionOut( mSelectedBackgroundContent );
- TransitionOut( mDisabledSelectedContent );
-
- mPaintState = DisabledUnselectedState;
- break;
- }
- case SelectedState:
- {
- //Layer Order
- //(5) mDisabledSelectedContent (Inserted)
- //(4) mSelectedContent
- //(3) mDisabledBackgroundContent (Inserted)
- //(2) mSelectedBackgroundContent
- //(1) mBackgroundContent
-
- AddButtonImage( mBackgroundContent );
- AddButtonImage( mSelectedBackgroundContent );
- TransitionButtonImage( mDisabledBackgroundContent );
- AddButtonImage( mSelectedContent );
- TransitionButtonImage( mDisabledSelectedContent );
-
- AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
- ReAddLabel();
-
- TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
- TransitionOut( mUnselectedContent );
- TransitionOut( mSelectedContent );
- TransitionOut( mBackgroundContent );
- TransitionOut( mSelectedBackgroundContent );
- TransitionOut( mDisabledContent );
-
- mPaintState = DisabledSelectedState;
- break;
- }
- case DisabledUnselectedState:
- {
- //Layer Order
- //(3) mUnselectedContent (Inserted)
- //(4) mDisabledContent
- //(2) mBackgroundContent (Inserted)
- //(1) mDisabledBackgroundContent
-
- AddButtonImage( mDisabledBackgroundContent );
- TransitionButtonImage( mBackgroundContent );
- AddButtonImage( mDisabledContent );
- TransitionButtonImage( mUnselectedContent );
-
- AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
- ReAddLabel();
-
- TransitionOut( mDecoration[ SELECTED_DECORATION ] );
- TransitionOut( mSelectedContent );
- TransitionOut( mSelectedBackgroundContent );
- TransitionOut( mDisabledContent );
- TransitionOut( mDisabledSelectedContent );
- TransitionOut( mDisabledBackgroundContent );
-
- mPaintState = UnselectedState;
- break;
- }
- case DisabledSelectedState:
- {
- //Layer Order
- //(4) mSelectedContent (Inserted)
- //(5) mDisabledSelectedContent
- //(3) mSelectedBackgroundContent (Inserted)
- //(2) mBackgroundContent (Inserted)
- //(1) mDisabledBackgroundContent
-
- AddButtonImage( mDisabledBackgroundContent );
- TransitionButtonImage( mBackgroundContent );
- TransitionButtonImage( mSelectedBackgroundContent );
- AddButtonImage( mDisabledSelectedContent );
- TransitionButtonImage( mSelectedContent );
-
- AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
- ReAddLabel();
-
- TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
- TransitionOut( mUnselectedContent );
- TransitionOut( mDisabledContent );
- TransitionOut( mDisabledSelectedContent );
- TransitionOut( mDisabledBackgroundContent );
-
- mPaintState = SelectedState;
- break;
- }
- }
-
- StartTransitionAnimation();
-}
-
-bool Button::IsDisabled() const
-{
- return mDisabled;
-}
-
void Button::SetAutoRepeating( bool autoRepeating )
{
mAutoRepeating = autoRepeating;
{
mTogglableButton = false;
- if( mSelected )
+ if( IsSelected() )
{
- // Emit a signal is not wanted, only change the appearance.
- SetSelected( false, false );
+ SetSelected( false );
}
}
}
void Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
{
- DALI_ASSERT_ALWAYS( initialAutoRepeatingDelay > 0.f );
+ DALI_ASSERT_DEBUG( initialAutoRepeatingDelay > 0.f );
mInitialAutoRepeatingDelay = initialAutoRepeatingDelay;
}
void Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
{
- DALI_ASSERT_ALWAYS( nextAutoRepeatingDelay > 0.f );
+ DALI_ASSERT_DEBUG( nextAutoRepeatingDelay > 0.f );
mNextAutoRepeatingDelay = nextAutoRepeatingDelay;
}
{
mTogglableButton = togglable;
- // A togglable button can't be an autorepeating button.
+ // A toggle button can't be an autorepeating button.
if( togglable )
{
mAutoRepeating = false;
void Button::SetSelected( bool selected )
{
- if( !mDisabled && mTogglableButton && ( selected != mSelected ) )
+ if( mTogglableButton )
{
- SetSelected( selected, true );
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetSelected (%s)\n", (selected?"true":"false") );
+
+ if ( selected && ( mButtonState != SELECTED_STATE ) )
+ {
+ ChangeState( SELECTED_STATE );
+ }
+ else if ( !selected && ( mButtonState != UNSELECTED_STATE ) )
+ {
+ ChangeState( UNSELECTED_STATE );
+ }
}
}
-void Button::SetSelected( bool selected, bool emitSignal )
+void Button::SetDisabled( bool disabled )
{
- StopTransitionAnimation();
-
- mSelected = selected;
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetDisabled(%s) state(%d)\n", (disabled)?"disabled":"active", mButtonState );
- // Notifies the derived class the button has been selected.
- OnSelected();
-
- switch( mPaintState )
+ if ( disabled )
{
- case UnselectedState:
+ if ( mButtonState == SELECTED_STATE )
{
- //Layer Order
- //(3) mSelectedContent (Inserted)
- //(4) mUnselectedContent
- //(2) mSelectedBackgroundContent (Inserted)
- //(1) mBackgroundContent
-
- AddButtonImage( mBackgroundContent );
- TransitionButtonImage( mSelectedBackgroundContent );
- AddButtonImage( mUnselectedContent );
- TransitionButtonImage( mSelectedContent );
-
- AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
- TransitionButtonImage( mDecoration[ SELECTED_DECORATION ] );
- ReAddLabel();
-
- TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
- TransitionOut( mUnselectedContent );
- TransitionOut( mDisabledContent );
- TransitionOut( mDisabledSelectedContent );
- TransitionOut( mDisabledBackgroundContent );
-
- mPaintState = SelectedState;
- break;
+ ChangeState( DISABLED_SELECTED_STATE );
}
- case SelectedState:
+ else if ( mButtonState == UNSELECTED_STATE )
{
- //Layer Order
- //(3) mUnselectedContent (Inserted)
- //(2) mSelectedContent
- //(1) mBackgroundContent
-
- AddButtonImage( mBackgroundContent );
- AddButtonImage( mSelectedContent );
- TransitionButtonImage( mUnselectedContent );
-
- AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
- TransitionButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
- ReAddLabel();
-
- TransitionOut( mDecoration[ SELECTED_DECORATION ] );
- TransitionOut( mSelectedContent );
- TransitionOut( mSelectedBackgroundContent );
- TransitionOut( mDisabledContent );
- TransitionOut( mDisabledSelectedContent );
- TransitionOut( mDisabledBackgroundContent );
-
- mPaintState = UnselectedState;
- break;
+ ChangeState( DISABLED_UNSELECTED_STATE );
+ }
+ }
+ else
+ {
+ if ( mButtonState == DISABLED_SELECTED_STATE )
+ {
+ ChangeState( SELECTED_STATE );
}
- case DisabledUnselectedState:
- case DisabledSelectedState:
+ else if ( mButtonState == DISABLED_UNSELECTED_STATE )
{
- DALI_ASSERT_DEBUG( 0 && "Shouldn't be able to change paint state if the button is disabled." );
- break;
+ ChangeState( UNSELECTED_STATE );
}
}
+}
- StartTransitionAnimation();
+bool Button::IsDisabled() const
+{
+ return ( mButtonState == DISABLED_SELECTED_STATE || mButtonState == DISABLED_UNSELECTED_STATE ) ;
+}
- if( emitSignal )
- {
- Toolkit::Button handle( GetOwner() );
+bool Button::ValidateState( State requestedState )
+{
+ /* Below tables shows allowed state transitions
+ * Match rows in first column to following columns, if true then transition allowed.
+ * eg UNSELECTED_STATE to DISABLED_UNSELECTED_STATE is true so state transition allowed.
+ *
+ to| UNSELECTED_STATE | SELECTED_STATE | DISABLED_UNSELECTED_STATE | DISABLED_SELECTED_STATE |*/
+ /* from*/
+ bool transitionTable[4][4] = { /* UNSELECTED_STATE*/ { false, true, true, false },
+ /* SELECTED_STATE*/ { true, false, false, true },
+ /* DISABLED_UNSELECTED_STATE*/{ true, true, false, false },
+ /* DISABLED_SELECTED_STATE*/ { false, true, false, false }
+ };
- // Emit signal.
- mStateChangedSignal.Emit( handle );
- }
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ValidateState ReuestedState:%d, CurrentState:%d, result:%s\n",
+ requestedState, mButtonState, (transitionTable[mButtonState][requestedState])?"change-accepted":"change-denied");
- RelayoutRequest();
+ return transitionTable[mButtonState][requestedState];
}
-bool Button::IsSelected() const
+void Button::PerformFunctionOnVisualsInState( void(Button::*functionPtr)( Property::Index visualIndex), State state )
{
- return mTogglableButton && mSelected;
+ 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] );
+
+ RelayoutRequest();
}
-void Button::SetAnimationTime( float animationTime )
+void Button::ChangeState( State requestedState )
{
- mAnimationTime = animationTime;
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ChangeState ReuestedState(%d)\n", requestedState );
+
+ // Validate State before changing
+ if ( !ValidateState( requestedState ))
+ {
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ChangeState ReuestedState(%d) not validated\n", requestedState );
+ return;
+ }
+
+ // If not on stage the button could have still been set to selected so update state/
+ mPreviousButtonState = mButtonState; // Store previous state for visual removal (used when animations ended)
+ mButtonState = requestedState; // Update current state
+
+ if ( Self().OnStage() )
+ {
+ OnStateChange( mButtonState ); // Notify derived buttons
+ PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState );
+ // If animation supported then visual removal should be performed after any transition animation has completed.
+ PerformFunctionOnVisualsInState( &Button::OnButtonVisualRemoval, mPreviousButtonState ); // Derived button can override OnButtonVisualRemoval
+ }
+
+ Toolkit::Button handle( GetOwner() );
+ // Emit signal.
+ mStateChangedSignal.Emit( handle );
}
-float Button::GetAnimationTime() const
+bool Button::IsSelected() const
{
- return mAnimationTime;
+ bool selected = ( mButtonState == SELECTED_STATE ) || ( mButtonState == DISABLED_SELECTED_STATE );
+ return mTogglableButton && selected;
}
void Button::SetLabelText( const std::string& label )
{
Property::Map labelProperty;
labelProperty.Insert( "text", label );
- ModifyLabel( labelProperty );
+ SetupLabel( labelProperty );
}
std::string Button::GetLabelText() const
return std::string();
}
-void Button::ModifyLabel( const Property::Map& properties )
+void Button::SetupLabel( const Property::Map& properties )
{
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "SetupLabel\n");
+
// If we don't have a label yet, create one.
if( !mLabel )
{
// If we don't have a label, create one and set it up.
// Note: The label text is set from the passed in property map after creation.
mLabel = Toolkit::TextLabel::New();
- mLabel.SetPosition( 0.0f, 0.0f );
- // label should be the top of the button
+ mLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+ mLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
+ mLabel.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+
+ // todo DEBUG
+ mLabel.SetProperty( Toolkit::Control::Property::BACKGROUND, Dali::Property::Map()
+ .Add( Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::COLOR )
+ .Add( Toolkit::ColorVisual::Property::MIX_COLOR, Color::RED )
+ );
+
+ ResizePolicy::Type policy = Self().GetResizePolicy( Dimension::ALL_DIMENSIONS );
+ if ( policy == ResizePolicy::USE_NATURAL_SIZE || policy == ResizePolicy::FIT_TO_CHILDREN )
+ {
+ mLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+ }
+ else
+ {
+ // todo Can't set Text Label to USE_ASSIGNED_SIZE as causes a relayout in it whilst doing a relayout = error
+ //mLabel.SetResizePolicy(ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS );
+ }
Self().Add( mLabel );
}
}
}
- // Notify derived button classes of the change.
- OnLabelSet( false );
-
RelayoutRequest();
}
-Actor& Button::GetLabelActor()
-{
- return mLabel;
-}
-
-void Button::SetDecoration( DecorationState state, Actor actor )
+void Button::SetLabelAlignment( Button::Align labelAlignment)
{
- if( mDecoration[ state ] && mDecoration[ state ].GetParent() )
- {
- mDecoration[ state ].Unparent();
- }
-
- mDecoration[ state ] = actor;
- mDecoration[ state ].SetColorMode( USE_OWN_COLOR );
-
- ResetImageLayers();
+ mTextLabelAlignment = labelAlignment;
RelayoutRequest();
}
-Actor& Button::GetDecoration( DecorationState state )
-{
- return mDecoration[ state ];
-}
-
-void Button::SetupContent( Actor& actorToModify, Actor newActor )
-{
- if( newActor )
- {
- StopTransitionAnimation();
-
- if( actorToModify && actorToModify.GetParent() )
- {
- actorToModify.Unparent();
- }
-
- actorToModify = newActor;
-
- if( actorToModify )
- {
- actorToModify.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- actorToModify.SetParentOrigin( ParentOrigin::TOP_LEFT );
- actorToModify.SetPosition( 0.f, 0.f );
- }
-
- ResetImageLayers();
- }
-}
-
-const Vector4 Button::GetUnselectedColor() const
+Button::Align Button::GetLabelAlignment()
{
- return mUnselectedColor;
+ return mTextLabelAlignment;
}
-void Button::SetColor( const Vector4& color, Button::PaintState selectedState )
+void Button::CreateVisualsForComponent( Property::Index index, const Property::Value& value, const float visualDepth )
{
- Actor* contentActor = NULL; // Using a pointer as SetupContent assigns the new Actor to this.
- bool imageFileExists = false;
- Property::Index visualIndex = Toolkit::Button::Property::SELECTED_STATE_IMAGE;
-
- if ( selectedState == SelectedState || selectedState == DisabledSelectedState )
- {
- mSelectedColor = color;
- contentActor = &mSelectedContent;
- imageFileExists = !GetSelectedImageFilename().empty();
- }
- else
- {
- mUnselectedColor = color;
- contentActor = &mUnselectedContent;
- imageFileExists = !GetUnselectedImageFilename().empty();
- visualIndex = Toolkit::Button::Property::UNSELECTED_STATE_IMAGE;
- }
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent index(%d)\n", index );
+ Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
+ Toolkit::Visual::Base buttonVisual;
- if ( contentActor )
+ std::string imageUrl;
+ if( value.Get( imageUrl ) )
{
- if( imageFileExists )
- {
- // If there is existing unselected content, change the color on it directly.
- contentActor->SetColor( color );
- }
- else
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent Using image URL(%d)\n", index );
+ if ( !imageUrl.empty() )
{
- // If there is no existing content, create a new actor to use for flat color.
- Actor placementActor = Actor::New();
- Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
- Toolkit::Visual::Base visual;
-
- Property::Map map;
- map[ Toolkit::VisualProperty::TYPE ] = Toolkit::Visual::COLOR;
- map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
-
- visual = visualFactory.CreateVisual( map );
-
- RegisterVisual( visualIndex, placementActor, visual );
-
- SetupContent( *contentActor, placementActor ); //
- contentActor->SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ buttonVisual = visualFactory.CreateVisual( imageUrl, ImageDimensions() );
}
}
-}
-
-const Vector4 Button::GetSelectedColor() const
-{
- return mSelectedColor;
-}
-
-void Button::SetUnselectedImage( const std::string& filename )
-{
- Toolkit::ImageView newContent;
- if( !filename.empty() )
- {
- newContent = Toolkit::ImageView::New( filename );
- }
- else
- {
- newContent = Toolkit::ImageView::New();
- }
-
- if( newContent )
- {
- SetupContent( mUnselectedContent, newContent );
-
- mUnselectedContent.SetColor( mUnselectedColor );
-
- OnUnselectedImageSet();
- RelayoutRequest();
- }
-}
-
-Actor& Button::GetUnselectedImage()
-{
- return mUnselectedContent;
-}
-
-void Button::SetSelectedImage( const std::string& filename )
-{
- Toolkit::ImageView newContent;
- if( !filename.empty() )
- {
- newContent = Toolkit::ImageView::New( filename );
- }
else
{
- newContent = Toolkit::ImageView::New();
- }
-
- if( newContent )
- {
- SetupContent( mSelectedContent, newContent );
-
- mSelectedContent.SetColor( mSelectedColor );
-
- OnSelectedImageSet();
- RelayoutRequest();
- }
-}
-
-Actor& Button::GetSelectedImage()
-{
- return mSelectedContent;
-}
-
-void Button::SetBackgroundImage( const std::string& filename )
-{
- SetupContent( mBackgroundContent, Toolkit::ImageView::New( filename ) );
-
- OnBackgroundImageSet();
- RelayoutRequest();
-}
-
-Actor& Button::GetBackgroundImage()
-{
- return mBackgroundContent;
-}
-
-void Button::SetSelectedBackgroundImage( const std::string& filename )
-{
- SetupContent( mSelectedBackgroundContent, Toolkit::ImageView::New( filename ) );
-
- OnSelectedBackgroundImageSet();
- RelayoutRequest();
-}
-
-Actor& Button::GetSelectedBackgroundImage()
-{
- return mSelectedBackgroundContent;
-}
-
-void Button::SetDisabledImage( const std::string& filename )
-{
- SetupContent( mDisabledContent, Toolkit::ImageView::New( filename ) );
-
- OnDisabledImageSet();
- RelayoutRequest();
-}
-
-Actor& Button::GetDisabledImage()
-{
- return mDisabledContent;
-}
-
-void Button::SetDisabledSelectedImage( const std::string& filename )
-{
- SetupContent( mDisabledSelectedContent, Toolkit::ImageView::New( filename ) );
-
- OnDisabledSelectedImageSet();
- RelayoutRequest();
-}
-
-Actor& Button::GetDisabledSelectedImage()
-{
- return mDisabledSelectedContent;
-}
-
-void Button::SetDisabledBackgroundImage( const std::string& filename )
-{
- SetupContent( mDisabledBackgroundContent, Toolkit::ImageView::New( filename ) );
-
- OnDisabledBackgroundImageSet();
- RelayoutRequest();
-}
-
-Actor& Button::GetDisabledBackgroundImage()
-{
- return mDisabledBackgroundContent;
-}
-
-std::string Button::GetUnselectedImageFilename() const
-{
- if( mUnselectedContent )
- {
- ResourceImage image = ResourceImage::DownCast( mUnselectedContent );
- if( image )
+ // if its not a string then get a Property::Map from the property if possible.
+ Property::Map *map = value.GetMap();
+ if( map && !map->Empty() ) // Empty map results in current visual removal.
{
- return image.GetUrl();
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent Using Map(%d)\n", index );
+ buttonVisual = visualFactory.CreateVisual( *map );
}
}
- return std::string();
-}
-std::string Button::GetSelectedImageFilename() const
-{
- if( mSelectedContent )
+ if ( buttonVisual )
{
- ResourceImage image = ResourceImage::DownCast( mSelectedContent );
- if( image )
- {
- return image.GetUrl();
- }
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "RegisterVisual index(%d)\n", index );
+ buttonVisual.SetDepthIndex( visualDepth );
+ // Background Visuals take full size of control
+ RegisterVisual( index, buttonVisual, false );
}
- return std::string();
-}
-
-std::string Button::GetDisabledImageFilename() const
-{
- if( mDisabledContent )
+ else
{
- ResourceImage image = ResourceImage::DownCast( mDisabledContent );
- if( image )
- {
- return image.GetUrl();
- }
+ UnregisterVisual( index );
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "Button visual not created or empty map provided (clearing visual).(%d)\n", index);
}
- return std::string();
}
bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
Toolkit::Button button = Toolkit::Button::DownCast( handle );
- DALI_ASSERT_ALWAYS( button );
+ DALI_ASSERT_DEBUG( button );
if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) )
{
if( !mClickActionPerforming )
{
mClickActionPerforming = true;
- OnButtonDown();
- mState = ButtonDown;
- OnButtonUp();
+ ButtonDown();
+ if ( !mTogglableButton )
+ {
+ mButtonPressedState = DEPRESSED;
+ }
+ ButtonUp();
mClickActionPerforming = false;
return true;
return false;
}
-void Button::OnButtonDown()
+void Button::ButtonDown()
{
- if( !mTogglableButton )
+ if( mTogglableButton )
+ {
+ if ( mButtonState != SELECTED_STATE )
+ {
+ SetSelected( true );
+ mButtonPressedState = TOGGLE_DEPRESSED;
+ }
+ else
+ {
+ mButtonPressedState = DEPRESSED;
+ }
+ }
+ else
{
Pressed();
-
+ mButtonPressedState = DEPRESSED;
if( mAutoRepeating )
{
- SetUpTimer( mInitialAutoRepeatingDelay );
+ SetUpTimer( mInitialAutoRepeatingDelay );
}
}
mPressedSignal.Emit( handle );
}
-void Button::OnButtonUp()
+void Button::ButtonUp()
{
- if( ButtonDown == mState )
+ if( DEPRESSED == mButtonPressedState )
{
- if( mTogglableButton )
+ bool validButtonAction = false;
+
+ if( mTogglableButton ) // Button up will change state
{
- SetSelected( !mSelected );
+ 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( ButtonDown == mState )
+ if( DEPRESSED == mButtonPressedState )
{
if( !mTogglableButton )
{
}
}
+ mButtonPressedState = UNPRESSED;
+
// The released signal should be emitted regardless of toggle mode.
Toolkit::Button handle( GetOwner() );
mReleasedSignal.Emit( handle );
void Button::OnInitialize()
{
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::OnInitialize\n" );
+
Actor self = Self();
mTapDetector = TapGestureDetector::New();
return OnKeyboardEnter();
}
-bool Button::OnKeyboardEnter()
-{
- // When the enter key is pressed, or button is activated, the click action is performed.
- Property::Map attributes;
- bool ret = DoClickAction( attributes );
-
- return ret;
-}
-
-void Button::OnStageDisconnection()
-{
- if( ButtonDown == mState )
- {
- if( !mTogglableButton )
- {
- Released();
-
- if( mAutoRepeating )
- {
- mAutoRepeatingTimer.Reset();
- }
- }
- }
-
- mState = ButtonUp;
-
- Control::OnStageDisconnection();
-}
-
bool Button::OnTouch( Actor actor, const TouchData& touch )
{
+
// Only events are processed when the button is not disabled and the touch event has only
// one touch point.
- if( ( !mDisabled ) && ( 1 == touch.GetPointCount() ) )
+
+ if( !IsDisabled() && ( 1 == touch.GetPointCount() ) )
{
switch( touch.GetState( 0 ) )
{
case PointState::DOWN:
{
- OnButtonDown(); // Notification for derived classes.
-
- // Sets the button state to ButtonDown.
- mState = ButtonDown;
+ ButtonDown();
break;
}
case PointState::UP:
{
- OnButtonUp(); // Notification for derived classes.
-
- // Sets the button state to ButtonUp.
- mState = ButtonUp;
+ ButtonUp();
break;
}
case PointState::INTERRUPTED:
{
- OnTouchPointInterrupted(); // Notification for derived classes.
-
- // Sets the button state to the default (ButtonUp).
- mState = ButtonUp;
+ OnTouchPointInterrupted();
break;
}
case PointState::LEAVE:
{
- OnTouchPointLeave(); // Notification for derived classes.
-
- // Sets the button state to the default (ButtonUp).
- mState = ButtonUp;
+ OnTouchPointLeave();
break;
}
case PointState::MOTION:
{
OnTouchPointLeave(); // Notification for derived classes.
- // Sets the button state to the default (ButtonUp).
- mState = ButtonUp;
+ // Sets the button state to the default
+ mButtonPressedState = UNPRESSED;
}
return false;
}
-void Button::OnTap(Actor actor, const TapGesture& tap)
+bool Button::OnKeyboardEnter()
{
- // Do nothing.
-}
+ // When the enter key is pressed, or button is activated, the click action is performed.
+ Property::Map attributes;
+ bool ret = DoClickAction( attributes );
-void Button::SetUpTimer( float delay )
-{
- mAutoRepeatingTimer = Dali::Timer::New( static_cast<unsigned int>( 1000.f * delay ) );
- mAutoRepeatingTimer.TickSignal().Connect( this, &Button::AutoRepeatingSlot );
- mAutoRepeatingTimer.Start();
+ return ret;
}
-bool Button::AutoRepeatingSlot()
+void Button::OnStageDisconnection()
{
- bool consumed = false;
- if( !mDisabled )
+ if( DEPRESSED == mButtonPressedState )
{
- // Restart the autorepeat timer.
- SetUpTimer( mNextAutoRepeatingDelay );
-
- Pressed();
+ if( !mTogglableButton )
+ {
+ Released();
- Toolkit::Button handle( GetOwner() );
+ if( mAutoRepeating )
+ {
+ mAutoRepeatingTimer.Reset();
+ }
+ }
+ }
- //Emit signal.
- consumed = mReleasedSignal.Emit( handle );
- consumed |= mClickedSignal.Emit( handle );
- consumed |= mPressedSignal.Emit( handle );
- }
+ mButtonPressedState = UNPRESSED;
- return consumed;
+ Control::OnStageDisconnection(); // Visuals will be set off stage
}
-void Button::Pressed()
+void Button::OnStageConnection( int depth )
{
- if( mPaintState == UnselectedState )
- {
- StopTransitionAnimation();
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::OnStageConnection ptr(%p) \n", this );
+ PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState );
+ Control::OnStageConnection( depth ); // Enabled visuals will be put on stage
- // Notifies the derived class the button has been pressed.
- OnPressed();
-
- //Layer Order
- //(4) mSelectedContent (Inserted)
- //(3) mUnselectedContent
- //(2) mSelectedBackgroundContent (Inserted)
- //(1) mBackgroundContent
-
- AddButtonImage( mBackgroundContent );
- TransitionButtonImage( mSelectedBackgroundContent );
- AddButtonImage( mUnselectedContent );
- TransitionButtonImage( mSelectedContent );
+}
- AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
- TransitionButtonImage( mDecoration[ SELECTED_DECORATION ] );
- ReAddLabel();
+Vector3 Button::GetNaturalSize()
+{
+ Vector3 size = Vector3::ZERO;
- TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
- TransitionOut( mUnselectedContent );
- TransitionOut( mDisabledContent );
- TransitionOut( mDisabledSelectedContent );
- TransitionOut( mDisabledBackgroundContent );
+ bool horizontalAlignment = mTextLabelAlignment == BEGIN || mTextLabelAlignment == END; // label and visual side by side
- mPaintState = SelectedState;
+ // Get natural size of foreground ( largest of the possible visuals )
+ Size largestForegroundVisual;
+ Size labelSize;
- StartTransitionAnimation();
+ for ( int state = Button::UNSELECTED_STATE; state < Button::STATE_COUNT; state++)
+ {
+ Toolkit::Visual::Base visual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND] );
+ Size visualSize;
+ if ( visual )
+ {
+ visual.GetNaturalSize( visualSize );
+ largestForegroundVisual.width = std::max(largestForegroundVisual.width, visualSize.width );
+ largestForegroundVisual.height = std::max(largestForegroundVisual.height, visualSize.height );
+ }
}
-}
-void Button::Released()
-{
- if( mPaintState == SelectedState )
+ // Get horizontal padding total
+ if ( largestForegroundVisual.width > 0 ) // if visual exists
{
- StopTransitionAnimation();
-
- // Notifies the derived class the button has been released.
- OnReleased();
+ size.width += largestForegroundVisual.width + mForegroundPadding.left + mForegroundPadding.right;
+ }
+ // Get vertical padding total
+ if ( largestForegroundVisual.height > 0 )
+ {
+ size.height += largestForegroundVisual.height + mForegroundPadding.top + mForegroundPadding.bottom;
+ }
- //Layer Order
- //(3) mUnselectedContent (Inserted)
- //(2) mSelectedContent
- //(1) mBackgroundContent
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize visual Size(%f,%f)\n",
+ largestForegroundVisual.width, largestForegroundVisual.height );
- AddButtonImage( mBackgroundContent );
- AddButtonImage( mSelectedContent );
- TransitionButtonImage( mUnselectedContent );
+ // Get natural size of label
+ if ( mLabel )
+ {
+ labelSize = Vector2( mLabel.GetNaturalSize());
- AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
- TransitionButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
- ReAddLabel();
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize labelSize(%f,%f) padding(%f,%f)\n",
+ labelSize.width, labelSize.height, mLabelPadding.left + mLabelPadding.right, mLabelPadding.top + mLabelPadding.bottom);
- TransitionOut( mDecoration[ SELECTED_DECORATION ] );
- TransitionOut( mSelectedContent );
- TransitionOut( mSelectedBackgroundContent );
- TransitionOut( mDisabledContent );
- TransitionOut( mDisabledSelectedContent );
- TransitionOut( mDisabledBackgroundContent );
+ labelSize.width += mLabelPadding.left + mLabelPadding.right;
+ labelSize.height += mLabelPadding.top + mLabelPadding.bottom;
- mPaintState = UnselectedState;
+ // Add label size to height or width depending on alignment position
+ if ( horizontalAlignment )
+ {
+ size.width += labelSize.width;
+ size.height = std::max(size.height, labelSize.height );
+ }
+ else
+ {
+ size.height += labelSize.height;
+ size.width = std::max(size.width, labelSize.width );
+ }
+ }
- StartTransitionAnimation();
+ if( size.width < 1 && size.height < 1 )
+ {
+ // if no image or label then use Control's natural size
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize Using control natural size\n");
+ size = Control::GetNaturalSize();
}
-}
-Button::ButtonState Button::GetState()
-{
- return mState;
-}
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "Button GetNaturalSize (%f,%f)\n", size.width, size.height );
-Button::PaintState Button::GetPaintState()
-{
- return mPaintState;
+ return size;
}
-void Button::PrepareAddButtonImage( Actor& actor )
+void Button::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
{
- if( actor )
- {
- Self().Add( actor );
- PrepareForTranstionOut( actor );
- }
-}
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnSetResizePolicy\n");
-void Button::TransitionButtonImage( Actor& actor )
-{
- if( actor )
+ if ( policy != ResizePolicy::USE_NATURAL_SIZE || policy != ResizePolicy::FIT_TO_CHILDREN )
{
- if( !actor.GetParent() )
+ if ( mLabel )
{
- Self().Add( actor );
+ // todo Can't set Text Label to USE_ASSIGNED_SIZE as causes a relayout in it whilst doing a relayout = error
+ //mLabel.SetResizePolicy(ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS );
}
-
- OnTransitionIn( actor );
}
-}
-void Button::AddButtonImage( Actor& actor )
-{
- if( actor )
- {
- Self().Add( actor );
- }
+ RelayoutRequest();
}
-void Button::ReAddLabel()
+void Button::OnRelayout( const Vector2& size, RelayoutContainer& container )
{
- if( mLabel )
- {
- mLabel.Unparent();
- Self().Add( mLabel );
- }
-}
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout targetSize(%f,%f) ptr(%p) state[%d]\n", size.width, size.height, this, mButtonState );
-void Button::RemoveButtonImage( Actor& actor )
-{
- if( actor )
+ Toolkit::Visual::Base currentVisual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[mButtonState][FOREGROUND] );
+
+ Toolkit::Visual::Base currentBackGroundVisual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[mButtonState][BACKGROUND] );
+
+ // Sizes and padding set to zero, if not present then values will no effect calculations.
+ Vector2 visualPosition = Vector2::ZERO;
+ Vector2 labelPosition = Vector2::ZERO;
+ Size visualSize = Size::ZERO;
+ Padding foregroundVisualPadding = Padding(0.0f, 0.0f, 0.0f, 0.0f );
+ Padding labelVisualPadding = Padding(0.0f, 0.0f, 0.0f, 0.0f );
+
+ if ( mLabel )
{
- if( actor.GetParent() )
- {
- Self().Remove( actor );
- }
- PrepareForTranstionIn( actor );
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Label padding setting padding:%f,%f,%f,%f\n", mLabelPadding.y, mLabelPadding.x, mLabelPadding.width,mLabelPadding.height );
+ labelVisualPadding = mLabelPadding;
}
-}
-unsigned int Button::FindChildIndex( Actor& actor )
-{
- Actor self = Self();
- unsigned int childrenNum = self.GetChildCount();
-
- for( unsigned int i = 0; i < childrenNum; i++ )
+ if ( currentVisual )
{
- Actor child = self.GetChildAt( i );
- if( child == actor )
- {
- return i;
- }
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Foreground Visual setting padding:%f,%f,%f,%f\n", mForegroundPadding.y, mForegroundPadding.x, mForegroundPadding.width,mForegroundPadding.height );
+ currentVisual.GetNaturalSize( visualSize );
+ foregroundVisualPadding = mForegroundPadding;
}
- return childrenNum;
-}
+ Toolkit::Align::Type visualAnchorPoint = Toolkit::Align::TOP_BEGIN;
-void Button::TransitionOut( Actor actor )
-{
- OnTransitionOut( actor );
-}
+ Vector2 visualAndPaddingSize = Vector2( ( foregroundVisualPadding.x + visualSize.width + foregroundVisualPadding.y ),
+ ( foregroundVisualPadding.width + visualSize.height + foregroundVisualPadding.height ));
-void Button::ResetImageLayers()
-{
- // Ensure that all layers are in the correct order and state according to the paint state
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout visualAndPaddingSize(%f,%f)\n", visualAndPaddingSize.width, visualAndPaddingSize.height);
- switch( mPaintState )
+ switch ( mTextLabelAlignment )
{
- case UnselectedState:
+ case BEGIN :
{
- //Layer Order
- //(2) mUnselectedContent
- //(1) mBackgroundContent
-
- RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] );
- RemoveButtonImage( mSelectedContent );
- RemoveButtonImage( mSelectedBackgroundContent );
- RemoveButtonImage( mDisabledContent );
- RemoveButtonImage( mDisabledSelectedContent );
- RemoveButtonImage( mDisabledBackgroundContent );
-
- PrepareAddButtonImage( mBackgroundContent );
- PrepareAddButtonImage( mUnselectedContent );
-
- PrepareAddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
- ReAddLabel();
+ visualAnchorPoint = Toolkit::Align::TOP_END;
+ visualPosition.x = foregroundVisualPadding.right;
+ visualPosition.y = foregroundVisualPadding.top;
+
+ labelPosition.x = labelVisualPadding.x;
+ labelPosition.y = labelVisualPadding.top;
break;
}
- case SelectedState:
+ case END :
{
- //Layer Order
- //(3) mSelectedContent
- //(2) mSelectedBackgroundContent
- //(1) mBackgroundContent
-
- RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
- RemoveButtonImage( mUnselectedContent );
- RemoveButtonImage( mDisabledContent );
- RemoveButtonImage( mDisabledSelectedContent );
- RemoveButtonImage( mDisabledBackgroundContent );
-
- PrepareAddButtonImage( mBackgroundContent );
- PrepareAddButtonImage( mSelectedBackgroundContent );
- PrepareAddButtonImage( mSelectedContent );
-
- PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] );
- ReAddLabel();
+ visualAnchorPoint = Toolkit::Align::TOP_BEGIN;
+ visualPosition.x = foregroundVisualPadding.left;
+ visualPosition.y = foregroundVisualPadding.top;
+
+ labelPosition.x = visualAndPaddingSize.width + labelVisualPadding.x;
+ labelPosition.y = labelVisualPadding.top;
break;
}
- case DisabledUnselectedState:
+ case TOP :
{
- //Layer Order
- //(2) mDisabledContent
- //(1) mDisabledBackgroundContent
-
- RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
- RemoveButtonImage( mUnselectedContent );
- RemoveButtonImage( mBackgroundContent );
- RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] );
- RemoveButtonImage( mSelectedContent );
- RemoveButtonImage( mDisabledSelectedContent );
- RemoveButtonImage( mSelectedBackgroundContent );
-
- PrepareAddButtonImage( mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent );
- PrepareAddButtonImage( mDisabledContent ? mDisabledContent : mUnselectedContent );
-
- PrepareAddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
- ReAddLabel();
+ visualAnchorPoint = Toolkit::Align::BOTTOM_END;
+ visualPosition.x = foregroundVisualPadding.left;
+ visualPosition.y = foregroundVisualPadding.bottom;
+
+ labelPosition.x = labelVisualPadding.left;
+ labelPosition.y = labelVisualPadding.top;
break;
}
- case DisabledSelectedState:
+ case BOTTOM :
{
- //Layer Order
- // (2) mDisabledSelectedContent
- // (1) mDisabledBackgroundContent
-
- RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
- RemoveButtonImage( mUnselectedContent );
- RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] );
- RemoveButtonImage( mSelectedContent );
- RemoveButtonImage( mBackgroundContent );
- RemoveButtonImage( mSelectedBackgroundContent );
- RemoveButtonImage( mDisabledContent );
-
- if( mDisabledBackgroundContent )
- {
- PrepareAddButtonImage( mDisabledBackgroundContent );
- }
- else
- {
- PrepareAddButtonImage( mBackgroundContent );
- PrepareAddButtonImage( mSelectedBackgroundContent );
- }
-
- PrepareAddButtonImage( mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent );
+ visualAnchorPoint = Toolkit::Align::TOP_END;
+ visualPosition.x = foregroundVisualPadding.left;
+ visualPosition.y = foregroundVisualPadding.top;
- PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] );
- ReAddLabel();
+ labelPosition.x = labelVisualPadding.left;
+ labelPosition.y = visualAndPaddingSize.height + labelVisualPadding.top;
break;
}
}
-}
-void Button::StartTransitionAnimation()
-{
- if( mTransitionAnimation )
+ if ( currentBackGroundVisual )
{
- mTransitionAnimation.Play();
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Setting visual bakcground size to(%f,%f)\n", size.width, size.height);
+
+ Property::Map visualTransform;
+
+ visualTransform.Add( Toolkit::DevelVisual::Transform::Property::SIZE, size )
+ .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4( 0.0f, 0.0f, 1.0f, 1.0f) ); // Use relative size
+
+ currentBackGroundVisual.SetTransformAndSize( visualTransform, size );
}
- else
+
+ if ( currentVisual )
{
- ResetImageLayers();
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Setting visual size to(%f,%f)\n", visualSize.width, visualSize.height);
+
+ currentVisual.SetProperty( Toolkit::Visual::DevelProperty::TRANSFORM,
+ Dali::Property::Map()
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::SIZE, visualSize )
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::OFFSET, visualPosition )
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::OFFSET_SIZE_MODE, Vector4(1.0f, 1.0f, 1.0f,1.0f) )
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
+ .Add( Toolkit::Visual::DevelProperty::Transform::Property::ANCHOR_POINT, visualAnchorPoint )
+ );
+ }
+
+ if ( mLabel )
+ {
+ // When Text visual size can be set, determine the size here.
+ // Text Visual should take all space available after foreground visual size and all padding is considered.
+ // Remaining Space priority, Foreground padding, foreground visual, Text padding then Text visual.
+
+ Size remainingSpaceForText = Size::ZERO;
+ remainingSpaceForText.width = size.width - visualAndPaddingSize.width - labelVisualPadding.x - labelVisualPadding.y;
+ remainingSpaceForText.height = size.height - visualAndPaddingSize.height - labelVisualPadding.width - labelVisualPadding.height;
+
+ if ( !currentVisual )
+ {
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Only Text\n");
+
+ // Center Text if no foreground visual
+ Size labelNaturalSize = Vector2( mLabel.GetNaturalSize() );
+
+ // A Text visual will take up all the remainingSpaceForText, for now TextLabel natural size needed for positioning.
+ labelPosition.x = labelVisualPadding.left + remainingSpaceForText.width*0.5 - labelNaturalSize.width *0.5;
+ labelPosition.y = labelVisualPadding.height + remainingSpaceForText.height*0.5 - labelNaturalSize.height *0.5;
+ }
+
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout text Size(%f,%f) text Position(%f,%f) \n", remainingSpaceForText.width, remainingSpaceForText.height, labelPosition.x, labelPosition.y);
+
+ mLabel.SetPosition( labelPosition.x, labelPosition.y );
+ container.Add( mLabel, remainingSpaceForText ); // Currently a TextLabel is used and size can not be set here.
}
+
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout << \n");
+}
+
+void Button::OnTap(Actor actor, const TapGesture& tap)
+{
+ DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnTap\n" );
+}
+
+void Button::SetUpTimer( float delay )
+{
+ mAutoRepeatingTimer = Dali::Timer::New( static_cast<unsigned int>( 1000.f * delay ) );
+ mAutoRepeatingTimer.TickSignal().Connect( this, &Button::AutoRepeatingSlot );
+ mAutoRepeatingTimer.Start();
+}
+
+bool Button::AutoRepeatingSlot()
+{
+ bool consumed = false;
+ if( !IsDisabled() )
+ {
+ // Restart the autorepeat timer.
+ SetUpTimer( mNextAutoRepeatingDelay );
+
+ Pressed();
+
+ Toolkit::Button handle( GetOwner() );
+
+ //Emit signal.
+ consumed = mReleasedSignal.Emit( handle );
+ consumed = mClickedSignal.Emit( handle );
+ consumed |= mPressedSignal.Emit( handle );
+ }
+
+ return consumed;
}
-void Button::StopTransitionAnimation()
+void Button::Pressed()
{
- if( mTransitionAnimation )
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::Pressed\n" );
+
+ if( mButtonState == UNSELECTED_STATE )
{
- mTransitionAnimation.Clear();
- mTransitionAnimation.Reset();
+ ChangeState( SELECTED_STATE );
+ OnPressed(); // Notifies the derived class the button has been pressed.
}
}
-Dali::Animation Button::GetTransitionAnimation()
+void Button::Released()
{
- if( !mTransitionAnimation )
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::Released\n" );
+
+ if( mButtonState == SELECTED_STATE && !mTogglableButton )
{
- mTransitionAnimation = Dali::Animation::New( GetAnimationTime() );
- mTransitionAnimation.FinishedSignal().Connect( this, &Button::TransitionAnimationFinished );
+ ChangeState( UNSELECTED_STATE );
+ OnReleased(); // // Notifies the derived class the button has been released.
}
+ mButtonPressedState = UNPRESSED;
+}
+
+void Button::SelectRequiredVisual( Property::Index visualIndex )
+{
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SelectRequiredVisual index(%d) state(%d)\n", visualIndex, mButtonState );
+
+ EnableVisual( visualIndex, true );
+}
- return mTransitionAnimation;
+void Button::RemoveVisual( Property::Index visualIndex )
+{
+ // Use OnButtonVisualRemoval if want button developer to have the option to override removal.
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::RemoveVisual index(%d) state(%d)\n", visualIndex, mButtonState );
+
+ Toolkit::Visual::Base visual = GetVisual( visualIndex );
+
+ if( visual )
+ {
+ EnableVisual( visualIndex, false );
+ }
}
-void Button::TransitionAnimationFinished( Dali::Animation& source )
+void Button::OnButtonVisualRemoval( Property::Index visualIndex )
{
- StopTransitionAnimation();
- ResetImageLayers();
+ // Derived Buttons can over ride this to prevent default removal.
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::OnButtonVisualRemoval index(%d)\n", visualIndex );
+ RemoveVisual( visualIndex );
}
void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
{
Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetProperty index[%d]\n", index );
+
if ( button )
{
switch ( index )
break;
}
- case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE:
+ case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE: // Legacy Tizen 3.0
{
- GetImplementation( button ).SetUnselectedImage( value.Get< std::string >() );
+ GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_VISUAL, value, DepthIndex::CONTENT );
break;
}
-
- case Toolkit::Button::Property::SELECTED_STATE_IMAGE:
+ case Toolkit::Button::Property::DISABLED_STATE_IMAGE: // Legacy Tizen 3.0
{
- GetImplementation( button ).SetSelectedImage( value.Get< std::string >() );
+ GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL, value, DepthIndex::CONTENT );
+ break;
+ }
+ case Toolkit::Button::Property::SELECTED_STATE_IMAGE: // Legacy Tizen 3.0
+ {
+ GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_VISUAL, value, DepthIndex::CONTENT );
+ break;
+ }
+ case Toolkit::Button::Property::UNSELECTED_VISUAL:
+ case Toolkit::Button::Property::SELECTED_VISUAL:
+ case Toolkit::Button::Property::DISABLED_SELECTED_VISUAL:
+ case Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL:
+ {
+ GetImplementation( button ).CreateVisualsForComponent( index, value, DepthIndex::CONTENT );
break;
}
- case Toolkit::Button::Property::DISABLED_STATE_IMAGE:
+ case Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL:
+ case Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL:
+ case Toolkit::Button::Property::DISABLED_SELECTED_BACKGROUND_VISUAL:
+ case Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL:
{
- GetImplementation( button ).SetDisabledImage( value.Get< std::string >() );
+ GetImplementation( button ).CreateVisualsForComponent( index , value, DepthIndex::BACKGROUND);
break;
}
case Toolkit::Button::Property::UNSELECTED_COLOR:
{
- GetImplementation( button ).SetColor( value.Get< Vector4 >(), UnselectedState );
+ DALI_LOG_WARNING("[%s] Using deprecated Property Button::Property::UNSELECTED_COLOR instead use Button::Property::UNSELECTED_BACKGROUND_VISUAL\n", __FUNCTION__);
+ GetImplementation( button ).SetColor( value.Get< Vector4 >(), Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL );
break;
}
case Toolkit::Button::Property::SELECTED_COLOR:
{
- GetImplementation( button ).SetColor( value.Get< Vector4 >(), SelectedState );
+ DALI_LOG_WARNING("[%s] Using deprecated Property Button::Property::SELECTED_COLOR instead use Button::Property::SELECTED_BACKGROUND_VISUAL\n", __FUNCTION__);
+ GetImplementation( button ).SetColor( value.Get< Vector4 >(), Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL );
break;
}
case Toolkit::Button::Property::LABEL_TEXT:
{
- GetImplementation( button ).SetLabelText( value.Get< std::string >() );
+ DALI_LOG_WARNING("[%s] Using deprecated Property Button::Property::LABEL_TEXT instead use Button::Property::LABEL\n", __FUNCTION__);
+ Property::Map labelTextProperty;
+ labelTextProperty.Insert( "text", value.Get< std::string >() );
+ GetImplementation( button ).SetupLabel( labelTextProperty );
break;
}
Property::Map setPropertyMap;
if( value.Get( setPropertyMap ) )
{
- GetImplementation( button ).ModifyLabel( setPropertyMap );
+ GetImplementation( button ).SetupLabel( setPropertyMap );
}
+ break;
+ }
+
+ case Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT:
+ {
+ Button::Align labelAlignment(END);
+ Scripting::GetEnumeration< Button::Align> ( value.Get< std::string >().c_str(),
+ ALIGNMENT_TABLE, ALIGNMENT_TABLE_COUNT,
+ labelAlignment );
+
+ GetImplementation( button ).SetLabelAlignment( labelAlignment );
+ break;
}
- break;
}
}
}
{
case Toolkit::Button::Property::DISABLED:
{
- value = GetImplementation( button ).mDisabled;
+ value = GetImplementation( button ).IsDisabled();
break;
}
case Toolkit::Button::Property::SELECTED:
{
- value = GetImplementation( button ).mSelected;
+ value = GetImplementation( button ).IsSelected();
break;
}
case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE:
{
- value = GetImplementation( button ).GetUnselectedImageFilename();
+ value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::UNSELECTED_VISUAL );
break;
}
case Toolkit::Button::Property::SELECTED_STATE_IMAGE:
{
- value = GetImplementation( button ).GetSelectedImageFilename();
+ value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::SELECTED_VISUAL );
break;
}
case Toolkit::Button::Property::DISABLED_STATE_IMAGE:
{
- value = GetImplementation( button ).GetDisabledImageFilename();
+ value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL );
break;
}
value = emptyMap;
break;
}
+
+ case Toolkit::Button::Property::LABEL_STRUT_LENGTH:
+ {
+ value = GetImplementation( button ).GetLabelStrutLength();
+ break;
+ }
+
+ case Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT:
+ {
+ const char* alignment = Scripting::GetEnumerationName< Button::Align >( GetImplementation( button ).GetLabelAlignment(),
+ ALIGNMENT_STRING_TABLE,
+ ALIGNMENT_STRING_TABLE_COUNT );
+ if( alignment )
+ {
+ value = std::string( alignment );
+ }
+
+ break;
+ }
}
}
return value;
}
-// Deprecated API
+void Button::SetLabelPadding( const Padding& padding)
+{
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetLabelPadding padding(%f,%f,%f,%f)\n", padding.left, padding.right, padding.bottom, padding.top );
+ mLabelPadding = Padding( padding.left, padding.right, padding.bottom, padding.top );
+ RelayoutRequest();
+}
-void Button::SetLabel( Actor label )
+Padding Button::GetLabelPadding()
{
- if( mLabel != label )
- {
- if( mLabel && mLabel.GetParent() )
- {
- mLabel.GetParent().Remove( mLabel );
- }
+ return mLabelPadding;
+}
- mLabel = label;
- mLabel.SetPosition( 0.0f, 0.0f );
+void Button::SetForegroundPadding( const Padding& padding)
+{
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetForegroundPadding padding(%f,%f,%f,%f)\n", padding.left, padding.right, padding.bottom, padding.top );
+ mForegroundPadding = Padding( padding.left, padding.right, padding.bottom, padding.top );
+ RelayoutRequest();
+}
- // label should be the top of the button
- Self().Add( mLabel );
+Padding Button::GetForegroundPadding()
+{
+ return mForegroundPadding;
+}
- ResetImageLayers();
- OnLabelSet( true );
+////////////////////////////////////////////////////////////////////////
+// Legacy functions from Tizen 2.4 and 3.0
- RelayoutRequest();
+// 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 );
}
-void Button::SetButtonImage( Actor image )
+const Vector4 Button::GetUnselectedColor() const
{
- if( image )
- {
- StopTransitionAnimation();
+ return mUnselectedColor;
+}
- SetupContent( mUnselectedContent, image );
+const Vector4 Button::GetSelectedColor() const
+{
+ return mSelectedColor;
+}
- OnUnselectedImageSet();
- RelayoutRequest();
- }
+void Button::SetAnimationTime( float animationTime )
+{
+ // Used by depreciated API
+ mAnimationTime = animationTime;
}
-void Button::SetSelectedImage( Actor image )
+float Button::GetAnimationTime() const
{
- if( image )
- {
- StopTransitionAnimation();
+ // Used by depreciated API
+ return mAnimationTime;
+}
- SetupContent( mSelectedContent, image );
+void Button::SetLabel( Actor label )
+{
+ if ( label )
+ {
+ Property::Value value ="";
+ value = label.GetProperty(Toolkit::TextLabel::Property::TEXT);
- OnSelectedImageSet();
- RelayoutRequest();
+ SetLabelText( value.Get<std::string>() );
}
}
-void Button::SetBackgroundImage( Actor image )
+void Button::SetUnselectedImage( const std::string& filename )
{
- if( image )
+ if( !filename.empty() )
{
- StopTransitionAnimation();
-
- SetupContent( mBackgroundContent, image );
-
- OnBackgroundImageSet();
- RelayoutRequest();
+ CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_VISUAL, filename, DepthIndex::CONTENT );
}
}
-void Button::SetSelectedBackgroundImage( Actor image )
+void Button::SetBackgroundImage( const std::string& filename )
{
- if( image )
+ if( !filename.empty() )
{
- StopTransitionAnimation();
-
- SetupContent( mSelectedBackgroundContent, image );
-
- OnSelectedBackgroundImageSet();
- RelayoutRequest();
+ CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
}
}
-void Button::SetDisabledImage( Actor image )
+void Button::SetSelectedImage( const std::string& filename )
{
- if( image )
+ if( !filename.empty() )
{
- StopTransitionAnimation();
-
- SetupContent( mDisabledContent, image );
-
- OnDisabledImageSet();
- RelayoutRequest();
+ CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_VISUAL, filename, DepthIndex::CONTENT );
}
}
-void Button::SetDisabledSelectedImage( Actor image )
+void Button::SetSelectedBackgroundImage( const std::string& filename )
{
- if( image )
+ if( !filename.empty() )
{
- StopTransitionAnimation();
+ CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
+ }
+}
- SetupContent( mDisabledSelectedContent, image );
+void Button::SetDisabledBackgroundImage( const std::string& filename )
+{
+ if( !filename.empty() )
+ {
+ CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
+ }
+}
- OnDisabledSelectedImageSet();
- RelayoutRequest();
+void Button::SetDisabledImage( const std::string& filename )
+{
+ if( !filename.empty() )
+ {
+ CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL, filename, DepthIndex::CONTENT );
}
}
-void Button::SetDisabledBackgroundImage( Actor image )
+void Button::SetDisabledSelectedImage( const std::string& filename )
{
- if( image )
+ if( !filename.empty() )
{
- StopTransitionAnimation();
+ CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_SELECTED_VISUAL, filename, DepthIndex::CONTENT );
+ }
+}
- SetupContent( mDisabledBackgroundContent, image );
+std::string Button::GetUrlForImageVisual( Property::Index index )
+{
+ Toolkit::Visual::Base visual = GetVisual( index );
+ std::string result;
- OnDisabledBackgroundImageSet();
- RelayoutRequest();
+ if ( visual )
+ {
+ Dali::Property::Map retreivedMap;
+ visual.CreatePropertyMap( retreivedMap );
+ Property::Value* value = retreivedMap.Find( Toolkit::ImageVisual::Property::URL, Property::STRING );
+ if ( value )
+ {
+ result = value->Get<std::string>();
+ }
}
+
+ return result;
}
+// Below functions DEPRECATED_1_0.50 - Return empty Actors
+
Actor Button::GetButtonImage() const
{
- return mUnselectedContent;
+ DALI_LOG_WARNING("Button::GetButtonImage @DEPRECATED_1_0.50 Returning empty Actor \n");
+ return Actor();;
}
Actor Button::GetSelectedImage() const
{
- return mSelectedContent;
+ DALI_LOG_WARNING("Button::GetSelectedImage @DEPRECATED_1_0.50 Returning empty Actor \n");
+ return Actor();
}
-
} // namespace Internal
} // namespace Toolkit