Button button = PushButton::New();
- button.SetLabel( "Button Label" );
+ button.SetLabelText( "Button Label" );
- DALI_TEST_CHECK( button.GetLabel() );
+ DALI_TEST_EQUALS( button.GetLabelText(), "Button Label", TEST_LOCATION );
END_TEST;
}
Button button = PushButton::New();
- TextLabel textLabel = TextLabel::New( "Button Label" );
- button.SetLabel( textLabel );
+ button.SetLabelText( "Button Label" );
- DALI_TEST_CHECK( button.GetLabel() );
+ DALI_TEST_EQUALS( button.GetLabelText(), "Button Label", TEST_LOCATION );
END_TEST;
}
-int UtcDaliButtonSetButtonImage(void)
+int UtcDaliButtonSetUnselectedImageP(void)
{
ToolkitTestApplication application;
- tet_infoline(" UtcDaliButtonSetButtonImage");
-
- Image image = CreateSolidColorImage( Color::RED, 10, 10 );
+ tet_infoline(" UtcDaliButtonSetUnselectedImageP");
PushButton pushButton = PushButton::New();
Stage::GetCurrent().Add( pushButton );
application.Render();
pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
- pushButton.SetButtonImage( image );
+ pushButton.SetUnselectedImage( "Image.jpg" );
application.SendNotification();
application.Render();
Vector3 size = pushButton.GetCurrentSize();
+ tet_printf( "todor: size: %f,%f", size.width, size.height );
DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
ToolkitTestApplication application;
tet_infoline(" UtcDaliButtonSetButtonImage");
- Image image = CreateSolidColorImage( Color::RED, 10, 10 );
-
PushButton pushButton = PushButton::New();
Stage::GetCurrent().Add( pushButton );
application.Render();
pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
- pushButton.SetSelectedImage( image );
+ pushButton.SetSelectedImage( "Image.jpg" );
application.SendNotification();
application.Render();
pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), false);
DALI_TEST_CHECK( false == pushButton.IsDisabled() );
+
pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), true);
DALI_TEST_CHECK( true == pushButton.IsDisabled() );
+
END_TEST;
}
ToolkitTestApplication application;
tet_infoline(" UtcDaliButtonSize");
- ImageActor image01 = ImageActor::New(CreateBufferImage());
- image01.SetSize( 100, 50 );
-
- PushButton pushButton;
-
- Vector3 size;
-
- // Test1 Size is set through Actor API
-
// First an image is set, then SetSize is called.
- pushButton = PushButton::New();
+ PushButton pushButton = PushButton::New();
Stage::GetCurrent().Add( pushButton );
- pushButton.SetBackgroundImage( image01 );
+ pushButton.SetBackgroundImage( "Image.jpg" );
pushButton.SetSize( 10.f, 10.f );
application.SendNotification();
application.Render();
- size = pushButton.GetCurrentSize();
+ Vector3 size = pushButton.GetCurrentSize();
DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
application.SendNotification();
application.Render();
- pushButton.SetLabel( STR );
+ pushButton.SetLabelText( STR );
- TextLabel label = TextLabel::DownCast( pushButton.GetLabel() );
- DALI_TEST_CHECK( STR == label.GetProperty<std::string>( TextLabel::Property::TEXT ) );
+ DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );
END_TEST;
}
DALI_TEST_CHECK( !gPushButtonSelectedState );
END_TEST;
}
+
+int UtcDaliPushButtonPropertySetIconAlignment(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
+
+ PushButton pushButton = PushButton::New();
+ pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
+ DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
+
+ pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
+ DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliPushButtonPropertySetLabelPadding(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
+
+ PushButton pushButton = PushButton::New();
+ pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
+ DALI_TEST_EQUALS( pushButton.GetProperty<Vector4>( Toolkit::PushButton::Property::LABEL_PADDING ), Vector4( 1.0f, 1.0f, 1.0f, 1.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
+ pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
+ DALI_TEST_EQUALS( pushButton.GetProperty<Vector4>( Toolkit::PushButton::Property::LABEL_PADDING ), Vector4( 10.0f, 10.0f, 10.0f, 10.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliPushButtonPropertySetIconPadding(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
+
+ PushButton pushButton = PushButton::New();
+ pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
+ DALI_TEST_EQUALS( pushButton.GetProperty<Vector4>( Toolkit::PushButton::Property::ICON_PADDING ), Vector4( 1.0f, 1.0f, 1.0f, 1.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
+ pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
+ DALI_TEST_EQUALS( pushButton.GetProperty<Vector4>( Toolkit::PushButton::Property::ICON_PADDING ), Vector4( 10.0f, 10.0f, 10.0f, 10.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliPushButtonPaddingLayout(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliPushButtonPaddingLayout");
+
+ // This test creates padding for an icon and a label.
+ // The icon and label are each enabled and disabled to confirm the correct padding is used.
+ PushButton pushButton = PushButton::New();
+
+ pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
+ pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 20.0f, 20.0f, 20.0f, 20.0f ) );
+
+ pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ pushButton.SetPosition( 0.0f, 0.0f );
+ pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+
+ Stage::GetCurrent().Add( pushButton );
+
+ application.SendNotification();
+ application.Render();
+
+ // First test the size is zero.
+ // No padding should be added as there is no label or icon.
+ Vector2 size( Vector2::ZERO );
+ size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
+ size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
+
+ DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
+ // Check label only padding.
+ pushButton.SetLabelText( "Label" );
+
+ application.SendNotification();
+ application.Render();
+
+ size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
+ size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
+
+ // We should not test against the exact label size, we just make sure it is larger than our label padding so we know the padding has been applied.
+ DALI_TEST_GREATER( size.width, 20.0f, TEST_LOCATION );
+ DALI_TEST_GREATER( size.height, 20.0f, TEST_LOCATION );
+
+ // Re-initialise the button so we can setup icon-only padding.
+ pushButton.Unparent();
+ pushButton = PushButton::New();
+
+ pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
+ pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 20.0f, 20.0f, 20.0f, 20.0f ) );
+
+ pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ pushButton.SetPosition( 0.0f, 0.0f );
+ pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+
+ Stage::GetCurrent().Add( pushButton );
+
+ const char* INVALID_IMAGE_FILE_NAME = "invalid-image.jpg";
+ pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
+ pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME );
+ pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME );
+
+ application.SendNotification();
+ application.Render();
+
+ size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
+ size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
+
+ DALI_TEST_EQUALS( size, Vector2( 40.0f, 40.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
+ // Now test padding for both label and icon simultaneously.
+ pushButton.SetLabelText( "Label" );
+
+ application.SendNotification();
+ application.Render();
+
+ size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
+ size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
+
+ // We should not test against the exact label size, we just make sure it is larger than our label padding so we know the padding has been applied.
+ // Note we only test the width as we are horizontally aligned and the label my be less high than the icon.
+ // Full directional alignment tests are done in UtcDaliPushButtonAlignmentLayout.
+ DALI_TEST_GREATER( size.width, 60.0f, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliPushButtonAlignmentLayout(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliPushButtonAlignmentLayout");
+
+ // This test checks different alignments for the icon against the label.
+ // The icon is then moved around the label in each of it's alignments.
+ // The final relayed out size is checked to confirm the layout has been done correctly.
+ PushButton pushButton = PushButton::New();
+
+ pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 30.0f, 30.0f, 30.0f, 30.0f ) );
+ pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 75.0f, 75.0f, 75.0f, 75.0f ) );
+
+ pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ pushButton.SetPosition( 0.0f, 0.0f );
+ pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+
+ Stage::GetCurrent().Add( pushButton );
+
+ const char* INVALID_IMAGE_FILE_NAME = "invalid-image.jpg";
+ pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
+ pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME );
+ pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME );
+
+ application.SendNotification();
+ application.Render();
+
+ // First get the base size (without label).
+ Vector2 baseSize( Vector2::ZERO );
+ baseSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
+ baseSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
+
+ DALI_TEST_EQUALS( baseSize, Vector2( 150.0f, 150.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
+ // Add a label to cause size to be modified in the direction of alignment.
+ pushButton.SetLabelText( "Label" );
+
+ application.SendNotification();
+ application.Render();
+
+ Vector2 size( Vector2::ZERO );
+ size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
+ size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
+
+ DALI_TEST_GREATER( size.width, 150.0f + 60.0f, TEST_LOCATION );
+ DALI_TEST_EQUALS( size.height, 150.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
+ // Now test left alignment matches right for size.
+ pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
+
+ application.SendNotification();
+ application.Render();
+
+ Vector2 compareSize( Vector2::ZERO );
+ compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
+ compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
+
+ DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
+ // Test top alignment.
+ pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
+
+ application.SendNotification();
+ application.Render();
+
+ compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
+ compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
+
+ DALI_TEST_EQUALS( compareSize.width, 150.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+ DALI_TEST_GREATER( compareSize.height, 150.0f + 60.0f, TEST_LOCATION );
+
+ // Test bottom alignment.
+ pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
+
+ application.SendNotification();
+ application.Render();
+
+ size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
+ size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
+
+ DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+
+ END_TEST;
+}
{
ToolkitTestApplication application;
- TextLabel actor1 = TextLabel::New( "test actor 1" );
+ std::string labelText = "test actor 1";
- RadioButton radioButton = RadioButton::New( actor1 );
- DALI_TEST_CHECK( actor1 == radioButton.GetLabel() );
+ RadioButton radioButton = RadioButton::New( labelText );
+ DALI_TEST_EQUALS( radioButton.GetLabelText(), labelText, TEST_LOCATION );
- TextLabel actor2 = TextLabel::New( "test actor 2" );
- radioButton.SetLabel( actor2 );
- DALI_TEST_CHECK( actor2 == radioButton.GetLabel() );
+ std::string labelText2 = "test actor 2";
+ radioButton.SetLabelText( labelText2 );
+ DALI_TEST_EQUALS( radioButton.GetLabelText(), labelText2, TEST_LOCATION );
END_TEST;
}
POPUP_PASTE_BUTTON_ICON_IMAGE, ///< name "popup-paste-button-image", The image to use as the popup paste icon, type STRING
POPUP_SELECT_BUTTON_ICON_IMAGE, ///< name "popup-select-button-image", The image to use as the popup select icon, type STRING
POPUP_SELECT_ALL_BUTTON_ICON_IMAGE, ///< name "popup-select-all-button-image", The image to use as the popup select all icon, type STRING
- DIVIDER_COLOR, ///< name "popup-divider-color", VECTOR4, The color of the divider between options, type VECTOR4
- ICON_COLOR, ///< name "popup-icon-color", VECTOR4, The color of the icons (if supplied), type VECTOR4
- PRESSED_COLOR ///< name "popup-pressed-color", VECTOR4, The color of the option when pressed, type VECTOR4
+ POPUP_DIVIDER_COLOR, ///< name "popup-divider-color", The color of the divider between options, type VECTOR4
+ POPUP_ICON_COLOR, ///< name "popup-icon-color", The color of the icons (if supplied), type VECTOR4
+ POPUP_PRESSED_COLOR, ///< name "popup-pressed-color", The color of the option when pressed, type VECTOR4
+ POPUP_PRESSED_IMAGE ///< name "popup-pressed-image", The image to use for the option when pressed, type STRING
};
};
// EXTERNAL INCLUDES
#include <cstring> // for strcmp
#include <dali/public-api/events/touch-event.h>
+#include <dali/public-api/images/resource-image.h>
#include <dali/public-api/object/type-registry.h>
#include <dali/devel-api/object/type-registry-helper.h>
#include <dali/public-api/actors/image-actor.h>
#include <dali/devel-api/scripting/scripting.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
/**
DALI_PROPERTY_REGISTRATION( Toolkit, Button, "next-auto-repeating-delay", 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, "normal-state-actor", MAP, NORMAL_STATE_ACTOR )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected-state-actor", MAP, SELECTED_STATE_ACTOR )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled-state-actor", MAP, DISABLED_STATE_ACTOR )
-DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label-actor", MAP, LABEL_ACTOR )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselected-state-image", STRING, UNSELECTED_STATE_IMAGE )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected-state-image", STRING, SELECTED_STATE_IMAGE )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled-state-image", STRING, DISABLED_STATE_IMAGE )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselected-color", VECTOR4, UNSELECTED_COLOR )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected-color", VECTOR4, SELECTED_COLOR )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label-text", STRING, LABEL_TEXT )
DALI_SIGNAL_REGISTRATION( Toolkit, Button, "pressed", SIGNAL_PRESSED )
DALI_SIGNAL_REGISTRATION( Toolkit, Button, "released", SIGNAL_RELEASED )
const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
+const char* const STYLE_BUTTON_LABEL = "button.label";
+
} // unnamed namespace
Button::Button()
: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
mAutoRepeatingTimer(),
+ mUnselectedColor( Color::WHITE ), // The natural colors of the specified images will be used by default.
+ mSelectedColor( Color::WHITE ),
mDisabled( false ),
mAutoRepeating( false ),
mTogglableButton( false ),
TransitionButtonImage( mDisabledBackgroundContent );
AddButtonImage( mUnselectedContent );
TransitionButtonImage( mDisabledContent );
+
+ AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
ReAddLabel();
+ TransitionOut( mDecoration[ SELECTED_DECORATION ] );
TransitionOut( mUnselectedContent );
TransitionOut( mSelectedContent );
TransitionOut( mBackgroundContent );
TransitionButtonImage( mDisabledBackgroundContent );
AddButtonImage( mSelectedContent );
TransitionButtonImage( mDisabledSelectedContent );
+
+ AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
ReAddLabel();
+ TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
TransitionOut( mUnselectedContent );
TransitionOut( mSelectedContent );
TransitionOut( mBackgroundContent );
TransitionButtonImage( mBackgroundContent );
AddButtonImage( mDisabledContent );
TransitionButtonImage( mUnselectedContent );
+
+ AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
ReAddLabel();
+ TransitionOut( mDecoration[ SELECTED_DECORATION ] );
TransitionOut( mSelectedContent );
TransitionOut( mSelectedBackgroundContent );
TransitionOut( mDisabledContent );
TransitionButtonImage( mSelectedBackgroundContent );
AddButtonImage( mDisabledSelectedContent );
TransitionButtonImage( mSelectedContent );
+
+ AddButtonImage( mDecoration[ SELECTED_DECORATION ] );
ReAddLabel();
+ TransitionOut( mDecoration[ UNSELECTED_DECORATION ] );
TransitionOut( mUnselectedContent );
TransitionOut( mDisabledContent );
TransitionOut( mDisabledSelectedContent );
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 );
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 );
return mAnimationTime;
}
-void Button::SetLabel( const std::string& label )
-{
- Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( label );
- SetLabel( textLabel );
-}
-
-void Button::SetLabel( Actor label )
+void Button::SetLabelText( const std::string& label )
{
- if( mLabel != label )
+ if( !mLabel || ( label != GetLabelText() ) )
{
- if( mLabel && mLabel.GetParent() )
+ // If we have a label, unparent and update it.
+ if( mLabel )
{
- mLabel.GetParent().Remove( mLabel );
+ mLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, label );
+ }
+ else
+ {
+ // If we don't have a label, create one and set it up.
+ mLabel = Toolkit::TextLabel::New( label );
+ mLabel.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_LABEL );
+ mLabel.SetPosition( 0.f, 0.f );
+ // label should be the top of the button
+ Self().Add( mLabel );
}
-
- mLabel = label;
- mLabel.SetPosition( 0.f, 0.f );
-
- // label should be the top of the button
- Self().Add( mLabel );
OnLabelSet();
}
}
-Actor Button::GetLabel() const
+std::string Button::GetLabelText() const
{
- return mLabel;
+ Toolkit::TextLabel label = Dali::Toolkit::TextLabel::DownCast( mLabel );
+ if( label )
+ {
+ return label.GetProperty<std::string>( Dali::Toolkit::TextLabel::Property::TEXT );
+ }
+ return std::string();
}
-Actor& Button::GetLabel()
+Actor& Button::GetLabelActor()
{
return mLabel;
}
-void Button::SetButtonImage( Actor image )
+void Button::SetDecoration( DecorationState state, Actor actor )
{
- StopTransitionAnimation();
-
- if( mUnselectedContent && mUnselectedContent.GetParent() )
+ if( mDecoration[ state ] && mDecoration[ state ].GetParent() )
{
- Self().Remove( mUnselectedContent );
+ mDecoration[ state ].Unparent();
}
- mUnselectedContent = image;
- if( mUnselectedContent )
- {
- mUnselectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mUnselectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mUnselectedContent.SetPosition( 0.f, 0.f );
- }
- ResetImageLayers();
- OnButtonImageSet();
+ mDecoration[ state ] = actor;
+ mDecoration[ state ].SetColorMode( USE_OWN_COLOR );
+ ResetImageLayers();
RelayoutRequest();
}
-Actor Button::GetButtonImage() const
+Actor& Button::GetDecoration( DecorationState state )
{
- return mUnselectedContent;
+ return mDecoration[ state ];
}
-Actor& Button::GetButtonImage()
+void Button::SetupContent( Actor& actorToModify, Actor newActor )
{
- return mUnselectedContent;
+ 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();
+ }
}
-void Button::SetSelectedImage( Actor image )
+void Button::SetUnselectedColor( const Vector4& color )
{
- StopTransitionAnimation();
+ mUnselectedColor = color;
- if( mSelectedContent && mSelectedContent.GetParent() )
+ if( mUnselectedContent && !GetUnselectedImageFilename().empty() )
{
- Self().Remove( mSelectedContent );
+ // If there is existing unselected content, change the color on it directly.
+ mUnselectedContent.SetColor( mUnselectedColor );
}
-
- mSelectedContent = image;
- if( mSelectedContent )
+ else
{
- mSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mSelectedContent.SetPosition( 0.f, 0.f );
+ // If there is no existing content, create a new actor to use for flat color.
+ SetupContent( mUnselectedContent, CreateSolidColorActor( mUnselectedColor ) );
+ mUnselectedContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
}
- ResetImageLayers();
- OnSelectedImageSet();
-
- RelayoutRequest();
}
-Actor Button::GetSelectedImage() const
+const Vector4 Button::GetUnselectedColor() const
{
- return mSelectedContent;
+ return mUnselectedColor;
}
-Actor& Button::GetSelectedImage()
+void Button::SetSelectedColor( const Vector4& color )
{
- return mSelectedContent;
+ mSelectedColor = color;
+
+ if( mSelectedContent && !GetSelectedImageFilename().empty() )
+ {
+ // If there is existing unselected content, change the color on it directly.
+ mSelectedContent.SetColor( mSelectedColor );
+ }
+ else
+ {
+ // If there is no existing content, create a new actor to use for flat color.
+ SetupContent( mSelectedContent, CreateSolidColorActor( mSelectedColor ) );
+ mSelectedContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ }
}
-void Button::SetBackgroundImage( Actor image )
+const Vector4 Button::GetSelectedColor() const
{
- StopTransitionAnimation();
+ return mSelectedColor;
+}
- if( mBackgroundContent && mBackgroundContent.GetParent() )
+void Button::SetUnselectedImage( const std::string& filename )
+{
+ ImageActor newContent;
+ if( !filename.empty() )
{
- Self().Remove( mBackgroundContent );
+ Image resourceimage = Dali::ResourceImage::New( filename );
+ if( resourceimage )
+ {
+ newContent = ImageActor::New( resourceimage );
+ }
}
-
- mBackgroundContent = image;
- if( mBackgroundContent )
+ else
{
- mBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mBackgroundContent.SetPosition( 0.f, 0.f );
+ newContent = ImageActor::New();
}
- ResetImageLayers();
- OnBackgroundImageSet();
- RelayoutRequest();
-}
+ if( newContent )
+ {
+ SetupContent( mUnselectedContent, newContent );
-Actor Button::GetBackgroundImage() const
-{
- return mBackgroundContent;
+ mUnselectedContent.SetColor( mUnselectedColor );
+
+ OnUnselectedImageSet();
+ RelayoutRequest();
+ }
}
-Actor& Button::GetBackgroundImage()
+Actor& Button::GetUnselectedImage()
{
- return mBackgroundContent;
+ return mUnselectedContent;
}
-void Button::SetSelectedBackgroundImage( Actor image )
+void Button::SetSelectedImage( const std::string& filename )
{
- StopTransitionAnimation();
-
- if( mSelectedBackgroundContent && mSelectedBackgroundContent.GetParent() )
+ ImageActor newContent;
+ if( !filename.empty() )
{
- Self().Remove( mSelectedBackgroundContent );
+ Image resourceimage = Dali::ResourceImage::New( filename );
+ if( resourceimage )
+ {
+ newContent = ImageActor::New( resourceimage );
+ }
}
-
- mSelectedBackgroundContent = image;
- if( mSelectedBackgroundContent )
+ else
{
- mSelectedBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mSelectedBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mSelectedBackgroundContent.SetPosition( 0.f, 0.f );
+ newContent = ImageActor::New();
}
- ResetImageLayers();
- OnSelectedBackgroundImageSet();
- RelayoutRequest();
+ if( newContent )
+ {
+ SetupContent( mSelectedContent, newContent );
+
+ mSelectedContent.SetColor( mSelectedColor );
+
+ OnSelectedImageSet();
+ RelayoutRequest();
+ }
}
-Actor Button::GetSelectedBackgroundImage() const
+Actor& Button::GetSelectedImage()
{
- return mSelectedBackgroundContent;
+ return mSelectedContent;
}
-Actor& Button::GetSelectedBackgroundImage()
+void Button::SetBackgroundImage( const std::string& filename )
{
- return mSelectedBackgroundContent;
+ Image resourceimage = Dali::ResourceImage::New( filename );
+ if( resourceimage )
+ {
+ SetupContent( mBackgroundContent, ImageActor::New( resourceimage ) );
+
+ OnBackgroundImageSet();
+ RelayoutRequest();
+ }
}
-void Button::SetDisabledImage( Actor image )
+Actor& Button::GetBackgroundImage()
{
- StopTransitionAnimation();
+ return mBackgroundContent;
+}
- if( mDisabledContent && mDisabledContent.GetParent() )
+void Button::SetSelectedBackgroundImage( const std::string& filename )
+{
+ Image resourceimage = Dali::ResourceImage::New( filename );
+ if( resourceimage )
{
- Self().Remove( mDisabledContent );
- }
+ SetupContent( mSelectedBackgroundContent, ImageActor::New( resourceimage ) );
- mDisabledContent = image;
- if( mDisabledContent )
- {
- mDisabledContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mDisabledContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mDisabledContent.SetPosition( 0.f, 0.f );
+ OnSelectedBackgroundImageSet();
+ RelayoutRequest();
}
+}
- ResetImageLayers();
- OnDisabledImageSet();
+Actor& Button::GetSelectedBackgroundImage()
+{
+ return mSelectedBackgroundContent;
}
-Actor Button::GetDisabledImage() const
+void Button::SetDisabledImage( const std::string& filename )
{
- return mDisabledContent;
+ Image resourceimage = Dali::ResourceImage::New( filename );
+ if( resourceimage )
+ {
+ SetupContent( mDisabledContent, ImageActor::New( resourceimage ) );
+
+ OnDisabledImageSet();
+ RelayoutRequest();
+ }
}
Actor& Button::GetDisabledImage()
return mDisabledContent;
}
-void Button::SetDisabledSelectedImage( Actor image )
+void Button::SetDisabledSelectedImage( const std::string& filename )
{
- StopTransitionAnimation();
-
- if( mDisabledSelectedContent && mDisabledSelectedContent.GetParent() )
+ Image resourceimage = Dali::ResourceImage::New( filename );
+ if( resourceimage )
{
- Self().Remove( mDisabledSelectedContent );
+ SetupContent( mDisabledSelectedContent, ImageActor::New( resourceimage ) );
+
+ OnDisabledSelectedImageSet();
+ RelayoutRequest();
}
+}
- mDisabledSelectedContent = image;
- if( mDisabledSelectedContent )
+Actor& Button::GetDisabledSelectedImage()
+{
+ return mDisabledSelectedContent;
+}
+
+void Button::SetDisabledBackgroundImage( const std::string& filename )
+{
+ Image resourceimage = Dali::ResourceImage::New( filename );
+ if( resourceimage )
{
- mDisabledSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mDisabledSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mDisabledSelectedContent.SetPosition( 0.f, 0.f );
+ SetupContent( mDisabledBackgroundContent, ImageActor::New( resourceimage ) );
+
+ OnDisabledBackgroundImageSet();
+ RelayoutRequest();
}
+}
- ResetImageLayers();
- OnDisabledSelectedImageSet();
+Actor& Button::GetDisabledBackgroundImage()
+{
+ return mDisabledBackgroundContent;
}
-Actor Button::GetDisabledSelectedImage() const
+std::string Button::GetUnselectedImageFilename() const
{
- return mDisabledSelectedContent;
+ if( mUnselectedContent )
+ {
+ ResourceImage image = ResourceImage::DownCast( mUnselectedContent );
+ if( image )
+ {
+ return image.GetUrl();
+ }
+ }
+ return std::string();
}
-Actor& Button::GetDisabledSelectedImage()
+std::string Button::GetSelectedImageFilename() const
{
- return mDisabledSelectedContent;
+ if( mSelectedContent )
+ {
+ ResourceImage image = ResourceImage::DownCast( mSelectedContent );
+ if( image )
+ {
+ return image.GetUrl();
+ }
+ }
+ return std::string();
}
-void Button::SetDisabledBackgroundImage( Actor image )
+std::string Button::GetBackgroundImageFilename() const
{
- StopTransitionAnimation();
+ if( mBackgroundContent )
+ {
+ ResourceImage image = ResourceImage::DownCast( mBackgroundContent );
+ if( image )
+ {
+ return image.GetUrl();
+ }
+ }
+ return std::string();
+}
- if( mDisabledBackgroundContent && mDisabledBackgroundContent.GetParent() )
+std::string Button::GetSelectedBackgroundImageFilename() const
+{
+ if( mSelectedBackgroundContent )
{
- Self().Remove( mDisabledBackgroundContent );
+ ResourceImage image = ResourceImage::DownCast( mSelectedBackgroundContent );
+ if( image )
+ {
+ return image.GetUrl();
+ }
}
+ return std::string();
+}
- mDisabledBackgroundContent = image;
- if( mDisabledBackgroundContent )
+std::string Button::GetDisabledImageFilename() const
+{
+ if( mDisabledContent )
{
- mDisabledBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mDisabledBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
- mDisabledBackgroundContent.SetPosition( 0.f, 0.f );
+ ResourceImage image = ResourceImage::DownCast( mDisabledContent );
+ if( image )
+ {
+ return image.GetUrl();
+ }
}
- ResetImageLayers();
- OnDisabledBackgroundImageSet();
+ return std::string();
}
-Actor Button::GetDisabledBackgroundImage() const
+std::string Button::GetDisabledSelectedImageFilename() const
{
- return mDisabledBackgroundContent;
+ if( mDisabledSelectedContent )
+ {
+ ResourceImage image = ResourceImage::DownCast( mDisabledSelectedContent );
+ if( image )
+ {
+ return image.GetUrl();
+ }
+ }
+ return std::string();
}
-Actor& Button::GetDisabledBackgroundImage()
+std::string Button::GetDisabledBackgroundImageFilename() const
{
- return mDisabledBackgroundContent;
+ if( mDisabledBackgroundContent )
+ {
+ ResourceImage image = ResourceImage::DownCast( mDisabledBackgroundContent );
+ if( image )
+ {
+ return image.GetUrl();
+ }
+ }
+ return std::string();
}
bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
StopTransitionAnimation();
// Notifies the derived class the button has been pressed.
- OnPressed();
+ OnPressed();
- //Layer Order
+ //Layer Order
//(4) mSelectedContent (Inserted)
//(3) mUnselectedContent
//(2) mSelectedBackgroundContent (Inserted)
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 );
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 );
{
if( actor )
{
+ actor.Unparent();
Self().Add( actor );
}
}
//(2) mUnselectedContent
//(1) mBackgroundContent
+ RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] );
RemoveButtonImage( mSelectedContent );
RemoveButtonImage( mSelectedBackgroundContent );
RemoveButtonImage( mDisabledContent );
PrepareAddButtonImage( mBackgroundContent );
PrepareAddButtonImage( mUnselectedContent );
+
+ PrepareAddButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
+ ReAddLabel();
break;
}
case SelectedState:
//(2) mSelectedBackgroundContent
//(1) mBackgroundContent
+ RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
RemoveButtonImage( mUnselectedContent );
RemoveButtonImage( mDisabledContent );
RemoveButtonImage( mDisabledSelectedContent );
PrepareAddButtonImage( mBackgroundContent );
PrepareAddButtonImage( mSelectedBackgroundContent );
PrepareAddButtonImage( mSelectedContent );
+
+ PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] );
ReAddLabel();
break;
}
//(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();
break;
}
// (2) mDisabledSelectedContent
// (1) mDisabledBackgroundContent
+ RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] );
RemoveButtonImage( mUnselectedContent );
+ RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] );
RemoveButtonImage( mSelectedContent );
RemoveButtonImage( mBackgroundContent );
RemoveButtonImage( mSelectedBackgroundContent );
}
PrepareAddButtonImage( mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent );
+
+ PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] );
ReAddLabel();
break;
}
break;
}
- case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
+ case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE:
+ {
+ GetImplementation( button ).SetUnselectedImage( value.Get< std::string >() );
+ break;
+ }
+
+ case Toolkit::Button::Property::SELECTED_STATE_IMAGE:
+ {
+ GetImplementation( button ).SetSelectedImage( value.Get< std::string >() );
+ break;
+ }
+
+ case Toolkit::Button::Property::DISABLED_STATE_IMAGE:
{
- GetImplementation( button ).SetButtonImage( Scripting::NewActor( value.Get< Property::Map >() ) );
+ GetImplementation( button ).SetDisabledImage( value.Get< std::string >() );
break;
}
- case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
+ case Toolkit::Button::Property::UNSELECTED_COLOR:
{
- GetImplementation( button ).SetSelectedImage( Scripting::NewActor( value.Get< Property::Map >() ) );
+ GetImplementation( button ).SetUnselectedColor( value.Get< Vector4 >() );
break;
}
- case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
+ case Toolkit::Button::Property::SELECTED_COLOR:
{
- GetImplementation( button ).SetDisabledImage( Scripting::NewActor( value.Get< Property::Map >() ) );
+ GetImplementation( button ).SetSelectedColor( value.Get< Vector4 >() );
break;
}
- case Toolkit::Button::Property::LABEL_ACTOR:
+ case Toolkit::Button::Property::LABEL_TEXT:
{
- GetImplementation( button ).SetLabel( Scripting::NewActor( value.Get< Property::Map >() ) );
+ GetImplementation( button ).SetLabelText( value.Get< std::string >() );
break;
}
}
break;
}
- case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
+ case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE:
{
- Property::Map map;
- Scripting::CreatePropertyMap( GetImplementation( button ).mUnselectedContent, map );
- value = map;
+ value = GetImplementation( button ).GetUnselectedImageFilename();
break;
}
- case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
+ case Toolkit::Button::Property::SELECTED_STATE_IMAGE:
{
- Property::Map map;
- Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedContent, map );
- value = map;
+ value = GetImplementation( button ).GetSelectedImageFilename();
break;
}
- case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
+ case Toolkit::Button::Property::DISABLED_STATE_IMAGE:
{
- Property::Map map;
- Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledContent, map );
- value = map;
+ value = GetImplementation( button ).GetDisabledImageFilename();
break;
}
- case Toolkit::Button::Property::LABEL_ACTOR:
+ case Toolkit::Button::Property::UNSELECTED_COLOR:
{
- Property::Map map;
- Scripting::CreatePropertyMap( GetImplementation( button ).mLabel, map );
- value = map;
+ value = GetImplementation( button ).GetUnselectedColor();
+ break;
+ }
+
+ case Toolkit::Button::Property::SELECTED_COLOR:
+ {
+ value = GetImplementation( button ).GetSelectedColor();
+ break;
+ }
+
+ case Toolkit::Button::Property::LABEL_TEXT:
+ {
+ value = GetImplementation( button ).GetLabelText();
break;
}
}
return value;
}
+// Deprecated API
+
+void Button::SetLabel( Actor label )
+{
+ if( mLabel != label )
+ {
+ if( mLabel && mLabel.GetParent() )
+ {
+ mLabel.GetParent().Remove( mLabel );
+ }
+
+ mLabel = label;
+ mLabel.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_LABEL );
+ mLabel.SetPosition( 0.f, 0.f );
+
+ // label should be the top of the button
+ Self().Add( mLabel );
+
+ OnLabelSet();
+
+ RelayoutRequest();
+ }
+}
+
+void Button::SetButtonImage( Actor image )
+{
+ if( image )
+ {
+ StopTransitionAnimation();
+
+ SetupContent( mUnselectedContent, image );
+
+ OnUnselectedImageSet();
+ RelayoutRequest();
+ }
+}
+
+void Button::SetSelectedImage( Actor image )
+{
+ if( image )
+ {
+ StopTransitionAnimation();
+
+ SetupContent( mSelectedContent, image );
+
+ OnSelectedImageSet();
+ RelayoutRequest();
+ }
+}
+
+void Button::SetBackgroundImage( Actor image )
+{
+ if( image )
+ {
+ StopTransitionAnimation();
+
+ SetupContent( mBackgroundContent, image );
+
+ OnBackgroundImageSet();
+ RelayoutRequest();
+ }
+}
+
+void Button::SetSelectedBackgroundImage( Actor image )
+{
+ if( image )
+ {
+ StopTransitionAnimation();
+
+ SetupContent( mSelectedBackgroundContent, image );
+
+ OnSelectedBackgroundImageSet();
+ RelayoutRequest();
+ }
+}
+
+void Button::SetDisabledImage( Actor image )
+{
+ if( image )
+ {
+ StopTransitionAnimation();
+
+ SetupContent( mDisabledContent, image );
+
+ OnDisabledImageSet();
+ RelayoutRequest();
+ }
+}
+
+void Button::SetDisabledSelectedImage( Actor image )
+{
+ if( image )
+ {
+ StopTransitionAnimation();
+
+ SetupContent( mDisabledSelectedContent, image );
+
+ OnDisabledSelectedImageSet();
+ RelayoutRequest();
+ }
+}
+
+void Button::SetDisabledBackgroundImage( Actor image )
+{
+ if( image )
+ {
+ StopTransitionAnimation();
+
+ SetupContent( mDisabledBackgroundContent, image );
+
+ OnDisabledBackgroundImageSet();
+ RelayoutRequest();
+ }
+}
+
+Actor Button::GetButtonImage() const
+{
+ return mUnselectedContent;
+}
+
+Actor Button::GetSelectedImage() const
+{
+ return mSelectedContent;
+}
+
+
} // namespace Internal
} // namespace Toolkit
float GetAnimationTime() const;
/**
- * @copydoc Dali::Toolkit::Button::SetLabel( const std::string& label )
+ * @copydoc Dali::Toolkit::Button::SetLabelText
*/
- void SetLabel( const std::string& label );
+ void SetLabelText( const std::string& label );
/**
- * @copydoc Dali::Toolkit::Button::SetLabel( Actor label )
+ * @copydoc Dali::Toolkit::Button::GetLabelText
*/
- void SetLabel( Actor label );
+ std::string GetLabelText() const;
/**
- * @copydoc Dali::Toolkit::Button::GetLabel()
+ * @copydoc Dali::Toolkit::PushButton::SetUnselectedImage
*/
- Actor GetLabel() const;
+ void SetUnselectedImage( const std::string& filename );
/**
- * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image )
+ * @copydoc Dali::Toolkit::PushButton::SetSelectedImage
*/
- void SetButtonImage( Actor image );
+ void SetSelectedImage( const std::string& filename );
/**
- * @copydoc Dali::Toolkit::PushButton::GetButtonImage()
+ * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage
*/
- Actor GetButtonImage() const;
+ void SetBackgroundImage( const std::string& filename );
/**
- * Internal use only.
- * @return A reference to the button image.
+ * @copydoc Dali::Toolkit::PushButton::SetSelectedBackgroundImage
*/
- Actor& GetButtonImage();
+ void SetSelectedBackgroundImage( const std::string& filename );
/**
- * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( Actor image )
+ * @copydoc Dali::Toolkit::PushButton::SetDisabledImage
*/
- void SetSelectedImage( Actor image );
+ void SetDisabledImage( const std::string& filename );
/**
- * @copydoc Dali::Toolkit::PushButton::GetSelectedImage()
+ * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage
*/
- Actor GetSelectedImage() const;
+ void SetDisabledSelectedImage( const std::string& filename );
/**
- * Internal use only.
- * @return A reference to the selected image.
+ * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage
*/
- Actor& GetSelectedImage();
+ void SetDisabledBackgroundImage( const std::string& filename );
/**
- * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
+ * @return The filename used for the button image.
*/
- void SetBackgroundImage( Actor image );
+ std::string GetUnselectedImageFilename() const;
/**
- * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage()
+ * @return The filename used for the selected image.
*/
- Actor GetBackgroundImage() const;
+ std::string GetSelectedImageFilename() const;
/**
- * Internal use only.
- * @return A reference to the background image.
+ * @return The filename used for the background image.
*/
- Actor& GetBackgroundImage();
+ std::string GetBackgroundImageFilename() const;
/**
- * @copydoc Dali::Toolkit::PushButton::SetSelectedBackgroundImage( Actor image )
+ * @return The filename used for the selected background image.
*/
- void SetSelectedBackgroundImage( Actor image );
+ std::string GetSelectedBackgroundImageFilename() const;
/**
- * @copydoc Dali::Toolkit::PushButton::GetSelectedBackgroundImage()
+ * @return The filename used for the disabled button image.
*/
- Actor GetSelectedBackgroundImage() const;
+ std::string GetDisabledImageFilename() const;
/**
- * Internal use only.
- * @return A reference to the selected background image.
+ * @return The filename used for the disabled selected image.
*/
- Actor& GetSelectedBackgroundImage();
+ std::string GetDisabledSelectedImageFilename() const;
/**
- * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Actor image )
+ * @return The filename used for the disabled background image.
*/
- void SetDisabledImage( Actor image );
+ std::string GetDisabledBackgroundImageFilename() const;
/**
- * @copydoc Dali::Toolkit::PushButton::GetDisabledImage()
+ * Performs actions as requested using the action name.
+ * @param[in] object The object on which to perform the action.
+ * @param[in] actionName The action to perform.
+ * @param[in] attributes The attributes with which to perfrom this action.
+ * @return true if action has been accepted by this control
*/
- Actor GetDisabledImage() const;
+ static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes );
+
+public: // Deprecated API
/**
- * Internal use only.
- * @return A reference to the disabled button image.
+ * @copydoc Dali::Toolkit::Button::SetLabel( Actor label )
*/
- Actor& GetDisabledImage();
+ void SetLabel( Actor label );
/**
- * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Actor image )
+ * @deprecated Sets the unselected image with an Actor.
+ * @param[in] image The Actor to use.
*/
- void SetDisabledSelectedImage( Actor image );
+ void SetButtonImage( Actor image );
/**
- * @copydoc Dali::Toolkit::CheckBoxButton::GetDisabledSelectedImage()
+ * @deprecated Sets the selected image with an Actor.
+ * @param[in] image The Actor to use.
*/
- Actor GetDisabledSelectedImage() const;
+ void SetSelectedImage( Actor image );
/**
- * Internal use only.
- * @return A reference to the disabled selected image.
+ * @deprecated Sets the background image with an Actor.
+ * @param[in] image The Actor to use.
*/
- Actor& GetDisabledSelectedImage();
+ void SetBackgroundImage( Actor image );
/**
- * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Actor image )
+ * @deprecated Sets the selected background image with an Actor.
+ * @param[in] image The Actor to use.
*/
- void SetDisabledBackgroundImage( Actor image );
+ void SetSelectedBackgroundImage( Actor image );
/**
- * @copydoc Dali::Toolkit::PushButton::GetDisabledBackgroundImage()
+ * @deprecated Sets the disabled image with an Actor.
+ * @param[in] image The Actor to use.
*/
- Actor GetDisabledBackgroundImage() const;
+ void SetDisabledImage( Actor image );
/**
- * Internal use only.
- * @return A reference to the disabled background image.
+ * @deprecated Sets the disabled selected image with an Actor.
+ * @param[in] image The Actor to use.
*/
- Actor& GetDisabledBackgroundImage();
+ void SetDisabledSelectedImage( Actor image );
/**
- * Performs actions as requested using the action name.
- * @param[in] object The object on which to perform the action.
- * @param[in] actionName The action to perform.
- * @param[in] attributes The attributes with which to perfrom this action.
- * @return true if action has been accepted by this control
+ * @deprecated Sets the disabled background image with an Actor.
+ * @param[in] image The Actor to use.
*/
- static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes );
+ void SetDisabledBackgroundImage( Actor image );
+
+ /**
+ * @copydoc Dali::Toolkit::Button::GetButtonImage()
+ */
+ Actor GetButtonImage() const;
+
+ /**
+ * @copydoc Dali::Toolkit::Button::GetSelectedImage()
+ */
+ Actor GetSelectedImage() const;
protected:
/**
* @return A reference to the label actor.
*/
- Actor& GetLabel();
+ Actor& GetLabelActor();
+
+ /**
+ * @return A reference to the unselected button image.
+ */
+ Actor& GetUnselectedImage();
+
+ /**
+ * @return A reference to the selected image.
+ */
+ Actor& GetSelectedImage();
+
+ /**
+ * @return A reference to the background image.
+ */
+ Actor& GetBackgroundImage();
+
+ /**
+ * @return A reference to the selected background image.
+ */
+ Actor& GetSelectedBackgroundImage();
+
+ /**
+ * @return A reference to the disabled button image.
+ */
+ Actor& GetDisabledImage();
+
+ /**
+ * @return A reference to the disabled selected image.
+ */
+ Actor& GetDisabledSelectedImage();
+
+ /**
+ * @return A reference to the disabled background image.
+ */
+ Actor& GetDisabledBackgroundImage();
private:
virtual void OnLabelSet() {}
/**
- * This method is called when the button image is set
+ * This method is called when the unselected button image is set
*/
- virtual void OnButtonImageSet() {}
+ virtual void OnUnselectedImageSet() {}
/**
* This method is called when the selected image is set
*/
void Released();
+ /**
+ * Used to perform common setup applied to images within button.
+ * This will replace the current image with the specifed one.
+ * @param[in] actorToModify The image to replace.
+ * @param[out] newActor The new image to use.
+ */
+ void SetupContent( Actor& actorToModify, Actor newActor );
+
+ /**
+ * Sets the color of the unselected image.
+ * If no image exists, it is created.
+ * @param[in] color The color to use.
+ */
+ void SetUnselectedColor( const Vector4& color );
+
+ /**
+ * Gets the unselected content color.
+ * @return The currently used unselected color.
+ */
+ const Vector4 GetUnselectedColor() const;
+
+ /**
+ * Sets the color of the selected image.
+ * If no image exists, it is created.
+ * @param[in] color The color to use.
+ */
+ void SetSelectedColor( const Vector4& color );
+
+ /**
+ * Gets the selected content color.
+ * @return The currently used selected color.
+ */
+ const Vector4 GetSelectedColor() const;
+
protected:
enum ButtonState
DisabledSelectedState, ///< The button is disabled and selected.
};
+ /**
+ * Enum to specify which decoration when getting and setting decorations.
+ */
+ enum DecorationState
+ {
+ UNSELECTED_DECORATION = 0,
+ SELECTED_DECORATION,
+ DECORATION_STATES
+ };
+
ButtonState GetState();
PaintState GetPaintState();
+ void SetDecoration( DecorationState state, Actor actor );
+ Actor& GetDecoration( DecorationState state );
+
/**
* Returns the animation to be used for transitioning creating the animation if needed.
virtual void OnTransitionOut( Actor actor ) {}
private:
+
/**
* Starts the transition animation.
* Button::TransitionFinished is called when the animation finishes.
Actor mLabel; ///< Stores the button label.
+ Actor mDecoration[ DECORATION_STATES ]; ///< Stores the decorations for both selected and unselected states.
+
Actor mUnselectedContent; ///< Stores the unselected content.
Actor mSelectedContent; ///< Stores the selected content.
Actor mBackgroundContent; ///< Stores the background content.
TapGestureDetector mTapDetector;
+ Vector4 mUnselectedColor; ///< Color to use for unselected content.
+ Vector4 mSelectedColor; ///< Color to use for selected content.
+
bool mDisabled; ///< Stores the disabled property.
bool mAutoRepeating; ///< Stores the autorepeating property.
bool mTogglableButton; ///< Stores the togglable property.
// Wrap around all children
Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
- Image buttonImage = Dali::ResourceImage::New( UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
- Image selectedImage = Dali::ResourceImage::New( SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
- Image disabledImage = Dali::ResourceImage::New( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
- Image disabledSelectedImage = Dali::ResourceImage::New( DISABLED_SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
-
- SetButtonImage( ImageActor::New( buttonImage ) );
- SetSelectedImage( ImageActor::New( selectedImage ) );
- SetDisabledImage( ImageActor::New( disabledImage ) );
- SetDisabledSelectedImage( ImageActor::New( disabledSelectedImage ) );
+ SetUnselectedImage( UNSELECTED_BUTTON_IMAGE_DIR );
+ SetSelectedImage( SELECTED_BUTTON_IMAGE_DIR );
+ SetDisabledImage( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR );
+ SetDisabledSelectedImage( DISABLED_SELECTED_BUTTON_IMAGE_DIR );
}
void CheckBoxButton::OnLabelSet()
{
- Actor& label = GetLabel();
+ Actor& label = GetLabelActor();
if( label )
{
{
label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
- else if( GetButtonImage() )
+ else if( GetUnselectedImage() )
{
- label.SetX( GetButtonImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
+ label.SetX( GetUnselectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
else
{
Actor& backgroundImage = GetBackgroundImage();
Actor& disabledBackgroundImage = GetDisabledBackgroundImage();
- Actor& label = GetLabel();
+ Actor& label = GetLabelActor();
if( label )
{
if( IsDisabled() && disabledBackgroundImage )
{
label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
- else if( GetButtonImage() )
+ else if( GetUnselectedImage() )
{
- label.SetX( GetButtonImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
+ label.SetX( GetUnselectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
else
{
// EXTERNAL INCLUDES
#include <dali/public-api/actors/image-actor.h>
#include <dali/public-api/object/type-registry.h>
+#include <dali/devel-api/object/type-registry-helper.h>
#include <dali/public-api/images/resource-image.h>
+#include <dali/devel-api/scripting/scripting.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
namespace
{
-const float TEXT_PADDING = 12.0f;
-const float ANIMATION_TIME( 0.2f );
+const float ANIMATION_TIME( 0.2f );
+const Padding DEFAULT_LABEL_PADDING( 12.0f, 12.0f, 12.0f, 12.0f );
+const Padding DEFAULT_ICON_PADDING( 12.0f, 12.0f, 12.0f, 12.0f );
BaseHandle Create()
{
return Toolkit::PushButton::New();
}
-TypeRegistration typeRegistration( typeid(Toolkit::PushButton), typeid(Toolkit::Button), Create );
+// Properties
+
+DALI_TYPE_REGISTRATION_BEGIN( Toolkit::PushButton, Toolkit::Button, Create )
+
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "unselected-icon", STRING, UNSELECTED_ICON )
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "selected-icon", STRING, SELECTED_ICON )
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "icon-alignment", STRING, ICON_ALIGNMENT )
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "label-padding", STRING, LABEL_PADDING )
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "icon-padding", STRING, ICON_PADDING )
+
+DALI_TYPE_REGISTRATION_END()
+
+/*
+ * Table to define Text-to-enum conversions for IconAlignment.
+ */
+const Dali::Scripting::StringEnum IconAlignmentTable[] = {
+ { "LEFT", Toolkit::Internal::PushButton::LEFT },
+ { "RIGHT", Toolkit::Internal::PushButton::RIGHT },
+ { "TOP", Toolkit::Internal::PushButton::TOP },
+ { "BOTTOM", Toolkit::Internal::PushButton::BOTTOM },
+}; const unsigned int IconAlignmentTableCount = sizeof( IconAlignmentTable ) / sizeof( IconAlignmentTable[0] );
const char* const UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-up.9.png";
const char* const SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-down.9.png";
PushButton::PushButton()
: Button(),
+ mLabelPadding( DEFAULT_LABEL_PADDING ),
+ mIconPadding( DEFAULT_ICON_PADDING ),
+ mIconAlignment( RIGHT ),
mSize()
{
SetAnimationTime( ANIMATION_TIME );
// Set resize policy to natural size so that buttons will resize to background images
self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
- Image buttonImage = Dali::ResourceImage::New( UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
- Image selectedImage = Dali::ResourceImage::New( SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
- Image disabledImage = Dali::ResourceImage::New( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
- Image disabledSelectedImage = Dali::ResourceImage::New( DISABLED_SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
+ SetUnselectedImage( UNSELECTED_BUTTON_IMAGE_DIR );
+ SetSelectedImage( SELECTED_BUTTON_IMAGE_DIR );
+ SetDisabledImage( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR );
+ SetDisabledSelectedImage( DISABLED_SELECTED_BUTTON_IMAGE_DIR );
+}
+
+void PushButton::SetIcon( DecorationState state, const std::string iconFilename )
+{
+ mIconName[ state ] = iconFilename;
+ SetDecoration( state, ImageActor::New( Dali::ResourceImage::New( iconFilename ) ) );
+ ConfigureSizeNegotiation();
+}
+
+std::string& PushButton::GetIcon( DecorationState state )
+{
+ return mIconName[ state ];
+}
+
+void PushButton::SetIconAlignment( const PushButton::IconAlignment iconAlignment )
+{
+ mIconAlignment = iconAlignment;
+ ConfigureSizeNegotiation();
+}
+
+const PushButton::IconAlignment PushButton::GetIconAlignment() const
+{
+ return mIconAlignment;
+}
- SetButtonImage( ImageActor::New( buttonImage ) );
- SetSelectedImage( ImageActor::New( selectedImage ) );
- SetDisabledImage( ImageActor::New( disabledImage ) );
- SetDisabledSelectedImage( ImageActor::New( disabledSelectedImage ) );
+void PushButton::SetLabelPadding( const Vector4& padding )
+{
+ mLabelPadding = Padding( padding.x, padding.y, padding.z, padding.w );
+ ConfigureSizeNegotiation();
+}
+
+Vector4 PushButton::GetLabelPadding()
+{
+ return Vector4( mLabelPadding.left, mLabelPadding.right, mLabelPadding.top, mLabelPadding.bottom );
+}
+
+void PushButton::SetIconPadding( const Vector4& padding )
+{
+ mIconPadding = Padding( padding.x, padding.y, padding.z, padding.w );
+ ConfigureSizeNegotiation();
+}
+
+Vector4 PushButton::GetIconPadding()
+{
+ return Vector4( mIconPadding.left, mIconPadding.right, mIconPadding.top, mIconPadding.bottom );
+}
+
+void PushButton::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
+{
+ Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) );
+
+ if ( pushButton )
+ {
+ PushButton& pushButtonImpl( GetImplementation( pushButton ) );
+
+ switch ( propertyIndex )
+ {
+ case Toolkit::PushButton::Property::UNSELECTED_ICON:
+ {
+ pushButtonImpl.SetIcon( UNSELECTED_DECORATION, value.Get< std::string >() );
+ break;
+ }
+ case Toolkit::PushButton::Property::SELECTED_ICON:
+ {
+ pushButtonImpl.SetIcon( SELECTED_DECORATION, value.Get< std::string >() );
+ break;
+ }
+ case Toolkit::PushButton::Property::ICON_ALIGNMENT:
+ {
+ IconAlignment iconAlignment;
+ if( Scripting::GetEnumeration< IconAlignment >( value.Get< std::string >().c_str(), IconAlignmentTable, IconAlignmentTableCount, iconAlignment ) )
+ {
+ pushButtonImpl.SetIconAlignment( iconAlignment );
+ }
+ break;
+ }
+ case Toolkit::PushButton::Property::LABEL_PADDING:
+ {
+ pushButtonImpl.SetLabelPadding( value.Get< Vector4 >() );
+ break;
+ }
+ case Toolkit::PushButton::Property::ICON_PADDING:
+ {
+ pushButtonImpl.SetIconPadding( value.Get< Vector4 >() );
+ break;
+ }
+ }
+ }
+}
+
+Property::Value PushButton::GetProperty( BaseObject* object, Property::Index propertyIndex )
+{
+ Property::Value value;
+
+ Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) );
+
+ if ( pushButton )
+ {
+ PushButton& pushButtonImpl( GetImplementation( pushButton ) );
+
+ switch ( propertyIndex )
+ {
+ case Toolkit::PushButton::Property::UNSELECTED_ICON:
+ {
+ value = pushButtonImpl.GetIcon( UNSELECTED_DECORATION );
+ break;
+ }
+ case Toolkit::PushButton::Property::SELECTED_ICON:
+ {
+ value = pushButtonImpl.GetIcon( UNSELECTED_DECORATION );
+ break;
+ }
+ case Toolkit::PushButton::Property::ICON_ALIGNMENT:
+ {
+ value = Scripting::GetLinearEnumerationName< IconAlignment >( pushButtonImpl.GetIconAlignment(), IconAlignmentTable, IconAlignmentTableCount );
+ break;
+ }
+ case Toolkit::PushButton::Property::LABEL_PADDING:
+ {
+ value = pushButtonImpl.GetLabelPadding();
+ break;
+ }
+ case Toolkit::PushButton::Property::ICON_PADDING:
+ {
+ value = pushButtonImpl.GetIconPadding();
+ break;
+ }
+ }
+ }
+
+ return value;
}
void PushButton::OnLabelSet()
{
- Actor& label = GetLabel();
+ Actor& label = GetLabelActor();
if( label )
{
- label.SetAnchorPoint( AnchorPoint::CENTER );
- label.SetParentOrigin( ParentOrigin::CENTER );
-
Toolkit::TextLabel textLabel = Toolkit::TextLabel::DownCast( label );
if( textLabel )
{
- textLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
- textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
- textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
+ textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, false );
}
-
- ConfigureSizeNegotiation();
}
+ ConfigureSizeNegotiation();
}
void PushButton::OnButtonImageSet()
{
ConfigureSizeNegotiation();
- RelayoutRequest();
}
void PushButton::OnSelectedImageSet()
{
ConfigureSizeNegotiation();
- RelayoutRequest();
}
void PushButton::OnBackgroundImageSet()
{
ConfigureSizeNegotiation();
- RelayoutRequest();
}
void PushButton::OnSelectedBackgroundImageSet()
{
ConfigureSizeNegotiation();
- RelayoutRequest();
}
void PushButton::OnDisabledImageSet()
{
ConfigureSizeNegotiation();
- RelayoutRequest();
}
void PushButton::OnDisabledSelectedImageSet()
{
ConfigureSizeNegotiation();
- RelayoutRequest();
}
void PushButton::OnDisabledBackgroundImageSet()
{
ConfigureSizeNegotiation();
- RelayoutRequest();
}
void PushButton::OnSizeSet( const Vector3& targetSize )
{
mSize = targetSize;
- Actor& label = GetLabel();
+ Actor& label = GetLabelActor();
if( label )
{
Vector3 size;
// If label, test against it's size
- Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabel() );
- if( label )
+ Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabelActor() );
+
+ Actor icon = GetDecoration( UNSELECTED_DECORATION );
+ if( label || icon )
{
- Padding padding( 0.0f, 0.0f, 0.0f, 0.0f );
- label.GetPadding( padding );
- size = label.GetNaturalSize();
- size.width += padding.x + padding.width;
- size.height += padding.y + padding.height;
+ Vector3 labelSize( Vector3::ZERO );
+ Vector3 iconSize( Vector3::ZERO );
+
+ if( label )
+ {
+ Vector3 labelNaturalSize = label.GetNaturalSize();
+ labelSize.width = labelNaturalSize.width + mLabelPadding.left + mLabelPadding.right;
+ labelSize.height = labelNaturalSize.height + mLabelPadding.top + mLabelPadding.bottom;
+ }
+
+ if( icon )
+ {
+ Vector3 iconNaturalSize = icon.GetNaturalSize();
+ iconSize.width = iconNaturalSize.width + mIconPadding.left + mIconPadding.right;
+ iconSize.height = iconNaturalSize.height + mIconPadding.top + mIconPadding.bottom;
+
+ switch( mIconAlignment )
+ {
+ case LEFT:
+ case RIGHT:
+ {
+ size.width = labelSize.width + iconSize.width;
+ size.height = std::max( labelSize.height, iconSize.height );
+ break;
+ }
+ case TOP:
+ case BOTTOM:
+ {
+ size.width = std::max( labelSize.width, iconSize.width );
+ size.height = labelSize.height + iconSize.height;
+ break;
+ }
+ }
+ }
+ else
+ {
+ // No icon, so size is the same as label size.
+ // (If there is no label this is zero).
+ size = labelSize;
+ }
}
else
{
// Check Image and Background image and use the largest size as the control's Natural size.
- SizeOfActorIfLarger( GetButtonImage(), size );
+ SizeOfActorIfLarger( GetUnselectedImage(), size );
SizeOfActorIfLarger( GetBackgroundImage(), size );
}
std::vector< Actor > images;
images.reserve( 7 );
- images.push_back( GetButtonImage() );
+ images.push_back( GetUnselectedImage() );
images.push_back( GetSelectedImage() );
images.push_back( GetSelectedBackgroundImage() );
images.push_back( GetBackgroundImage() );
images.push_back( GetDisabledSelectedImage() );
images.push_back( GetDisabledBackgroundImage() );
- Actor label = GetLabel();
+ Actor label = GetLabelActor();
for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
{
ConfigureSizeNegotiationDimension( static_cast< Dimension::Type >( 1 << i ), images, label );
}
+ // Add any vertical padding directly to the actors.
+ Actor icon = GetDecoration( UNSELECTED_DECORATION );
+ Actor selectedIcon = GetDecoration( SELECTED_DECORATION );
+ bool iconExists = icon || selectedIcon;
+
if( label )
{
- Padding padding;
+ label.SetPadding( mLabelPadding );
+ }
+ if( icon )
+ {
+ icon.SetPadding( mIconPadding );
+ }
+ if( selectedIcon )
+ {
+ selectedIcon.SetPadding( mIconPadding );
+ }
- if( label.GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::USE_NATURAL_SIZE )
- {
- padding.left = TEXT_PADDING;
- padding.right = TEXT_PADDING;
- }
+ // Calculate and apply horizontal alignments and offsets
+ // to text and icon (depending on existence).
+ Vector3 iconPosition( Vector3::ZERO );
+ Vector3 labelPosition( Vector3::ZERO );
+ Vector3 iconAnchoring( AnchorPoint::CENTER );
+ Vector3 labelAnchoring( AnchorPoint::CENTER );
+ std::string horizontalLabelAlignment = "CENTER";
+ std::string verticalLabelAlignment = "CENTER";
- if( label.GetResizePolicy( Dimension::HEIGHT ) == ResizePolicy::USE_NATURAL_SIZE )
+ if( iconExists && label )
+ {
+ // There is an icon and a label to lay out.
+ switch( mIconAlignment )
{
- padding.top = TEXT_PADDING;
- padding.bottom = TEXT_PADDING;
+ case LEFT:
+ {
+ iconPosition.x = mIconPadding.left;
+ labelPosition.x = -mLabelPadding.right;
+ iconAnchoring = AnchorPoint::CENTER_LEFT;
+ labelAnchoring = AnchorPoint::CENTER_RIGHT;
+ horizontalLabelAlignment = "END";
+ break;
+ }
+ case RIGHT:
+ {
+ iconPosition.x = -mIconPadding.right;
+ labelPosition.x = mLabelPadding.left;
+ iconAnchoring = AnchorPoint::CENTER_RIGHT;
+ labelAnchoring = AnchorPoint::CENTER_LEFT;
+ horizontalLabelAlignment = "BEGIN";
+ break;
+ }
+ case TOP:
+ {
+ iconPosition.y = mIconPadding.top;
+ labelPosition.y = -mLabelPadding.bottom;
+ iconAnchoring = AnchorPoint::TOP_CENTER;
+ labelAnchoring = AnchorPoint::BOTTOM_CENTER;
+ verticalLabelAlignment = "BOTTOM";
+ break;
+ }
+ case BOTTOM:
+ {
+ iconPosition.y = -mIconPadding.bottom;
+ labelPosition.y = mLabelPadding.top;
+ iconAnchoring = AnchorPoint::BOTTOM_CENTER;
+ labelAnchoring = AnchorPoint::TOP_CENTER;
+ verticalLabelAlignment = "TOP";
+ break;
+ }
}
+ }
- label.SetPadding( padding );
+ // Note: If there is only an icon, or only a label, the default values are now correct.
+ // Setup the icon(s) with the precalculated values.
+ if( icon )
+ {
+ icon.SetPosition( iconPosition );
+ icon.SetParentOrigin( iconAnchoring );
+ icon.SetAnchorPoint( iconAnchoring );
}
+ if( selectedIcon )
+ {
+ selectedIcon.SetPosition( iconPosition );
+ selectedIcon.SetParentOrigin( iconAnchoring );
+ selectedIcon.SetAnchorPoint( iconAnchoring );
+ }
+
+ // Setup the label.
+ if( label )
+ {
+ label.SetPosition( labelPosition );
+ label.SetParentOrigin( labelAnchoring );
+ label.SetAnchorPoint( labelAnchoring );
+ label.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, horizontalLabelAlignment );
+ label.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, verticalLabelAlignment );
+ }
+
+ RelayoutRequest();
}
void PushButton::ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label )
ResizePolicy::Type imageResizePolicy = ResizePolicy::FILL_TO_PARENT;
ResizePolicy::Type labelResizePolicy = ResizePolicy::FILL_TO_PARENT;
- switch( Self().GetResizePolicy( dimension ) )
+ ResizePolicy::Type resizePolicy = Self().GetResizePolicy( dimension );
+
+ if( resizePolicy == ResizePolicy::FIT_TO_CHILDREN || resizePolicy == ResizePolicy::USE_NATURAL_SIZE )
{
- case ResizePolicy::FIT_TO_CHILDREN:
- {
- imageResizePolicy = labelResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
- break;
- }
- case ResizePolicy::USE_NATURAL_SIZE:
+ if( label )
{
- if( label )
- {
- labelResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
- }
- else
- {
- imageResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
- }
- break;
+ labelResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
}
- default:
+ else
{
- break;
+ imageResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
}
}
}
}
+
} // namespace Internal
} // namespace Toolkit
*/
virtual ~PushButton();
+public:
+
+ // Properties
+
+ /**
+ * Enum for the alignment modes of the icon.
+ */
+ enum IconAlignment
+ {
+ LEFT,
+ RIGHT,
+ TOP,
+ BOTTOM,
+ DEFAULT = RIGHT
+ };
+
+ /**
+ * 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 propertyIndex );
+
private: // From Button
/**
*/
void ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label );
+ /**
+ * @brief Sets either the selected or unselected icon.
+ *
+ * @param[in] state The icon state to set
+ * @param[in] iconFilename The filename of the icon
+ */
+ void SetIcon( DecorationState state, const std::string iconFilename );
+
+ /**
+ * @brief Gets either the selected or unselected icon.
+ *
+ * @param[in] state The icon state to get
+ * @return The filename of the icon
+ */
+ std::string& GetIcon( DecorationState state );
+
+ /**
+ * @brief Sets the alignment mode to use to align the icon to the label.
+ *
+ * @param[in] iconAlignment The alignment mode to use
+ */
+ void SetIconAlignment( const PushButton::IconAlignment iconAlignment );
+
+ /**
+ * @brief Gets the alignment mode used to align the icon to the label.
+ *
+ * @return The alignment mode in use
+ */
+ const PushButton::IconAlignment GetIconAlignment() const;
+
+ /**
+ * @brief Sets the padding for the label.
+ *
+ * @param[in] padding The padding to set
+ */
+ void SetLabelPadding( const Vector4& padding );
+
+ /**
+ * @brief Gets the padding for the label.
+ *
+ * @return The label padding
+ */
+ Vector4 GetLabelPadding();
+
+ /**
+ * @brief Sets the padding for the icon.
+ *
+ * @param[in] padding The padding to set
+ */
+ void SetIconPadding( const Vector4& padding );
+
+ /**
+ * @brief Gets the padding for the icon.
+ *
+ * @return The icon padding
+ */
+ Vector4 GetIconPadding();
+
private:
// Undefined
private:
- Vector3 mSize; ///< The button's size.
+ std::string mIconName[ DECORATION_STATES ]; ///< The original filenames for the icons.
+ Padding mLabelPadding; ///< The padding around the label (if present).
+ Padding mIconPadding; ///< The padding around the icon (if present).
+ IconAlignment mIconAlignment; ///< The alignment of the icon against the label.
+ Vector3 mSize; ///< The button's size.
};
} // namespace Internal
// Wrap size of radio button around all its children
self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
- Image buttonImage = Dali::ResourceImage::New( UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
- Image selectedImage = Dali::ResourceImage::New( SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
- Image disabledImage = Dali::ResourceImage::New( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
- Image disabledSelectedImage = Dali::ResourceImage::New( DISABLED_SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
-
- SetButtonImage( ImageActor::New( buttonImage ) );
- SetSelectedImage( ImageActor::New( selectedImage ) );
- SetDisabledImage( ImageActor::New( disabledImage ) );
- SetDisabledSelectedImage( ImageActor::New( disabledSelectedImage ) );
+ SetUnselectedImage( UNSELECTED_BUTTON_IMAGE_DIR );
+ SetSelectedImage( SELECTED_BUTTON_IMAGE_DIR );
+ SetDisabledImage( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR );
+ SetDisabledSelectedImage( DISABLED_SELECTED_BUTTON_IMAGE_DIR );
RelayoutRequest();
}
void RadioButton::OnLabelSet()
{
- Actor& label = GetLabel();
+ Actor& label = GetLabelActor();
if( label )
{
{
label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
- else if( GetButtonImage() )
+ else if( GetUnselectedImage() )
{
- label.SetX( GetButtonImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
+ label.SetX( GetUnselectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
}
else
{
void RadioButton::OnSelected()
{
- Actor& label = GetLabel();
+ Actor& label = GetLabelActor();
PaintState paintState = GetPaintState();
switch( paintState )
}
case SelectedState:
{
- Actor& buttonImage = GetButtonImage();
+ Actor& buttonImage = GetUnselectedImage();
if( label && buttonImage )
{
label.SetX( buttonImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL );
// todo Move this to adaptor??
#define GET_LOCALE_TEXT(string) dgettext("elementary", string)
-const std::string TEXT_SELECTION_POPUP_LABEL = "textselectionpopuplabel";
+const std::string TEXT_SELECTION_POPUP_LABEL( "textselectionpopuplabel" );
+const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) );
#ifdef DGETTEXT_ENABLED
DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-paste-button-image", STRING, POPUP_PASTE_BUTTON_ICON_IMAGE )
DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-button-image", STRING, POPUP_SELECT_BUTTON_ICON_IMAGE )
DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-select-all-button-image", STRING, POPUP_SELECT_ALL_BUTTON_ICON_IMAGE )
-DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-divider-color", VECTOR4, DIVIDER_COLOR )
-DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-icon-color", VECTOR4, ICON_COLOR )
-DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-pressed-color", VECTOR4, PRESSED_COLOR )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-divider-color", VECTOR4, POPUP_DIVIDER_COLOR )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-icon-color", VECTOR4, POPUP_ICON_COLOR )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-pressed-color", VECTOR4, POPUP_PRESSED_COLOR )
+DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionPopup, "popup-pressed-image", STRING, POPUP_PRESSED_IMAGE )
DALI_TYPE_REGISTRATION_END()
impl.SetButtonImage( Toolkit::TextSelectionPopup::SELECT_ALL, image );
break;
}
- case Toolkit::TextSelectionPopup::Property::DIVIDER_COLOR:
+ case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
{
impl.mDividerColor = value.Get< Vector4 >();
break;
}
- case Toolkit::TextSelectionPopup::Property::ICON_COLOR:
+ case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
{
impl.mIconColor = value.Get< Vector4 >();
break;
}
- case Toolkit::TextSelectionPopup::Property::PRESSED_COLOR:
+ case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
{
impl.mPressedColor = value.Get< Vector4 >();
break;
}
+ case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
+ {
+ impl.SetPressedImage( value.Get< std::string >() );
+ break;
+ }
} // switch
} // TextSelectionPopup
}
}
break;
}
+ case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
+ {
+ value = impl.GetPressedImage();
+ break;
+ }
} // switch
}
return value;
return Dali::Image();
}
+void TextSelectionPopup::SetPressedImage( const std::string& filename )
+{
+ mPressedImage = filename;
+}
+
+std::string TextSelectionPopup::GetPressedImage() const
+{
+ return mPressedImage;
+}
+
void TextSelectionPopup::CreateOrderedListOfPopupOptions()
{
mOrderListOfButtons.clear();
void TextSelectionPopup::AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption )
{
- const std::string& name = button.name;
- const std::string& caption = button.caption;
- Image iconImage = button.icon;
-
- // 1. Create the backgrounds for the popup option both normal and pressed.
- // Both containers will be added to a button.
-
- Toolkit::TableView optionContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
- optionContainer.SetFitHeight( 0 );
- optionContainer.SetFitWidth( 0 );
-
- Toolkit::TableView optionPressedContainer = Toolkit::TableView::New( (showIcons&showCaption)?2:1 , 1 );
- optionPressedContainer.SetFitHeight( 0 );
- optionPressedContainer.SetFitWidth( 0 );
- optionPressedContainer.SetBackgroundColor( mPressedColor );
-
-#ifdef DECORATOR_DEBUG
- optionContainer.SetName("optionContainer");
- optionPressedContainer.SetName("optionPressedContainer");
-#endif
- // 2. Add text.
-
- if ( showCaption )
- {
- Toolkit::TextLabel captionTextLabel = Toolkit::TextLabel::New();
- captionTextLabel.SetStyleName( TEXT_SELECTION_POPUP_LABEL );
- captionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
- captionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
-
- Toolkit::TextLabel pressedCaptionTextLabel = Toolkit::TextLabel::New();
- pressedCaptionTextLabel.SetStyleName( TEXT_SELECTION_POPUP_LABEL );
- pressedCaptionTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, caption );
- pressedCaptionTextLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
-
- Padding padding;
- padding.left = 24.0f;
- padding.right = 24.0f;
- padding.top = 14.0f;
- padding.bottom = 14.0f;
- captionTextLabel.SetPadding( padding );
- pressedCaptionTextLabel.SetPadding( padding );
-
- optionContainer.AddChild( captionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
- optionPressedContainer.AddChild( pressedCaptionTextLabel, Toolkit::TableView::CellPosition(( showIcons&showCaption)?1:0, 0 ) );
- }
-
- int depth = Self().GetHierarchyDepth();
- // 3. Create the icons
- if ( showIcons && iconImage )
- {
- ImageActor pressedIcon = ImageActor::New( iconImage );
- ImageActor icon = ImageActor::New( iconImage );
- icon.SetSortModifier( DECORATION_DEPTH_INDEX + depth - 1 );
- pressedIcon.SetSortModifier( DECORATION_DEPTH_INDEX + depth - 1 );
-
- icon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
- pressedIcon.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
- icon.SetColor( mIconColor );
-
- if ( showCaption & showIcons )
- {
- optionContainer.SetFitHeight( 1 );
- optionContainer.SetFitWidth( 1 );
- optionPressedContainer.SetFitHeight( 1 );
- optionPressedContainer.SetFitWidth( 1 );
- }
-
- optionContainer.AddChild( icon, Toolkit::TableView::CellPosition( 0, 0 ) );
- optionPressedContainer.AddChild( pressedIcon, Toolkit::TableView::CellPosition( 0, 0 ) );
-
- icon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
- pressedIcon.SetPadding( Padding( 10.0f, 10.0f, 10.0f, 10.0f ) );
- }
-
- // 4. Create a option.
+ // 1. Create a option.
Toolkit::PushButton option = Toolkit::PushButton::New();
- option.SetName( name );
+ option.SetName( button.name );
option.SetAnimationTime( 0.0f );
- option.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
+ option.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
switch( button.id )
{
}
}
- // 5. Set the normal option image.
- option.SetButtonImage( optionContainer );
+ // 2. Set the options contents.
+ if( showCaption )
+ {
+ option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
+ option.SetLabelText( button.caption );
+ }
+ if( showIcons )
+ {
+ option.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
+ option.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
+
+ // TODO: This is temporarily disabled until the text-selection-popup image API is changed to strings.
+ //option.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, button.icon );
+ //option.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, button.icon );
+ }
+
+ // 3. Set the normal option image (blank / Transparent).
+ option.SetUnselectedImage( "" );
- // 6. Set the pressed option image
- option.SetSelectedImage( optionPressedContainer );
+ // 4. Set the pressed option image.
+ // The image can be blank, the color can be used regardless.
+ option.SetSelectedImage( mPressedImage );
+ option.SetProperty( Toolkit::Button::Property::SELECTED_COLOR, mPressedColor );
- // 7 Add option to tool bar
+ // 5 Add option to tool bar
mToolbar.AddOption( option );
- // 8. Add the divider
+ // 6. Add the divider
if( showDivider )
{
const Size size( mOptionDividerSize.width, 0.0f ); // Height FILL_TO_PARENT
divider.SetSize( size );
divider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
divider.SetColor( mDividerColor );
- divider.SetSortModifier( DECORATION_DEPTH_INDEX + depth );
+ divider.SetSortModifier( DECORATION_DEPTH_INDEX );
mToolbar.AddDivider( divider );
}
}
mOptionDividerSize(),
mEnabledButtons( Toolkit::TextSelectionPopup::NONE ),
mCallbackInterface( callbackInterface ),
+ mPressedColor( DEFAULT_OPTION_PRESSED_COLOR ),
mDividerColor( Color::WHITE ),
- mIconColor( Color::WHITE ),
- mPressedColor( Color::WHITE ),
+ mIconColor( Color::WHITE ),
mSelectOptionPriority( 1 ),
mSelectAllOptionPriority ( 2 ),
mCutOptionPriority ( 4 ),
*/
Dali::Image GetButtonImage( Toolkit::TextSelectionPopup::Buttons button );
+ /**
+ * @brief Sets the image for the pressed state of a popup option.
+ *
+ * @param[in] filename The image filename to use.
+ */
+ void SetPressedImage( const std::string& filename);
+
+ /**
+ * @brief Gets the image used for the pressed state of a popup option.
+ *
+ * @return The image filename used.
+ */
+ std::string GetPressedImage() const;
+
void CreateOrderedListOfPopupOptions();
void AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption );
Image mSelectIconImage;
Image mSelectAllIconImage;
- Size mOptionMaxSize; // Maximum size of an Option button
- Size mOptionMinSize; // Minimum size of an Option button
- Size mOptionDividerSize; // Size of divider line
+ Size mOptionMaxSize; // Maximum size of an Option button
+ Size mOptionMinSize; // Minimum size of an Option button
+ Size mOptionDividerSize; // Size of divider line
std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
Toolkit::TextSelectionPopup::Buttons mEnabledButtons; // stores enabled buttons
Toolkit::TextSelectionPopupCallbackInterface* mCallbackInterface;
+ std::string mPressedImage; // Image used for the popup option when pressed.
+ Vector4 mPressedColor; // Color of the popup option when pressed.
Vector4 mDividerColor; // Color of the divider between buttons
Vector4 mIconColor; // Color of the popup icon.
- Vector4 mPressedColor; // Color of the popup option when pressed.
// Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
std::size_t mSelectOptionPriority; // Position of Select Button
return Dali::Toolkit::GetImplementation( *this ).GetAnimationTime();
}
-void Button::SetLabel( const std::string& label )
+void Button::SetLabelText( const std::string& label )
{
- Dali::Toolkit::GetImplementation( *this ).SetLabel( label );
-}
-
-void Button::SetLabel( Actor label )
-{
- Dali::Toolkit::GetImplementation( *this ).SetLabel( label );
+ Dali::Toolkit::GetImplementation( *this ).SetLabelText( label );
}
-Actor Button::GetLabel() const
+std::string Button::GetLabelText() const
{
- return Dali::Toolkit::GetImplementation( *this ).GetLabel();
+ return Dali::Toolkit::GetImplementation( *this ).GetLabelText();
}
-void Button::SetButtonImage( Image image )
+void Button::SetUnselectedImage( const std::string& filename )
{
- Actor imageActor = ImageActor::New( image );
- Dali::Toolkit::GetImplementation( *this ).SetButtonImage( imageActor );
+ Dali::Toolkit::GetImplementation( *this ).SetUnselectedImage( filename );
}
-void Button::SetBackgroundImage( Image image )
+void Button::SetBackgroundImage( const std::string& filename )
{
- Actor imageActor = ImageActor::New( image );
- Dali::Toolkit::GetImplementation( *this ).SetBackgroundImage( imageActor );
+ Dali::Toolkit::GetImplementation( *this ).SetBackgroundImage( filename );
}
-void Button::SetSelectedImage( Image image )
+void Button::SetSelectedImage( const std::string& filename )
{
- Actor imageActor = ImageActor::New( image );
- imageActor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
- Dali::Toolkit::GetImplementation( *this ).SetSelectedImage( imageActor );
+ Dali::Toolkit::GetImplementation( *this ).SetSelectedImage( filename );
}
-void Button::SetSelectedBackgroundImage( Image image )
+void Button::SetSelectedBackgroundImage( const std::string& filename )
{
- Dali::Toolkit::GetImplementation( *this ).SetSelectedBackgroundImage( ImageActor::New( image ) );
+ Dali::Toolkit::GetImplementation( *this ).SetSelectedBackgroundImage( filename );
}
-void Button::SetDisabledBackgroundImage( Image image )
+void Button::SetDisabledBackgroundImage( const std::string& filename )
{
- Actor imageActor = ImageActor::New( image );
- imageActor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
- Dali::Toolkit::GetImplementation( *this ).SetDisabledBackgroundImage( imageActor );
+ Dali::Toolkit::GetImplementation( *this ).SetDisabledBackgroundImage( filename );
}
-void Button::SetDisabledImage( Image image )
+void Button::SetDisabledImage( const std::string& filename )
{
- Actor imageActor = ImageActor::New( image );
- imageActor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
- Dali::Toolkit::GetImplementation( *this ).SetDisabledImage( imageActor );
+ Dali::Toolkit::GetImplementation( *this ).SetDisabledImage( filename );
}
-void Button::SetDisabledSelectedImage( Image image )
+void Button::SetDisabledSelectedImage( const std::string& filename )
{
- Actor imageActor = ImageActor::New( image );
- imageActor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
- Dali::Toolkit::GetImplementation( *this ).SetDisabledSelectedImage( imageActor );
+ Dali::Toolkit::GetImplementation( *this ).SetDisabledSelectedImage( filename );
}
Button::ButtonSignalType& Button::PressedSignal()
return Dali::Toolkit::GetImplementation( *this ).StateChangedSignal();
}
+// Deprecated API
+
+void Button::SetLabel( Actor label )
+{
+ Dali::Toolkit::GetImplementation( *this ).SetLabel( label );
+}
+
+void Button::SetButtonImage( Image image )
+{
+ Actor imageActor = ImageActor::New( image );
+ imageActor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+ Dali::Toolkit::GetImplementation( *this ).SetButtonImage( imageActor );
+}
+
+void Button::SetSelectedImage( Image image )
+{
+ Actor imageActor = ImageActor::New( image );
+ imageActor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+ Dali::Toolkit::GetImplementation( *this ).SetSelectedImage( imageActor );
+}
+
+Actor Button::GetButtonImage() const
+{
+ return Dali::Toolkit::GetImplementation( *this ).GetButtonImage();
+}
+
+Actor Button::GetSelectedImage() const
+{
+ return Dali::Toolkit::GetImplementation( *this ).GetSelectedImage();
+}
+
+
Button::Button( Internal::Button& implementation )
: Control( implementation )
{
*
* This class provides the disabled property and the clicked signal.
*
- * A ClickedSignal() is emitted when the button is touched and the touch
- * point doesn't leave the boundary of the button.
+ * A ClickedSignal() is emitted when the button is touched and the touch point doesn't leave the boundary of the button.
*
* When the \e disabled property is set to \e true, no signal is emitted.
*
+ * Button provides the following properties which modify the signals emitted:
+ * <ul>
+ * <li>\e autorepeating
+ * When \e autorepeating is set to \e true, a Button::PressedSignal(), Button::ReleasedSignal() and Button::ClickedSignal() signals are emitted at regular
+ * intervals while the button is touched.
+ * The intervals could be modified with the Button::SetInitialAutoRepeatingDelay and Button::SetNextAutoRepeatingDelay methods.
+ *
+ * A \e togglable button can't be \e autorepeating. If the \e autorepeating property is set to \e true, then the \e togglable property is set to
+ * false but no signal is emitted.
+ *
+ * <li>\e togglable
+ * When \e togglable is set to \e true, a Button::StateChangedSignal() signal is emitted, with the selected state.
+ * </ul>
+ *
+ * The button's appearance can be modified by setting properties for the various image filenames.
+ *
+ * The \e background is always shown and doesn't change if the button is pressed or released. The \e button image is shown over the \e background image when the
+ * button is not pressed and is replaced by the \e selected image when the button is pressed. The text label is placed always on the top of all images.
+ *
+ * When the button is disabled, \e background, \e button and \e selected images are replaced by their \e disabled images.
+ *
+ * Is not mandatory set all images. A button could be defined only by setting its \e background image or by setting its \e background and \e selected images.
+ *
* Signals
* | %Signal Name | Method |
* |-------------------|-----------------------------|
NEXT_AUTO_REPEATING_DELAY, ///< name "next-auto-repeating-delay", @see SetNextAutoRepeatingDelay(), type float
TOGGLABLE, ///< name "togglable", @see SetTogglableButton(), type bool
SELECTED, ///< name "selected", @see SetSelected(), type bool
- NORMAL_STATE_ACTOR, ///< name "normal-state-actor", @see SetButtonImage(), type Map
- SELECTED_STATE_ACTOR, ///< name "selected-state-actor", @see SetSelectedImage(), type Map
- DISABLED_STATE_ACTOR, ///< name "disabled-state-actor", @see SetDisabledImage(), type Map
- LABEL_ACTOR, ///< name "label-actor", @see SetLabel(), type Map
+ UNSELECTED_STATE_IMAGE, ///< name "unselected-state-image", @see SetUnselectedImage(), type std::string
+ SELECTED_STATE_IMAGE, ///< name "selected-state-image", @see SetSelectedImage(), type std::string
+ DISABLED_STATE_IMAGE, ///< name "disabled-state-image", @see SetDisabledImage(), type std::string
+ UNSELECTED_COLOR, ///< name "unselected-color", @see SetUnselectedColor(), type Vector4
+ SELECTED_COLOR, ///< name "selected-color", @see SetSelectedColor(), type Vector4
+ LABEL_TEXT, ///< name "label-text", @see SetLabelText(), type std::string
};
};
/**
* @brief Sets the animation time.
*
- * @param [in] animationTime The animation time in seconds.
+ * @param[in] animationTime The animation time in seconds.
*/
void SetAnimationTime( float animationTime );
float GetAnimationTime() const;
/**
- * @brief Sets the button label.
+ * @brief Sets the button's label.
*
- * @param[in] label The button label.
- */
- void SetLabel( const std::string& label );
-
- /**
- * @copydoc SetLabel( const std::string& label )
+ * @param[in] label The label text.
*/
- void SetLabel( Actor label );
+ void SetLabelText( const std::string& label );
/**
* @brief Gets the label.
*
- * @return An actor with the label.
+ * @return The label text.
*/
- Actor GetLabel() const;
+ std::string GetLabelText() const;
/**
- * @brief Sets the button image.
+ * @brief Sets the unselected button image.
*
- * @param[in] image The button image.
+ * @param[in] filename The button image.
*/
- void SetButtonImage( Image image );
+ void SetUnselectedImage( const std::string& filename );
/**
* @brief Sets the background image.
*
- * @param[in] image The background image.
+ * @param[in] filename The background image.
*/
- void SetBackgroundImage( Image image );
+ void SetBackgroundImage( const std::string& filename );
/**
* @brief Sets the selected image.
*
- * @param[in] image The selected image.
+ * @param[in] filename The selected image.
*/
- void SetSelectedImage( Image image );
+ void SetSelectedImage( const std::string& filename );
/**
* @brief Sets the selected background image.
*
- * @param[in] image The selected background image.
+ * @param[in] filename The selected background image.
*/
- void SetSelectedBackgroundImage( Image image );
+ void SetSelectedBackgroundImage( const std::string& filename );
/**
* @brief Sets the disabled background image.
*
- * @param[in] image The disabled background image.
+ * @param[in] filename The disabled background image.
*/
- void SetDisabledBackgroundImage( Image image );
+ void SetDisabledBackgroundImage( const std::string& filename );
/**
* @brief Sets the disabled button image.
*
- * @param[in] image The disabled button image.
+ * @param[in] filename The disabled button image.
*/
- void SetDisabledImage( Image image );
+ void SetDisabledImage( const std::string& filename );
/**
* @brief Sets the disabled selected button image.
*
- * @param[in] image The disabled selected button image.
+ * @param[in] filename The disabled selected button image.
+ */
+ void SetDisabledSelectedImage( const std::string& filename );
+
+ // Deprecated API
+
+ /**
+ * @deprecated Sets the label with an actor.
+ * @param[in] label The actor to use as a label
+ */
+ void SetLabel( Actor label );
+
+ /**
+ * @deprecated Sets the button image.
+ * @param[in] image The button image.
+ */
+ void SetButtonImage( Image image );
+
+ /**
+ * @deprecated Sets the selected image.
+ * @param[in] image The selected image.
+ */
+ void SetSelectedImage( Image image );
+
+ /**
+ * @deprecated Gets the button image.
+ * @return An actor with the button image.
+ */
+ Actor GetButtonImage() const;
+
+ /**
+ * @deprecated Gets the selected image.
+ * @return An actor with the selected image.
*/
- void SetDisabledSelectedImage( Image image );
+ Actor GetSelectedImage() const;
public: //Signals
return Control::DownCast<PushButton, Internal::PushButton>(handle);
}
+// Deprecated API
+
void PushButton::SetButtonImage( Actor image )
{
Dali::Toolkit::GetImplementation( *this ).SetButtonImage( image );
}
-Actor PushButton::GetButtonImage() const
-{
- return Dali::Toolkit::GetImplementation( *this ).GetButtonImage();
-}
-
void PushButton::SetBackgroundImage( Actor image )
{
Dali::Toolkit::GetImplementation( *this ).SetBackgroundImage( image );
}
-Actor PushButton::GetBackgroundImage() const
-{
- return Dali::Toolkit::GetImplementation( *this ).GetBackgroundImage();
-}
-
void PushButton::SetSelectedImage( Actor image )
{
Dali::Toolkit::GetImplementation( *this ).SetSelectedImage( image );
}
-Actor PushButton::GetSelectedImage() const
-{
- return Dali::Toolkit::GetImplementation( *this ).GetSelectedImage();
-}
-
void PushButton::SetSelectedBackgroundImage( Actor image )
{
Dali::Toolkit::GetImplementation( *this ).SetSelectedBackgroundImage( image );
}
-Actor PushButton::GetSelectedBackgroundImage() const
-{
- return Dali::Toolkit::GetImplementation( *this ).GetSelectedBackgroundImage();
-}
-
void PushButton::SetDisabledBackgroundImage( Actor image )
{
Dali::Toolkit::GetImplementation( *this ).SetDisabledBackgroundImage( image );
}
-Actor PushButton::GetDisabledBackgroundImage() const
-{
- return Dali::Toolkit::GetImplementation( *this ).GetDisabledBackgroundImage();
-}
-
void PushButton::SetDisabledImage( Actor image )
{
Dali::Toolkit::GetImplementation( *this ).SetDisabledImage( image );
}
-Actor PushButton::GetDisabledImage() const
+void PushButton::SetDisabledSelectedImage( Actor image )
{
- return Dali::Toolkit::GetImplementation( *this ).GetDisabledImage();
+ Dali::Toolkit::GetImplementation( *this ).SetDisabledSelectedImage( image );
}
} // namespace Toolkit
* By default a PushButton emits a Button::PressedSignal() signal when the button is pressed, a Button::ClickedSignal() signal when it's clicked
* and a Button::ReleasedSignal() signal when it's released or having pressed it, the touch point leaves the boundary of the button.
*
- * PushButton provides the following properties which modify signals emitted:
- * <ul>
- * <li>\e autorepeating
- *
- * When \e autorepeating is set to \e true, a Button::PressedSignal(), Button::ReleasedSignal() and Button::ClickedSignal() signals are emitted at regular
- * intervals while the button is touched.
- *
- * The intervals could be modified with the PushButton::SetInitialAutoRepeatingDelay and PushButton::SetNextAutoRepeatingDelay methods.
- *
- * A \e togglable button can't be \e autorepeating. If the \e autorepeating property is set to \e true, then the \e togglable property is set to
- * false but no signal is emitted.
- *
- * <li>\e togglable
- *
- * When \e togglable is set to \e true, a Button::StateChangedSignal() signal is emitted, with the selected state, every time the button is touched instead
- * of emit Button::PressedSignal(), Button::ClickedSignal() and Button::ReleasedSignal() signals.
- *
- * An \e autorepeating button can't be \e togglable. If the \e togglable property is set to \e true, then the \e autorepeating property is set to false.
- * </ul>
- *
- * The button's appearance could be modified by setting images or actors with PushButton::SetButtonImage, PushButton::SetBackgroundImage,
- * PushButton::SetSelectedImage, PushButton::SetDisabledBackgroundImage and PushButton::SetDisabledImage or setting a text with
- * PushButton::SetLabel.
- *
- * The \e background is always shown and doesn't change if the button is pressed or released. The \e button image is shown over the \e background image when the
- * button is not pressed and is replaced by the \e selected image when the button is pressed. The text label is placed always on the top of all images.
- *
- * When the button is disabled, \e background, \e button and \e selected images are replaced by their \e disabled images.
- *
- * The methods used to modify the button's appearance could receive Dali::Actor objects as a parameter, so more complex images could be defined.
- *
- * Is not mandatory set all images. A button could be defined only by setting its \e background image or by setting its \e background and \e selected images.
+ * See Button for more detail on signals and modifying appearance via properties.
*/
class DALI_IMPORT_API PushButton : public Button
{
public:
/**
+ * @brief The start and end property ranges for this control.
+ */
+ enum PropertyRange
+ {
+ PROPERTY_START_INDEX = Button::PROPERTY_END_INDEX + 1,
+ PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
+ };
+
+ /**
+ * @brief An enumeration of properties belonging to the PushButton class.
+ */
+ struct Property
+ {
+ enum
+ {
+ UNSELECTED_ICON = PROPERTY_START_INDEX, ///< Property, name "unselected-icon", type std::string
+ SELECTED_ICON, ///< Property, name "selected-icon", type std::string
+ ICON_ALIGNMENT, ///< Property, name "icon-alignment", type std::string
+ LABEL_PADDING, ///< Property, name "label-padding", type Vector4
+ ICON_PADDING, ///< Property, name "icon-padding", type Vector4
+ };
+ };
+
+public:
+
+ /**
* @brief Create an uninitialized PushButton; this can be initialized with PushButton::New().
*
* Calling member functions with an uninitialized Dali::Object is not allowed.
*/
static PushButton DownCast( BaseHandle handle );
+
+ // Deprecated API
+
using Button::SetButtonImage;
/**
- * @brief SetButtonImage
- *
- * @param[in] image The Actor to be used as the button image.
- *
- * The natural size of the button would be the size of this Actor
- * if it's larger than the background and label
+ * @deprecated Sets the unselected image with an Actor.
+ * @param[in] image The Actor to use.
*/
void SetButtonImage( Actor image );
- /**
- * @brief Gets the button image.
- *
- * @return An actor with the button image.
- */
- Actor GetButtonImage() const;
-
using Button::SetBackgroundImage;
/**
- * @brief SetBackgroundImage
- *
- * @param[in] image The Actor to be used as the background image.
- *
- * The natural size of the button would be the size of this Actor
- * if it's larger than the button and label
+ * @deprecated Sets the background image with an Actor.
+ * @param[in] image The Actor to use.
*/
void SetBackgroundImage( Actor image );
- /**
- * @brief Gets the background image.
- *
- * @return An actor with the background image.
- */
- Actor GetBackgroundImage() const;
-
using Button::SetSelectedImage;
/**
- * @copydoc SetSelectedImage( Image image )
+ * @deprecated Sets the selected image with an Actor.
+ * @param[in] image The Actor to use.
*/
void SetSelectedImage( Actor image );
- /**
- * @brief Gets the selected image.
- *
- * @return An actor with the selected image.
- */
- Actor GetSelectedImage() const;
-
using Button::SetSelectedBackgroundImage;
/**
- * @copydoc SetSelectedBackgroundImage( Image image )
+ * @deprecated Sets the selected background image with an Actor.
+ * @param[in] image The Actor to use.
*/
void SetSelectedBackgroundImage( Actor image );
- /**
- * @brief Gets the selected background image.
- *
- * @return An actor with the selected background image.
- */
- Actor GetSelectedBackgroundImage() const;
-
using Button::SetDisabledBackgroundImage;
/**
- * @copydoc SetDisabledBackgroundImage( Image image )
+ * @deprecated Sets the disabled background image with an Actor.
+ * @param[in] image The Actor to use.
*/
void SetDisabledBackgroundImage( Actor image );
- /**
- * @brief Gets the disabled background image.
- *
- * @return An actor with the disabled background image.
- */
- Actor GetDisabledBackgroundImage() const;
-
using Button::SetDisabledImage;
/**
- * @copydoc SetDisabledImage( Image image )
+ * @deprecated Sets the disabled image with an Actor.
+ * @param[in] image The Actor to use.
*/
void SetDisabledImage( Actor image );
+ using Button::SetDisabledSelectedImage;
+
/**
- * @brief Gets the disabled image.
- *
- * @return An actor with the disabled image.
+ * @deprecated Sets the disabled selected image with an Actor.
+ * @param[in] image The Actor to use.
*/
- Actor GetDisabledImage() const;
+ void SetDisabledSelectedImage( Actor image );
+
public: // Not intended for application developers
RadioButton RadioButton::New( const std::string& label )
{
RadioButton radioButton = Internal::RadioButton::New();
- radioButton.SetLabel( label );
- return radioButton;
-}
-
-RadioButton RadioButton::New( Actor label )
-{
- RadioButton radioButton = Internal::RadioButton::New();
- radioButton.SetLabel( label );
+ radioButton.SetLabelText( label );
return radioButton;
}
static RadioButton New( const std::string& label );
/**
- * @brief Create an initialized RadioButton with existing Actor.
- *
- * @param[in] label An Actor with the label.
- *
- * @return A handle to a newly allocated Dali resource.
- */
- static RadioButton New( Actor label );
-
- /**
* @brief Downcast an Object handle to RadioButton.
*
* If handle points to a RadioButton the downcast produces valid