/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <iostream>
#include <stdlib.h>
-#include <float.h> // for FLT_MAX
-
-// Need to override adaptor classes for toolkit test harness, so include
-// test harness headers before dali headers.
#include <dali-toolkit-test-suite-utils.h>
+#include <toolkit-event-thread-callback.h>
-#include <dali.h>
#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/layouting/absolute-layout.h>
+#include <dali-toolkit/devel-api/layouting/grid.h>
+#include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
+#include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
+
+#include <../custom-layout.h>
+
+#include <layout-utils.h>
using namespace Dali;
using namespace Toolkit;
-void utc_dali_toolkit_grid_layout_startup(void)
+void utc_dali_toolkit_grid_layouting_startup(void)
{
test_return_value = TET_UNDEF;
}
-void utc_dali_toolkit_grid_layout_cleanup(void)
+void utc_dali_toolkit_grid_layouting_cleanup(void)
{
test_return_value = TET_PASS;
}
-
-namespace
+int UtcDaliLayouting_GridLayout01(void)
{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliLayouting_GridLayout01 2 Column, 4 Items");
-const unsigned int TOTAL_ITEM_NUMBER = 200;
-
-Vector3 GridLayoutItemSizeFunction(unsigned int numberOfColumns, float layoutWidth, float sideMargin, float columnSpacing)
-{
- float width = (layoutWidth - sideMargin * 2.0f - columnSpacing * static_cast<float>(numberOfColumns - 1)) / static_cast<float>(numberOfColumns);
-
- return Vector3(width, width, width);
-}
+ const auto NUMBER_OF_COLUMNS = 2;
+ const auto NUMBER_OF_ITEMS = 4;
+ tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
-// Implementation of ItemFactory for providing actors to ItemView
-class TestItemFactory : public ItemFactory
-{
-public:
+ Stage stage = Stage::GetCurrent();
- /**
- * Constructor
- * @param application class, stored as reference
- */
- TestItemFactory()
- {
- }
+ auto rootControl = Control::New();
+ auto absoluteLayout = AbsoluteLayout::New();
+ DevelControl::SetLayout( rootControl, absoluteLayout );
+ rootControl.SetName( "AbsoluteLayout" );
+ stage.Add( rootControl );
-public: // From ItemFactory
+ auto gridContainer = Control::New();
+ auto gridLayout = Grid::New();
+ gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
+ gridContainer.SetName( "GridLayout");
+ DevelControl::SetLayout( gridContainer, gridLayout );
+ gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
+ gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
- /**
- * Query the number of items available from the factory.
- * The maximum available item has an ID of GetNumberOfItems() - 1.
- */
- virtual unsigned int GetNumberOfItems()
+ std::vector< Control > controls;
+ for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
{
- return TOTAL_ITEM_NUMBER;
+ controls.push_back( CreateLeafControl( 100, 100 ) );
}
- /**
- * Create an Actor to represent a visible item.
- * @param itemId
- * @return the created actor.
- */
- virtual Actor NewItem(unsigned int itemId)
+ for( auto&& iter : controls )
{
- // Create an test actor for this item
- ImageActor actor = CreateSolidColorActor(Color::RED);
- actor.SetSize(64.0f, 64.0f);
- return actor;
+ gridContainer.Add( iter );
}
-};
-
-} // namespace
-
-
-
-int UtcDaliGridLayoutNew(void)
-{
- ToolkitTestApplication application;
-
- // Create a grid layout
- GridLayoutPtr gridLayout = GridLayout::New();
-
- DALI_TEST_CHECK(gridLayout);
- END_TEST;
-}
-
-int UtcDaliGridLayoutSetAndGetNumberOfColumns(void)
-{
- ToolkitTestApplication application;
-
- // Create a grid layout
- GridLayoutPtr gridLayout = GridLayout::New();
-
- // Set the number of columns
- gridLayout->SetNumberOfColumns(6);
-
- // Check whether we get the correct number of columns
- DALI_TEST_CHECK(gridLayout->GetNumberOfColumns() == 6);
- END_TEST;
-}
-
-int UtcDaliGridLayoutSetAndGetRowSpacing(void)
-{
- ToolkitTestApplication application;
-
- // Create a grid layout
- GridLayoutPtr gridLayout = GridLayout::New();
-
- // Set the row spacing
- gridLayout->SetRowSpacing(10.0f);
-
- // Check whether we get the correct row spacing
- DALI_TEST_EQUALS(gridLayout->GetRowSpacing(), 10.0f, TEST_LOCATION );
- END_TEST;
-}
-
-int UtcDaliGridLayoutSetAndGetColumnSpacing(void)
-{
- ToolkitTestApplication application;
-
- // Create a grid layout
- GridLayoutPtr gridLayout = GridLayout::New();
-
- // Set the column spacing
- gridLayout->SetColumnSpacing(10.0f);
-
- // Check whether we get the correct column spacing
- DALI_TEST_EQUALS(gridLayout->GetColumnSpacing(), 10.0f, TEST_LOCATION );
- END_TEST;
-}
-
-int UtcDaliGridLayoutSetAndGetTopMargin(void)
-{
- ToolkitTestApplication application;
-
- // Create a grid layout
- GridLayoutPtr gridLayout = GridLayout::New();
-
- // Set the top margin
- gridLayout->SetTopMargin(30.0f);
-
- // Check whether we get the correct top margin
- DALI_TEST_EQUALS(gridLayout->GetTopMargin(), 30.0f, TEST_LOCATION );
- END_TEST;
-}
-int UtcDaliGridLayoutSetAndGetBottomMargin(void)
-{
- ToolkitTestApplication application;
-
- // Create a grid layout
- GridLayoutPtr gridLayout = GridLayout::New();
-
- // Set the bottom margin
- gridLayout->SetBottomMargin(30.0f);
-
- // Check whether we get the correct bottom margin
- DALI_TEST_EQUALS(gridLayout->GetBottomMargin(), 30.0f, TEST_LOCATION );
- END_TEST;
-}
-
-int UtcDaliGridLayoutSetAndGetSideMargin(void)
-{
- ToolkitTestApplication application;
-
- // Create a grid layout
- GridLayoutPtr gridLayout = GridLayout::New();
-
- // Set the side margin
- gridLayout->SetSideMargin(10.0f);
+ rootControl.Add( gridContainer );
- // Check whether we get the correct side margin
- DALI_TEST_EQUALS(gridLayout->GetSideMargin(), 10.0f, TEST_LOCATION );
- END_TEST;
-}
+ // Ensure layouting happens
+ application.SendNotification();
+ application.Render();
-int UtcDaliGridLayoutSetAndGetZGap(void)
-{
- ToolkitTestApplication application;
+ // Grid will layout first 2 items on first row then last 2 on second row.
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
- // Create a grid layout
- GridLayoutPtr gridLayout = GridLayout::New();
+ // Item sizes will not be changed
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
- // Set the gap of items in the Z axis in different columns
- gridLayout->SetZGap(5.0f);
+ tet_printf( "Confirm number of columns is as set\n");
+ DALI_TEST_EQUALS( gridLayout.GetNumberOfColumns(), NUMBER_OF_COLUMNS, TEST_LOCATION );
- // Check whether we get the correct Z gap
- DALI_TEST_EQUALS(gridLayout->GetZGap(), 5.0f, TEST_LOCATION );
END_TEST;
}
-int UtcDaliGridLayoutSetAndGetItemSizeFunction(void)
+int UtcDaliLayouting_GridLayout02(void)
{
ToolkitTestApplication application;
+ tet_infoline("UtcDaliLayouting_GridLayout02");
- // Create a grid layout
- GridLayoutPtr gridLayout = GridLayout::New();
+ const auto NUMBER_OF_COLUMNS = 3;
+ const auto NUMBER_OF_ITEMS = 7;
- // Set the item size function
- gridLayout->SetItemSizeFunction(GridLayoutItemSizeFunction);
+ tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
- // Check whether we get the correct item size function
- DALI_TEST_CHECK(gridLayout->GetItemSizeFunction() == GridLayoutItemSizeFunction);
- END_TEST;
-}
+ Stage stage = Stage::GetCurrent();
-int UtcDaliGridLayoutSetAndGetScrollSpeedFactor(void)
-{
- ToolkitTestApplication application;
+ auto rootControl = Control::New();
+ auto absoluteLayout = AbsoluteLayout::New();
+ DevelControl::SetLayout( rootControl, absoluteLayout );
+ rootControl.SetName( "AbsoluteLayout" );
+ stage.Add( rootControl );
- // Create a grid layout
- GridLayoutPtr gridLayout = GridLayout::New();
+ auto gridContainer = Control::New();
+ auto gridLayout = Grid::New();
+ gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
+ gridContainer.SetName( "GridLayout");
+ DevelControl::SetLayout( gridContainer, gridLayout );
+ gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
+ gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
- // Set the scroll speed factor
- gridLayout->SetScrollSpeedFactor(0.05f);
+ std::vector< Control > controls;
+ for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
+ {
+ controls.push_back( CreateLeafControl( 100, 100 ) );
+ }
- // Check whether we get the correct scroll speed factor
- DALI_TEST_EQUALS(gridLayout->GetScrollSpeedFactor(), 0.05f, TEST_LOCATION );
- END_TEST;
-}
+ for( auto&& iter : controls )
+ {
+ gridContainer.Add( iter );
+ }
-int UtcDaliGridLayoutSetAndGetMaximumSwipeSpeed(void)
-{
- ToolkitTestApplication application;
+ rootControl.Add( gridContainer );
- // Create a grid layout
- GridLayoutPtr gridLayout = GridLayout::New();
+ // Ensure layouting happens
+ application.SendNotification();
+ application.Render();
- // Set the maximum swipe speed
- gridLayout->SetMaximumSwipeSpeed(50.0f);
+ // grid layouts out 3 items per row, which is 480x800.
+ // Row 1
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 200.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ // Row 2
+ DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 200.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ // Row 3
+ DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 200.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[4].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[5].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[6].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
- // Check whether we get the correct maximum swipe speed
- DALI_TEST_EQUALS(gridLayout->GetMaximumSwipeSpeed(), 50.0f, TEST_LOCATION );
END_TEST;
}
-int UtcDaliGridLayoutSetAndGetItemFlickAnimationDuration(void)
+int UtcDaliLayouting_GridLayout03(void)
{
ToolkitTestApplication application;
+ tet_infoline(" UtcDaliLayouting_GridLayout03 Grid Padding");
- // Create a grid layout
- GridLayoutPtr gridLayout = GridLayout::New();
+ const auto NUMBER_OF_COLUMNS = 2;
+ const auto NUMBER_OF_ITEMS = 4;
- // Set the flick animaiton duration
- gridLayout->SetItemFlickAnimationDuration(0.35f);
+ tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
- // Check whether we get the correct flick animaiton duration
- DALI_TEST_EQUALS( gridLayout->GetItemFlickAnimationDuration(), 0.35f, TEST_LOCATION );
- END_TEST;
-}
-
-int UtcDaliGridLayoutConstraintLeft(void)
-{
- ToolkitTestApplication application;
+ Extents GRID_PADDING( Extents( 10, 10, 20, 20 ) ); // start,end,top,bottom
- // Create the ItemView actor
- TestItemFactory factory;
- ItemView view = ItemView::New(factory);
- Vector3 vec(480.0f, 800.0f, 0.0f);
- GridLayoutPtr gridLayout = GridLayout::New();
- gridLayout->SetNumberOfColumns(6);
+ tet_printf( "Testing with Padding 10,10,20,20\n");
- view.SetName("view actor");
- view.AddLayout(*gridLayout);
- view.SetSize(vec);
+ Stage stage = Stage::GetCurrent();
- Stage::GetCurrent().Add(view);
- gridLayout->SetOrientation(ControlOrientation::Left);
- view.ActivateLayout(0, vec, 0.0f);
+ auto rootControl = Control::New();
+ auto absoluteLayout = AbsoluteLayout::New();
+ DevelControl::SetLayout( rootControl, absoluteLayout );
+ rootControl.SetName( "AbsoluteLayout" );
+ stage.Add( rootControl );
- application.SendNotification();
- application.Render(0);
+ auto gridContainer = Control::New();
+ auto gridLayout = Grid::New();
+ gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
+ gridContainer.SetName( "GridLayout");
+ DevelControl::SetLayout( gridContainer, gridLayout );
+ gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
+ gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
+ gridContainer.SetProperty( Control::Property::PADDING, GRID_PADDING );
- // render 10 frames
- for(int i = 0; i < 10; ++i)
+ std::vector< Control > controls;
+ for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
{
- application.Render(16); // 60hz frames
+ controls.push_back( CreateLeafControl( 100, 100 ) );
}
- // Confirm: we have actors in the view and they are positioned some distance from the origin.
- int nonZeroCount = 0;
- int elementsFound = 0;
- for(unsigned int i = 0; i < 10; i++)
+ for( auto&& iter : controls )
{
- Actor testActor = view.GetItem(i);
- if (testActor)
- {
- elementsFound++;
- Vector3 pos = testActor.GetCurrentPosition();
-
- if (pos.LengthSquared() > 0.0f)
- {
- nonZeroCount++;
- }
- }
+ gridContainer.Add( iter );
}
- DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
- Stage::GetCurrent().Remove(view);
- END_TEST;
-}
-
-int UtcDaliGridLayoutConstraintRight(void)
-{
- ToolkitTestApplication application;
-
- // Create the ItemView actor
- TestItemFactory factory;
- ItemView view = ItemView::New(factory);
- Vector3 vec(480.0f, 800.0f, 0.0f);
- GridLayoutPtr gridLayout = GridLayout::New();
- gridLayout->SetNumberOfColumns(6);
-
- view.SetName("view actor");
- view.AddLayout(*gridLayout);
- view.SetSize(vec);
-
- Stage::GetCurrent().Add(view);
- gridLayout->SetOrientation(ControlOrientation::Right);
- view.ActivateLayout(0, vec, 0.0f);
+ rootControl.Add( gridContainer );
+ // Ensure layouting happens
application.SendNotification();
- application.Render(0);
+ application.Render();
- // render 10 frames
- for(int i = 0; i < 10; ++i)
- {
- application.Render(16); // 60hz frames
- }
+ tet_infoline(" UtcDaliLayouting_GridLayout03 Grid Padding 2 Column, 4 Items");
+ 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 );
+ 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 );
+ 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 );
+ 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 );
- // Confirm: we have actors in the view and they are positioned some distance from the origin.
- int nonZeroCount = 0;
- int elementsFound = 0;
- for(unsigned int i = 0; i < 10; i++)
- {
- Actor testActor = view.GetItem(i);
- if (testActor)
- {
- elementsFound++;
- Vector3 pos = testActor.GetCurrentPosition();
-
- if (pos.LengthSquared() > 0.0f)
- {
- nonZeroCount++;
- }
- }
- }
+ tet_infoline(" UtcDaliLayouting_GridLayout03 Size of Grid should include padding");
+ DALI_TEST_EQUALS( gridContainer.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f * NUMBER_OF_COLUMNS + GRID_PADDING.start + + GRID_PADDING.end,
+ 100.0f * ( NUMBER_OF_ITEMS / NUMBER_OF_COLUMNS ) +
+ GRID_PADDING.top + GRID_PADDING.bottom,
+ 0.0f ), 0.0001f, TEST_LOCATION );
+
+ tet_infoline(" UtcDaliLayouting_GridLayout03 Item sizes unchanged");
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
- DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
- Stage::GetCurrent().Remove(view);
END_TEST;
}
-int UtcDaliGridLayoutConstraintUp(void)
+int UtcDaliLayouting_GridLayout04(void)
{
ToolkitTestApplication application;
+ tet_infoline(" UtcDaliLayouting_GridLayout04 Child Margin");
- // Create the ItemView actor
- TestItemFactory factory;
- ItemView view = ItemView::New(factory);
- Vector3 vec(480.0f, 800.0f, 0.0f);
- GridLayoutPtr gridLayout = GridLayout::New();
- gridLayout->SetNumberOfColumns(6);
-
- view.SetName("view actor");
- view.AddLayout(*gridLayout);
- view.SetSize(vec);
-
- Stage::GetCurrent().Add(view);
- gridLayout->SetOrientation(ControlOrientation::Up);
- view.ActivateLayout(0, vec, 0.0f);
+ const auto NUMBER_OF_COLUMNS = 2;
+ const auto NUMBER_OF_ITEMS = 4;
- application.SendNotification();
- application.Render(0);
-
- // render 10 frames
- for(int i = 0; i < 10; ++i)
- {
- application.Render(16); // 60hz frames
- }
-
- // Confirm: we have actors in the view and they are positioned some distance from the origin.
- int nonZeroCount = 0;
- int elementsFound = 0;
- for(unsigned int i = 0; i < 10; i++)
- {
- Actor testActor = view.GetItem(i);
- if (testActor)
- {
- elementsFound++;
- Vector3 pos = testActor.GetCurrentPosition();
-
- if (pos.LengthSquared() > 0.0f)
- {
- nonZeroCount++;
- }
- }
- }
-
- DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
-
- ItemLayoutPtr layout = gridLayout;
- layout->GetClosestOnScreenLayoutPosition(0, 0.0f, vec);
- int nextItem = layout->GetNextFocusItemID(0, 10, Dali::Toolkit::Control::Right, false);
- DALI_TEST_CHECK(nextItem == 1);
+ tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
- Stage::GetCurrent().Remove(view);
- END_TEST;
-}
+ Extents GRID_PADDING( Extents( 10, 10, 20, 20 ) ); // start,end,top,bottom
+ Extents ITEM_MARGIN( Extents( 10, 10, 5, 5 ) ); // start,end,top,bottom
-int UtcDaliGridLayoutConstraintDown(void)
-{
- ToolkitTestApplication application;
+ tet_printf( "Testing with Margin 10,10,5,5\n");
- // Create the ItemView actor
- TestItemFactory factory;
- ItemView view = ItemView::New(factory);
- Vector3 vec(480.0f, 800.0f, 0.0f);
- GridLayoutPtr gridLayout = GridLayout::New();
- gridLayout->SetNumberOfColumns(6);
+ Stage stage = Stage::GetCurrent();
- view.SetName("view actor");
- view.AddLayout(*gridLayout);
- view.SetSize(vec);
+ auto rootControl = Control::New();
+ auto absoluteLayout = AbsoluteLayout::New();
+ DevelControl::SetLayout( rootControl, absoluteLayout );
+ rootControl.SetName( "AbsoluteLayout" );
+ stage.Add( rootControl );
- Stage::GetCurrent().Add(view);
- gridLayout->SetOrientation(ControlOrientation::Down);
- view.ActivateLayout(0, vec, 0.0f);
+ auto gridContainer = Control::New();
+ auto gridLayout = Grid::New();
+ gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
+ gridContainer.SetName( "GridLayout");
+ DevelControl::SetLayout( gridContainer, gridLayout );
+ gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
+ gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
+ gridContainer.SetProperty( Control::Property::PADDING, GRID_PADDING );
- application.SendNotification();
- application.Render(0);
-
- // render 10 frames
- for(int i = 0; i < 10; ++i)
+ std::vector< Control > controls;
+ for( auto i=0; i < NUMBER_OF_ITEMS; i++ )
{
- application.Render(16); // 60hz frames
+ auto control = CreateLeafControl( 100, 100 );
+ control.SetProperty(Toolkit::Control::Property::MARGIN, ITEM_MARGIN );
+ controls.push_back( control );
}
- // Confirm: we have actors in the view and they are positioned some distance from the origin.
- int nonZeroCount = 0;
- int elementsFound = 0;
- for(unsigned int i = 0; i < 10; i++)
+ for( auto&& iter : controls )
{
- Actor testActor = view.GetItem(i);
- if (testActor)
- {
- elementsFound++;
- Vector3 pos = testActor.GetCurrentPosition();
-
- if (pos.LengthSquared() > 0.0f)
- {
- nonZeroCount++;
- }
- }
+ gridContainer.Add( iter );
}
- DALI_TEST_CHECK((elementsFound > 0) && (nonZeroCount == elementsFound));
- Stage::GetCurrent().Remove(view);
- END_TEST;
-}
+ rootControl.Add( gridContainer );
-int UtcDaliGridLayoutScrollDirection(void)
-{
- ToolkitTestApplication application;
+ // Ensure layouting happens
+ application.SendNotification();
+ application.Render();
- // Create the ItemView actor
- TestItemFactory factory;
- ItemView view = ItemView::New(factory);
- Vector3 vec(480.0f, 800.0f, 0.0f);
- GridLayoutPtr gridLayout = GridLayout::New();
- gridLayout->SetNumberOfColumns(6);
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ),
+ Vector3( 0.0f + GRID_PADDING.start + ITEM_MARGIN.start,
+ 0.0f + GRID_PADDING.top + ITEM_MARGIN.top,
+ 0.0f ),
+ 0.0001f, TEST_LOCATION );
- view.SetName("view actor");
- view.AddLayout(*gridLayout);
- view.SetSize(vec);
+ DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ),
+ Vector3( 100.0f + GRID_PADDING.start + ITEM_MARGIN.start *2 + ITEM_MARGIN.end,
+ 0.0f + GRID_PADDING.top + ITEM_MARGIN.top,
+ 0.0f ), 0.0001f, TEST_LOCATION );
- Stage::GetCurrent().Add(view);
- gridLayout->SetOrientation(ControlOrientation::Left);
- view.ActivateLayout(0, vec, 0.0f);
+ DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ),
+ Vector3( 0.0f + GRID_PADDING.start + ITEM_MARGIN.start,
+ 100.0f + GRID_PADDING.top + ITEM_MARGIN.top*2 + ITEM_MARGIN.bottom,
+ 0.0f ), 0.0001f, TEST_LOCATION );
- application.SendNotification();
- application.Render(0);
+ DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ),
+ Vector3( 100.0f + GRID_PADDING.start + ITEM_MARGIN.start*2 + ITEM_MARGIN.end,
+ 100.0f + GRID_PADDING.top + ITEM_MARGIN.top*2 + ITEM_MARGIN.bottom,
+ 0.0f ), 0.0001f, TEST_LOCATION );
- ItemLayoutPtr layout = gridLayout;
+ tet_infoline(" UtcDaliLayouting_GridLayout03 Size of Grid should include padding and margins");
- // render 10 frames
- for(int i = 0; i < 10; ++i)
- {
- application.Render(16); // 60hz frames
- }
+ const auto NUMBER_OF_ROWS = ( NUMBER_OF_ITEMS / NUMBER_OF_COLUMNS );
- gridLayout->SetOrientation(ControlOrientation::Up);
- view.ActivateLayout(0, vec, 0.0f);
- application.SendNotification();
- application.Render();
+ DALI_TEST_EQUALS( gridContainer.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f * NUMBER_OF_COLUMNS + GRID_PADDING.start + GRID_PADDING.end +
+ ITEM_MARGIN.start *NUMBER_OF_COLUMNS + ITEM_MARGIN.end *NUMBER_OF_COLUMNS,
+ 100.0f * NUMBER_OF_ROWS +
+ GRID_PADDING.top + GRID_PADDING.bottom +
+ ITEM_MARGIN.bottom *NUMBER_OF_ROWS + ITEM_MARGIN.bottom *NUMBER_OF_ROWS,
+ 0.0f ), 0.0001f, TEST_LOCATION );
- Degree deg = layout->GetScrollDirection();
- DALI_TEST_CHECK(deg.degree == 0.0f);
+ tet_infoline(" UtcDaliLayouting_GridLayout03 Item sizes unchanged");
+ DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+ DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
- gridLayout->SetOrientation(ControlOrientation::Down);
- view.ActivateLayout(0, vec, 0.0f);
- application.SendNotification();
- application.Render();
+ END_TEST;
+}
- deg = layout->GetScrollDirection();
- DALI_TEST_CHECK((deg.degree == 180.0f));
- layout->SetOrientation(ControlOrientation::Left);
- view.ActivateLayout(0, vec, 0.0f);
- application.SendNotification();
- application.Render();
+int UtcDaliLayouting_GridLayoutDownCast(void)
+{
+ TestApplication application;
+ tet_infoline(" UtcDaliLayouting_GridLayoutDownCast - Testing Downcast");
- deg = layout->GetScrollDirection();
- DALI_TEST_CHECK(deg.degree == 90.f);
+ Grid gridLayout = Grid::New();
- gridLayout->SetOrientation(ControlOrientation::Right);
- view.ActivateLayout(0, vec, 0.0f);
- application.SendNotification();
- application.Render();
+ LayoutGroup layoutGroup( gridLayout );
- deg = layout->GetScrollDirection();
- DALI_TEST_CHECK(deg.degree == 270.0f);
+ Grid gridLayoutCandidate = Grid::DownCast( layoutGroup );
+ DALI_TEST_CHECK( gridLayoutCandidate );
- Stage::GetCurrent().Remove(view);
END_TEST;
-}
+}
\ No newline at end of file