Fix for Control::GetNaturalSize()
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control-impl.cpp
index 07d7f02..5d9880b 100644 (file)
@@ -302,8 +302,7 @@ Actor CreateBackground( Actor parent, const Vector4& color, Image image = Image(
   mesh.SetIndexBuffer( indexBuffer );
 
   //Add uniforms to the shader
-  Property::Index backgroundColorIndex = shader.RegisterProperty( "uBackgroundColor", color );
-  shader.AddUniformMapping( backgroundColorIndex, "uBackgroundColor" );
+  shader.RegisterProperty( "uBackgroundColor", color );
 
   //Create the renderer
   Renderer renderer = Renderer::New( mesh, material );
@@ -1074,15 +1073,23 @@ void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dime
 
 Vector3 Control::GetNaturalSize()
 {
+  //Control's natural size is the size of its background image if it has been set, or ZERO otherwise
+  Vector3 naturalSize = Vector3::ZERO;
   if( mImpl->mBackground )
   {
-    Actor actor = mImpl->mBackground->actor;
-    if( actor )
+    Material backgroundMaterial = mImpl->mBackground->actor.GetRendererAt(0).GetMaterial();
+    if( backgroundMaterial.GetNumberOfSamplers() > 0 )
     {
-      return actor.GetNaturalSize();
+      Image backgroundImage =  backgroundMaterial.GetSamplerAt(0).GetImage();
+      if( backgroundImage )
+      {
+        naturalSize.x = backgroundImage.GetWidth();
+        naturalSize.y = backgroundImage.GetHeight();
+      }
     }
   }
-  return Vector3();
+
+  return naturalSize;
 }
 
 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )