Add alignment support in LinearLayout. 48/184648/9
authorAnton Obzhirov <a.obzhirov@samsung.com>
Thu, 19 Jul 2018 16:54:19 +0000 (17:54 +0100)
committerAnton Obzhirov <a.obzhirov@samsung.com>
Thu, 23 Aug 2018 10:28:43 +0000 (11:28 +0100)
Change-Id: Ie9a575c4318335ab7806f06502a5e624f8365b50

automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp
dali-toolkit/devel-api/layouting/linear-layout.cpp
dali-toolkit/devel-api/layouting/linear-layout.h
dali-toolkit/internal/layouting/linear-layout-impl.cpp
dali-toolkit/internal/layouting/linear-layout-impl.h

index 29e3726..0806353 100644 (file)
@@ -76,6 +76,7 @@ int UtcDaliLayouting_HboxLayout01(void)
   {
     hbox.Add( iter );
   }
+
   hbox.SetParentOrigin( ParentOrigin::CENTER );
   hbox.SetAnchorPoint( AnchorPoint::CENTER );
   stage.Add( hbox );
@@ -652,6 +653,278 @@ int UtcDaliLayouting_HboxLayout08(void)
   END_TEST;
 }
 
+int UtcDaliLayouting_HboxLayout09(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliLayouting_HboxLayout07 - Set alignment");
+
+  Stage stage = Stage::GetCurrent();
+  auto hbox = Control::New();
+  auto hboxLayout = LinearLayout::New();
+  DevelControl::SetLayout( hbox, hboxLayout );
+  hbox.SetName( "HBox");
+
+  std::vector< Control > controls;
+  controls.push_back( CreateLeafControl( 40, 40 ) );
+  controls.push_back( CreateLeafControl( 60, 60 ) );
+
+  for( auto&& iter : controls )
+  {
+    hbox.Add( iter );
+  }
+  hbox.SetParentOrigin( ParentOrigin::CENTER );
+  hbox.SetAnchorPoint( AnchorPoint::CENTER );
+  stage.Add( hbox );
+
+  // Check default orientation
+  DALI_TEST_EQUALS( static_cast<unsigned int>( hboxLayout.GetOrientation() ), static_cast<unsigned int>( LinearLayout::Orientation::HORIZONTAL ), TEST_LOCATION );
+  // Check default alignment
+  DALI_TEST_EQUALS( hboxLayout.GetAlignment(), ( Dali::Toolkit::LinearLayout::Alignment::BEGIN | Dali::Toolkit::LinearLayout::Alignment::CENTER_VERTICAL ), TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::BEGIN );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 40.0f, 370.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::END );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 380.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 420.0f, 370.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 190.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 230.0f, 370.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::BEGIN | Dali::Toolkit::LinearLayout::Alignment::TOP );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  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( 40.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::END | Dali::Toolkit::LinearLayout::Alignment::TOP );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 380.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 420.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL | Dali::Toolkit::LinearLayout::Alignment::TOP );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 190.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 230.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::BEGIN | Dali::Toolkit::LinearLayout::Alignment::BOTTOM );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 760.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 40.0f, 740.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::END | Dali::Toolkit::LinearLayout::Alignment::BOTTOM );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 380.0f, 760.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 420.0f, 740.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL | Dali::Toolkit::LinearLayout::Alignment::BOTTOM );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 190.0f, 760.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 230.0f, 740.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL | Dali::Toolkit::LinearLayout::Alignment::CENTER_VERTICAL );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 190.0f, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 230.0f, 370.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::BEGIN );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 350.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 390.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::END );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 440.0f, 350.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 420.0f, 390.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 220.0f, 350.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 210.0f, 390.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::BEGIN | Dali::Toolkit::LinearLayout::Alignment::TOP );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  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( 0.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::END | Dali::Toolkit::LinearLayout::Alignment::TOP );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 440.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 420.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL | Dali::Toolkit::LinearLayout::Alignment::TOP );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 220.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 210.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::BEGIN | Dali::Toolkit::LinearLayout::Alignment::BOTTOM );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 700.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 740.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::END | Dali::Toolkit::LinearLayout::Alignment::BOTTOM );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 440.0f, 700.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 420.0f, 740.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL | Dali::Toolkit::LinearLayout::Alignment::BOTTOM );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 220.0f, 700.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 210.0f, 740.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  hboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL | Dali::Toolkit::LinearLayout::Alignment::CENTER_VERTICAL );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 220.0f, 350.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 210.0f, 390.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  END_TEST;
+}
+
 namespace
 {
 const char* TEST_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR  "/broken.png";
@@ -1336,6 +1609,7 @@ int UtcDaliLayouting_VboxLayout01(void)
   auto vbox = Control::New();
   auto vboxLayout = LinearLayout::New();
   vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
+  vboxLayout.SetAlignment( LinearLayout::Alignment::TOP | LinearLayout::Alignment::CENTER_HORIZONTAL );
   DevelControl::SetLayout( vbox, vboxLayout );
   vbox.SetName( "Vbox");
 
@@ -1396,6 +1670,7 @@ int UtcDaliLayouting_VboxLayout02(void)
   auto vbox = Control::New();
   auto vboxLayout = LinearLayout::New();
   vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
+  vboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::TOP | Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL );
   DevelControl::SetLayout( vbox, vboxLayout );
   vbox.SetName( "Vbox");
   rootControl.Add( vbox );
@@ -1468,6 +1743,7 @@ int UtcDaliLayouting_VboxLayout03(void)
   auto vboxLayout = LinearLayout::New();
   vboxLayout.SetCellPadding( LayoutSize( 0, 10 ) );
   vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
+  vboxLayout.SetAlignment( Dali::Toolkit::LinearLayout::Alignment::TOP | Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL );
 
   DALI_TEST_EQUALS( vboxLayout.GetCellPadding(), LayoutSize( 0, 10 ), TEST_LOCATION );
 
index 4a63036..25e88ab 100644 (file)
@@ -59,7 +59,7 @@ void LinearLayout::SetCellPadding( LayoutSize size )
   GetImplementation(*this).SetCellPadding( size );
 }
 
-LayoutSize LinearLayout::GetCellPadding()
+LayoutSize LinearLayout::GetCellPadding() const
 {
   return GetImplementation(*this).GetCellPadding();
 }
@@ -69,11 +69,21 @@ void LinearLayout::SetOrientation( LinearLayout::Orientation orientation )
   GetImplementation(*this).SetOrientation( orientation );
 }
 
-LinearLayout::Orientation LinearLayout::GetOrientation()
+LinearLayout::Orientation LinearLayout::GetOrientation() const
 {
   return GetImplementation(*this).GetOrientation();
 }
 
+void LinearLayout::SetAlignment( unsigned int alignment )
+{
+  GetImplementation(*this).SetAlignment( alignment );
+}
+
+unsigned int LinearLayout::GetAlignment() const
+{
+  return GetImplementation(*this).GetAlignment();
+}
+
 LinearLayout::LinearLayout( Dali::Toolkit::Internal::LinearLayout* object )
 : LayoutGroup( object )
 {
index f30911b..07924db 100644 (file)
@@ -57,6 +57,22 @@ public:
   };
 
   /**
+   * @brief Enumeration for the alignment of the linear layout items.
+   */
+  struct Alignment
+  {
+    enum Type
+    {
+      BEGIN                     = 0x1,  ///< At the left/right edge of the container (maps to LTR/RTL direction for horizontal orientation)
+      END                       = 0x2,  ///< At the right/left edge of the container (maps to LTR/RTL direction for horizontal orientation)
+      CENTER_HORIZONTAL         = 0x4,  ///< At the horizontal center of the container
+      TOP                       = 0x8,  ///< At the top edge of the container
+      BOTTOM                    = 0x10, ///< At the bottom edge of the container
+      CENTER_VERTICAL           = 0x20  ///< At the vertical center of the container
+    };
+  };
+
+  /**
    * @brief Creates an uninitialized LinearLayout handle.
    *
    * Initialize it using LinearLayout::New().
@@ -109,7 +125,7 @@ public:
    *
    * @return The padding between cells.
    */
-  LayoutSize GetCellPadding();
+  LayoutSize GetCellPadding() const;
 
   /**
    * @brief Set the orientation in the layout
@@ -123,7 +139,21 @@ public:
    *
    * @return The orientation.
    */
-  Orientation GetOrientation();
+  Orientation GetOrientation() const;
+
+  /**
+   * @brief Set the alignment in the layout
+   *
+   * @param[in] alignment The alignment.
+   */
+  void SetAlignment( unsigned int alignment );
+
+  /**
+   * @brief Get the alignment in the layout
+   *
+   * @return The alignment.
+   */
+  unsigned int GetAlignment() const;
 
 public: // Not intended for application developers
 
index f989a54..c85c5fe 100644 (file)
@@ -41,6 +41,9 @@ namespace Toolkit
 namespace Internal
 {
 
+const int HORIZONTAL_ALIGNMENT_MASK  = ( Dali::Toolkit::LinearLayout::Alignment::BEGIN | Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL | Dali::Toolkit::LinearLayout::Alignment::END );
+const int VERTICAL_ALIGNMENT_MASK = ( Dali::Toolkit::LinearLayout::Alignment::TOP | Dali::Toolkit::LinearLayout::Alignment::CENTER_VERTICAL | Dali::Toolkit::LinearLayout::Alignment::BOTTOM );
+
 LinearLayoutPtr LinearLayout::New()
 {
   LinearLayoutPtr layout( new LinearLayout() );
@@ -51,6 +54,7 @@ LinearLayout::LinearLayout()
 : LayoutGroup(),
   mCellPadding( 0, 0 ),
   mOrientation( Dali::Toolkit::LinearLayout::Orientation::HORIZONTAL ),
+  mAlignment( Dali::Toolkit::LinearLayout::Alignment::BEGIN | Dali::Toolkit::LinearLayout::Alignment::CENTER_VERTICAL ),
   mTotalLength( 0 )
 {
 }
@@ -68,7 +72,7 @@ void LinearLayout::SetCellPadding( LayoutSize size )
   }
 }
 
-LayoutSize LinearLayout::GetCellPadding()
+LayoutSize LinearLayout::GetCellPadding() const
 {
   return mCellPadding;
 }
@@ -82,11 +86,25 @@ void LinearLayout::SetOrientation( Dali::Toolkit::LinearLayout::Orientation orie
   }
 }
 
-Dali::Toolkit::LinearLayout::Orientation LinearLayout::GetOrientation()
+Dali::Toolkit::LinearLayout::Orientation LinearLayout::GetOrientation() const
 {
   return mOrientation;
 }
 
