2 * Copyright (c) 2015 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 "vertical-layout-impl.h"
22 #include "vertical-layout.h"
33 Toolkit::VerticalLayout VerticalLayout::New()
35 // Create the implementation, temporarily owned by this handle on stack
36 IntrusivePtr< VerticalLayout > impl = new VerticalLayout();
38 // Pass ownership to CustomActor handle
39 Toolkit::VerticalLayout handle( *impl );
41 // Second-phase init of the implementation
42 // This can only be done after the CustomActor connection has been made...
48 VerticalLayout::VerticalLayout()
49 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) )
53 VerticalLayout::~VerticalLayout()
57 void VerticalLayout::OnInitialize()
61 Vector3 VerticalLayout::GetNaturalSize()
63 Vector3 size = Vector3::ZERO;
65 CustomActor self = Self();
66 for( unsigned int index = 0u, count = self.GetChildCount(); index < count; ++index )
68 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( self.GetChildAt( index ) );
72 Vector3 labelSize = label.GetNaturalSize();
74 size.width = ( labelSize.width > size.width ) ? labelSize.width : size.width;
75 size.height += labelSize.height;
82 float VerticalLayout::GetHeightForWidth( float width )
86 CustomActor self = Self();
87 for( unsigned int index = 0u, count = self.GetChildCount(); index < count; ++index )
89 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( self.GetChildAt( index ) );
93 height += label.GetHeightForWidth( width );
100 float VerticalLayout::GetWidthForHeight( float height )
105 void VerticalLayout::OnFontChange( bool defaultFontChange, bool defaultFontSizeChange )
109 void VerticalLayout::OnRelayout( const Vector2& size, ActorSizeContainer& container )
111 CustomActor self = Self();
114 for( unsigned int index = 0u, count = self.GetChildCount(); index < count; ++index )
116 Size childSize = size;
117 Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( self.GetChildAt( index ) );
121 label.SetPosition( position );
123 childSize.height = label.GetHeightForWidth( size.width );
124 position.height += childSize.height;
126 label.SetSize( childSize );
129 container.push_back( ActorSizePair( label, childSize ) );
133 void VerticalLayout::AddLabel( Toolkit::TextLabel label )
140 } // namespace Internal
142 } // namespace Toolkit