From: David Steele Date: Thu, 21 Jun 2018 21:08:23 +0000 (+0100) Subject: Changed Control::SetLayout to handle empty layouts X-Git-Tag: dali_1.3.31~6 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=refs%2Fchanges%2F56%2F182256%2F2 Changed Control::SetLayout to handle empty layouts Setting an empty layout now removes the layout from the control and unparents it's children from that layout, orphaning them (removes them from the layout hierarchy - they will no longer get measured/laid out). Change-Id: Ice74ad251111f59c34b65f233ad288c412bb6883 Signed-off-by: David Steele --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp index 714a4eb..a9712d0 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp @@ -1447,3 +1447,58 @@ int UtcDaliLayouting_HboxLayout_TargetSize(void) END_TEST; } + + +int UtcDaliLayouting_RemoveLayout01(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliLayouting_RemoveLayout"); + + Stage stage = Stage::GetCurrent(); + + auto rootControl = Control::New(); + auto absoluteLayout = AbsoluteLayout::New(); + DevelControl::SetLayout( rootControl, absoluteLayout ); + rootControl.SetName( "AbsoluteLayout" ); + stage.Add( rootControl ); + + auto hbox = Control::New(); + auto hboxLayout = LinearLayout::New(); + hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL ); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "HBox" ); + + std::vector< Control > controls; + controls.push_back( CreateLeafControl( 40, 40 ) ); + controls.push_back( CreateLeafControl( 60, 40 ) ); + + for( auto&& iter : controls ) + { + hbox.Add( iter ); + } + hbox.SetParentOrigin( ParentOrigin::CENTER ); + hbox.SetAnchorPoint( AnchorPoint::CENTER ); + rootControl.Add( hbox ); + + tet_infoline("Layout as normal"); + application.SendNotification(); + application.Render(); + + tet_infoline("Set an empty layout on hbox container"); + LinearLayout emptyLayout; + DevelControl::SetLayout( hbox, emptyLayout ); + + tet_infoline("Run another layout"); + application.SendNotification(); + application.Render(); + + tet_infoline("Check leaf controls haven't moved"); + + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::POSITION ), Vector3( 40.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} diff --git a/dali-toolkit/devel-api/controls/control-devel.cpp b/dali-toolkit/devel-api/controls/control-devel.cpp index 29ceb14..a4685ff 100755 --- a/dali-toolkit/devel-api/controls/control-devel.cpp +++ b/dali-toolkit/devel-api/controls/control-devel.cpp @@ -133,7 +133,14 @@ void SetLayout( Control control, Toolkit::LayoutItem layout ) { Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control ); Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( internalControl ); - controlDataImpl.SetLayout( GetImplementation( layout ) ); + if( layout ) + { + controlDataImpl.SetLayout( GetImplementation( layout ) ); + } + else + { + controlDataImpl.RemoveLayout(); + } } } // namespace DevelControl diff --git a/dali-toolkit/internal/controls/control/control-data-impl.cpp b/dali-toolkit/internal/controls/control/control-data-impl.cpp index 73769c8..a6d30d9 100755 --- a/dali-toolkit/internal/controls/control/control-data-impl.cpp +++ b/dali-toolkit/internal/controls/control/control-data-impl.cpp @@ -1442,6 +1442,15 @@ void Control::Impl::SetLayout( Toolkit::Internal::LayoutItem& layout ) mLayout->Initialize( controlHandle, controlHandle.GetTypeName() ); // LayoutGroup takes ownership of existing children } +void Control::Impl::RemoveLayout() +{ + if( mLayout ) + { + mLayout->Unparent(); + mLayout.Reset(); + } +} + } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/controls/control/control-data-impl.h b/dali-toolkit/internal/controls/control/control-data-impl.h index 2a06d4c..d2eb48e 100755 --- a/dali-toolkit/internal/controls/control/control-data-impl.h +++ b/dali-toolkit/internal/controls/control/control-data-impl.h @@ -337,6 +337,14 @@ public: */ void SetLayout( Toolkit::Internal::LayoutItem& layout ); + /** + * @brief Remove the layout from this control + * + * @note This does not remove any children from this control, nor does it strip + * layouts from them but it does remove them from the layout hierarchy. + */ + void RemoveLayout(); + private: /**