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_resize_policy_startup(void)
56 test_return_value = TET_UNDEF;
59 void utc_dali_toolkit_layouting_resize_policy_cleanup(void)
61 test_return_value = TET_PASS;
64 // Test setting of the MeasureSpecs with the legacy ResizePolicies
66 int UtcDaliLayoutingResizePolicy_01(void)
71 Control (LinearLayout Horizontal)
73 Control (LayoutingRequired)
75 Control (ResizePolicy::FILL_TO_PARENT)
80 ToolkitTestApplication application;
81 tet_infoline("UtcDaliLayoutingResizePolicy_01 - Set ResizePolicy FILL_TO_PARENT on Control");
83 Stage stage = Stage::GetCurrent();
85 auto rootControl = Control::New();
86 SetupRootLayoutControl( rootControl );
88 auto hbox = Control::New();
89 auto hboxLayout = LinearLayout::New();
90 hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
91 DevelControl::SetLayout( hbox, hboxLayout );
92 hbox.SetName( "hBox" );
93 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
94 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
96 auto layoutingControl = Control::New();
97 layoutingControl.SetName( "layoutingRequiredControl" );
98 DevelControl::SetLayoutingRequired( layoutingControl, true );
99 layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
100 layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
101 hbox.Add( layoutingControl );
103 auto control = Control::New();
104 control.SetName( "fillToParentControl" );
105 DevelControl::SetLayoutingRequired( control, true );
106 control.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
107 layoutingControl.Add( control );
109 std::vector< Control > controls;
110 controls.push_back( CreateLeafControl( 40, 40 ) );
112 for( auto&& iter : controls )
117 rootControl.Add( hbox );
119 // Ensure layouting happens
120 application.SendNotification();
121 application.Render();
123 DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), true , 0.0001f, TEST_LOCATION );
125 DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
126 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
132 int UtcDaliLayoutingResizePolicy_02(void)
137 Control (LinearLayout Horizontal)
139 Control (LayoutingRequired)
141 Control (ResizePolicy::FIT_TO_CHILDREN)
146 ToolkitTestApplication application;
147 tet_infoline("UtcDaliLayoutingResizePolicy_02 - Set ResizePolicy FIT_TO_CHILDREN on Control");
149 Stage stage = Stage::GetCurrent();
151 auto rootControl = Control::New();
152 SetupRootLayoutControl( rootControl );
154 auto hbox = Control::New();
155 auto hboxLayout = LinearLayout::New();
156 hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
157 DevelControl::SetLayout( hbox, hboxLayout );
158 hbox.SetName( "hBox" );
159 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
160 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
162 auto layoutingControl = Control::New();
163 layoutingControl.SetName( "layoutingRequiredControl" );
164 DevelControl::SetLayoutingRequired( layoutingControl, true );
165 layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
166 layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
167 hbox.Add( layoutingControl );
169 auto control = Control::New();
170 control.SetName( "fitToChildrenControl" );
171 DevelControl::SetLayoutingRequired( control, true );
172 control.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
173 layoutingControl.Add( control );
175 std::vector< Control > controls;
176 controls.push_back( CreateLeafControl( 40, 40 ) );
178 for( auto&& iter : controls )
183 rootControl.Add( hbox );
185 // Ensure layouting happens
186 application.SendNotification();
187 application.Render();
189 DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), true , 0.0001f, TEST_LOCATION );
191 DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.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 UtcDaliLayoutingResizePolicy_03(void)
202 Control (LinearLayout Horizontal)
204 Control (LayoutingRequired)
206 Control (ResizePolicy::SIZE_RELATIVE_TO_PARENT)
211 ToolkitTestApplication application;
212 tet_infoline("UtcDaliLayoutingResizePolicy_03 - Set ResizePolicy SIZE_RELATIVE_TO_PARENT on Control");
214 Stage stage = Stage::GetCurrent();
216 auto rootControl = Control::New();
217 SetupRootLayoutControl( rootControl );
219 auto hbox = Control::New();
220 auto hboxLayout = LinearLayout::New();
221 hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
222 DevelControl::SetLayout( hbox, hboxLayout );
223 hbox.SetName( "hBox" );
224 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
225 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
227 auto layoutingControl = Control::New();
228 layoutingControl.SetName( "layoutingRequiredControl" );
229 DevelControl::SetLayoutingRequired( layoutingControl, true );
230 layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
231 layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
232 hbox.Add( layoutingControl );
234 auto control = Control::New();
235 control.SetName( "fitToChildrenControl" );
236 DevelControl::SetLayoutingRequired( control, true );
237 control.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
238 control.SetSizeModeFactor( Vector3( 0.50f, 1.0f, 1.0f ) );
239 layoutingControl.Add( control );
241 std::vector< Control > controls;
242 controls.push_back( CreateLeafControl( 40, 40 ) );
244 for( auto&& iter : controls )
249 rootControl.Add( hbox );
251 // Ensure layouting happens
252 application.SendNotification();
253 application.Render();
255 DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), true , 0.0001f, TEST_LOCATION );
257 DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 240.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
258 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
263 int UtcDaliLayoutingResizePolicy_04(void)
268 Control (LinearLayout Horizontal)
270 Control (LayoutingRequired)
272 Control (ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT)
277 ToolkitTestApplication application;
278 tet_infoline("UtcDaliLayoutingResizePolicy_04 - Set ResizePolicy SIZE_FIXED_OFFSET_FROM_PARENT on Control");
280 Stage stage = Stage::GetCurrent();
282 auto rootControl = Control::New();
283 SetupRootLayoutControl( rootControl );
285 auto hbox = Control::New();
286 auto hboxLayout = LinearLayout::New();
287 hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
288 DevelControl::SetLayout( hbox, hboxLayout );
289 hbox.SetName( "hBox" );
290 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
291 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
293 auto layoutingControl = Control::New();
294 layoutingControl.SetName( "layoutingRequiredControl" );
295 DevelControl::SetLayoutingRequired( layoutingControl, true );
296 layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
297 layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
298 hbox.Add( layoutingControl );
300 auto control = Control::New();
301 control.SetName( "fitToChildrenControl" );
302 DevelControl::SetLayoutingRequired( control, true );
303 control.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
304 control.SetSizeModeFactor( Vector3( -100.0f, 10.0f, 0.0f ) );
305 layoutingControl.Add( control );
307 std::vector< Control > controls;
308 controls.push_back( CreateLeafControl( 40, 40 ) );
310 for( auto&& iter : controls )
315 rootControl.Add( hbox );
317 // Ensure layouting happens
318 application.SendNotification();
319 application.Render();
321 DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), true , 0.0001f, TEST_LOCATION );
323 DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 380.0f, 810.0f, 0.0f ), 0.0001f, TEST_LOCATION );
324 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
329 int UtcDaliLayoutingResizePolicy_05(void)
334 Control (LinearLayout Horizontal)
336 Control (LayoutingRequired)
338 Control (ResizePolicy::FIXED)
343 ToolkitTestApplication application;
344 tet_infoline("UtcDaliLayoutingResizePolicy_05 - Set ResizePolicy FIXED on Control");
346 Stage stage = Stage::GetCurrent();
348 auto rootControl = Control::New();
349 SetupRootLayoutControl( rootControl );
351 auto hbox = Control::New();
352 auto hboxLayout = LinearLayout::New();
353 hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
354 DevelControl::SetLayout( hbox, hboxLayout );
355 hbox.SetName( "hBox" );
356 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
357 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
359 auto layoutingControl = Control::New();
360 layoutingControl.SetName( "layoutingRequiredControl" );
361 DevelControl::SetLayoutingRequired( layoutingControl, true );
362 layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
363 layoutingControl.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
364 hbox.Add( layoutingControl );
366 auto control = Control::New();
367 control.SetName( "fitToChildrenControl" );
368 DevelControl::SetLayoutingRequired( control, true );
369 control.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
370 control.SetSize( Vector3( 300.0f, 300.0f, 0.0f ) );
371 layoutingControl.Add( control );
373 std::vector< Control > controls;
374 controls.push_back( CreateLeafControl( 40, 40 ) );
376 for( auto&& iter : controls )
381 rootControl.Add( hbox );
383 // Ensure layouting happens
384 application.SendNotification();
385 application.Render();
387 DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), true , 0.0001f, TEST_LOCATION );
389 DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 300.0f, 300.0f, 0.0f ), 0.0001f, TEST_LOCATION );
390 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );