842d9f8841841ab6f797519587003341d0530102
[platform/core/uifw/dali-demo.git] / examples / text-label-emojis / vertical-layout-impl.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "vertical-layout-impl.h"
20
21 // INTERNAL INCLUDES
22 #include "vertical-layout.h"
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Internal
31 {
32
33 Toolkit::VerticalLayout VerticalLayout::New()
34 {
35   // Create the implementation, temporarily owned by this handle on stack
36   IntrusivePtr< VerticalLayout > impl = new VerticalLayout();
37
38   // Pass ownership to CustomActor handle
39   Toolkit::VerticalLayout handle( *impl );
40
41   // Second-phase init of the implementation
42   // This can only be done after the CustomActor connection has been made...
43   impl->Initialize();
44
45   return handle;
46 }
47
48 VerticalLayout::VerticalLayout()
49 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) )
50 {
51 }
52
53 VerticalLayout::~VerticalLayout()
54 {
55 }
56
57 void VerticalLayout::OnInitialize()
58 {
59 }
60
61 Vector3 VerticalLayout::GetNaturalSize()
62 {
63   Vector3 size = Vector3::ZERO;
64
65   CustomActor self = Self();
66   for( unsigned int index = 0u, count = self.GetChildCount(); index < count; ++index )
67   {
68     Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( self.GetChildAt( index ) );
69
70     if( label )
71     {
72       Vector3 labelSize = label.GetNaturalSize();
73
74       size.width = ( labelSize.width > size.width ) ? labelSize.width : size.width;
75       size.height += labelSize.height + 50.0f/*FIXME*/;
76     }
77   }
78
79   return size;
80 }
81
82 float VerticalLayout::GetHeightForWidth( float width )
83 {
84   float height = 0.f;
85
86   CustomActor self = Self();
87   for( unsigned int index = 0u, count = self.GetChildCount(); index < count; ++index )
88   {
89     Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( self.GetChildAt( index ) );
90
91     if( label )
92     {
93       height += label.GetHeightForWidth( width ) + 50.0f/*FIXME*/;
94     }
95   }
96
97   return height;
98 }
99
100 float VerticalLayout::GetWidthForHeight( float height )
101 {
102   return 0.f;
103 }
104
105 void VerticalLayout::OnFontChange( bool defaultFontChange, bool defaultFontSizeChange )
106 {
107 }
108
109 void VerticalLayout::OnRelayout( const Vector2& size, ActorSizeContainer& container )
110 {
111   CustomActor self = Self();
112
113   Vector3 position;
114   for( unsigned int index = 0u, count = self.GetChildCount(); index < count; ++index )
115   {
116     Size childSize = size;
117     Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( self.GetChildAt( index ) );
118
119     if( label )
120     {
121       label.SetPosition( position );
122
123       childSize.height = label.GetHeightForWidth( size.width );
124       position.height += childSize.height + 50.0f/*FIXME*/;
125
126       label.SetSize( childSize );
127     }
128
129     container.push_back( ActorSizePair( label, childSize ) );
130   }
131 }
132
133 void VerticalLayout::AddLabel( Toolkit::TextLabel label )
134 {
135   Self().Add( label );
136
137   RelayoutRequest();
138 }
139
140 } // namespace Internal
141
142 } // namespace Toolkit
143
144 } // namespace Dali