From 56c2c6b9998a38276bd619ef7ca4e20522cf0da8 Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Tue, 7 Apr 2015 16:17:07 +0100 Subject: [PATCH] PushButton to use container Actor size not just ImageActors added to it Change-Id: Ie8ca930bd6d9fb7ce7f4c232342bbdf38f8c7783 Signed-off-by: Agnelo Vaz --- .../internal/controls/buttons/push-button-impl.cpp | 39 ++++++---------------- .../public-api/controls/buttons/push-button.h | 14 ++++++-- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp index a2cb95d..1890686 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( WIDTH ), size.width ); + size.height = std::max( root.GetRelayoutSize( HEIGHT ), size.height ); } - - return imageActor; } } // unnamed namespace @@ -580,20 +574,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::TextView textView = Toolkit::TextView::DownCast( GetLabel() ); diff --git a/dali-toolkit/public-api/controls/buttons/push-button.h b/dali-toolkit/public-api/controls/buttons/push-button.h index 4a1974f..0b4fa5f 100644 --- a/dali-toolkit/public-api/controls/buttons/push-button.h +++ b/dali-toolkit/public-api/controls/buttons/push-button.h @@ -129,7 +129,12 @@ public: void SetButtonImage( Image image ); /** - * @copydoc SetButtonImage( Image image ) + * @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 */ void SetButtonImage( Actor image ); @@ -148,7 +153,12 @@ public: void SetBackgroundImage( Image image ); /** - * @copydoc SetBackgroundImage( Image image ) + * @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 */ void SetBackgroundImage( Actor image ); -- 2.7.4