Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / push-button-impl.cpp
index 207d3f0..3910e43 100644 (file)
@@ -23,7 +23,7 @@
 #include <dali/public-api/object/type-registry.h>
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/public-api/controls/text-view/text-view.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
 
 namespace Dali
 {
@@ -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
@@ -128,6 +122,10 @@ void PushButton::OnButtonImageSet()
   Actor& buttonImage = GetButtonImage();
 
   buttonImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+
+  buttonImage.RelayoutRequestTree();
+
+  RelayoutRequest();
 }
 
 void PushButton::OnSelectedImageSet()
@@ -135,6 +133,10 @@ void PushButton::OnSelectedImageSet()
   Actor& selectedImage = GetSelectedImage();
 
   selectedImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+
+  selectedImage.RelayoutRequestTree();
+
+  RelayoutRequest();
 }
 
 void PushButton::OnBackgroundImageSet()
@@ -142,6 +144,10 @@ void PushButton::OnBackgroundImageSet()
   Actor& backgroundImage = GetBackgroundImage();
 
   backgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+
+  backgroundImage.RelayoutRequestTree();
+
+  RelayoutRequest();
 }
 
 void PushButton::OnSelectedBackgroundImageSet()
@@ -156,6 +162,10 @@ void PushButton::OnDisabledImageSet()
   Actor& disabledImage = GetDisabledImage();
 
   disabledImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+
+  disabledImage.RelayoutRequestTree();
+
+  RelayoutRequest();
 }
 
 void PushButton::OnDisabledBackgroundImageSet()
@@ -163,6 +173,10 @@ void PushButton::OnDisabledBackgroundImageSet()
   Actor& disabledBackgroundImage = GetDisabledBackgroundImage();
 
   disabledBackgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
+
+  disabledBackgroundImage.RelayoutRequestTree();
+
+  RelayoutRequest();
 }
 
 bool PushButton::OnSelected()
@@ -558,62 +572,20 @@ void PushButton::OnControlSizeSet( const Vector3& targetSize )
 
 Vector3 PushButton::GetNaturalSize()
 {
-  Vector3 size = Control::GetNaturalSize();
+  Vector3 size;
 
-  const bool widthIsZero = EqualsZero( size.width );
-  const bool heightIsZero = EqualsZero( size.height );
+  // Check Image and Background image and use the largest size as the control's Natural size.
+  SizeOfActorIfLarger( GetButtonImage(), size );
+  SizeOfActorIfLarger( GetBackgroundImage(), size );
 
-  if( widthIsZero || heightIsZero )
+  // If label, test against it's size
+  Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabel() );
+  if( label )
   {
-    // 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 = imageActor.GetNaturalSize();
+    Vector3 labelSize = label.GetNaturalSize();
 
-      if( widthIsZero )
-      {
-        size.width = imageSize.width;
-      }
-
-      if( heightIsZero )
-      {
-        size.height = imageSize.height;
-      }
-    }
-
-    ImageActor backgroundImageActor = FindImageActor( GetBackgroundImage() );
-    if( backgroundImageActor && backgroundImageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
-    {
-      Vector3 imageSize = backgroundImageActor.GetNaturalSize();
-
-      if( widthIsZero )
-      {
-        size.width = std::max( size.width, imageSize.width );
-      }
-
-      if( heightIsZero )
-      {
-        size.height = std::max( size.height, imageSize.height );
-      }
-    }
-
-    // If label, test against it's size
-    Toolkit::TextView textView = Toolkit::TextView::DownCast( GetLabel() );
-    if( textView )
-    {
-      Vector3 textViewSize = textView.GetNaturalSize();
-
-      if( widthIsZero )
-      {
-        size.width = std::max( size.width, textViewSize.width + TEXT_PADDING * 2.0f );
-      }
-
-      if( heightIsZero )
-      {
-        size.height = std::max( size.height, textViewSize.height + TEXT_PADDING * 2.0f );
-      }
-    }
+    size.width  = std::max( size.width,  labelSize.width  + TEXT_PADDING * 2.0f );
+    size.height = std::max( size.height, labelSize.height + TEXT_PADDING * 2.0f );
   }
 
   return size;