2 * Copyright (c) 2022 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.
21 #include <dali-toolkit-test-suite-utils.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/layouting/flex-node.h>
25 #include <dali/devel-api/actors/actor-devel.h>
28 using namespace Toolkit;
30 void dali_flexNodeContainer_startup(void)
32 test_return_value = TET_UNDEF;
35 void dali_flexNodeContainer_cleanup(void)
37 test_return_value = TET_PASS;
42 const Flex::SizeTuple ITEM_SIZE = Flex::SizeTuple{10.0f, 10.0f};
43 const Flex::SizeTuple ITEM_SIZE_CALLBACK_TEST = Flex::SizeTuple{15.0f, 15.0f};
45 void MeasureChild(Actor child, float width, int measureModeWidth, float height, int measureModeHeight, Flex::SizeTuple* childSize)
47 *childSize = ITEM_SIZE;
48 if(child.GetProperty<std::string>(Dali::Actor::Property::NAME) == "callbackTest")
50 *childSize = ITEM_SIZE_CALLBACK_TEST;
52 tet_printf(" MeasureChild test callback executed (%f,%f)\n", childSize->width, childSize->height);
57 int UtcDaliToolkitFlexNodeConstructorP(void)
59 ToolkitTestApplication application;
60 tet_infoline(" UtcDaliToolkitFlexNodeNewP");
61 Flex::Node* flexNode = new Flex::Node();
62 DALI_TEST_CHECK(flexNode);
66 int UtcDaliToolkitFlexNodeAddChildWithMarginP(void)
68 ToolkitTestApplication application;
69 tet_infoline(" UtcDaliToolkitFlexNodeAddChildWithMarginP");
70 Flex::Node* flexNode = new Flex::Node();
71 DALI_TEST_CHECK(flexNode);
73 // Position elements as a Row
74 flexNode->SetFlexDirection(Flex::FlexDirection::ROW);
76 // Create two actors and add them to the parent flex node
77 Actor actor = Actor::New();
78 DALI_TEST_CHECK(actor);
80 Extents margin(5, 5, 5, 5);
81 flexNode->AddChild(actor, margin, &MeasureChild, 0);
83 DALI_TEST_EQUALS((int)flexNode->GetFlexDirection(), (int)Flex::FlexDirection::ROW, TEST_LOCATION);
85 flexNode->CalculateLayout(480, 800, false);
87 Vector4 actorFrame = flexNode->GetNodeFrame(0);
89 tet_printf("Actor frame(left:%f,top:%f,right:%f,bottom:%f)\n", actorFrame.x, actorFrame.y, actorFrame.z, actorFrame.w);
91 DALI_TEST_EQUALS(actorFrame, Vector4(5.0f, 5.0f, ITEM_SIZE.width + 5, ITEM_SIZE.height + 5), TEST_LOCATION);
98 int UtcDaliToolkitFlexNodeAddChildrenRowP(void)
100 ToolkitTestApplication application;
101 tet_infoline(" UtcDaliToolkitFlexNodeAddChildrenRowP");
102 Flex::Node* flexNode = new Flex::Node();
103 DALI_TEST_CHECK(flexNode);
105 // Position elements as a Row
106 flexNode->SetFlexDirection(Flex::FlexDirection::ROW);
108 // Create two actors and add them to the parent flex node
109 Actor actor1 = Actor::New();
110 Actor actor2 = Actor::New();
111 DALI_TEST_CHECK(actor1);
112 DALI_TEST_CHECK(actor2);
114 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
115 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
117 DALI_TEST_EQUALS((int)flexNode->GetFlexDirection(), (int)Flex::FlexDirection::ROW, TEST_LOCATION);
119 flexNode->CalculateLayout(480, 800, false);
121 Vector4 actor1Frame = flexNode->GetNodeFrame(0);
122 Vector4 actor2Frame = flexNode->GetNodeFrame(1);
124 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
125 tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
127 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
128 DALI_TEST_EQUALS(actor2Frame, Vector4(ITEM_SIZE.width, 0.0f, ITEM_SIZE.width * 2, ITEM_SIZE.height), TEST_LOCATION);
135 int UtcDaliToolkitFlexNodeAddChildrenColumnP(void)
137 ToolkitTestApplication application;
138 tet_infoline("UtcDaliToolkitFlexNodeAddChildrenColumnP");
139 Flex::Node* flexNode = new Flex::Node();
140 DALI_TEST_CHECK(flexNode);
142 // Position elements in a Column
143 flexNode->SetFlexDirection(Flex::FlexDirection::COLUMN);
145 // Create two actors and add them to the parent flex node
146 Actor actor1 = Actor::New();
147 Actor actor2 = Actor::New();
148 DALI_TEST_CHECK(actor1);
149 DALI_TEST_CHECK(actor2);
151 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
152 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
154 flexNode->CalculateLayout(480, 800, false);
156 Vector4 root = flexNode->GetNodeFrame(-1); // -1 is the root
157 Vector4 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
158 Vector4 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
160 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
162 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
163 tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
165 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
166 DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, ITEM_SIZE.height, ITEM_SIZE.width, ITEM_SIZE.height * 2), TEST_LOCATION);
173 int UtcDaliToolkitFlexNodeAddChildrenColumnJustify(void)
175 ToolkitTestApplication application;
176 tet_infoline("UtcDaliToolkitFlexNodeAddChildrenColumnJustify");
177 Flex::Node* flexNode = new Flex::Node();
178 DALI_TEST_CHECK(flexNode);
180 // Position elements in a Column
181 flexNode->SetFlexDirection(Flex::FlexDirection::COLUMN);
183 tet_infoline("Justify to the Start, align to start, third item should be displayed at the top and the end");
184 flexNode->SetFlexJustification(Flex::Justification::FLEX_START);
185 flexNode->SetFlexItemsAlignment(Flex::Alignment::FLEX_START);
187 // Create three actors and add them to the parent flex node
188 Actor actor1 = Actor::New();
189 Actor actor2 = Actor::New();
190 Actor actor3 = Actor::New();
191 DALI_TEST_CHECK(actor1);
192 DALI_TEST_CHECK(actor2);
193 DALI_TEST_CHECK(actor3);
195 DALI_TEST_EQUALS((int)flexNode->GetFlexJustification(), (int)Flex::Justification::FLEX_START, TEST_LOCATION);
196 DALI_TEST_EQUALS((int)flexNode->GetFlexItemsAlignment(), (int)Flex::Alignment::FLEX_START, TEST_LOCATION);
198 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
199 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
200 Flex::Node* actor3node = flexNode->AddChild(actor3, Extents(0, 0, 0, 0), &MeasureChild, 2);
201 actor3node->SetFlexAlignmentSelf(Flex::Alignment::FLEX_END);
203 flexNode->CalculateLayout(480, 800, false);
205 Vector4 root = flexNode->GetNodeFrame(-1); // -1 is the root
206 Vector4 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
207 Vector4 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
208 Vector4 actor3Frame = flexNode->GetNodeFrame(2); // 2 is third child
210 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
212 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
213 tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
214 tet_printf("Actor 3 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
226 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
227 DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, ITEM_SIZE.height, ITEM_SIZE.width, ITEM_SIZE.height * 2), TEST_LOCATION);
228 DALI_TEST_EQUALS(actor3Frame, Vector4(root.z - ITEM_SIZE.width, ITEM_SIZE.height * 2, root.z, ITEM_SIZE.height * 3), TEST_LOCATION);
230 tet_infoline(" Justify to the End, items should now be displayed at the bottom, third item should now be displayed at the end");
231 flexNode->SetFlexJustification(Flex::Justification::FLEX_END);
232 flexNode->SetFlexItemsAlignment(Flex::Alignment::FLEX_START);
235 flexNode->CalculateLayout(480, 800, false);
237 root = flexNode->GetNodeFrame(-1); // -1 is the root
238 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
239 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
240 actor3Frame = flexNode->GetNodeFrame(2); // 2 is third child
242 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
244 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
245 tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
246 tet_printf("Actor 3 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
258 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, root.w - (ITEM_SIZE.height * 3), ITEM_SIZE.width, root.w - (ITEM_SIZE.height * 2)), TEST_LOCATION);
259 DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, root.w - (ITEM_SIZE.height * 2), ITEM_SIZE.width, root.w - ITEM_SIZE.height), TEST_LOCATION);
260 DALI_TEST_EQUALS(actor3Frame, Vector4(root.z - ITEM_SIZE.width, root.w - ITEM_SIZE.height, root.z, root.w), TEST_LOCATION);
262 tet_infoline(" Align to End, items should now be displayed at the bottom and the end");
263 flexNode->SetFlexJustification(Flex::Justification::FLEX_END);
264 flexNode->SetFlexItemsAlignment(Flex::Alignment::FLEX_END);
266 flexNode->CalculateLayout(480, 800, false);
268 root = flexNode->GetNodeFrame(-1); // -1 is the root
269 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
270 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
271 actor3Frame = flexNode->GetNodeFrame(2); // 2 is third child
273 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
274 tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
275 tet_printf("Actor 3 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
287 DALI_TEST_EQUALS(actor1Frame, Vector4(root.z - ITEM_SIZE.width, root.w - (ITEM_SIZE.height * 3), root.z, root.w - (ITEM_SIZE.height * 2)), TEST_LOCATION);
288 DALI_TEST_EQUALS(actor2Frame, Vector4(root.z - ITEM_SIZE.width, root.w - (ITEM_SIZE.height * 2), root.z, root.w - ITEM_SIZE.height), TEST_LOCATION);
289 DALI_TEST_EQUALS(actor3Frame, Vector4(root.z - ITEM_SIZE.width, root.w - ITEM_SIZE.height, root.z, root.w), TEST_LOCATION);
296 int UtcDaliToolkitFlexNodeSizingP(void)
298 ToolkitTestApplication application;
299 tet_infoline(" UtcDaliToolkitFlexNodeSizingP");
300 Flex::Node* flexNode = new Flex::Node();
301 DALI_TEST_CHECK(flexNode);
303 // Create two actors and add them to the parent flex node
304 Actor actor1 = Actor::New();
305 Actor actor2 = Actor::New();
306 DALI_TEST_CHECK(actor1);
307 DALI_TEST_CHECK(actor2);
309 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
310 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
312 flexNode->CalculateLayout(480, 800, false);
314 DALI_TEST_EQUALS(flexNode->GetFlexWidth(), 480.0f, TEST_LOCATION);
315 DALI_TEST_EQUALS(flexNode->GetFlexHeight(), 800.0f, TEST_LOCATION);
322 int UtcDaliToolkitFlexNodeWrapModeP(void)
324 ToolkitTestApplication application;
325 tet_infoline("UtcDaliToolkitFlexNodeWrapModeP");
326 Flex::Node* flexNode = new Flex::Node();
327 DALI_TEST_CHECK(flexNode);
329 // Position elements in a Column
330 flexNode->SetFlexDirection(Flex::FlexDirection::ROW);
331 flexNode->SetFlexAlignment(Flex::Alignment::FLEX_START);
332 flexNode->SetFlexWrap(Flex::WrapType::NO_WRAP);
334 // Create two actors and add them to the parent flex node
335 Actor actor1 = Actor::New();
336 Actor actor2 = Actor::New();
337 Actor actor3 = Actor::New();
338 Actor actor4 = Actor::New();
340 DALI_TEST_EQUALS((int)flexNode->GetFlexJustification(), (int)Flex::Justification::FLEX_START, TEST_LOCATION);
341 DALI_TEST_EQUALS((int)flexNode->GetFlexItemsAlignment(), (int)Flex::Alignment::FLEX_START, TEST_LOCATION);
342 DALI_TEST_EQUALS((int)flexNode->GetFlexAlignment(), (int)Flex::Alignment::FLEX_START, TEST_LOCATION);
343 DALI_TEST_EQUALS((int)flexNode->GetFlexWrap(), (int)Flex::WrapType::NO_WRAP, TEST_LOCATION);
345 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
346 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
347 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 2);
348 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 3);
350 flexNode->CalculateLayout(30, 800, false);
352 Vector4 root = flexNode->GetNodeFrame(-1); // -1 is the root
353 Vector4 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
354 Vector4 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
355 Vector4 actor3Frame = flexNode->GetNodeFrame(2); // 2 is first child
356 Vector4 actor4Frame = flexNode->GetNodeFrame(3); // 3 is second child
358 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
359 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
360 tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
361 tet_printf("Actor 3 frame(left:%f,top:%f,right:cdt%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
362 tet_printf("Actor 4 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor4Frame.x, actor4Frame.y, actor4Frame.z, actor4Frame.w);
374 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
375 DALI_TEST_EQUALS(actor2Frame, Vector4(ITEM_SIZE.width, 0.0f, ITEM_SIZE.width * 2, ITEM_SIZE.height), TEST_LOCATION);
376 DALI_TEST_EQUALS(actor3Frame, Vector4(ITEM_SIZE.width * 2, 0.0f, ITEM_SIZE.width * 3, ITEM_SIZE.height), TEST_LOCATION);
377 DALI_TEST_EQUALS(actor4Frame, Vector4(ITEM_SIZE.width * 3, 0.0f, ITEM_SIZE.width * 4, ITEM_SIZE.height), TEST_LOCATION);
379 flexNode->SetFlexWrap(Flex::WrapType::WRAP);
381 flexNode->CalculateLayout(30, 800, false);
382 root = flexNode->GetNodeFrame(-1); // -1 is the root
384 DALI_TEST_EQUALS((int)flexNode->GetFlexWrap(), (int)Flex::WrapType::WRAP, TEST_LOCATION);
385 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
387 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
388 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
389 actor3Frame = flexNode->GetNodeFrame(2); // 2 is first child
390 actor4Frame = flexNode->GetNodeFrame(3); // 3 is second child
392 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
393 tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
394 tet_printf("Actor 3 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
395 tet_printf("Actor 4 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor4Frame.x, actor4Frame.y, actor4Frame.z, actor4Frame.w);
407 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
408 DALI_TEST_EQUALS(actor2Frame, Vector4(ITEM_SIZE.width, 0.0f, ITEM_SIZE.width * 2, ITEM_SIZE.height), TEST_LOCATION);
409 DALI_TEST_EQUALS(actor3Frame, Vector4(ITEM_SIZE.width * 2, 0.0f, ITEM_SIZE.width * 3, ITEM_SIZE.height), TEST_LOCATION);
410 DALI_TEST_EQUALS(actor4Frame, Vector4(0.0, ITEM_SIZE.height, ITEM_SIZE.width, ITEM_SIZE.height * 2), TEST_LOCATION);
417 int UtcDaliToolkitFlexNodeRemoveChildP(void)
419 ToolkitTestApplication application;
420 tet_infoline(" UtcDaliToolkitFlexNodeRemoveChildP");
421 Flex::Node* flexNode = new Flex::Node();
422 DALI_TEST_CHECK(flexNode);
424 // Create two actors and add them to the parent flex node
425 Actor actor1 = Actor::New();
426 Actor actor2 = Actor::New();
427 actor1.SetProperty(Dali::Actor::Property::NAME, "Actor1");
428 actor2.SetProperty(Dali::Actor::Property::NAME, "Actor2");
430 DALI_TEST_CHECK(actor1);
431 DALI_TEST_CHECK(actor2);
433 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
434 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
436 flexNode->CalculateLayout(480, 800, false);
438 Vector4 actor1Frame = flexNode->GetNodeFrame(0);
439 Vector4 actor2Frame = flexNode->GetNodeFrame(1);
441 tet_printf("Actor 1 frame(%f,%f,%f,%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
442 tet_printf("Actor 2 frame(%f,%f,%f,%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
444 DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, ITEM_SIZE.width, ITEM_SIZE.width, ITEM_SIZE.height * 2), TEST_LOCATION);
446 flexNode->RemoveChild(actor1);
448 flexNode->CalculateLayout(480, 800, false);
450 actor2Frame = flexNode->GetNodeFrame(0);
452 tet_printf("Actor 1 frame(%f,%f,%f,%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
453 tet_printf("Actor 2 frame(%f,%f,%f,%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
455 DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
462 int UtcDaliToolkitFlexNodeRemoveAllChildrenP(void)
464 ToolkitTestApplication application;
465 tet_infoline(" UtcDaliToolkitFlexNodeRemoveAllChildrenP");
466 Flex::Node* flexNode = new Flex::Node();
467 DALI_TEST_CHECK(flexNode);
469 // Create two actors and add them to the parent flex node
470 Actor actor1 = Actor::New();
471 Actor actor2 = Actor::New();
472 actor1.SetProperty(Dali::Actor::Property::NAME, "Actor1");
473 actor2.SetProperty(Dali::Actor::Property::NAME, "Actor2");
475 DALI_TEST_CHECK(actor1);
476 DALI_TEST_CHECK(actor2);
478 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
479 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
481 flexNode->CalculateLayout(480, 800, false);
483 Vector4 actor1Frame = flexNode->GetNodeFrame(0);
484 Vector4 actor2Frame = flexNode->GetNodeFrame(1);
486 tet_printf("Actor 1 frame(%f,%f,%f,%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
487 tet_printf("Actor 2 frame(%f,%f,%f,%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
489 flexNode->RemoveChild(actor1);
490 flexNode->RemoveChild(actor2);
492 flexNode->CalculateLayout(480, 800, false);
494 Vector4 actor1FrameRemoved = flexNode->GetNodeFrame(0);
495 Vector4 actor2FrameRemoved = flexNode->GetNodeFrame(1);
497 tet_printf("Actor 1 frame(%f,%f,%f,%f)\n", actor1FrameRemoved.x, actor1FrameRemoved.y, actor1FrameRemoved.z, actor1FrameRemoved.w);
498 tet_printf("Actor 2 frame(%f,%f,%f,%f)\n", actor2FrameRemoved.x, actor2FrameRemoved.y, actor2FrameRemoved.z, actor2FrameRemoved.w);
500 DALI_TEST_NOT_EQUALS(actor1Frame, actor1FrameRemoved, 0.1, TEST_LOCATION);
501 DALI_TEST_NOT_EQUALS(actor2Frame, actor2FrameRemoved, 0.1, TEST_LOCATION);
508 int UtcDaliToolkitFlexNodePaddingMarginP(void)
510 ToolkitTestApplication application;
511 tet_infoline(" UtcDaliToolkitFlexNodePaddingMarginP");
512 Flex::Node* flexNode = new Flex::Node();
513 DALI_TEST_CHECK(flexNode);
514 flexNode->SetFlexDirection(Flex::FlexDirection::ROW);
516 // Create two actors and add them to the parent flex node
517 Actor actor1 = Actor::New();
518 Actor actor2 = Actor::New();
519 DALI_TEST_CHECK(actor1);
520 DALI_TEST_CHECK(actor2);
522 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
523 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
525 Extents padding(5, 5, 5, 5);
526 Extents margin(5, 5, 5, 5);
528 flexNode->SetPadding(padding);
529 flexNode->SetMargin(margin);
531 flexNode->CalculateLayout(480, 800, false);
533 Vector4 actor1Frame = flexNode->GetNodeFrame(0);
534 Vector4 actor2Frame = flexNode->GetNodeFrame(1);
544 DALI_TEST_EQUALS(actor1Frame, Vector4(5.0f, 5.0f, ITEM_SIZE.width + 5, ITEM_SIZE.height + 5), TEST_LOCATION);
545 DALI_TEST_EQUALS(actor2Frame, Vector4(5 + ITEM_SIZE.width, 5.0f, (ITEM_SIZE.width * 2) + 5, ITEM_SIZE.height + 5), TEST_LOCATION);
552 int UtcDaliToolkitFlexNodeCallbackTestP(void)
554 ToolkitTestApplication application;
555 tet_infoline("UtcDaliToolkitFlexNodeCallbackTestP");
556 Flex::Node* flexNode = new Flex::Node();
557 DALI_TEST_CHECK(flexNode);
559 // Position elements in a Column
560 flexNode->SetFlexDirection(Flex::FlexDirection::COLUMN);
562 // Create two actors and add them to the parent flex node
563 Actor actor1 = Actor::New();
564 Actor actor2 = Actor::New();
566 actor1.SetProperty(Dali::Actor::Property::NAME, "callbackTest");
568 DALI_TEST_CHECK(actor1);
569 DALI_TEST_CHECK(actor2);
571 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
572 flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
574 flexNode->CalculateLayout(480, 800, false);
576 Vector4 root = flexNode->GetNodeFrame(-1); // -1 is the root
577 Vector4 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
578 Vector4 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
580 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
582 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
583 tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
585 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE_CALLBACK_TEST.width, ITEM_SIZE_CALLBACK_TEST.height), TEST_LOCATION);
586 DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, ITEM_SIZE_CALLBACK_TEST.height, ITEM_SIZE.width, ITEM_SIZE_CALLBACK_TEST.height + ITEM_SIZE.height), TEST_LOCATION);
593 int UtcDaliToolkitFlexNodeFlexPositionType(void)
595 ToolkitTestApplication application;
596 tet_infoline("UtcDaliToolkitFlexNodeFlexPositionType");
597 Flex::Node* flexNode = new Flex::Node();
598 DALI_TEST_CHECK(flexNode);
600 tet_infoline(" FlexPositionType is RELATIVE by default");
602 // Create two actors and add them to the parent flex node
603 Actor actor1 = Actor::New();
604 Actor actor2 = Actor::New();
605 DALI_TEST_CHECK(actor1);
606 DALI_TEST_CHECK(actor2);
608 flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
609 Flex::Node* actor2node = flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
611 DALI_TEST_EQUALS((int)actor2node->GetFlexPositionType(), (int)Flex::PositionType::RELATIVE, TEST_LOCATION);
613 flexNode->CalculateLayout(480, 800, false);
615 Vector4 root = flexNode->GetNodeFrame(-1); // -1 is the root
616 Vector4 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
617 Vector4 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
619 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
621 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
622 tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
634 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
635 DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, ITEM_SIZE.height, ITEM_SIZE.width, ITEM_SIZE.height * 2), TEST_LOCATION);
637 tet_infoline(" ABSOLUTE FlexPositionType, second item should now be ignore any properties");
638 actor2node->SetFlexPositionType(Flex::PositionType::ABSOLUTE);
641 flexNode->CalculateLayout(480, 800, false);
643 root = flexNode->GetNodeFrame(-1); // -1 is the root
644 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
645 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
647 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
649 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
650 tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
662 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
663 DALI_TEST_EQUALS(actor2Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
670 int UtcDaliToolkitFlexNodeFlexAspectRatio(void)
672 ToolkitTestApplication application;
673 tet_infoline("UtcDaliToolkitFlexNodeFlexAspectRatio");
674 Flex::Node* flexNode = new Flex::Node();
675 DALI_TEST_CHECK(flexNode);
677 // Create a actor and add them to the parent flex node
678 Actor actor1 = Actor::New();
679 DALI_TEST_CHECK(actor1);
681 tet_infoline(" 1.0 FlexAspectRatio");
682 Flex::Node* actor1node = flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
683 actor1node->SetFlexAspectRatio(1.0);
685 DALI_TEST_EQUALS(actor1node->GetFlexAspectRatio(), 1.0f, TEST_LOCATION);
687 flexNode->CalculateLayout(480, 800, false);
689 Vector4 root = flexNode->GetNodeFrame(-1); // -1 is the root
690 Vector4 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
692 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
694 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
706 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width, ITEM_SIZE.height), TEST_LOCATION);
708 tet_infoline(" 2.0 FlexAspectRatio");
709 actor1node->SetFlexAspectRatio(2.0);
711 DALI_TEST_EQUALS(actor1node->GetFlexAspectRatio(), 2.0f, TEST_LOCATION);
714 flexNode->CalculateLayout(480, 800, false);
716 root = flexNode->GetNodeFrame(-1); // -1 is the root
717 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
719 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
721 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
733 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, ITEM_SIZE.width * 2, ITEM_SIZE.height), TEST_LOCATION);
740 int UtcDaliToolkitFlexNodeFlexBasisShrinkGrow(void)
742 ToolkitTestApplication application;
743 tet_infoline("UtcDaliToolkitFlexNodeFlexBasisShrinkGrow");
744 Flex::Node* flexNode = new Flex::Node();
745 DALI_TEST_CHECK(flexNode);
747 // Position elements as a Row
748 flexNode->SetFlexDirection(Flex::FlexDirection::ROW);
750 // Create three actors and add them to the parent flex node
751 Actor actor1 = Actor::New();
752 Actor actor2 = Actor::New();
753 Actor actor3 = Actor::New();
754 DALI_TEST_CHECK(actor1);
755 DALI_TEST_CHECK(actor2);
756 DALI_TEST_CHECK(actor3);
758 Flex::Node* actor1node = flexNode->AddChild(actor1, Extents(0, 0, 0, 0), &MeasureChild, 0);
759 Flex::Node* actor2node = flexNode->AddChild(actor2, Extents(0, 0, 0, 0), &MeasureChild, 1);
760 Flex::Node* actor3node = flexNode->AddChild(actor3, Extents(0, 0, 0, 0), &MeasureChild, 2);
764 actor1node->SetFlexGrow(0.0);
765 actor2node->SetFlexGrow(0.0);
766 actor3node->SetFlexGrow(0.0);
767 actor1node->SetFlexShrink(1.0);
768 actor2node->SetFlexShrink(1.0);
769 actor3node->SetFlexShrink(1.0);
770 actor1node->SetFlexBasis(basis);
771 actor2node->SetFlexBasis(basis);
772 actor3node->SetFlexBasis(basis);
774 DALI_TEST_EQUALS(actor1node->GetFlexGrow(), 0.0f, TEST_LOCATION);
775 DALI_TEST_EQUALS(actor1node->GetFlexShrink(), 1.0f, TEST_LOCATION);
776 DALI_TEST_EQUALS(actor1node->GetFlexBasis(), basis, TEST_LOCATION);
778 flexNode->CalculateLayout(600, 200, false);
780 Vector4 root = flexNode->GetNodeFrame(-1); // -1 is the root
781 Vector4 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
782 Vector4 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
783 Vector4 actor3Frame = flexNode->GetNodeFrame(2); // 2 is third child
785 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
787 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
788 tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
789 tet_printf("Actor 3 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
798 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, basis, ITEM_SIZE.height), TEST_LOCATION);
799 DALI_TEST_EQUALS(actor2Frame, Vector4(basis, 0.0f, basis * 2, ITEM_SIZE.height), TEST_LOCATION);
800 DALI_TEST_EQUALS(actor3Frame, Vector4(basis * 2, 0.0f, basis * 3, ITEM_SIZE.height), TEST_LOCATION);
802 actor2node->SetFlexGrow(1.0);
803 actor3node->SetFlexGrow(1.0);
806 flexNode->CalculateLayout(605, 200, false);
808 root = flexNode->GetNodeFrame(-1); // -1 is the root
809 actor1Frame = flexNode->GetNodeFrame(0); // 0 is first child
810 actor2Frame = flexNode->GetNodeFrame(1); // 1 is second child
811 actor3Frame = flexNode->GetNodeFrame(2); // 2 is third child
813 tet_printf("Root frame(left:%f,top:%f,right:%f,bottom:%f)\n", root.x, root.y, root.z, root.w);
815 tet_printf("Actor 1 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor1Frame.x, actor1Frame.y, actor1Frame.z, actor1Frame.w);
816 tet_printf("Actor 2 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor2Frame.x, actor2Frame.y, actor2Frame.z, actor2Frame.w);
817 tet_printf("Actor 3 frame(left:%f,top:%f,right:%f,bottom:%f)\n", actor3Frame.x, actor3Frame.y, actor3Frame.z, actor3Frame.w);
826 DALI_TEST_EQUALS(actor1Frame, Vector4(0.0f, 0.0f, basis, ITEM_SIZE.height), TEST_LOCATION);
827 DALI_TEST_EQUALS(actor2Frame, Vector4(basis, 0.0f, basis + (root.z - basis) / 2, ITEM_SIZE.height), TEST_LOCATION);
828 DALI_TEST_EQUALS(actor3Frame, Vector4(basis + (root.z - basis) / 2, 0.0f, root.z, ITEM_SIZE.height), TEST_LOCATION);