2 * Copyright (c) 2018 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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-event-thread-callback.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/controls/control-devel.h>
25 #include <dali-toolkit/devel-api/layouting/absolute-layout.h>
26 #include <dali-toolkit/devel-api/layouting/linear-layout.h>
27 #include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
28 #include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
29 #include <dali/devel-api/actors/actor-devel.h>
31 #include <../custom-layout.h>
33 #include <layout-utils.h>
36 using namespace Toolkit;
41 // Turns the given control into a Root layout control and adds it to the stage.
42 void SetupRootLayoutControl( Control& rootControl )
44 rootControl = Control::New();
45 auto absoluteLayout = AbsoluteLayout::New();
46 DevelControl::SetLayout( rootControl, absoluteLayout );
47 rootControl.SetName( "RootAbsoluteLayout" );
48 Stage stage = Stage::GetCurrent();
49 stage.Add( rootControl );
52 } // unnamed namespace
54 void utc_dali_toolkit_layouting_nesting_startup(void)
56 test_return_value = TET_UNDEF;
59 void utc_dali_toolkit_layouting_nesting_cleanup(void)
61 test_return_value = TET_PASS;
64 // Test nesting of Layouts and Controls
66 int UtcDaliLayoutingNesting_01(void)
72 Control (LinearLayout Horizontal)
74 Control (LinearLayout Vertical)
80 ToolkitTestApplication application;
81 tet_infoline("UtcDaliLayoutingNesting_01 - Nesting a LinearLayout (MATCH_PARENT) containing a leaf control within a LinearLayout");
83 auto rootControl = Control::New();
84 SetupRootLayoutControl( rootControl );
86 auto hbox = Control::New();
87 auto hboxLayout = LinearLayout::New();
88 hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
89 DevelControl::SetLayout( hbox, hboxLayout );
90 hbox.SetName( "hBox" );
91 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 480 );
92 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 800 );
95 auto vbox = Control::New();
96 auto vboxLayout = LinearLayout::New();
97 vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
98 DevelControl::SetLayout( vbox, vboxLayout );
99 vbox.SetName( "vBox" );
100 vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
101 vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
104 std::vector< Control > controls;
105 controls.push_back( CreateLeafControl( 40, 40 ) );
107 for( auto&& iter : controls )
112 rootControl.Add( hbox );
114 // Ensure layouting happens
115 application.SendNotification();
116 application.Render();
118 DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
119 DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
121 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
126 int UtcDaliLayoutingNesting_02(void)
132 Control (LinearLayout Horizontal)
134 Control (LinearLayout Vertical)
140 ToolkitTestApplication application;
141 tet_infoline("UtcDaliLayoutingNesting_02 - Nesting a LinearLayout (MATCH_PARENT) containing a leaf control within a LinearLayout");
142 tet_infoline("Then change the parent's size and test child responded correctly");
144 auto rootControl = Control::New();
145 SetupRootLayoutControl( rootControl );
147 auto hbox = Control::New();
148 auto hboxLayout = LinearLayout::New();
149 hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
150 DevelControl::SetLayout( hbox, hboxLayout );
151 hbox.SetName( "hBox" );
152 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 480 );
153 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 800 );
156 auto vbox = Control::New();
157 auto vboxLayout = LinearLayout::New();
158 vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
159 DevelControl::SetLayout( vbox, vboxLayout );
160 vbox.SetName( "vBox" );
161 vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
162 vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
165 std::vector< Control > controls;
166 controls.push_back( CreateLeafControl( 40, 40 ) );
168 for( auto&& iter : controls )
173 rootControl.Add( hbox );
175 // Ensure layouting happens
176 application.SendNotification();
177 application.Render();
179 DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
180 DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
181 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
183 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 400 );
185 // Ensure layouting happens
186 application.SendNotification();
187 application.Render();
190 DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 400.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
191 DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 400.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
192 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
197 int UtcDaliLayoutingNesting_LeafSizeChange(void)
202 Control (LayoutingRequired)
204 Control (LinearLayout Horizontal) (WRAP_CONTENT)
209 ToolkitTestApplication application;
210 tet_infoline("UtcDaliLayoutingNesting_LeafSizeChange - Nesting a TextLabel within a layout that is parented to a control");
211 tet_infoline("Then change the TextLabels size and test the parent resized to wrap the new size");
213 auto rootControl = Control::New();
214 SetupRootLayoutControl( rootControl );
216 auto control = Control::New();
217 DevelControl::SetLayoutingRequired( control, true );
218 control.SetName( "control" );
220 auto hbox = Control::New();
221 auto hboxLayout = LinearLayout::New();
222 hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
223 DevelControl::SetLayout( hbox, hboxLayout );
224 hbox.SetName( "hBox" );
225 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
226 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
230 TextLabel textLabel = CreateTextLabel("SmallText" );
232 hbox.Add( textLabel );
234 rootControl.Add( control );
236 // Ensure layouting happens
237 application.SendNotification();
238 application.Render();
240 DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 254.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
241 DALI_TEST_EQUALS( textLabel.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 254.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
243 tet_infoline("Changing to longer text");
244 textLabel.SetProperty( TextLabel::Property::TEXT, "muchlongerText" );
246 // Ensure layouting happens
247 application.SendNotification();
248 application.Render();
250 DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 426.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );
251 DALI_TEST_EQUALS( textLabel.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 426.0f, 64.0f, 0.0f ), 0.0001f, TEST_LOCATION );