Use Actor target size for default layout. 84/182384/2
authorAnton Obzhirov <a.obzhirov@samsung.com>
Fri, 22 Jun 2018 10:49:23 +0000 (11:49 +0100)
committerAnton Obzhirov <a.obzhirov@samsung.com>
Mon, 25 Jun 2018 13:46:58 +0000 (14:46 +0100)
Change-Id: I0497f5e3284e6a5e733d5dbf9ebb13c7562ba7ab

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

index 75b42b8..5ba721b 100644 (file)
@@ -1192,3 +1192,37 @@ int UtcDaliLayouting_RelayoutOnChildOrderChanged(void)
 
   END_TEST;
 }
+
+int UtcDaliLayouting_HboxLayout_TargetSize(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliLayouting_HboxLayout07 - Set target size on leaf");
+
+  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 ) );
+  for( auto&& iter : controls )
+  {
+    iter.SetSize( 100, 100 );
+    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 from left to right.
+  // hbox left justifies elements
+  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[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  END_TEST;
+}
index 18dd1d6..67a673c 100644 (file)
@@ -470,6 +470,18 @@ void LayoutGroup::ChildAddedToOwner( Actor child )
 #endif
       childControlDataImpl.SetLayout( *childLayout.Get() );
 
+      Vector3 size = child.GetTargetSize();
+      // If the size of the control is set explicitly make sure that the control size
+      // stays the same after the layout except it is over written with match parent specs.
+      if ( size.x != 0 )
+      {
+        childLayout->SetMinimumWidth( size.x );
+      }
+
+      if ( size.y != 0 )
+      {
+        childLayout->SetMinimumHeight( size.y );
+      }
       // Default layout data will be generated by Add().
     }
     else