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.
19 #include "relayout-helper.h"
22 #include <dali/public-api/actors/image-actor.h>
25 #include <dali-toolkit/public-api/controls/control.h>
37 namespace RelayoutHelper
40 Vector3 GetNaturalSize( Actor actor )
42 Vector3 size( 0.0f, 0.0f, 0.0f );
44 Toolkit::Control control = Toolkit::Control::DownCast( actor );
47 size = control.GetNaturalSize();
51 size = actor.GetCurrentSize();
52 const float depth = size.depth;
54 // Get natural size for ImageActor.
55 // TODO: currently it doesn't work as expected.
56 ImageActor imageActor = ImageActor::DownCast( actor );
57 if( ( imageActor ) && ( imageActor.GetImage() ) )
59 Image image = imageActor.GetImage();
60 size = Vector3( static_cast<float>( image.GetWidth() ), static_cast<float>( image.GetHeight() ), depth );
67 float GetHeightForWidth( Actor actor, float width )
71 Toolkit::Control control = Toolkit::Control::DownCast( actor );
74 height = control.GetHeightForWidth( width );
78 bool constrainSize = false;
79 Vector3 size( 0.0f, 0.0f, 0.0f );
81 ImageActor imageActor = ImageActor::DownCast( actor );
82 if( ( imageActor ) && ( imageActor.GetImage() ) )
84 Image image = imageActor.GetImage();
85 size = Vector3( static_cast<float>( image.GetWidth() ), static_cast<float>( image.GetHeight() ), 0.0f );
91 size = actor.GetCurrentSize();
95 float scaleRatio = width / size.width;
98 // Allow the scale to decrease if greater than input width but not increase if less than input width
99 if( scaleRatio > 1.0f )
105 height = size.height * scaleRatio;
111 } // namespace RelayoutHelper
113 } // namespace Internal
115 } // namespace Toolkit