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 (LayoutingRequired)
76 Control (LinearLayout Horizontal)
82 ToolkitTestApplication application;
83 tet_infoline("UtcDaliLayoutingNesting_01 - Nesting a LinearLayout (MATCH_PARENT) containing a leaf control within a LinearLayout");
85 Stage stage = Stage::GetCurrent();
87 auto rootControl = Control::New();
88 SetupRootLayoutControl( rootControl );
90 auto hbox = Control::New();
91 auto hboxLayout = LinearLayout::New();
92 hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
93 DevelControl::SetLayout( hbox, hboxLayout );
94 hbox.SetName( "hBox" );
95 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 480 );
96 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 800 );
99 auto vbox = Control::New();
100 auto vboxLayout = LinearLayout::New();
101 vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
102 DevelControl::SetLayout( vbox, vboxLayout );
103 vbox.SetName( "vBox" );
104 vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
105 vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
108 std::vector< Control > controls;
109 controls.push_back( CreateLeafControl( 40, 40 ) );
111 for( auto&& iter : controls )
116 rootControl.Add( hbox );
118 // Ensure layouting happens
119 application.SendNotification();
120 application.Render();
122 DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
123 DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
125 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
130 int UtcDaliLayoutingNesting_02(void)
136 Control (LinearLayout Horizontal)
138 Control (LayoutingRequired)
140 Control (LinearLayout Horizontal)
146 ToolkitTestApplication application;
147 tet_infoline("UtcDaliLayoutingNesting_02 - Nesting a LinearLayout (MATCH_PARENT) containing a leaf control within a LinearLayout");
148 tet_infoline("Then change the parent's size and test child responded correctly");
150 Stage stage = Stage::GetCurrent();
152 auto rootControl = Control::New();
153 SetupRootLayoutControl( rootControl );
155 auto hbox = Control::New();
156 auto hboxLayout = LinearLayout::New();
157 hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
158 DevelControl::SetLayout( hbox, hboxLayout );
159 hbox.SetName( "hBox" );
160 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 480 );
161 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 800 );
164 auto vbox = Control::New();
165 auto vboxLayout = LinearLayout::New();
166 vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
167 DevelControl::SetLayout( vbox, vboxLayout );
168 vbox.SetName( "vBox" );
169 vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
170 vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
173 std::vector< Control > controls;
174 controls.push_back( CreateLeafControl( 40, 40 ) );
176 for( auto&& iter : controls )
181 rootControl.Add( hbox );
183 // Ensure layouting happens
184 application.SendNotification();
185 application.Render();
187 DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
188 DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
189 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
191 hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 400 );
193 // Ensure layouting happens
194 application.SendNotification();
195 application.Render();
198 DALI_TEST_EQUALS( hbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 400.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
199 DALI_TEST_EQUALS( vbox.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 400.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION );
200 DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );