X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Frelayout-helper.cpp;h=d7aab5b7e3ceda427000b67b8bf42a78044afd4a;hp=b5f1fc967b8653b62806d2fec1ed62cdd17e5393;hb=306d2f61a1b64179e801fa8a0bb2bd7b4e9dd682;hpb=e2eda444afbe82e9591fe198eef339227f90a616 diff --git a/dali-toolkit/internal/controls/relayout-helper.cpp b/dali-toolkit/internal/controls/relayout-helper.cpp index b5f1fc9..d7aab5b 100644 --- a/dali-toolkit/internal/controls/relayout-helper.cpp +++ b/dali-toolkit/internal/controls/relayout-helper.cpp @@ -1,21 +1,30 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER #include "relayout-helper.h" +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include + + namespace Dali { @@ -30,29 +39,26 @@ namespace RelayoutHelper Vector3 GetNaturalSize( Actor actor ) { - Vector3 size = actor.GetCurrentSize(); - const float depth = size.depth; + Vector3 size( 0.0f, 0.0f, 0.0f ); - // Get natural size for TextActor. - TextActor textActor = TextActor::DownCast( actor ); - if( textActor ) + Toolkit::Control control = Toolkit::Control::DownCast( actor ); + if( control ) { - Font font = textActor.GetFont(); - if( !font ) - { - font = Font::New(); - } - size = font.MeasureText( textActor.GetText() ); - size.depth = depth; + size = control.GetNaturalSize(); } - - // Get natural size for ImageActor. - // TODO: currently it doesn't work as expected. - ImageActor imageActor = ImageActor::DownCast( actor ); - if( ( imageActor ) && ( imageActor.GetImage() ) ) + else { - Image image = imageActor.GetImage(); - size = Vector3( static_cast( image.GetWidth() ), static_cast( image.GetHeight() ), depth ); + size = actor.GetCurrentSize(); + const float depth = size.depth; + + // Get natural size for ImageActor. + // TODO: currently it doesn't work as expected. + ImageActor imageActor = ImageActor::DownCast( actor ); + if( ( imageActor ) && ( imageActor.GetImage() ) ) + { + Image image = imageActor.GetImage(); + size = Vector3( static_cast( image.GetWidth() ), static_cast( image.GetHeight() ), depth ); + } } return size; @@ -60,28 +66,44 @@ Vector3 GetNaturalSize( Actor actor ) float GetHeightForWidth( Actor actor, float width ) { - Vector3 size = actor.GetCurrentSize(); - float height = 0.f; + float height = 0.0f; - TextActor textActor = TextActor::DownCast( actor ); - if( textActor ) + Toolkit::Control control = Toolkit::Control::DownCast( actor ); + if( control ) + { + height = control.GetHeightForWidth( width ); + } + else { - Font font = textActor.GetFont(); - if( !font ) + bool constrainSize = false; + Vector3 size( 0.0f, 0.0f, 0.0f ); + + ImageActor imageActor = ImageActor::DownCast( actor ); + if( ( imageActor ) && ( imageActor.GetImage() ) ) + { + Image image = imageActor.GetImage(); + size = Vector3( static_cast( image.GetWidth() ), static_cast( image.GetHeight() ), 0.0f ); + + constrainSize = true; + } + else { - font = Font::New(); + size = actor.GetCurrentSize(); } - size = font.MeasureText( textActor.GetText() ); - } - ImageActor imageActor = ImageActor::DownCast( actor ); - if( ( imageActor ) && ( imageActor.GetImage() ) ) - { - Image image = imageActor.GetImage(); - size = Vector3( static_cast( image.GetWidth() ), static_cast( image.GetHeight() ), 0.f ); - } + // Scale the actor + float scaleRatio = width / size.width; + if( constrainSize ) + { + // Allow the scale to decrease if greater than input width but not increase if less than input width + if( scaleRatio > 1.0f ) + { + scaleRatio = 1.0f; + } + } - height = size.height / ( size.width / width ); + height = size.height * scaleRatio; + } return height; }