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/bin-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-toolkit/devel-api/layouting/linear-layout.h>
31 #include <../custom-layout.h>
33 #include <layout-utils.h>
36 using namespace Toolkit;
40 // Turns the given control into a Root layout control and adds it to the stage.
41 void SetupRootLayoutControl( Control& rootControl )
43 rootControl = Control::New();
44 auto absoluteLayout = AbsoluteLayout::New();
45 DevelControl::SetLayout( rootControl, absoluteLayout );
46 rootControl.SetName( "RootAbsoluteLayout" );
47 Stage stage = Stage::GetCurrent();
48 stage.Add( rootControl );
51 void CreateDefaultBinContainer( Control& binContainer )
53 binContainer = Control::New();
54 binContainer.SetName( "binContainer" );
55 DevelControl::SetLayout( binContainer, BinLayout::New() );
56 binContainer.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
57 binContainer.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
62 void utc_dali_toolkit_bin_layouting_startup(void)
64 test_return_value = TET_UNDEF;
67 void utc_dali_toolkit_bin_layouting_cleanup(void)
69 test_return_value = TET_PASS;
72 int UtcDaliLayouting_BinLayoutDownCast(void)
74 TestApplication application;
75 tet_infoline(" UtcDaliLayouting_BinLayoutDownCast - Testing Downcast");
77 BinLayout binLayout = BinLayout::New();
79 LayoutGroup layoutGroup( binLayout );
81 BinLayout binLayoutCandidate = BinLayout::DownCast( layoutGroup );
82 DALI_TEST_CHECK( binLayoutCandidate );
87 int UtcDaliLayouting_BinLayoutAssignment(void)
89 TestApplication application;
90 tet_infoline(" UtcDaliLayouting_BinLayoutAssignment - Testing operator=");
92 BinLayout binLayout = BinLayout::New();
95 binLayout2 = binLayout;
97 DALI_TEST_EQUALS( binLayout2, binLayout, TEST_LOCATION );
102 int UtcDaliLayouting_BinLayoutCopyConstructor(void)
104 TestApplication application;
105 tet_infoline(" UtcDaliLayouting_BinLayoutCopyConstructor - Testing copy constructor");
107 BinLayout binLayout1 = BinLayout::New();
108 BinLayout binLayout2( binLayout1 );
110 DALI_TEST_EQUALS( binLayout1, binLayout2, TEST_LOCATION );
114 int UtcDaliLayouting_BinLayout01(void)
116 const auto NUMBER_OF_ITEMS = 4;
118 ToolkitTestApplication application;
119 tet_infoline(" UtcDaliLayouting_BinLayout01 BinLayout WRAP_CONTENT");
121 Stage stage = Stage::GetCurrent();
123 auto rootControl = Control::New();
124 auto absoluteLayout = AbsoluteLayout::New();
125 DevelControl::SetLayout( rootControl, absoluteLayout );
126 rootControl.SetName( "AbsoluteLayout" );
127 stage.Add( rootControl );
129 auto binContainer = Control::New();
130 auto binLayout = BinLayout::New();
131 binContainer.SetName( "BinLayout");
132 DevelControl::SetLayout( binContainer, binLayout );
133 binContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
134 binContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
136 std::vector< Control > controls;
137 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
139 controls.push_back( CreateLeafControl( 100, 100 ) );
142 for( auto&& iter : controls )
144 binContainer.Add( iter );
147 rootControl.Add( binContainer );
149 // Ensure layouting happens
150 application.SendNotification();
151 application.Render();
153 // Items will be laid out at the same position
154 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
155 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
156 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
157 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
159 // Item sizes will not be changed
160 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
161 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
162 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
163 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
165 // BinLayout size to be that of greatest child dimensions
166 DALI_TEST_EQUALS( binContainer.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
171 int UtcDaliLayouting_BinLayout02(void)
173 const auto NUMBER_OF_ITEMS = 4;
175 ToolkitTestApplication application;
176 tet_infoline(" UtcDaliLayouting_BinLayout02 BinLayout MATCH_PARENT");
178 Stage stage = Stage::GetCurrent();
180 auto rootControl = Control::New();
181 auto absoluteLayout = AbsoluteLayout::New();
182 DevelControl::SetLayout( rootControl, absoluteLayout );
183 rootControl.SetName( "AbsoluteLayout" );
184 stage.Add( rootControl );
186 auto binContainer = Control::New();
187 auto binLayout = BinLayout::New();
188 binContainer.SetName( "BinLayout");
189 DevelControl::SetLayout( binContainer, binLayout );
190 binContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
191 binContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
193 std::vector< Control > controls;
194 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
196 controls.push_back( CreateLeafControl( 100, 100 ) );
199 for( auto&& iter : controls )
201 binContainer.Add( iter );
204 rootControl.Add( binContainer );
206 // Ensure layouting happens
207 application.SendNotification();
208 application.Render();
210 // Items will be laid out at the same position
211 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
212 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
213 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
214 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
216 // Item sizes will not be changed
217 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
218 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
219 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
220 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
222 // BinLayout size to be that of greatest child dimensions
223 DALI_TEST_EQUALS( binContainer.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
228 int UtcDaliLayouting_BinLayout03(void)
230 const auto NUMBER_OF_ITEMS = 4;
232 ToolkitTestApplication application;
233 tet_infoline(" UtcDaliLayouting_BinLayout03 Explicit child Positioning when Bin layout MATCH_PARENT");
235 Stage stage = Stage::GetCurrent();
237 auto rootControl = Control::New();
238 auto absoluteLayout = AbsoluteLayout::New();
239 DevelControl::SetLayout( rootControl, absoluteLayout );
240 rootControl.SetName( "AbsoluteLayout" );
241 stage.Add( rootControl );
243 auto binContainer = Control::New();
244 auto binLayout = BinLayout::New();
245 binContainer.SetName( "BinLayout");
246 DevelControl::SetLayout( binContainer, binLayout );
247 binContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
248 binContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
250 std::vector< Control > controls;
251 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
253 controls.push_back( CreateLeafControl( 100, 100 ) );
256 for( auto&& iter : controls )
258 binContainer.Add( iter );
261 tet_infoline("Position child explicitly from top left");
262 controls[0].SetProperty(Actor::Property::POSITION_X, 50.0f );
264 tet_infoline("Position child explicitly from top left");
265 controls[2].SetProperty(Actor::Property::POSITION_Y, 50.0f );
267 rootControl.Add( binContainer );
269 // Ensure layouting happens
270 application.SendNotification();
271 application.Render();
273 // Items will be laid out at the same position
274 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 50.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
275 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
276 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 50.0f, 0.0f ), 0.0001f, TEST_LOCATION );
277 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
279 // Item sizes will not be changed
280 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
281 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
282 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
283 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
285 // BinLayout size to be that of parent
286 DALI_TEST_EQUALS( binContainer.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
291 int UtcDaliLayoutingBinLayoutResizePolicy_01(void)
296 Control (LinearLayout Horizontal)
300 Control (ResizePolicy::FILL_TO_PARENT)
305 ToolkitTestApplication application;
306 tet_infoline("UtcDaliLayoutingBinLayoutResizePolicy_01 - Test ResizePolicy mapping with FILL_TO_PARENT on BinLayout child");
308 Stage stage = Stage::GetCurrent();
310 auto rootControl = Control::New();
311 SetupRootLayoutControl( rootControl );
313 auto hbox = Control::New();
314 auto hboxLayout = LinearLayout::New();
315 hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
316 DevelControl::SetLayout( hbox, hboxLayout );
317 hbox.SetName( "hBox" );
318 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
319 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
321 auto binContainer = Control::New();
322 CreateDefaultBinContainer( binContainer );
323 hbox.Add( binContainer );
325 auto control = Control::New();
326 control.SetName( "fillToParentControl" );
327 DevelControl::SetLayoutingRequired( control, true );
328 control.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
329 binContainer.Add( control );
331 std::vector< Control > controls;
332 controls.push_back( CreateLeafControl( 40, 40 ) );
334 for( auto&& iter : controls )
339 rootControl.Add( hbox );
341 // Ensure layouting happens
342 application.SendNotification();
343 application.Render();
345 tet_infoline("Testing child of BinLayout is size of parent");
346 DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
348 tet_infoline("Testing BinLayout's child control has not altered it's children's sizes ");
349 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
351 tet_infoline("Testing BinLayout is size of parent");
352 DALI_TEST_EQUALS( binContainer.GetProperty<Vector3>( Actor::Property::SIZE ), hbox.GetProperty<Vector3>( Actor::Property::SIZE ), 0.0001f, TEST_LOCATION );
357 int UtcDaliLayoutingBinLayoutResizePolicy_02(void)
362 Control (LinearLayout Horizontal)
366 Control (ResizePolicy::SIZE_RELATIVE_TO_PARENT)
371 ToolkitTestApplication application;
372 tet_infoline("UtcDaliLayoutingBinLayoutResizePolicy_02 - Set ResizePolicy SIZE_RELATIVE_TO_PARENT on BinLayout child");
374 const auto NUMBER_OF_ITEMS = 4;
376 Stage stage = Stage::GetCurrent();
378 auto rootControl = Control::New();
379 SetupRootLayoutControl( rootControl );
381 auto hbox = Control::New();
382 auto hboxLayout = LinearLayout::New();
383 hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
384 DevelControl::SetLayout( hbox, hboxLayout );
385 hbox.SetName( "hBox" );
386 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
387 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
389 auto binContainer = Control::New();
390 CreateDefaultBinContainer( binContainer );
391 hbox.Add( binContainer );
393 auto control = Control::New();
394 control.SetName( "fitToChildrenControl" );
395 DevelControl::SetLayoutingRequired( control, true );
396 control.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
397 control.SetSizeModeFactor( Vector3( 0.50f, 1.0f, 1.0f ) );
398 binContainer.Add( control );
400 std::vector< Control > controls;
401 for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
403 controls.push_back( CreateLeafControl( 40, 40 ) );
406 for( auto&& iter : controls )
411 rootControl.Add( hbox );
413 // Ensure layouting happens
414 application.SendNotification();
415 application.Render();
417 tet_infoline("Testing child of BinLayout is the defined relative size of parent");
418 DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 240.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
420 tet_infoline("Testing BinLayout's child control has not altered it's children's sizes ");
421 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
422 DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
423 DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
424 DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
426 tet_infoline("Testing BinLayout is size of parent");
427 DALI_TEST_EQUALS( binContainer.GetProperty<Vector3>( Actor::Property::SIZE ), hbox.GetProperty<Vector3>( Actor::Property::SIZE ), 0.0001f, TEST_LOCATION );
432 int UtcDaliBinLayoutResizePolicy_03(void)
437 Control (LinearLayout Horizontal)
439 Control (LayoutingRequired)
441 Control (ResizePolicy::SIZE_RELATIVE_TO_PARENT)
446 ToolkitTestApplication application;
447 tet_infoline("UtcDaliBinLayoutResizePolicy_03 - Set ResizePolicy SIZE_FIXED_OFFSET_FROM_PARENT on BinLayout child");
449 Stage stage = Stage::GetCurrent();
451 auto rootControl = Control::New();
452 SetupRootLayoutControl( rootControl );
454 auto hbox = Control::New();
455 auto hboxLayout = LinearLayout::New();
456 hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
457 DevelControl::SetLayout( hbox, hboxLayout );
458 hbox.SetName( "hBox" );
459 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
460 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
462 auto binContainer = Control::New();
463 CreateDefaultBinContainer( binContainer );
464 hbox.Add( binContainer );
466 hbox.Add( binContainer );
468 auto control = Control::New();
469 control.SetName( "fitToChildrenControl" );
470 DevelControl::SetLayoutingRequired( control, true );
471 control.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
472 control.SetSizeModeFactor( Vector3( -100.0f, 10.0f, 0.0f ) );
473 binContainer.Add( control );
475 std::vector< Control > controls;
476 controls.push_back( CreateLeafControl( 40, 40 ) );
478 for( auto&& iter : controls )
483 rootControl.Add( hbox );
485 // Ensure layouting happens
486 application.SendNotification();
487 application.Render();
489 DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), true , 0.0001f, TEST_LOCATION );
491 DALI_TEST_EQUALS( control.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 380.0f, 810.0f, 0.0f ), 0.0001f, TEST_LOCATION );
492 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );