From 703bc0c9e46c18a3290ba24f64f6237fffc9304f Mon Sep 17 00:00:00 2001 From: Anton Obzhirov Date: Fri, 22 Jun 2018 11:49:23 +0100 Subject: [PATCH] Use Actor target size for default layout. Change-Id: I0497f5e3284e6a5e733d5dbf9ebb13c7562ba7ab --- .../src/dali-toolkit/utc-Dali-Layouting.cpp | 34 ++++++++++++++++++++++ .../devel-api/layouting/layout-group-impl.cpp | 12 ++++++++ 2 files changed, 46 insertions(+) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp index 75b42b8..5ba721b 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp @@ -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( Actor::Property::POSITION ), Vector3( 0.0f, 350.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} diff --git a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp index 18dd1d6..67a673c 100644 --- a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp +++ b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp @@ -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 -- 2.7.4