+void LinearLayout::SetAlignment( unsigned int alignment )
+{
+  if ( mAlignment != alignment )
+  {
+    mAlignment = alignment;
+    RequestLayout();
+  }
+}
+
+unsigned int LinearLayout::GetAlignment() const
+{
+  return mAlignment;
+}
+
 void LinearLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec )
 {
 #if defined(DEBUG_ENABLED)
@@ -284,15 +302,48 @@ void LinearLayout::LayoutHorizontal( LayoutLength left, LayoutLength top, Layout
 
   auto count = GetChildCount();
 
+  switch ( mAlignment & HORIZONTAL_ALIGNMENT_MASK )
+  {
+    case Dali::Toolkit::LinearLayout::Alignment::BEGIN:
+    default:
+    {
+      // mTotalLength contains the padding already
+      // In case of RTL map BEGIN alignment to the right edge
+      if ( isLayoutRtl ) {
+        childLeft = LayoutLength( padding.start ) + right - left - mTotalLength;
+      }
+      else {
+        childLeft = LayoutLength( padding.start );
+      }
+      break;
+    }
+    case Dali::Toolkit::LinearLayout::Alignment::END:
+    {
+      // mTotalLength contains the padding already
+      // In case of RTL map END alignment to the left edge
+      if ( isLayoutRtl ) {
+        childLeft = LayoutLength( padding.start );
+      }
+      else {
+        childLeft = LayoutLength( padding.start ) + right - left - mTotalLength;
+      }
+      break;
+    }
+    case Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL:
+    {
+      // mTotalLength contains the padding already
+      childLeft = LayoutLength( padding.start ) + ( right - left - mTotalLength ) / 2;
+      break;
+    }
+  }
+
   int start = 0;
   int dir = 1;
 
-  // In case of RTL, start drawing from the last child and apply right alignment.
-  // @TODO Should we have also support Actor HorizontalAlignment|VerticalAlignment in general for LinearLayout?
+  // In case of RTL, start drawing from the last child.
   if( isLayoutRtl ) {
     start = count - 1;
     dir = -1;
-    childLeft = padding.start + right - left - mTotalLength;
   }
 
   for( unsigned int i = 0; i < count; i++)
@@ -305,8 +356,25 @@ void LinearLayout::LayoutHorizontal( LayoutLength left, LayoutLength top, Layout
       auto childHeight = childLayout->GetMeasuredHeight();
       auto childMargin = childLayout->GetMargin();
 
-      childTop = LayoutLength(padding.top) + ((childSpace - childHeight) / 2) + childMargin.top - childMargin.bottom;
-
+      switch ( mAlignment & VERTICAL_ALIGNMENT_MASK )
+      {
+        case Dali::Toolkit::LinearLayout::Alignment::TOP:
+        {
+          childTop = LayoutLength( padding.top ) + childMargin.top;
+          break;
+        }
+        case Dali::Toolkit::LinearLayout::Alignment::BOTTOM:
+        {
+          childTop = height - padding.bottom - childHeight - childMargin.bottom;
+          break;
+        }
+        case Dali::Toolkit::LinearLayout::Alignment::CENTER_VERTICAL:
+        default:
+        {
+          childTop = LayoutLength( padding.top ) + ( ( childSpace - childHeight ) / 2 ) + childMargin.top - childMargin.bottom;
+          break;
+        }
+      }
       childLeft += childMargin.start;
       childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight );
       childLeft += childWidth + childMargin.end + mCellPadding.width;
@@ -436,13 +504,36 @@ void LinearLayout::LayoutVertical( LayoutLength left, LayoutLength top, LayoutLe
   LayoutLength childTop( padding.top );
   LayoutLength childLeft( padding.start );
 
-  // Where bottom of child should go
+  // Where end of child should go
   auto width = right - left;
 
   // Space available for child
   auto childSpace = width - padding.start - padding.end;
   auto count = GetChildCount();
 
+  switch ( mAlignment & VERTICAL_ALIGNMENT_MASK )
+  {
+    case Dali::Toolkit::LinearLayout::Alignment::TOP:
+    {
+      // mTotalLength contains the padding already
+      childTop = LayoutLength( padding.top );
+      break;
+    }
+    case Dali::Toolkit::LinearLayout::Alignment::BOTTOM:
+    {
+      // mTotalLength contains the padding already
+      childTop = LayoutLength( padding.top ) + bottom - top - mTotalLength;
+      break;
+    }
+    case Dali::Toolkit::LinearLayout::Alignment::CENTER_VERTICAL:
+    default:
+    {
+      // mTotalLength contains the padding already
+      childTop = LayoutLength( padding.top ) + ( bottom - top - mTotalLength ) / 2;
+      break;
+    }
+  }
+
   for( unsigned int childIndex = 0; childIndex < count; childIndex++)
   {
     LayoutItemPtr childLayout = GetChildAt( childIndex );
@@ -453,8 +544,25 @@ void LinearLayout::LayoutVertical( LayoutLength left, LayoutLength top, LayoutLe
       auto childMargin = childLayout->GetMargin();
 
       childTop += childMargin.top;
-      childLeft = LayoutLength( padding.start ) + ( childSpace - childWidth ) / 2 + childMargin.start - childMargin.end;
-
+      switch ( mAlignment & HORIZONTAL_ALIGNMENT_MASK )
+      {
+        case Dali::Toolkit::LinearLayout::Alignment::BEGIN:
+        default:
+        {
+          childLeft = LayoutLength( padding.start ) + childMargin.start;
+          break;
+        }
+        case Dali::Toolkit::LinearLayout::Alignment::END:
+        {
+          childLeft = width - padding.end - childWidth - childMargin.end;
+          break;
+        }
+        case Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL:
+        {
+          childLeft = LayoutLength( padding.start ) + ( childSpace - childWidth ) / 2 + childMargin.start - childMargin.end;
+          break;
+        }
+      }
       childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight );
       childTop += childHeight + childMargin.bottom + mCellPadding.height;
     }
index d9fb90a..23f3184 100644 (file)
@@ -35,16 +35,63 @@ using LinearLayoutPtr = IntrusivePtr<LinearLayout>;
 class LinearLayout final : public LayoutGroup
 {
 public:
+  /**
+   * Creates a pointer to a LinearLayout implementation.
+   */
   static LinearLayoutPtr New();
 
 public:
+  /**
+   * @brief Set the padding between cells in the layout
+   *
+   * @param[in] size The padding between cells.
+   */
   void SetCellPadding( LayoutSize size );
-  LayoutSize GetCellPadding();
+
+  /**
+   * @brief Get the padding between cells in the layout
+   *
+   * @return The padding between cells.
+   */
+  LayoutSize GetCellPadding() const;
+
+  /**
+   * @brief Set the orientation in the layout
+   *
+   * @param[in] orientation The orientation.
+   */
   void SetOrientation( Dali::Toolkit::LinearLayout::Orientation orientation );
-  Dali::Toolkit::LinearLayout::Orientation GetOrientation();
+
+  /**
+   * @brief Get the orientation in the layout
+   *
+   * @return The orientation.
+   */
+  Dali::Toolkit::LinearLayout::Orientation GetOrientation() const;
+
+  /**
+   * @brief Set the alignment in the layout
+   *
+   * @param[in] alignment The alignment.
+   */
+  void SetAlignment( unsigned int alignment );
+
+  /**
+   * @brief Get the alignment in the layout
+   *
+   * @return The alignment.
+   */
+  unsigned int GetAlignment() const;
 
 protected:
+  /**
+   * Default Constructor
+   */
   LinearLayout();
+
+  /**
+   * Destructor
+   */
   virtual ~LinearLayout();
 
   /**
@@ -94,6 +141,7 @@ private:
 private:
   LayoutSize mCellPadding;
   Dali::Toolkit::LinearLayout::Orientation mOrientation;
+  unsigned int mAlignment;
   LayoutLength mTotalLength;
 };