2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "relayout-helper.h"
20 #include <dali-toolkit/public-api/controls/control.h>
32 namespace RelayoutHelper
35 Vector3 GetNaturalSize( Actor actor )
37 Vector3 size( 0.0f, 0.0f, 0.0f );
39 Toolkit::Control control = Toolkit::Control::DownCast( actor );
42 size = control.GetNaturalSize();
46 size = actor.GetCurrentSize();
47 const float depth = size.depth;
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 );
59 // Get natural size for TextActor.
60 TextActor textActor = TextActor::DownCast( actor );
63 Font font = textActor.GetFont();
68 size = font.MeasureText( textActor.GetText() );
77 float GetHeightForWidth( Actor actor, float width )
81 Toolkit::Control control = Toolkit::Control::DownCast( actor );
84 height = control.GetHeightForWidth( width );
88 bool constrainSize = false;
89 Vector3 size( 0.0f, 0.0f, 0.0f );
91 ImageActor imageActor = ImageActor::DownCast( actor );
92 if( ( imageActor ) && ( imageActor.GetImage() ) )
94 Image image = imageActor.GetImage();
95 size = Vector3( static_cast<float>( image.GetWidth() ), static_cast<float>( image.GetHeight() ), 0.0f );
101 TextActor textActor = TextActor::DownCast( actor );
104 Font font = textActor.GetFont();
109 size = font.MeasureText( textActor.GetText() );
111 constrainSize = true;
115 size = actor.GetCurrentSize();
120 float scaleRatio = width / size.width;
123 // Allow the scale to decrease if greater than input width but not increase if less than input width
124 if( scaleRatio > 1.0f )
130 height = size.height * scaleRatio;
136 } // namespace RelayoutHelper
138 } // namespace Internal
140 } // namespace Toolkit