X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fpush-button-impl.cpp;h=cf34f85cc409078894308024b9f326d9e9ca20cf;hb=de3afc02ae1077be95857285b2228bfadf3cabd7;hp=24fa23070f2dc4f6e1bc991ba3c5f658d4edf8dd;hpb=56d412791a44c2a79135d2293c13fddb135c9d54;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 24fa230..cf34f85 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp @@ -53,24 +53,18 @@ namespace { /** - * Find the first image actor in the actor hierarchy + * 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 */ -ImageActor FindImageActor( Actor root ) +void SizeOfActorIfLarger( Actor root, Vector3& size ) { - ImageActor imageActor = ImageActor::DownCast( root ); - if( !imageActor && root ) + if ( root ) { - for( unsigned int i = 0, numChildren = root.GetChildCount(); i < numChildren; ++i ) - { - ImageActor childImageActor = FindImageActor( root.GetChildAt( i ) ); - if( childImageActor ) - { - return childImageActor; - } - } + // 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 ); } - - return imageActor; } } // unnamed namespace @@ -108,7 +102,7 @@ void PushButton::OnButtonInitialize() self.SetLeaveRequired( true ); // Set resize policy to natural size so that buttons will resize to background images - self.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS ); + self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); } void PushButton::OnLabelSet() @@ -119,7 +113,15 @@ void PushButton::OnLabelSet() { label.SetAnchorPoint( AnchorPoint::CENTER ); label.SetParentOrigin( ParentOrigin::CENTER ); - label.SetSize( mSize ); + label.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + + 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 ); + } } } @@ -127,7 +129,7 @@ void PushButton::OnButtonImageSet() { Actor& buttonImage = GetButtonImage(); - buttonImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + buttonImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); buttonImage.RelayoutRequestTree(); @@ -138,7 +140,7 @@ void PushButton::OnSelectedImageSet() { Actor& selectedImage = GetSelectedImage(); - selectedImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + selectedImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); selectedImage.RelayoutRequestTree(); @@ -149,7 +151,7 @@ void PushButton::OnBackgroundImageSet() { Actor& backgroundImage = GetBackgroundImage(); - backgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + backgroundImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); backgroundImage.RelayoutRequestTree(); @@ -160,14 +162,14 @@ void PushButton::OnSelectedBackgroundImageSet() { Actor& selectedBackgroundImage = GetSelectedBackgroundImage(); - selectedBackgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + selectedBackgroundImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); } void PushButton::OnDisabledImageSet() { Actor& disabledImage = GetDisabledImage(); - disabledImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + disabledImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); disabledImage.RelayoutRequestTree(); @@ -178,7 +180,7 @@ void PushButton::OnDisabledBackgroundImageSet() { Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); - disabledBackgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + disabledBackgroundImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); disabledBackgroundImage.RelayoutRequestTree(); @@ -580,20 +582,9 @@ Vector3 PushButton::GetNaturalSize() { Vector3 size; - // If background and background not scale9 try get size from that - ImageActor imageActor = FindImageActor( GetButtonImage() ); - if( imageActor && imageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH ) - { - size.width = imageActor.GetRelayoutSize( WIDTH ); - size.height = imageActor.GetRelayoutSize( HEIGHT ); - } - - ImageActor backgroundImageActor = FindImageActor( GetBackgroundImage() ); - if( backgroundImageActor && backgroundImageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH ) - { - size.width = std::max( size.width, backgroundImageActor.GetRelayoutSize( WIDTH ) ); - size.height = std::max( size.height, backgroundImageActor.GetRelayoutSize( HEIGHT ) ); - } + // Check Image and Background image and use the largest size as the control's Natural size. + SizeOfActorIfLarger( GetButtonImage(), size ); + SizeOfActorIfLarger( GetBackgroundImage(), size ); // If label, test against it's size Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabel() );