X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=base%2Fdali-toolkit%2Finternal%2Fcontrols%2Frelayout-helper.cpp;h=5315c5322f0156fe421d7c049f5cf9e5e5c96ea5;hb=1b26c32c4c0114c69e8dd7cd51280f284b8ded14;hp=b5f1fc967b8653b62806d2fec1ed62cdd17e5393;hpb=e58fa784d19a558e35f458ecf6d262a2344beb4f;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/base/dali-toolkit/internal/controls/relayout-helper.cpp b/base/dali-toolkit/internal/controls/relayout-helper.cpp index b5f1fc9..5315c53 100644 --- a/base/dali-toolkit/internal/controls/relayout-helper.cpp +++ b/base/dali-toolkit/internal/controls/relayout-helper.cpp @@ -1,21 +1,25 @@ -// -// 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. + * + */ #include "relayout-helper.h" +#include + + namespace Dali { @@ -30,29 +34,41 @@ 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 ); + } + else + { + // Get natural size for TextActor. + TextActor textActor = TextActor::DownCast( actor ); + if( textActor ) + { + Font font = textActor.GetFont(); + if( !font ) + { + font = Font::New(); + } + size = font.MeasureText( textActor.GetText() ); + size.depth = depth; + } + } } return size; @@ -60,28 +76,59 @@ 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(); + TextActor textActor = TextActor::DownCast( actor ); + if( textActor ) + { + Font font = textActor.GetFont(); + if( !font ) + { + font = Font::New(); + } + size = font.MeasureText( textActor.GetText() ); + + constrainSize = true; + } + else + { + 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; }