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"
28 namespace RelayoutHelper
31 Vector3 GetNaturalSize( Actor actor )
33 Vector3 size = actor.GetCurrentSize();
34 const float depth = size.depth;
36 // Get natural size for TextActor.
37 TextActor textActor = TextActor::DownCast( actor );
40 Font font = textActor.GetFont();
45 size = font.MeasureText( textActor.GetText() );
49 // Get natural size for ImageActor.
50 // TODO: currently it doesn't work as expected.
51 ImageActor imageActor = ImageActor::DownCast( actor );
52 if( ( imageActor ) && ( imageActor.GetImage() ) )
54 Image image = imageActor.GetImage();
55 size = Vector3( static_cast<float>( image.GetWidth() ), static_cast<float>( image.GetHeight() ), depth );
61 float GetHeightForWidth( Actor actor, float width )
63 Vector3 size = actor.GetCurrentSize();
66 TextActor textActor = TextActor::DownCast( actor );
69 Font font = textActor.GetFont();
74 size = font.MeasureText( textActor.GetText() );
77 ImageActor imageActor = ImageActor::DownCast( actor );
78 if( ( imageActor ) && ( imageActor.GetImage() ) )
80 Image image = imageActor.GetImage();
81 size = Vector3( static_cast<float>( image.GetWidth() ), static_cast<float>( image.GetHeight() ), 0.f );
84 height = size.height / ( size.width / width );
89 } // namespace RelayoutHelper
91 } // namespace Internal
93 } // namespace Toolkit