Control Padding and Margin Properties used for layouts 49/180449/1
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Fri, 27 Apr 2018 16:08:45 +0000 (17:08 +0100)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Tue, 29 May 2018 13:13:02 +0000 (14:13 +0100)
Layout base gets and sets padding and margin using Control Properties.

Control::Property::PADDING
Control::Property::MARGIN

Extra logging and GetNaturalSize fix squashed in

Change-Id: I4a8acbb2bf9761fea153581a66c1f76d620f852b

automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp
dali-toolkit/devel-api/layouting/layout-group-impl.cpp
dali-toolkit/devel-api/layouting/layout-item-impl.cpp
dali-toolkit/devel-api/layouting/layout-item-impl.h
dali-toolkit/internal/layouting/hbox-layout-impl.cpp
dali-toolkit/internal/layouting/layout-controller-impl.cpp
dali-toolkit/internal/layouting/layout-item-data-impl.cpp
dali-toolkit/internal/layouting/layout-item-data-impl.h
dali-toolkit/internal/layouting/vbox-layout-impl.cpp

index 989ad95..deb8eb8 100644 (file)
@@ -109,9 +109,6 @@ int UtcDaliLayouting_HboxLayout01(void)
   END_TEST;
 }
 
-
-
-
 int UtcDaliLayouting_HboxLayout02(void)
 {
   ToolkitTestApplication application;
@@ -317,9 +314,6 @@ int UtcDaliLayouting_HboxLayout03(void)
   END_TEST;
 }
 
-
-
-
 int UtcDaliLayouting_HboxLayout04(void)
 {
   ToolkitTestApplication application;
@@ -420,6 +414,299 @@ int UtcDaliLayouting_HboxLayout04(void)
   END_TEST;
 }
 
