X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fpush-button-impl.cpp;h=d09f7811aa23677ca964387e5d21f4965d4d49a5;hb=b1e8521ad77e7b4e62b59613b2edef64429130e9;hp=0df4e3cfdc827bd05c1832d2e1fa1546d4c233ad;hpb=87f440c3d0367ca5a7027eef8d01d79b8703cf05;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp index 0df4e3c..d09f781 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,15 +19,20 @@ #include "push-button-impl.h" // EXTERNAL INCLUDES -#include -#include #include +#include +#include +#include // INTERNAL INCLUDES -#include "push-button-default-painter-impl.h" +#include +#include +#include +#include -#include -#include +#if defined(DEBUG_ENABLED) + extern Debug::Filter* gLogButtonFilter; +#endif namespace Dali { @@ -46,36 +51,19 @@ BaseHandle Create() return Toolkit::PushButton::New(); } -TypeRegistration typeRegistration( typeid(Toolkit::PushButton), typeid(Toolkit::Button), Create ); +// Properties -} // unnamed namespace - -namespace -{ +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::PushButton, Toolkit::Button, Create ) -const float TEXT_PADDING = 12.0f; +DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "labelPadding", STRING, LABEL_PADDING ) +DALI_PROPERTY_REGISTRATION( Toolkit, PushButton, "iconPadding", STRING, ICON_PADDING ) -/** - * Find the first image actor in the actor hierarchy - */ -ImageActor FindImageActor( Actor root ) -{ - ImageActor imageActor = ImageActor::DownCast( root ); - if( !imageActor && root ) - { - for( unsigned int i = 0, numChildren = root.GetChildCount(); i < numChildren; ++i ) - { - ImageActor childImageActor = FindImageActor( root.GetChildAt( i ) ); - if( childImageActor ) - { - return childImageActor; - } - } - } +DALI_TYPE_REGISTRATION_END() - return imageActor; -} +} // unnamed namespace +namespace +{ } // unnamed namespace @@ -94,87 +82,116 @@ Dali::Toolkit::PushButton PushButton::New() return pushButton; } -void PushButton::OnButtonInitialize() +PushButton::PushButton() +: Button(), + mIconAlignment( RIGHT ) { - // Push button requires the Leave event. - Actor root = Self(); - root.SetLeaveRequired( true ); } -PushButton::PushButton() -: Button() +PushButton::~PushButton() { - // Creates specific painter.GetBu - ButtonPainterPtr painter = PushButtonDefaultPainterPtr( new PushButtonDefaultPainter() ); - SetPainter( painter ); } -PushButton::~PushButton() +void PushButton::OnInitialize() { - SetPainter( NULL ); + Button::OnInitialize(); + + // Push button requires the Leave event. + Actor self = Self(); + self.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); } -Vector3 PushButton::GetNaturalSize() +void PushButton::SetIconAlignment( const PushButton::IconAlignment iconAlignment ) { - Vector3 size = Control::GetNaturalSize(); + 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; + } - const bool widthIsZero = EqualsZero( size.width ); - const bool heightIsZero = EqualsZero( size.height ); + Button::SetLabelAlignment( labelAlignment ); +} - if( widthIsZero || heightIsZero ) +const PushButton::IconAlignment PushButton::GetIconAlignment() const +{ + return mIconAlignment; +} + +void PushButton::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value ) +{ + Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) ); + + if ( pushButton ) { - // If background and background not scale9 try get size from that - ImageActor imageActor = FindImageActor( GetButtonImage() ); - if( imageActor && imageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH ) - { - Vector3 imageSize = RelayoutHelper::GetNaturalSize( imageActor ); + PushButton& pushButtonImpl( GetImplementation( pushButton ) ); + + // Properties remain here for Tizen 3.0 legacy requirements. Are now in Button base class - if( widthIsZero ) + switch ( propertyIndex ) + { + case Toolkit::PushButton::Property::LABEL_PADDING: { - size.width = imageSize.width; + Vector4 padding ( value.Get< Vector4 >() ); + pushButtonImpl.Button::SetLabelPadding( Padding( padding.x, padding.y, padding.z, padding.w ) ); + break; } - - if( heightIsZero ) + case Toolkit::PushButton::Property::ICON_PADDING: { - size.height = imageSize.height; + Vector4 padding ( value.Get< Vector4 >() ); + pushButtonImpl.Button::SetForegroundPadding( Padding( padding.x, padding.y, padding.z, padding.w ) ); + break; } } + } +} - ImageActor backgroundImageActor = FindImageActor( GetBackgroundImage() ); - if( backgroundImageActor && backgroundImageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH ) - { - Vector3 imageSize = RelayoutHelper::GetNaturalSize( backgroundImageActor ); +Property::Value PushButton::GetProperty( BaseObject* object, Property::Index propertyIndex ) +{ + Property::Value value; - if( widthIsZero ) - { - size.width = std::max( size.width, imageSize.width ); - } + Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) ); - if( heightIsZero ) - { - size.height = std::max( size.height, imageSize.height ); - } - } + if ( pushButton ) + { + PushButton& pushButtonImpl( GetImplementation( pushButton ) ); - // If label, test against it's size - Toolkit::TextView textView = Toolkit::TextView::DownCast( GetLabel() ); - if( textView ) + switch ( propertyIndex ) { - Vector3 textViewSize = textView.GetNaturalSize(); - - if( widthIsZero ) + case Toolkit::PushButton::Property::LABEL_PADDING: { - size.width = std::max( size.width, textViewSize.width + TEXT_PADDING * 2.0f ); + Padding padding = pushButtonImpl.Button::GetLabelPadding(); + value = Vector4( padding.x, padding.y, padding.top, padding.bottom); + break; } - - if( heightIsZero ) + case Toolkit::PushButton::Property::ICON_PADDING: { - size.height = std::max( size.height, textViewSize.height + TEXT_PADDING * 2.0f ); + Padding padding = pushButtonImpl.Button::GetForegroundPadding(); + value = Vector4( padding.x, padding.y, padding.top, padding.bottom); + break; } } } - return size; + return value; } } // namespace Internal