2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #include "relayout-helper.h"
19 #include <dali-toolkit/public-api/controls/control.h>
31 namespace RelayoutHelper
34 Vector3 GetNaturalSize( Actor actor )
36 Vector3 size( 0.0f, 0.0f, 0.0f );
38 Toolkit::Control control = Toolkit::Control::DownCast( actor );
41 size = control.GetNaturalSize();
45 size = actor.GetCurrentSize();
46 const float depth = size.depth;
48 // Get natural size for ImageActor.
49 // TODO: currently it doesn't work as expected.
50 ImageActor imageActor = ImageActor::DownCast( actor );
51 if( ( imageActor ) && ( imageActor.GetImage() ) )
53 Image image = imageActor.GetImage();
54 size = Vector3( static_cast<float>( image.GetWidth() ), static_cast<float>( image.GetHeight() ), depth );
58 // Get natural size for TextActor.
59 TextActor textActor = TextActor::DownCast( actor );
62 Font font = textActor.GetFont();
67 size = font.MeasureText( textActor.GetText() );
76 float GetHeightForWidth( Actor actor, float width )
80 Toolkit::Control control = Toolkit::Control::DownCast( actor );
83 height = control.GetHeightForWidth( width );
87 bool constrainSize = false;
88 Vector3 size( 0.0f, 0.0f, 0.0f );
90 ImageActor imageActor = ImageActor::DownCast( actor );
91 if( ( imageActor ) && ( imageActor.GetImage() ) )
93 Image image = imageActor.GetImage();
94 size = Vector3( static_cast<float>( image.GetWidth() ), static_cast<float>( image.GetHeight() ), 0.0f );
100 TextActor textActor = TextActor::DownCast( actor );
103 Font font = textActor.GetFont();
108 size = font.MeasureText( textActor.GetText() );
110 constrainSize = true;
114 size = actor.GetCurrentSize();
119 float scaleRatio = width / size.width;
122 // Allow the scale to decrease if greater than input width but not increase if less than input width
123 if( scaleRatio > 1.0f )
129 height = size.height * scaleRatio;
135 } // namespace RelayoutHelper
137 } // namespace Internal
139 } // namespace Toolkit