+// Padding tests
+
+int UtcDaliLayouting_HboxLayout_Padding01(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliLayouting_HboxLayout_Padding01 - Adding Padding to a single child");
+
+  Stage stage = Stage::GetCurrent();
+  auto hbox = Control::New();
+  auto hboxLayout = HboxLayout::New();
+  DevelControl::SetLayout( hbox, hboxLayout );
+  hbox.SetName( "HBox");
+
+  std::vector< Control > controls;
+  controls.push_back( CreateLeafControl( 40, 40 ) );
+  controls.push_back( CreateLeafControl( 60, 40 ) );
+  controls.push_back( CreateLeafControl( 80, 40 ) );
+  controls.push_back( CreateLeafControl( 100, 40 ) );
+
+  const Extents CONTROL_PADDING = Extents(5, 10, 20, 2 );
+  tet_printf( "\nAdding Padding to control at index %u \n", 1 );
+  controls[1].SetProperty(Toolkit::Control::Property::PADDING, CONTROL_PADDING );
+
+  for( auto&& iter : controls )
+  {
+    hbox.Add( iter );
+  }
+  hbox.SetParentOrigin( ParentOrigin::CENTER );
+  hbox.SetAnchorPoint( AnchorPoint::CENTER );
+  stage.Add( hbox );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  // hbox centers elements vertically, it fills test harness stage, which is 480x800.
+  // hbox left justifies elements
+  tet_infoline("Test Child Actor Position");
+  float xPositionOfControlBeingTested = 0.0f;
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
+                                                                                            380.0f,
+                                                                                            0.0f ), 0.0001f, TEST_LOCATION );
+  xPositionOfControlBeingTested += 40.0f;
+
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
+                                                                                            380.0f - ( ( CONTROL_PADDING.top + CONTROL_PADDING.bottom) * 0.5f ),                                                                                            0.0f ),
+                                                                                            0.0001f, TEST_LOCATION );
+
+  xPositionOfControlBeingTested += 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
+  DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  xPositionOfControlBeingTested += 80.0f;
+  DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  tet_infoline("Test Child Actor Size");
+  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 + CONTROL_PADDING.start + CONTROL_PADDING.end,
+                                                                                        40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom , 0.0f ),
+                                                                                        0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliLayouting_HboxLayout_Padding02(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliLayouting_HboxLayout_Padding02 - Adding Padding to a all children");
+
+  Stage stage = Stage::GetCurrent();
+  auto hbox = Control::New();
+  auto hboxLayout = HboxLayout::New();
+  DevelControl::SetLayout( hbox, hboxLayout );
+  hbox.SetName( "HBox");
+
+  std::vector< Control > controls;
+  controls.push_back( CreateLeafControl( 40, 40 ) );
+  controls.push_back( CreateLeafControl( 60, 40 ) );
+  controls.push_back( CreateLeafControl( 80, 40 ) );
+  controls.push_back( CreateLeafControl( 100, 40 ) );
+
+  const Extents CONTROL_PADDING = Extents(5, 10, 20, 2 );
+
+  for( auto&& iter : controls )
+  {
+    iter.SetProperty(Toolkit::Control::Property::PADDING, CONTROL_PADDING );
+    hbox.Add( iter );
+  }
+  hbox.SetParentOrigin( ParentOrigin::CENTER );
+  hbox.SetAnchorPoint( AnchorPoint::CENTER );
+  stage.Add( hbox );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  // hbox centers elements vertically, it fills test harness stage, which is 480x800.
+  // hbox left justifies elements
+  tet_infoline("Test Child Actor Position");
+  float xPositionOfControlBeingTested = 0.0f;
+  float yPositionOfControlBeingTested = ( 800.0f * 0.5) - ( 0.5 * ( 40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom ) );
+
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
+                                                                                            yPositionOfControlBeingTested,
+                                                                                            0.0f ), 0.0001f, TEST_LOCATION );
+  xPositionOfControlBeingTested += 40.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
+
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
+                                                                                            yPositionOfControlBeingTested,
+                                                                                            0.0f ),
+                                                                                            0.0001f, TEST_LOCATION );
+
+  xPositionOfControlBeingTested += 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
+  DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
+                                                                                            yPositionOfControlBeingTested,
+                                                                                            0.0f ), 0.0001f, TEST_LOCATION );
+
+  xPositionOfControlBeingTested += 80.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
+  DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
+                                                                                            yPositionOfControlBeingTested,
+                                                                                            0.0f ), 0.0001f, TEST_LOCATION );
+
+  tet_infoline("Test Child Actor Size");
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f + CONTROL_PADDING.start + CONTROL_PADDING.end,
+                                                                                        40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom,
+                                                                                        0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end,
+                                                                                        40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom,
+                                                                                        0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f + CONTROL_PADDING.start + CONTROL_PADDING.end ,
+                                                                                        40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom,
+                                                                                        0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f + CONTROL_PADDING.start + CONTROL_PADDING.end,
+                                                                                        40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom,
+                                                                                        0.0f ), 0.0001f, TEST_LOCATION );
+
+  END_TEST;
+}
+
+
+int UtcDaliLayouting_HboxLayout_Padding03(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliLayouting_HboxLayout_Padding03 - Adding Changing padding on a single child");
+
+  Stage stage = Stage::GetCurrent();
+  auto hbox = Control::New();
+  auto hboxLayout = HboxLayout::New();
+  DevelControl::SetLayout( hbox, hboxLayout );
+  hbox.SetName( "HBox");
+
+  std::vector< Control > controls;
+  controls.push_back( CreateLeafControl( 40, 40 ) );
+  controls.push_back( CreateLeafControl( 40, 40 ) );
+  controls.push_back( CreateLeafControl( 40, 40 ) );
+
+  const Extents CONTROL_PADDING = Extents(5, 10, 20, 2 );
+  tet_printf( "\nAdding Padding to control at index 1 \n" );
+  controls[1].SetProperty(Toolkit::Control::Property::PADDING, CONTROL_PADDING );
+
+  for( auto&& iter : controls )
+  {
+    hbox.Add( iter );
+  }
+  hbox.SetParentOrigin( ParentOrigin::CENTER );
+  hbox.SetAnchorPoint( AnchorPoint::CENTER );
+  stage.Add( hbox );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  // hbox centers elements vertically, it fills test harness stage, which is 480x800.
+  // hbox left justifies elements
+  tet_infoline("Test Child Actor Position");
+  float xPositionOfControlBeingTested = 0.0f;
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
+                                                                                            380.0f,
+                                                                                            0.0f ), 0.0001f, TEST_LOCATION );
+  xPositionOfControlBeingTested += 40.0f;
+
+  DALI_TEST_EQUALS( controls[ 1 ].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
+                                                                                            380.0f - ( ( CONTROL_PADDING.top + CONTROL_PADDING.bottom) * 0.5f ),                                                                                            0.0f ),
+                                                                                            0.0001f, TEST_LOCATION );
+
+  xPositionOfControlBeingTested += 40.0f + CONTROL_PADDING.start + CONTROL_PADDING.end;
+  DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  const Extents NEW_CONTROL_PADDING = Extents(10, 10, 20, 2 );
+  tet_printf( "\nChanging Padding to control at index 1 \n" );
+  controls[1].SetProperty(Toolkit::Control::Property::PADDING, NEW_CONTROL_PADDING );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  xPositionOfControlBeingTested = 0.0f; // reset
+
+  tet_infoline("Test Child Actor Position");
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
+                                                                                            380.0f,
+                                                                                            0.0f ), 0.0001f, TEST_LOCATION );
+  xPositionOfControlBeingTested += 40.0f;
+
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
+                                                                                            380.0f - ( ( NEW_CONTROL_PADDING.top + NEW_CONTROL_PADDING.bottom) * 0.5f ),                                                                                            0.0f ),
+                                                                                            0.0001f, TEST_LOCATION );
+
+  xPositionOfControlBeingTested += 40.0f + NEW_CONTROL_PADDING.start + NEW_CONTROL_PADDING.end;
+  tet_printf( "\nIf x position %u then change has not been processed \n", 40 + 40 + CONTROL_PADDING.start + CONTROL_PADDING.end );
+  DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  tet_infoline("Test Child Actor Size");
+  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( 40.0f + NEW_CONTROL_PADDING.start + NEW_CONTROL_PADDING.end,
+                                                                                        40.0f + NEW_CONTROL_PADDING.top + NEW_CONTROL_PADDING.bottom , 0.0f ),
+                                                                                        0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ) , Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  END_TEST;
+}
+
+// Margin Tests
+
+int UtcDaliLayouting_HboxLayout_Margin01(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliLayouting_HboxLayout_Margin01 - Adding a margin to a single child");
+
+  Stage stage = Stage::GetCurrent();
+  auto hbox = Control::New();
+  auto hboxLayout = HboxLayout::New();
+  DevelControl::SetLayout( hbox, hboxLayout );
+  hbox.SetName( "HBox");
+
+  std::vector< Control > controls;
+  controls.push_back( CreateLeafControl( 40, 40 ) );
+  controls.push_back( CreateLeafControl( 60, 40 ) );
+  controls.push_back( CreateLeafControl( 80, 40 ) );
+  controls.push_back( CreateLeafControl( 100, 40 ) );
+
+  const Extents CONTROL_MARGIN = Extents(5, 10, 20, 0 );
+  tet_printf( "\nAdding Margin to control at index 1 \n" );
+  controls[1].SetProperty(Toolkit::Control::Property::MARGIN, CONTROL_MARGIN );
+
+  for( auto&& iter : controls )
+  {
+    hbox.Add( iter );
+  }
+  hbox.SetParentOrigin( ParentOrigin::CENTER );
+  hbox.SetAnchorPoint( AnchorPoint::CENTER );
+  stage.Add( hbox );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  // hbox centers elements vertically, it fills test harness stage, which is 480x800.
+  // hbox left justifies elements
+  tet_infoline("Test Child Actor Position");
+  auto xPositionOfControlBeingTested = 0.0f;
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
+                                                                                            380.0f,
+                                                                                            0.0f ), 0.0001f, TEST_LOCATION );
+  xPositionOfControlBeingTested += 40.0f + CONTROL_MARGIN.start;
+
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,
+                                                                                            380.0f + CONTROL_MARGIN.top, 0.0f ),
+                                                                                            0.0001f, TEST_LOCATION );
+
+  xPositionOfControlBeingTested += 60.0f + CONTROL_MARGIN.end;
+  DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  xPositionOfControlBeingTested += 80.0f;
+  DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,380.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  tet_infoline("Test Child Actor Size is the same after Margin added");
+  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, 40.0f , 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[2].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[3].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  END_TEST;
+}
+
 
 int UtcDaliLayouting_VboxLayout01(void)
 {
index 21fb391..9df05c6 100644 (file)
  */
 
 // CLASS HEADER
+#include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
+
+// EXTERNAL INCLUDES
 #include <dali/public-api/object/type-registry-helper.h>
 #include <dali/devel-api/actors/actor-devel.h>
 #include <dali/devel-api/object/handle-devel.h>
-#include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
+#include <dali/integration-api/debug.h>
+
+// INTERNAL INCLUDES
 #include <dali-toolkit/internal/layouting/layout-group-data-impl.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
 
-
 namespace
 {
-const char* MARGIN_SPECIFICATION_NAME( "marginSpec" );
+#if defined(DEBUG_ENABLED)
+Debug::Filter* gLogFilter = Debug::Filter::New( Debug::Concise, false, "LOG_LAYOUT" );
+#endif
 }
 
 namespace Dali
@@ -176,7 +182,12 @@ void LayoutGroup::DoRegisterChildProperties( const std::string& containerType )
 
 void LayoutGroup::OnSetChildProperties( Handle& handle, Property::Index index, Property::Value value )
 {
-  if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnSetChildProperties");
+
+  if ( ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) &&
+         ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
+       ||
+       ( index == Toolkit::Control::Property::MARGIN || index == Toolkit::Control::Property::PADDING ) )
   {
     // If any child properties are set, must perform relayout
     RequestLayout();
@@ -189,7 +200,6 @@ void LayoutGroup::GenerateDefaultChildPropertyValues( Handle child )
                      Toolkit::ChildLayoutData::WRAP_CONTENT );
   child.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,
                      Toolkit::ChildLayoutData::WRAP_CONTENT );
