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_GridLayout01(void)
49 ToolkitTestApplication application;
50 tet_infoline(" UtcDaliLayouting_GridLayout01 2 Column, 4 Items");
52 const auto NUMBER_OF_COLUMNS = 2;
53 const auto NUMBER_OF_ITEMS = 4;
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 std::vector< Control > controls;
74 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
76 controls.push_back( CreateLeafControl( 100, 100 ) );
79 for( auto&& iter : controls )
81 gridContainer.Add( iter );
84 rootControl.Add( gridContainer );
86 // Ensure layouting happens
87 application.SendNotification();
90 // Grid will layout first 2 items on first row then last 2 on second row.
91 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
92 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
93 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
94 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
96 // Item sizes will not be changed
97 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
98 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
99 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
100 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
102 tet_printf( "Confirm number of columns is as set\n");
103 DALI_TEST_EQUALS( gridLayout.GetNumberOfColumns(), NUMBER_OF_COLUMNS, TEST_LOCATION );
108 int UtcDaliLayouting_GridLayout02(void)
110 ToolkitTestApplication application;
111 tet_infoline("UtcDaliLayouting_GridLayout02");
113 const auto NUMBER_OF_COLUMNS = 3;
114 const auto NUMBER_OF_ITEMS = 7;
116 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
118 Stage stage = Stage::GetCurrent();
120 auto rootControl = Control::New();
121 auto absoluteLayout = AbsoluteLayout::New();
122 DevelControl::SetLayout( rootControl, absoluteLayout );
123 rootControl.SetName( "AbsoluteLayout" );
124 stage.Add( rootControl );
126 auto gridContainer = Control::New();
127 auto gridLayout = Grid::New();
128 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
129 gridContainer.SetName( "GridLayout");
130 DevelControl::SetLayout( gridContainer, gridLayout );
131 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
132 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
134 std::vector< Control > controls;
135 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
137 controls.push_back( CreateLeafControl( 100, 100 ) );
140 for( auto&& iter : controls )
142 gridContainer.Add( iter );
145 rootControl.Add( gridContainer );
147 // Ensure layouting happens
148 application.SendNotification();
149 application.Render();
151 // grid layouts out 3 items per row, which is 480x800.
153 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
154 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
155 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 200.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
157 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
158 DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
159 DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 200.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
161 DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 200.0f, 0.0f ), 0.0001f, TEST_LOCATION );
163 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
164 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
165 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
166 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
167 DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
168 DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
169 DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
174 int UtcDaliLayouting_GridLayout03(void)
176 ToolkitTestApplication application;
177 tet_infoline(" UtcDaliLayouting_GridLayout03 Grid Padding");
179 const auto NUMBER_OF_COLUMNS = 2;
180 const auto NUMBER_OF_ITEMS = 4;
182 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
184 Extents GRID_PADDING( Extents( 10, 10, 20, 20 ) ); // start,end,top,bottom
186 tet_printf( "Testing with Padding 10,10,20,20\n");
188 Stage stage = Stage::GetCurrent();
190 auto rootControl = Control::New();
191 auto absoluteLayout = AbsoluteLayout::New();
192 DevelControl::SetLayout( rootControl, absoluteLayout );
193 rootControl.SetName( "AbsoluteLayout" );
194 stage.Add( rootControl );
196 auto gridContainer = Control::New();
197 auto gridLayout = Grid::New();
198 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
199 gridContainer.SetName( "GridLayout");
200 DevelControl::SetLayout( gridContainer, gridLayout );
201 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
202 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
203 gridContainer.SetProperty( Control::Property::PADDING, GRID_PADDING );
205 std::vector< Control > controls;
206 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
208 controls.push_back( CreateLeafControl( 100, 100 ) );
211 for( auto&& iter : controls )
213 gridContainer.Add( iter );
216 rootControl.Add( gridContainer );
218 // Ensure layouting happens
219 application.SendNotification();
220 application.Render();
222 tet_infoline(" UtcDaliLayouting_GridLayout03 Grid Padding 2 Column, 4 Items");
223 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 );
224 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 );
225 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 );
226 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 );
228 tet_infoline(" UtcDaliLayouting_GridLayout03 Size of Grid should include padding");
229 DALI_TEST_EQUALS( gridContainer.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f * NUMBER_OF_COLUMNS + GRID_PADDING.start + + GRID_PADDING.end,
230 100.0f * ( NUMBER_OF_ITEMS / NUMBER_OF_COLUMNS ) +
231 GRID_PADDING.top + GRID_PADDING.bottom,
232 0.0f ), 0.0001f, TEST_LOCATION );
234 tet_infoline(" UtcDaliLayouting_GridLayout03 Item sizes unchanged");
235 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
236 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
237 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
238 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
243 int UtcDaliLayouting_GridLayout04(void)
245 ToolkitTestApplication application;
246 tet_infoline(" UtcDaliLayouting_GridLayout04 Child Margin");
248 const auto NUMBER_OF_COLUMNS = 2;
249 const auto NUMBER_OF_ITEMS = 4;
251 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
253 Extents GRID_PADDING( Extents( 10, 10, 20, 20 ) ); // start,end,top,bottom
254 Extents ITEM_MARGIN( Extents( 10, 10, 5, 5 ) ); // start,end,top,bottom
256 tet_printf( "Testing with Margin 10,10,5,5\n");
258 Stage stage = Stage::GetCurrent();
260 auto rootControl = Control::New();
261 auto absoluteLayout = AbsoluteLayout::New();
262 DevelControl::SetLayout( rootControl, absoluteLayout );
263 rootControl.SetName( "AbsoluteLayout" );
264 stage.Add( rootControl );
266 auto gridContainer = Control::New();
267 auto gridLayout = Grid::New();
268 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
269 gridContainer.SetName( "GridLayout");
270 DevelControl::SetLayout( gridContainer, gridLayout );
271 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
272 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
273 gridContainer.SetProperty( Control::Property::PADDING, GRID_PADDING );
275 std::vector< Control > controls;
276 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
278 auto control = CreateLeafControl( 100, 100 );
279 control.SetProperty(Toolkit::Control::Property::MARGIN, ITEM_MARGIN );
280 controls.push_back( control );
283 for( auto&& iter : controls )
285 gridContainer.Add( iter );
288 rootControl.Add( gridContainer );
290 // Ensure layouting happens
291 application.SendNotification();
292 application.Render();
294 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ),
295 Vector3( 0.0f + GRID_PADDING.start + ITEM_MARGIN.start,
296 0.0f + GRID_PADDING.top + ITEM_MARGIN.top,
298 0.0001f, TEST_LOCATION );
300 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ),
301 Vector3( 100.0f + GRID_PADDING.start + ITEM_MARGIN.start *2 + ITEM_MARGIN.end,
302 0.0f + GRID_PADDING.top + ITEM_MARGIN.top,
303 0.0f ), 0.0001f, TEST_LOCATION );
305 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ),
306 Vector3( 0.0f + GRID_PADDING.start + ITEM_MARGIN.start,
307 100.0f + GRID_PADDING.top + ITEM_MARGIN.top*2 + ITEM_MARGIN.bottom,
308 0.0f ), 0.0001f, TEST_LOCATION );
310 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ),
311 Vector3( 100.0f + GRID_PADDING.start + ITEM_MARGIN.start*2 + ITEM_MARGIN.end,
312 100.0f + GRID_PADDING.top + ITEM_MARGIN.top*2 + ITEM_MARGIN.bottom,
313 0.0f ), 0.0001f, TEST_LOCATION );
315 tet_infoline(" UtcDaliLayouting_GridLayout03 Size of Grid should include padding and margins");
317 const auto NUMBER_OF_ROWS = ( NUMBER_OF_ITEMS / NUMBER_OF_COLUMNS );
319 DALI_TEST_EQUALS( gridContainer.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f * NUMBER_OF_COLUMNS + GRID_PADDING.start + GRID_PADDING.end +
320 ITEM_MARGIN.start *NUMBER_OF_COLUMNS + ITEM_MARGIN.end *NUMBER_OF_COLUMNS,
321 100.0f * NUMBER_OF_ROWS +
322 GRID_PADDING.top + GRID_PADDING.bottom +
323 ITEM_MARGIN.bottom *NUMBER_OF_ROWS + ITEM_MARGIN.bottom *NUMBER_OF_ROWS,
324 0.0f ), 0.0001f, TEST_LOCATION );
326 tet_infoline(" UtcDaliLayouting_GridLayout03 Item sizes unchanged");
327 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
328 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
329 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
330 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
335 int UtcDaliLayouting_GridLayout05(void)
337 ToolkitTestApplication application;
338 tet_infoline(" UtcDaliLayouting_GridLayout05 2 Column, 4 Items UNSPECIFIED width and height SPECIFICATIONS");
340 const auto NUMBER_OF_COLUMNS = 2;
341 const auto NUMBER_OF_ITEMS = 4;
343 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
345 Stage stage = Stage::GetCurrent();
347 auto rootControl = Control::New();
348 auto absoluteLayout = AbsoluteLayout::New();
349 DevelControl::SetLayout( rootControl, absoluteLayout );
350 rootControl.SetName( "AbsoluteLayout" );
351 stage.Add( rootControl );
353 auto customLayout = Test::CustomLayout::New();
354 tet_printf( "Set Flag so child is measured with an unconstrained measure spec\n");
355 customLayout.SetCustomBehaviourFlag( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_WIDTH );
356 customLayout.SetCustomBehaviourFlag( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_HEIGHT );
357 auto customHBox = Control::New();
358 customHBox.SetName("CustomHBox");
359 DevelControl::SetLayout( customHBox, customLayout );
360 tet_printf( "Set width of custom layout to be smaller than child Grid wants to be\n");
361 customHBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 150 );
362 customHBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 150 );
363 rootControl.Add( customHBox );
365 auto gridContainer = Control::New();
366 auto gridLayout = Grid::New();
367 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
368 gridContainer.SetName( "GridLayout");
369 DevelControl::SetLayout( gridContainer, gridLayout );
370 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");
371 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
372 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
374 std::vector< Control > controls;
375 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
377 controls.push_back( CreateLeafControl( 100, 100 ) );
380 for( auto&& iter : controls )
382 gridContainer.Add( iter );
385 customHBox.Add( gridContainer );
387 // Ensure layouting happens
388 application.SendNotification();
389 application.Render();
391 // Grid will layout first 2 items on first row then last 2 on second row.
392 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
393 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
394 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
395 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
397 // Item sizes will not be changed
398 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
399 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
400 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
401 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
406 int UtcDaliLayouting_GridLayout06(void)
408 ToolkitTestApplication application;
409 tet_infoline(" UtcDaliLayouting_GridLayout06 2 Column, 4 Items UNSPECIFIED width SPECIFICATION");
411 const auto NUMBER_OF_COLUMNS = 2;
412 const auto NUMBER_OF_ITEMS = 4;
414 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
416 Stage stage = Stage::GetCurrent();
418 auto rootControl = Control::New();
419 auto absoluteLayout = AbsoluteLayout::New();
420 DevelControl::SetLayout( rootControl, absoluteLayout );
421 rootControl.SetName( "AbsoluteLayout" );
422 stage.Add( rootControl );
424 auto customLayout = Test::CustomLayout::New();
425 tet_printf( "Set Flag so child is measured with an unconstrained measure spec\n");
426 customLayout.SetCustomBehaviourFlag( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_WIDTH );
427 auto customHBox = Control::New();
428 customHBox.SetName("CustomHBox");
429 DevelControl::SetLayout( customHBox, customLayout );
430 tet_printf( "Set width of custom layout to be smaller than child Grid wants to be\n");
431 customHBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 150 );
432 customHBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 150 );
433 rootControl.Add( customHBox );
435 auto gridContainer = Control::New();
436 auto gridLayout = Grid::New();
437 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
438 gridContainer.SetName( "GridLayout");
439 DevelControl::SetLayout( gridContainer, gridLayout );
440 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");
441 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
442 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
444 std::vector< Control > controls;
445 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
447 controls.push_back( CreateLeafControl( 100, 100 ) );
450 for( auto&& iter : controls )
452 gridContainer.Add( iter );
455 customHBox.Add( gridContainer );
457 // Ensure layouting happens
458 application.SendNotification();
459 application.Render();
461 // Grid will layout first 2 items on first row then last 2 on second row.
462 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
463 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
464 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
465 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
467 // Item sizes will not be changed
468 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
469 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
470 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
471 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 75.0f, 0.0f ), 0.0001f, TEST_LOCATION );
477 int UtcDaliLayouting_GridLayout07(void)
479 ToolkitTestApplication application;
480 tet_infoline(" UtcDaliLayouting_GridLayout07 2 Column, 4 Items UNSPECIFIED height SPECIFICATION");
482 const auto NUMBER_OF_COLUMNS = 2;
483 const auto NUMBER_OF_ITEMS = 4;
485 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
487 Stage stage = Stage::GetCurrent();
489 auto rootControl = Control::New();
490 auto absoluteLayout = AbsoluteLayout::New();
491 DevelControl::SetLayout( rootControl, absoluteLayout );
492 rootControl.SetName( "AbsoluteLayout" );
493 stage.Add( rootControl );
495 auto customLayout = Test::CustomLayout::New();
496 tet_printf( "Set Flag so child is measured with an unconstrained measure spec\n");
497 customLayout.SetCustomBehaviourFlag( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_HEIGHT );
498 auto customHBox = Control::New();
499 customHBox.SetName("CustomHBox");
500 DevelControl::SetLayout( customHBox, customLayout );
501 tet_printf( "Set width of custom layout to be smaller than child Grid wants to be\n");
502 customHBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 150 );
503 customHBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 150 );
504 rootControl.Add( customHBox );
506 auto gridContainer = Control::New();
507 auto gridLayout = Grid::New();
508 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
509 gridContainer.SetName( "GridLayout");
510 DevelControl::SetLayout( gridContainer, gridLayout );
511 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");
512 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
513 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
515 std::vector< Control > controls;
516 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
518 controls.push_back( CreateLeafControl( 100, 100 ) );
521 for( auto&& iter : controls )
523 gridContainer.Add( iter );
526 customHBox.Add( gridContainer );
528 // Ensure layouting happens
529 application.SendNotification();
530 application.Render();
532 // Grid will layout first 2 items on first row then last 2 on second row.
533 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
534 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 75.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
535 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
536 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
538 // Item sizes will not be changed
539 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
540 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
541 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
542 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
548 int UtcDaliLayouting_GridLayout08(void)
550 ToolkitTestApplication application;
551 tet_infoline(" UtcDaliLayouting_GridLayout08 2 Column, 4 Items Grid with children too wide for parent spec");
553 const auto NUMBER_OF_COLUMNS = 2;
554 const auto NUMBER_OF_ITEMS = 4;
556 tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
558 Stage stage = Stage::GetCurrent();
560 auto rootControl = Control::New();
561 auto absoluteLayout = AbsoluteLayout::New();
562 DevelControl::SetLayout( rootControl, absoluteLayout );
563 rootControl.SetName( "AbsoluteLayout" );
564 stage.Add( rootControl );
566 auto customLayout = Test::CustomLayout::New();
567 auto customHBox = Control::New();
568 customHBox.SetName("CustomHBox");
569 DevelControl::SetLayout( customHBox, customLayout );
570 tet_printf( "Set width of custom layout to be smaller than child Grid wants to be\n");
571 customHBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 150 );
572 customHBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 200 );
573 rootControl.Add( customHBox );
575 auto gridContainer = Control::New();
576 auto gridLayout = Grid::New();
577 gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
578 gridContainer.SetName( "GridLayout");
579 DevelControl::SetLayout( gridContainer, gridLayout );
580 gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
581 gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
583 std::vector< Control > controls;
584 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
586 controls.push_back( CreateLeafControl( 100, 100 ) );
589 for( auto&& iter : controls )
591 gridContainer.Add( iter );
594 customHBox.Add( gridContainer );
596 // Ensure layouting happens
597 application.SendNotification();
598 application.Render();
600 tet_printf( "Children width reduced from 100 to 75\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
601 // Grid will layout first 2 items on first row then last 2 on second row.
602 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
603 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 75.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
604 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
605 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
607 // Item sizes will be changed
608 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
609 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
610 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
611 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 75.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
617 int UtcDaliLayouting_GridLayoutDownCast(void)
619 TestApplication application;
620 tet_infoline(" UtcDaliLayouting_GridLayoutDownCast - Testing Downcast");
622 Grid gridLayout = Grid::New();
624 LayoutGroup layoutGroup( gridLayout );
626 Grid gridLayoutCandidate = Grid::DownCast( layoutGroup );
627 DALI_TEST_CHECK( gridLayoutCandidate );