PushButton to use container Actor size not just ImageActors added to it 76/37876/4
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Tue, 7 Apr 2015 15:17:07 +0000 (16:17 +0100)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Thu, 9 Apr 2015 10:02:06 +0000 (03:02 -0700)
Change-Id: Ie8ca930bd6d9fb7ce7f4c232342bbdf38f8c7783
Signed-off-by: Agnelo Vaz <agnelo.vaz@samsung.com>
dali-toolkit/internal/controls/buttons/push-button-impl.cpp
dali-toolkit/public-api/controls/buttons/push-button.h

index a2cb95d..1890686 100644 (file)
@@ -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
 }
 
 } // unnamed namespace
@@ -580,20 +574,9 @@ Vector3 PushButton::GetNaturalSize()
 {
   Vector3 size;
 
 {
   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() );
 
   // If label, test against it's size
   Toolkit::TextView textView = Toolkit::TextView::DownCast( GetLabel() );
index 4a1974f..0b4fa5f 100644 (file)
@@ -129,7 +129,12 @@ public:
   void SetButtonImage( Image image );
 
   /**
   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 );
 
    */
   void SetButtonImage( Actor image );
 
@@ -148,7 +153,12 @@ public:
   void SetBackgroundImage( Image image );
 
   /**
   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 );
 
    */
   void SetBackgroundImage( Actor image );