-  child.SetProperty( Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION, Extents() );
 }
 
 void LayoutGroup::MeasureChildren( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec)
@@ -207,11 +217,47 @@ void LayoutGroup::MeasureChild( LayoutItemPtr child,
                                 MeasureSpec parentWidthMeasureSpec,
                                 MeasureSpec parentHeightMeasureSpec )
 {
+  DALI_LOG_TRACE_METHOD( gLogFilter );
+
   auto childOwner = child->GetOwner();
+
+  auto control = Toolkit::Control::DownCast( childOwner );
+
+#if defined( DEBUG_ENABLED )
+  if ( control )
+  {
+    DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins naturalSizewidth(%f)\n",  control.GetNaturalSize().width );
+  }
+#endif
+
+  // Get last stored width and height specifications for the child
   auto desiredWidth = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
   auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
 
-  auto padding = GetPadding();
+  // The size of the control could have changed due to padding being altered, the XXX_SPECIFICATIONs will not have been updated.
+  // So GetNaturalSize is called, if the control's natural size includes padding then th size will be updated.
+  if ( control )
+  {
+    auto desiredSize = control.GetNaturalSize();  // Get's child control's size which could include new padding values.
+
+    // Check if WIDTH_SPECIFICATION was a size value, if so then get update to child controls's width.
+    if ( desiredWidth > 0  )
+    {
+      desiredWidth = desiredSize.width;
+      childOwner.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, LayoutLength::IntType( desiredWidth ) );
+    }
+
+    // Check if HEIGHT_SPECIFICATION was a size value, if so then get update to child controls's height.
+    if ( desiredHeight > 0)
+    {
+      desiredHeight = desiredSize.height;
+      childOwner.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, LayoutLength::IntType( desiredHeight ) );
+    }
+  }
+
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChild desiredWidth(%d)\n",  desiredWidth );
+
+  auto padding = GetPadding(); // Padding of this layout's owner, not of the child being measured.
 
   const MeasureSpec childWidthMeasureSpec = GetChildMeasureSpec( parentWidthMeasureSpec,
                                                                  padding.start + padding.end,
@@ -230,17 +276,20 @@ void LayoutGroup::MeasureChildWithMargins( LayoutItemPtr child,
   auto childOwner = child->GetOwner();
   auto desiredWidth = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
   auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
-  auto desiredMargin = childOwner.GetProperty<Extents>( Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION );
-  auto padding = GetPadding();
+
+  auto padding = GetPadding(); // Padding of this layout's owner, not of the child being measured.
+
+
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins desiredWidth(%d)\n",  desiredWidth );
 
   MeasureSpec childWidthMeasureSpec = GetChildMeasureSpec( parentWidthMeasureSpec,
                                                            padding.start + padding.end +
-                                                           desiredMargin.start + desiredMargin.end +
                                                            widthUsed, desiredWidth );
 
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins desiredHeight(%d)\n",  desiredHeight );
+
   MeasureSpec childHeightMeasureSpec = GetChildMeasureSpec( parentHeightMeasureSpec,
                                                             padding.top + padding.bottom +
-                                                            desiredMargin.top + desiredMargin.end +
                                                             heightUsed, desiredHeight );
 
   child->Measure( childWidthMeasureSpec, childHeightMeasureSpec );
@@ -255,7 +304,7 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec(
   auto specMode = measureSpec.GetMode();
   LayoutLength specSize = measureSpec.GetSize();
 
-  auto size = std::max( LayoutLength(0), specSize - padding );
+  auto size = std::max( LayoutLength(0), specSize - padding ); // reduce available size by the owners padding
 
   MeasureSpec::IntType resultSize = 0;
   MeasureSpec::Mode resultMode = MeasureSpec::Mode::UNSPECIFIED;
@@ -265,15 +314,19 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec(
     // Parent has imposed an exact size on us
     case MeasureSpec::Mode::EXACTLY:
     {
-
+      DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec MeasureSpec::Mode::EXACTLY\n");
       if (childDimension == Toolkit::ChildLayoutData::MATCH_PARENT)
       {
+        DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec childDimension MATCH_PARENT\n");
+
         // Child wants to be our size. So be it.
         resultSize = size;
         resultMode = MeasureSpec::Mode::EXACTLY;
       }
       else if (childDimension == Toolkit::ChildLayoutData::WRAP_CONTENT)
       {
+        DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec childDimension WRAP_CONTENT\n");
+
         // Child wants to determine its own size. It can't be
         // bigger than us.
         resultSize = size;
@@ -281,6 +334,7 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec(
       }
       else
       {
+        DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec childDimension UNSPECIFIED\n");
         resultSize = childDimension;
         resultMode = MeasureSpec::Mode::EXACTLY;
       }
@@ -291,6 +345,7 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec(
       // Parent has imposed a maximum size on us
     case MeasureSpec::Mode::AT_MOST:
     {
+      DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec MeasureSpec::Mode::AT_MOST\n");
       if (childDimension == Toolkit::ChildLayoutData::MATCH_PARENT)
       {
         // Child wants to be our size, but our size is not fixed.
@@ -308,7 +363,7 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec(
       else
       {
         // Child wants a specific size... so be it
-        resultSize = childDimension;
+        resultSize = childDimension + padding;
         resultMode = MeasureSpec::Mode::EXACTLY;
       }
 
@@ -318,6 +373,8 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec(
       // Parent asked to see how big we want to be
     case MeasureSpec::Mode::UNSPECIFIED:
     {
+      DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec MeasureSpec::Mode::UNSPECIFIED\n");
+
       if (childDimension == Toolkit::ChildLayoutData::MATCH_PARENT)
       {
         // Child wants to be our size... find out how big it should be
@@ -334,13 +391,16 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec(
       else
       {
         // Child wants a specific size... let him have it
-        resultSize = childDimension;
+        resultSize = childDimension + padding;
         resultMode = MeasureSpec::Mode::EXACTLY;
       }
       break;
     }
   }
 
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec resultSize(%u)\n", resultSize );
+
+
   //noinspection ResourceType
   return MeasureSpec( resultSize, resultMode );
 }
@@ -366,19 +426,6 @@ void LayoutGroup::OnInitialize()
 
 void LayoutGroup::OnRegisterChildProperties( const std::string& containerType )
 {
-  auto typeInfo = TypeRegistry::Get().GetTypeInfo( containerType );
-  if( typeInfo )
-  {
-    Property::IndexContainer indices;
-    typeInfo.GetChildPropertyIndices( indices );
-
-    if( std::find( indices.Begin(), indices.End(), Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION ) ==
-        indices.End() )
-    {
-      ChildPropertyRegistration( typeInfo.GetName(), MARGIN_SPECIFICATION_NAME, Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION, Property::EXTENTS );
-    }
-  }
-
   DoRegisterChildProperties( containerType );
 }
 
@@ -391,6 +438,7 @@ void LayoutGroup::ChildAddedToOwner( Actor child )
 {
   LayoutItemPtr childLayout;
   Toolkit::Control control = Toolkit::Control::DownCast( child );
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner(%s)\n", control.GetName().c_str() );
 
   if( control ) // Can only support adding Controls, not Actors to layout
   {
@@ -405,12 +453,13 @@ void LayoutGroup::ChildAddedToOwner( Actor child )
       childLayout->SetAnimateLayout( IsLayoutAnimated() ); // @todo this essentially forces animation inheritance. Bad?
 
       auto desiredSize = control.GetNaturalSize();
+      DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner desiredSize(%f,%f) (naturalSize)\n", desiredSize.width, desiredSize.height );
+
       childControlDataImpl.SetLayout( *childLayout.Get() );
 
-      // HBoxLayout will apply default layout data for this object
+      // Default layout data for this object
       child.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, LayoutLength::IntType( desiredSize.width ) );
       child.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, LayoutLength::IntType( desiredSize.height ) );
-      child.SetProperty( Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION, Extents() );
     }
 
     Add( *childLayout.Get() );
@@ -434,14 +483,20 @@ void LayoutGroup::ChildRemovedFromOwner( Actor child )
 
 void LayoutGroup::OnOwnerPropertySet( Handle& handle, Property::Index index, Property::Value value )
 {
+  DALI_LOG_INFO( gLogFilter, Debug::Concise, "LayoutGroup::OnOwnerPropertySet\n");
   auto actor = Actor::DownCast( handle );
-  if( actor && index == Actor::Property::LAYOUT_DIRECTION )
+  if( actor &&
+      (
+        index == Actor::Property::LAYOUT_DIRECTION  ||
+        index == Toolkit::Control::Property::PADDING  ||
+        index == Toolkit::Control::Property::MARGIN
+      )
+    )
   {
     RequestLayout();
   }
 }
 
-
 } // namespace Internal
 } // namespace Toolkit
 } // namespace Dali
index e31045f..be5b0ed 100644 (file)
 #include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
 #include <dali-toolkit/internal/layouting/layout-item-data-impl.h>
 
+namespace
+{
+
 #if defined(DEBUG_ENABLED)
-    Debug::Filter* gLayoutFilter = Debug::Filter::New( Debug::Verbose, false, "LOG_LAYOUT" );
+Debug::Filter* gLayoutFilter = Debug::Filter::New( Debug::Verbose, false, "LOG_LAYOUT" );
 #endif
 
-namespace
-{
 const char* WIDTH_SPECIFICATION_NAME( "widthSpecification" );
 const char* HEIGHT_SPECIFICATION_NAME( "heightSpecification" );
 
@@ -121,6 +122,8 @@ void LayoutItem::OnRegisterChildProperties( const std::string& containerType )
 
 void LayoutItem::Measure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec )
 {
+  DALI_LOG_TRACE_METHOD( gLayoutFilter );
+
   const bool forceLayout = mImpl->GetPrivateFlag( Impl::PRIVATE_FLAG_FORCE_LAYOUT );
 
   const bool specChanged =
@@ -199,7 +202,34 @@ void LayoutItem::SetMinimumHeight( LayoutLength minimumHeight )
 
 Extents LayoutItem::GetPadding() const
 {
-  return mImpl->mPadding;
+  Toolkit::Control control = Toolkit::Control::DownCast( mImpl->mOwner );
+  if( control )
+  {
+    Extents padding = control.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
+
+    DALI_LOG_INFO( gLayoutFilter, Debug::Verbose, "LayoutBase::Padding for %s : (%d,%d,%d,%d) \n",
+                   control.GetName().c_str(),
+                   padding.start, padding.end, padding.top, padding.bottom
+                 );
+    return padding;
+  }
+  else
+  {
+    return Extents();
+  }
+}
+
+Extents LayoutItem::GetMargin() const
+{
+  Toolkit::Control control = Toolkit::Control::DownCast( mImpl->mOwner );
+  if ( control )
+  {
+    return control.GetProperty<Extents>( Toolkit::Control::Property::MARGIN );
+  }
+  else
+  {
+    return Extents();
+  }
 }
 
 LayoutLength LayoutItem::GetDefaultSize( LayoutLength size, MeasureSpec measureSpec )
@@ -255,6 +285,11 @@ bool LayoutItem::IsLayoutRequested() const
 
 void LayoutItem::SetMeasuredDimensions( MeasuredSize measuredWidth, MeasuredSize measuredHeight )
 {
+  DALI_LOG_INFO( gLayoutFilter, Debug::Verbose, "LayoutBase::SetMeasuredDimensions width(%d) height(%d) \n",
+                                                 MeasureSpec::IntType( measuredWidth.GetSize() ),
+                                                 MeasureSpec::IntType( measuredHeight.GetSize() )
+               );
+
   mImpl->SetPrivateFlag( Impl::PRIVATE_FLAG_MEASURED_DIMENSION_SET );
   mImpl->mMeasuredWidth = measuredWidth;
   mImpl->mMeasuredHeight = measuredHeight;
index fb12913..e91e7f9 100644 (file)
@@ -289,11 +289,17 @@ public:
   LayoutLength GetMinimumHeight() const;
 
   /**
-   * Get the padding information
+   * Get the padding information.
    * @return The padding information
    */
   Extents GetPadding() const;
 
+  /**
+   * Get the margin information.
+   * @return The margin information
+   */
+  Extents GetMargin() const;
+
 protected:
   /**
    * @brief Allow directly deriving classes to remove layout children when unparented
@@ -307,7 +313,6 @@ protected:
    */
   virtual void OnRegisterChildProperties( const std::string& containerType );
 
-
   /**
    * @brief Measure the layout and its content to determine the measured width and the
    * measured height.
index ca86db6..0caf08d 100644 (file)
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
 
-
+namespace
+{
 #if defined(DEBUG_ENABLED)
 static Debug::Filter* gLogFilter = Debug::Filter::New( Debug::Concise, false, "LOG_LAYOUT" );
 #endif
+}
 
 namespace Dali
 {
@@ -106,6 +108,8 @@ void HboxLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeas
   DALI_LOG_INFO( gLogFilter, Debug::Concise, oss.str().c_str() );
 #endif
 
+  DALI_LOG_INFO( gLogFilter, Debug::Concise, "HboxLayout::OnMeasure widthSize(%d) \n", widthMeasureSpec.GetSize());
+
   auto widthMode = widthMeasureSpec.GetMode();
   auto heightMode = heightMeasureSpec.GetMode();
   bool isExactly = (widthMode == MeasureSpec::Mode::EXACTLY);
@@ -128,9 +132,12 @@ void HboxLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeas
       auto childOwner = childLayout->GetOwner();
       auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
 
-      MeasureChildWithMargins( childLayout, widthMeasureSpec, 0, heightMeasureSpec, 0 );
+      MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec );
       auto childWidth = childLayout->GetMeasuredWidth();
-      auto childMargin = childOwner.GetProperty<Extents>( Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION );
+      auto childMargin = childLayout->GetMargin();
+
+      DALI_LOG_INFO( gLogFilter, Debug::Verbose, "HboxLayout::OnMeasure childWidth(%d)\n", MeasureSpec::IntType( childWidth ) );
+
       auto length = childWidth + LayoutLength::IntType(childMargin.start + childMargin.end);
 
       auto cellPadding = i<GetChildCount()-1 ? mCellPadding.width: 0;
@@ -265,8 +272,7 @@ void HboxLayout::OnLayout( bool changed, LayoutLength left, LayoutLength top, La
       auto childWidth = childLayout->GetMeasuredWidth();
       auto childHeight = childLayout->GetMeasuredHeight();
 
-      auto childOwner = childLayout->GetOwner();
-      auto childMargin = childOwner.GetProperty<Extents>( Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION );
+      auto childMargin = childLayout->GetMargin();
 
       childTop = LayoutLength(padding.top) + ((childSpace - childHeight) / 2) + childMargin.top - childMargin.bottom;
 
index 90f125b..0ca1847 100644 (file)
 
 using namespace Dali;
 
+namespace
+{
+
 #if defined(DEBUG_ENABLED)
 static Debug::Filter* gLogFilter = Debug::Filter::New( Debug::Concise, false, "LOG_LAYOUT" );
 #endif
 
+}
+
 namespace Dali
 {
 namespace Toolkit
@@ -105,7 +110,9 @@ void LayoutController::MeasureHierarchy( Actor root, MeasureSpec widthSpec, Meas
   Toolkit::Control control = Toolkit::Control::DownCast( root );
   if( control )
   {
+    DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutController::Measuring leaf\n" );
     Internal::Control& controlImpl = GetImplementation( control );
+
     Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
     LayoutItemPtr layout = controlDataImpl.GetLayout();
 
@@ -116,6 +123,7 @@ void LayoutController::MeasureHierarchy( Actor root, MeasureSpec widthSpec, Meas
   }
   else
   {
+    DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutController::Measuring (%u) children\n", root.GetChildCount() );
     // Depth first descent through actor children
     for( unsigned int i = 0, count = root.GetChildCount(); i < count; ++i )
     {
@@ -130,17 +138,20 @@ void LayoutController::PerformLayout( Actor root, int left, int top, int right,
   Toolkit::Control control = Toolkit::Control::DownCast( root );
   if( control )
   {
+    DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutController::PerformLayout on leaf\n" );
     Internal::Control& controlImpl = GetImplementation( control );
     Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
     LayoutItemPtr layout = controlDataImpl.GetLayout();
 
     if( layout )
     {
+      DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutController::PerformLayout on layout\n" );
       layout->Layout( left, top, right, bottom );
     }
   }
   else
   {
+    DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutController::PerformLayout (%u) children\n", root.GetChildCount() );
     // Depth first descent through actor children
     for( unsigned int i = 0, count = root.GetChildCount(); i < count; ++i )
     {
index d3b394d..cd0460d 100644 (file)
@@ -41,7 +41,7 @@ LayoutItem::Impl::Impl()
   mBottom( 0 ),
   mViewFlags( 0 ),
   mPrivateFlags( 0 ),
-  mAnimated(false)
+  mAnimated( false )
 {
 }
 
index 3758460..0e5c0e7 100644 (file)
@@ -46,9 +46,6 @@ public:
   MeasuredSize mMeasuredWidth;
   MeasuredSize mMeasuredHeight;
 
-  Extents mMargin; ///< Distances in pixels from the edges of this view to this view's parent.
-  Extents mPadding; ///< Distances in pixels from the edges of this view to this view's content.
-
   LayoutLength mLeft;
   LayoutLength mRight;
   LayoutLength mTop;
index 56fb230..3097a21 100644 (file)
@@ -17,7 +17,6 @@
 //CLASS HEADER
 #include <dali-toolkit/internal/layouting/vbox-layout-impl.h>
 
-//EXTERNAL HEADERS
 //INTERNAL HEADERS
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/common/extents.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
 
-
+namespace
+{
 #if defined(DEBUG_ENABLED)
 static Debug::Filter* gLogFilter = Debug::Filter::New( Debug::Concise, false, "LOG_LAYOUT" );
 #endif
+}
 
 namespace Dali
 {
@@ -165,7 +166,6 @@ void VboxLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeas
       alternativeMaxWidth = std::max( alternativeMaxWidth, matchWidthLocally ? marginWidth : childWidth );
     }
   }
-
   Extents padding = GetPadding();
   mTotalLength += padding.top + padding.bottom;
   auto heightSize = mTotalLength;
@@ -223,7 +223,6 @@ void VboxLayout::ForceUniformWidth( int count, MeasureSpec heightMeasureSpec )
 
 void VboxLayout::OnLayout( bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom )
 {
-  auto owner = GetOwner();
   Extents padding = GetPadding();
 
   LayoutLength childTop( 0 );