From d03f1020366656f2980e19e395cf8a18b0b8adba Mon Sep 17 00:00:00 2001 From: Ferran Sole Date: Mon, 15 Jun 2015 10:44:57 +0100 Subject: [PATCH] Fix for Control::GetNaturalSize() Control will now return background image size if there is one or Vector3::ZERO otherwise. Change-Id: I8480964ffbe2049e53ccf8ebb0103cceeb9caa49 --- dali-toolkit/public-api/controls/control-impl.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index 1d1e5b0..5d9880b 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -1073,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 ) -- 2.7.4