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/grid.h>
27 #include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
28 #include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
30 #include <../custom-layout.h>
32 #include <layout-utils.h>
35 using namespace Toolkit;
37 void utc_dali_toolkit_grid_layouting_startup(void)
39 test_return_value = TET_UNDEF;
42 void utc_dali_toolkit_grid_layouting_cleanup(void)
44 test_return_value = TET_PASS;
47 int UtcDaliLayouting_GridLayout00(void)
49 ToolkitTestApplication application;
50 tet_infoline(" UtcDaliLayouting_GridLayout00 1 Column, 0 Items");
52 const auto NUMBER_OF_COLUMNS = 1;
53 const auto NUMBER_OF_ITEMS = 0;
55 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
57 Stage stage = Stage::GetCurrent();
59 auto rootControl = Control::New();
60 auto absoluteLayout = AbsoluteLayout::New();
61 DevelControl::SetLayout( rootControl, absoluteLayout );
62 rootControl.SetName( "AbsoluteLayout" );
63 stage.Add( rootControl );
65 auto gridContainer = Control::New();
66 auto gridLayout = Grid::New();
67 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
68 gridContainer.SetName( "GridLayout");
69 DevelControl::SetLayout( gridContainer, gridLayout );
70 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
71 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
73 rootControl.Add( gridContainer );
75 // Ensure layouting happens
76 application.SendNotification();
79 tet_printf( "Confirm number of columns is as set\n");
80 DALI_TEST_EQUALS( gridLayout.GetNumberOfColumns(), NUMBER_OF_COLUMNS, TEST_LOCATION );
85 int UtcDaliLayouting_GridLayout01(void)
87 ToolkitTestApplication application;
88 tet_infoline(" UtcDaliLayouting_GridLayout01 2 Column, 4 Items");
90 const auto NUMBER_OF_COLUMNS = 2;
91 const auto NUMBER_OF_ITEMS = 4;
93 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
95 Stage stage = Stage::GetCurrent();
97 auto rootControl = Control::New();
98 auto absoluteLayout = AbsoluteLayout::New();
99 DevelControl::SetLayout( rootControl, absoluteLayout );
100 rootControl.SetName( "AbsoluteLayout" );
101 stage.Add( rootControl );
103 auto gridContainer = Control::New();
104 auto gridLayout = Grid::New();
105 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
106 gridContainer.SetName( "GridLayout");
107 DevelControl::SetLayout( gridContainer, gridLayout );
108 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
109 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
111 std::vector< Control > controls;
112 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
114 controls.push_back( CreateLeafControl( 100, 100 ) );
117 for( auto&& iter : controls )
119 gridContainer.Add( iter );
122 rootControl.Add( gridContainer );
124 // Ensure layouting happens
125 application.SendNotification();
126 application.Render();
128 // Grid will layout first 2 items on first row then last 2 on second row.
129 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
130 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
131 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
132 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
134 // Item sizes will not be changed
135 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
136 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
137 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
138 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
140 tet_printf( "Confirm number of columns is as set\n");
141 DALI_TEST_EQUALS( gridLayout.GetNumberOfColumns(), NUMBER_OF_COLUMNS, TEST_LOCATION );
146 int UtcDaliLayouting_GridLayout02(void)
148 ToolkitTestApplication application;
149 tet_infoline("UtcDaliLayouting_GridLayout02");
151 const auto NUMBER_OF_COLUMNS = 3;
152 const auto NUMBER_OF_ITEMS = 7;
154 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
156 Stage stage = Stage::GetCurrent();
158 auto rootControl = Control::New();
159 auto absoluteLayout = AbsoluteLayout::New();
160 DevelControl::SetLayout( rootControl, absoluteLayout );
161 rootControl.SetName( "AbsoluteLayout" );
162 stage.Add( rootControl );
164 auto gridContainer = Control::New();
165 auto gridLayout = Grid::New();
166 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
167 gridContainer.SetName( "GridLayout");
168 DevelControl::SetLayout( gridContainer, gridLayout );
169 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
170 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
172 std::vector< Control > controls;
173 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
175 controls.push_back( CreateLeafControl( 100, 100 ) );
178 for( auto&& iter : controls )
180 gridContainer.Add( iter );
183 rootControl.Add( gridContainer );
185 // Ensure layouting happens
186 application.SendNotification();
187 application.Render();
189 // grid layouts out 3 items per row, which is 480x800.
191 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
192 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
193 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 200.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
195 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
196 DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
197 DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 200.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
199 DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 200.0f, 0.0f ), 0.0001f, TEST_LOCATION );
201 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
202 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
203 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
204 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
205 DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
206 DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
207 DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
212 int UtcDaliLayouting_GridLayout03(void)
214 ToolkitTestApplication application;
215 tet_infoline(" UtcDaliLayouting_GridLayout03 Grid Padding");
217 const auto NUMBER_OF_COLUMNS = 2;
218 const auto NUMBER_OF_ITEMS = 4;
220 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
222 Extents GRID_PADDING( Extents( 10, 10, 20, 20 ) ); // start,end,top,bottom
224 tet_printf( "Testing with Padding 10,10,20,20\n");
226 Stage stage = Stage::GetCurrent();
228 auto rootControl = Control::New();
229 auto absoluteLayout = AbsoluteLayout::New();
230 DevelControl::SetLayout( rootControl, absoluteLayout );
231 rootControl.SetName( "AbsoluteLayout" );
232 stage.Add( rootControl );
234 auto gridContainer = Control::New();
235 auto gridLayout = Grid::New();
236 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
237 gridContainer.SetName( "GridLayout");
238 DevelControl::SetLayout( gridContainer, gridLayout );
239 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
240 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
241 gridContainer.SetProperty( Control::Property::PADDING, GRID_PADDING );
243 std::vector< Control > controls;
244 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
246 controls.push_back( CreateLeafControl( 100, 100 ) );
249 for( auto&& iter : controls )
251 gridContainer.Add( iter );
254 rootControl.Add( gridContainer );
256 // Ensure layouting happens
257 application.SendNotification();
258 application.Render();
260 tet_infoline(" UtcDaliLayouting_GridLayout03 Grid Padding 2 Column, 4 Items");
261 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f + GRID_PADDING.start , 0.0f + GRID_PADDING.top, 0.0f ), 0.0001f, TEST_LOCATION );
262 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f + GRID_PADDING.start, 0.0f + GRID_PADDING.top, 0.0f ), 0.0001f, TEST_LOCATION );
263 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f + GRID_PADDING.start, 100.0f + GRID_PADDING.top , 0.0f ), 0.0001f, TEST_LOCATION );
264 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f + GRID_PADDING.start, 100.0f + GRID_PADDING.top, 0.0f ), 0.0001f, TEST_LOCATION );
266 tet_infoline(" UtcDaliLayouting_GridLayout03 Size of Grid should include padding");
267 DALI_TEST_EQUALS( gridContainer.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f * NUMBER_OF_COLUMNS + GRID_PADDING.start + + GRID_PADDING.end,
268 100.0f * ( NUMBER_OF_ITEMS / NUMBER_OF_COLUMNS ) +
269 GRID_PADDING.top + GRID_PADDING.bottom,
270 0.0f ), 0.0001f, TEST_LOCATION );
272 tet_infoline(" UtcDaliLayouting_GridLayout03 Item sizes unchanged");
273 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
274 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
275 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
276 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
281 int UtcDaliLayouting_GridLayout04(void)
283 ToolkitTestApplication application;
284 tet_infoline(" UtcDaliLayouting_GridLayout04 Child Margin");
286 const auto NUMBER_OF_COLUMNS = 2;
287 const auto NUMBER_OF_ITEMS = 4;
289 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
291 Extents GRID_PADDING( Extents( 10, 10, 20, 20 ) ); // start,end,top,bottom
292 Extents ITEM_MARGIN( Extents( 10, 10, 5, 5 ) ); // start,end,top,bottom
294 tet_printf( "Testing with Margin 10,10,5,5\n");
296 Stage stage = Stage::GetCurrent();
298 auto rootControl = Control::New();
299 auto absoluteLayout = AbsoluteLayout::New();
300 DevelControl::SetLayout( rootControl, absoluteLayout );
301 rootControl.SetName( "AbsoluteLayout" );
302 stage.Add( rootControl );
304 auto gridContainer = Control::New();
305 auto gridLayout = Grid::New();
306 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
307 gridContainer.SetName( "GridLayout");
308 DevelControl::SetLayout( gridContainer, gridLayout );
309 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
310 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
311 gridContainer.SetProperty( Control::Property::PADDING, GRID_PADDING );
313 std::vector< Control > controls;
314 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
316 auto control = CreateLeafControl( 100, 100 );
317 control.SetProperty(Toolkit::Control::Property::MARGIN, ITEM_MARGIN );
318 controls.push_back( control );
321 for( auto&& iter : controls )
323 gridContainer.Add( iter );
326 rootControl.Add( gridContainer );
328 // Ensure layouting happens
329 application.SendNotification();
330 application.Render();
332 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ),
333 Vector3( 0.0f + GRID_PADDING.start + ITEM_MARGIN.start,
334 0.0f + GRID_PADDING.top + ITEM_MARGIN.top,
336 0.0001f, TEST_LOCATION );
338 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ),
339 Vector3( 100.0f + GRID_PADDING.start + ITEM_MARGIN.start *2 + ITEM_MARGIN.end,
340 0.0f + GRID_PADDING.top + ITEM_MARGIN.top,
341 0.0f ), 0.0001f, TEST_LOCATION );
343 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ),
344 Vector3( 0.0f + GRID_PADDING.start + ITEM_MARGIN.start,
345 100.0f + GRID_PADDING.top + ITEM_MARGIN.top*2 + ITEM_MARGIN.bottom,
346 0.0f ), 0.0001f, TEST_LOCATION );
348 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ),
349 Vector3( 100.0f + GRID_PADDING.start + ITEM_MARGIN.start*2 + ITEM_MARGIN.end,
350 100.0f + GRID_PADDING.top + ITEM_MARGIN.top*2 + ITEM_MARGIN.bottom,
351 0.0f ), 0.0001f, TEST_LOCATION );
353 tet_infoline(" UtcDaliLayouting_GridLayout03 Size of Grid should include padding and margins");
355 const auto NUMBER_OF_ROWS = ( NUMBER_OF_ITEMS / NUMBER_OF_COLUMNS );
357 DALI_TEST_EQUALS( gridContainer.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f * NUMBER_OF_COLUMNS + GRID_PADDING.start + GRID_PADDING.end +
358 ITEM_MARGIN.start *NUMBER_OF_COLUMNS + ITEM_MARGIN.end *NUMBER_OF_COLUMNS,
359 100.0f * NUMBER_OF_ROWS +
360 GRID_PADDING.top + GRID_PADDING.bottom +
361 ITEM_MARGIN.bottom *NUMBER_OF_ROWS + ITEM_MARGIN.bottom *NUMBER_OF_ROWS,
362 0.0f ), 0.0001f, TEST_LOCATION );
364 tet_infoline(" UtcDaliLayouting_GridLayout03 Item sizes unchanged");
365 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
366 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
367 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
368 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
373 int UtcDaliLayouting_GridLayout05(void)
375 ToolkitTestApplication application;
376 tet_infoline(" UtcDaliLayouting_GridLayout05 2 Column, 4 Items UNSPECIFIED width and height SPECIFICATIONS");
378 const auto NUMBER_OF_COLUMNS = 2;
379 const auto NUMBER_OF_ITEMS = 4;
381 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
383 Stage stage = Stage::GetCurrent();
385 auto rootControl = Control::New();
386 auto absoluteLayout = AbsoluteLayout::New();
387 DevelControl::SetLayout( rootControl, absoluteLayout );
388 rootControl.SetName( "AbsoluteLayout" );
389 stage.Add( rootControl );
391 auto customLayout = Test::CustomLayout::New();
392 tet_printf( "Set Flag so child is measured with an unconstrained measure spec\n");
393 customLayout.SetCustomBehaviourFlag( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_WIDTH );
394 customLayout.SetCustomBehaviourFlag( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_HEIGHT );
395 auto customHBox = Control::New();
396 customHBox.SetName("CustomHBox");
397 DevelControl::SetLayout( customHBox, customLayout );
398 tet_printf( "Set width of custom layout to be smaller than child Grid wants to be\n");
399 customHBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 150 );
400 customHBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 150 );
401 rootControl.Add( customHBox );
403 auto gridContainer = Control::New();
404 auto gridLayout = Grid::New();
405 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
406 gridContainer.SetName( "GridLayout");
407 DevelControl::SetLayout( gridContainer, gridLayout );
408 tet_printf( "Grid SPEC set to MATCH_PARENT, this will be ignored if BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_WIDTH or BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_HEIGHT flags are set\n");
409 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
410 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
412 std::vector< Control > controls;
413 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
415 controls.push_back( CreateLeafControl( 100, 100 ) );
418 for( auto&& iter : controls )
420 gridContainer.Add( iter );
423 customHBox.Add( gridContainer );
425 // Ensure layouting happens
426 application.SendNotification();
427 application.Render();
429 // Grid will layout first 2 items on first row then last 2 on second row.
430 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
431 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
432 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
433 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
435 // Item sizes will not be changed
436 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
437 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
438 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
439 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
444 int UtcDaliLayouting_GridLayout06(void)
446 ToolkitTestApplication application;
447 tet_infoline(" UtcDaliLayouting_GridLayout06 2 Column, 4 Items UNSPECIFIED width SPECIFICATION");
449 const auto NUMBER_OF_COLUMNS = 2;
450 const auto NUMBER_OF_ITEMS = 4;
452 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
454 Stage stage = Stage::GetCurrent();
456 auto rootControl = Control::New();
457 auto absoluteLayout = AbsoluteLayout::New();
458 DevelControl::SetLayout( rootControl, absoluteLayout );
459 rootControl.SetName( "AbsoluteLayout" );
460 stage.Add( rootControl );
462 auto customLayout = Test::CustomLayout::New();
463 tet_printf( "Set Flag so child is measured with an unconstrained measure spec\n");
464 customLayout.SetCustomBehaviourFlag( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_WIDTH );
465 auto customHBox = Control::New();
466 customHBox.SetName("CustomHBox");
467 DevelControl::SetLayout( customHBox, customLayout );
468 tet_printf( "Set width of custom layout to be smaller than child Grid wants to be\n");
469 customHBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 150 );
470 customHBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 150 );
471 rootControl.Add( customHBox );
473 auto gridContainer = Control::New();
474 auto gridLayout = Grid::New();
475 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
476 gridContainer.SetName( "GridLayout");
477 DevelControl::SetLayout( gridContainer, gridLayout );
478 tet_printf( "Grid SPEC set to MATCH_PARENT, this will be ignored if BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_WIDTH or BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_HEIGHT flags are set\n");
479 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
480 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
482 std::vector< Control > controls;
483 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
485 controls.push_back( CreateLeafControl( 100, 100 ) );
488 for( auto&& iter : controls )
490 gridContainer.Add( iter );
493 customHBox.Add( gridContainer );
495 // Ensure layouting happens
496 application.SendNotification();
497 application.Render();
499 // Grid will layout first 2 items on first row then last 2 on second row.
500 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
501 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
502 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
503 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
505 // Item sizes will not be changed
506 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
507 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
508 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
509 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
515 int UtcDaliLayouting_GridLayout07(void)
517 ToolkitTestApplication application;
518 tet_infoline(" UtcDaliLayouting_GridLayout07 2 Column, 4 Items UNSPECIFIED height SPECIFICATION");
520 const auto NUMBER_OF_COLUMNS = 2;
521 const auto NUMBER_OF_ITEMS = 4;
523 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
525 Stage stage = Stage::GetCurrent();
527 auto rootControl = Control::New();
528 auto absoluteLayout = AbsoluteLayout::New();
529 DevelControl::SetLayout( rootControl, absoluteLayout );
530 rootControl.SetName( "AbsoluteLayout" );
531 stage.Add( rootControl );
533 auto customLayout = Test::CustomLayout::New();
534 tet_printf( "Set Flag so child is measured with an unconstrained measure spec\n");
535 customLayout.SetCustomBehaviourFlag( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_HEIGHT );
536 auto customHBox = Control::New();
537 customHBox.SetName("CustomHBox");
538 DevelControl::SetLayout( customHBox, customLayout );
539 tet_printf( "Set width of custom layout to be smaller than child Grid wants to be\n");
540 customHBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 150 );
541 customHBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 150 );
542 rootControl.Add( customHBox );
544 auto gridContainer = Control::New();
545 auto gridLayout = Grid::New();
546 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
547 gridContainer.SetName( "GridLayout");
548 DevelControl::SetLayout( gridContainer, gridLayout );
549 tet_printf( "Grid SPEC set to MATCH_PARENT, this will be ignored if BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_WIDTH or BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_HEIGHT flags are set\n");
550 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
551 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
553 std::vector< Control > controls;
554 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
556 controls.push_back( CreateLeafControl( 100, 100 ) );
559 for( auto&& iter : controls )
561 gridContainer.Add( iter );
564 customHBox.Add( gridContainer );
566 // Ensure layouting happens
567 application.SendNotification();
568 application.Render();
570 // Grid will layout first 2 items on first row then last 2 on second row.
571 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
572 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 75.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
573 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
574 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
576 // Item sizes will not be changed
577 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
578 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
579 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
580 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
586 int UtcDaliLayouting_GridLayout08(void)
588 ToolkitTestApplication application;
589 tet_infoline(" UtcDaliLayouting_GridLayout08 2 Column, 4 Items Grid with children too wide for parent spec");
591 const auto NUMBER_OF_COLUMNS = 2;
592 const auto NUMBER_OF_ITEMS = 4;
594 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
596 Stage stage = Stage::GetCurrent();
598 auto rootControl = Control::New();
599 auto absoluteLayout = AbsoluteLayout::New();
600 DevelControl::SetLayout( rootControl, absoluteLayout );
601 rootControl.SetName( "AbsoluteLayout" );
602 stage.Add( rootControl );
604 auto customLayout = Test::CustomLayout::New();
605 auto customHBox = Control::New();
606 customHBox.SetName("CustomHBox");
607 DevelControl::SetLayout( customHBox, customLayout );
608 tet_printf( "Set width of custom layout to be smaller than child Grid wants to be\n");
609 customHBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 150 );
610 customHBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 200 );
611 rootControl.Add( customHBox );
613 auto gridContainer = Control::New();
614 auto gridLayout = Grid::New();
615 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
616 gridContainer.SetName( "GridLayout");
617 DevelControl::SetLayout( gridContainer, gridLayout );
618 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
619 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
621 std::vector< Control > controls;
622 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
624 controls.push_back( CreateLeafControl( 100, 100 ) );
627 for( auto&& iter : controls )
629 gridContainer.Add( iter );
632 customHBox.Add( gridContainer );
634 // Ensure layouting happens
635 application.SendNotification();
636 application.Render();
638 tet_printf( "Children width reduced from 100 to 75\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
639 // Grid will layout first 2 items on first row then last 2 on second row.
640 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
641 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 75.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
642 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
643 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
645 // Item sizes will be changed
646 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
647 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
648 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
649 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
655 int UtcDaliLayouting_GridLayoutDownCast(void)
657 TestApplication application;
658 tet_infoline(" UtcDaliLayouting_GridLayoutDownCast - Testing Downcast");
660 Grid gridLayout = Grid::New();
662 LayoutGroup layoutGroup( gridLayout );
664 Grid gridLayoutCandidate = Grid::DownCast( layoutGroup );
665 DALI_TEST_CHECK( gridLayoutCandidate );