#include "push-button-impl.h"
// EXTERNAL INCLUDES
-#include <dali/public-api/actors/image-actor.h>
#include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/object/type-registry-helper.h>
#include <dali/public-api/images/resource-image.h>
+#include <dali/devel-api/scripting/scripting.h>
+#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/controls/image-view/image-view.h>
#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
+#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
+
+#if defined(DEBUG_ENABLED)
+ extern Debug::Filter* gLogButtonFilter;
+#endif
namespace Dali
{
namespace
{
-const float TEXT_PADDING = 12.0f;
-const float ANIMATION_TIME( 0.2f );
-
BaseHandle Create()
{
return Toolkit::PushButton::New();
}
-TypeRegistration typeRegistration( typeid(Toolkit::PushButton), typeid(Toolkit::Button), Create );
+// Properties
-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";
-const char* const DISABLED_UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-disabled.9.png";
-const char* const DISABLED_SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-down-disabled.9.png";
+DALI_TYPE_REGISTRATION_BEGIN( Toolkit::PushButton, Toolkit::Button, Create )
-} // unnamed namespace
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "unselectedIcon", STRING, UNSELECTED_ICON )
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "selectedIcon", STRING, SELECTED_ICON )
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "iconAlignment", STRING, ICON_ALIGNMENT )
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "labelPadding", STRING, LABEL_PADDING )
+DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "iconPadding", STRING, ICON_PADDING )
-namespace
-{
+DALI_TYPE_REGISTRATION_END()
-/**
- * Get size of Actor if larger than given size
- * @param[in] root the actor to get the size of
- * @param[out] size the greater of the given size or the size of the Actor
+/*
+ * Table to define Text-to-enum conversions for IconAlignment.
*/
-void SizeOfActorIfLarger( Actor root, Vector3& size )
+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] );
+
+} // unnamed namespace
+
+namespace
{
- if ( root )
- {
- // RelayoutSize retreived for Actor to use any padding set to it.
- size.width = std::max( root.GetRelayoutSize( Dimension::WIDTH ), size.width );
- size.height = std::max( root.GetRelayoutSize( Dimension::HEIGHT ), size.height );
- }
-}
} // unnamed namespace
PushButton::PushButton()
: Button(),
- mSize()
+ mIconAlignment( RIGHT )
{
- SetAnimationTime( ANIMATION_TIME );
}
PushButton::~PushButton()
{
}
-void PushButton::OnButtonInitialize()
+void PushButton::OnInitialize()
{
+ Button::OnInitialize();
+
// Push button requires the Leave event.
Actor self = Self();
self.SetLeaveRequired( true );
+}
- // Set resize policy to natural size so that buttons will resize to background images
- self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+void PushButton::SetIconAlignment( const PushButton::IconAlignment iconAlignment )
+{
+ mIconAlignment = iconAlignment;
+ Button::Align labelAlignment;
+ switch ( iconAlignment )
+ {
+ case RIGHT:
+ {
+ labelAlignment = Button::BEGIN;
+ break;
+ }
+ case TOP:
+ {
+ labelAlignment = Button::BOTTOM;
+ break;
+ }
+ case BOTTOM:
+ {
+ labelAlignment = Button::TOP;
+ break;
+ }
+ case LEFT:
+ default:
+ labelAlignment = Button::END;
+ break;
+ }
- 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 );
+ Button::SetLabelAlignment( labelAlignment );
+}
- SetButtonImage( ImageActor::New( buttonImage ) );
- SetSelectedImage( ImageActor::New( selectedImage ) );
- SetDisabledImage( ImageActor::New( disabledImage ) );
- SetDisabledSelectedImage( ImageActor::New( disabledSelectedImage ) );
+const PushButton::IconAlignment PushButton::GetIconAlignment() const
+{
+ return mIconAlignment;
}
-void PushButton::OnLabelSet()
+void PushButton::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
{
- Actor& label = GetLabel();
+ Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) );
- if( label )
+ if ( pushButton )
{
- label.SetAnchorPoint( AnchorPoint::CENTER );
- label.SetParentOrigin( ParentOrigin::CENTER );
+ PushButton& pushButtonImpl( GetImplementation( pushButton ) );
- Toolkit::TextLabel textLabel = Toolkit::TextLabel::DownCast( label );
- if( textLabel )
+ // Properties remain here for Tizen 3.0 legacy requirements. Are now in Button base class
+
+ switch ( propertyIndex )
{
- textLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
- textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
- textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
+ case Toolkit::PushButton::Property::UNSELECTED_ICON:
+ {
+ pushButtonImpl.CreateVisualsForComponent( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, value, DepthIndex::CONTENT );
+ break;
+ }
+ case Toolkit::PushButton::Property::SELECTED_ICON:
+ {
+ pushButtonImpl.CreateVisualsForComponent( Toolkit::DevelButton::Property::SELECTED_VISUAL, value, DepthIndex::CONTENT );
+ 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:
+ {
+ Vector4 padding ( value.Get< Vector4 >() );
+ pushButtonImpl.Button::SetLabelPadding( Padding( padding.x, padding.y, padding.z, padding.w ) );
+ break;
+ }
+ case Toolkit::PushButton::Property::ICON_PADDING:
+ {
+ Vector4 padding ( value.Get< Vector4 >() );
+ pushButtonImpl.Button::SetForegroundPadding( Padding( padding.x, padding.y, padding.z, padding.w ) );
+ break;
+ }
}
-
- ConfigureSizeNegotiation();
}
}
-void PushButton::OnButtonImageSet()
+Property::Value PushButton::GetProperty( BaseObject* object, Property::Index propertyIndex )
{
- ConfigureSizeNegotiation();
- RelayoutRequest();
-}
+ Property::Value value;
-void PushButton::OnSelectedImageSet()
-{
- ConfigureSizeNegotiation();
- RelayoutRequest();
-}
+ Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) );
-void PushButton::OnBackgroundImageSet()
-{
- ConfigureSizeNegotiation();
- RelayoutRequest();
-}
+ if ( pushButton )
+ {
+ PushButton& pushButtonImpl( GetImplementation( pushButton ) );
-void PushButton::OnSelectedBackgroundImageSet()
-{
- ConfigureSizeNegotiation();
- RelayoutRequest();
-}
+ 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:
+ {
+ Padding padding = pushButtonImpl.Button::GetLabelPadding();
+ value = Vector4( padding.x, padding.y, padding.top, padding.bottom);
+ break;
+ }
+ case Toolkit::PushButton::Property::ICON_PADDING:
+ {
+ Padding padding = pushButtonImpl.Button::GetForegroundPadding();
+ value = Vector4( padding.x, padding.y, padding.top, padding.bottom);
+ break;
+ }
+ }
+ }
-void PushButton::OnDisabledImageSet()
-{
- ConfigureSizeNegotiation();
- RelayoutRequest();
+ return value;
}
-void PushButton::OnDisabledSelectedImageSet()
-{
- ConfigureSizeNegotiation();
- RelayoutRequest();
-}
+// Deprecated API using Actor to set images
-void PushButton::OnDisabledBackgroundImageSet()
+void PushButton::SetButtonImage( Actor image )
{
- ConfigureSizeNegotiation();
- RelayoutRequest();
-}
+ DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetButtonImage() is deprecated and will be removed from next release. Use Button.SetProperty UNSELECTED_STATE_IMAGE or Styling file instead.\n" );
-void PushButton::OnSizeSet( const Vector3& targetSize )
-{
- if( targetSize != mSize )
+ Image retreivedButtonImage = Toolkit::ImageView::DownCast( image ).GetImage();
+ if ( retreivedButtonImage )
{
- mSize = targetSize;
-
- Actor& label = GetLabel();
+ ResourceImage resourceImage = ResourceImage::DownCast( retreivedButtonImage );
- if( label )
+ if ( resourceImage )
{
- label.SetSize( mSize );
+ Self().SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, resourceImage.GetUrl() );
+
}
}
}
-void PushButton::PrepareForTranstionIn( Actor actor )
+void PushButton::SetBackgroundImage( Actor image )
{
- actor.SetOpacity( 0.0f );
-}
+ DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetBackgroundImage() is deprecated and will be removed from next release.\n" );
-void PushButton::PrepareForTranstionOut( Actor actor )
-{
- actor.SetOpacity( 1.0f );
-}
+ SetButtonImage( image );
-void PushButton::OnTransitionIn( Actor actor )
-{
- FadeImageTo( actor, 1.f );
}
-void PushButton::OnTransitionOut( Actor actor )
+void PushButton::SetSelectedImage( Actor image )
{
- FadeImageTo( actor, 0.0f );
-}
+ DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetSelectedImage() is deprecated and will be removed from next release. Use Button.SetProperty SELECTED_STATE_IMAGE or Styling file instead.\n" );
-void PushButton::FadeImageTo( Actor actor, float opacity )
-{
- if( actor )
+ Image retreivedButtonImage = Toolkit::ImageView::DownCast( image ).GetImage();
+ if ( retreivedButtonImage )
{
- Dali::Animation transitionAnimation = GetTransitionAnimation();
- DALI_ASSERT_DEBUG( transitionAnimation );
+ ResourceImage resourceImage = ResourceImage::DownCast( retreivedButtonImage );
- if( transitionAnimation )
+ if ( resourceImage )
{
- transitionAnimation.AnimateTo( Property( actor, Actor::Property::COLOR_ALPHA ), opacity );
+ Self().SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, resourceImage.GetUrl() );
}
}
}
-Vector3 PushButton::GetNaturalSize()
+void PushButton::SetSelectedBackgroundImage( Actor image )
{
- Vector3 size;
+ DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetSelectedBackgroundImage() is deprecated and will be removed from next release.\n" );
- // If label, test against it's size
- Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabel() );
- if( label )
- {
- size.width = std::max( size.width, label.GetRelayoutSize( Dimension::WIDTH ) );
- size.height = std::max( size.height, label.GetRelayoutSize( Dimension::HEIGHT ) );
- }
- else
- {
- // Check Image and Background image and use the largest size as the control's Natural size.
- SizeOfActorIfLarger( GetButtonImage(), size );
- SizeOfActorIfLarger( GetBackgroundImage(), size );
- }
-
- return size;
+ SetSelectedImage( image );
}
-void PushButton::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
+void PushButton::SetDisabledBackgroundImage( Actor image )
{
- ConfigureSizeNegotiation();
-}
+ DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetDisabledBackgroundImage() is deprecated and will be removed from next release.\n" );
-void PushButton::ConfigureSizeNegotiation()
-{
- std::vector< Actor > images;
- images.reserve( 7 );
-
- images.push_back( GetButtonImage() );
- images.push_back( GetSelectedImage() );
- images.push_back( GetSelectedBackgroundImage() );
- images.push_back( GetBackgroundImage() );
- images.push_back( GetDisabledImage() );
- images.push_back( GetDisabledSelectedImage() );
- images.push_back( GetDisabledBackgroundImage() );
-
- Actor label = GetLabel();
-
- for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
- {
- ConfigureSizeNegotiationDimension( static_cast< Dimension::Type >( 1 << i ), images, label );
- }
-
- if( label )
+ Image retreivedButtonImage = Toolkit::ImageView::DownCast( image ).GetImage();
+ if ( retreivedButtonImage )
{
- Padding padding;
+ ResourceImage resourceImage = ResourceImage::DownCast( retreivedButtonImage );
- if( label.GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::USE_NATURAL_SIZE )
+ if ( resourceImage )
{
- padding.left = TEXT_PADDING;
- padding.right = TEXT_PADDING;
+ Self().SetProperty( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, resourceImage.GetUrl() );
}
-
- if( label.GetResizePolicy( Dimension::HEIGHT ) == ResizePolicy::USE_NATURAL_SIZE )
- {
- padding.top = TEXT_PADDING;
- padding.bottom = TEXT_PADDING;
- }
-
- label.SetPadding( padding );
}
}
-void PushButton::ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label )
+void PushButton::SetDisabledImage( Actor image )
{
- ResizePolicy::Type imageResizePolicy = ResizePolicy::FILL_TO_PARENT;
- ResizePolicy::Type labelResizePolicy = ResizePolicy::FILL_TO_PARENT;
+ DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetDisabledImage() is deprecated and will be removed from next release. Use Button.SetProperty DISABLED_STATE_IMAGE or Styling file instead.\n" );
- switch( Self().GetResizePolicy( dimension ) )
+ Image retreivedButtonImage = Toolkit::ImageView::DownCast( image ).GetImage();
+ if ( retreivedButtonImage )
{
- case ResizePolicy::FIT_TO_CHILDREN:
- {
- imageResizePolicy = labelResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
- break;
- }
- case ResizePolicy::USE_NATURAL_SIZE:
- {
- if( label )
- {
- labelResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
- }
- else
- {
- imageResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
- }
- break;
- }
- default:
+ ResourceImage resourceImage = ResourceImage::DownCast( retreivedButtonImage );
+
+ if ( resourceImage )
{
- break;
+ Self().SetProperty( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, resourceImage.GetUrl() );
}
}
+}
- if( label )
- {
- label.SetResizePolicy( labelResizePolicy, dimension );
- }
+void PushButton::SetDisabledSelectedImage( Actor image )
+{
+ DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetDisabledSelectedImage() is deprecated and will be removed from next release.\n" );
- for( std::vector< Actor >::const_iterator it = images.begin(), itEnd = images.end(); it != itEnd; ++it )
+ Image retreivedButtonImage = Toolkit::ImageView::DownCast( image ).GetImage();
+ if ( retreivedButtonImage )
{
- Actor actor = *it;
- if( actor )
+ ResourceImage resourceImage = ResourceImage::DownCast( retreivedButtonImage );
+
+ if ( resourceImage )
{
- actor.SetResizePolicy( imageResizePolicy, dimension );
+ Self().SetProperty( Toolkit::DevelButton::Property::DISABLED_SELECTED_BACKGROUND_VISUAL, resourceImage.GetUrl() );
}
}
}