From 057a5b8dc25bf54f83799c4dda33bba6e8ed698b Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Wed, 20 Jun 2018 15:00:35 +0900 Subject: [PATCH] Fix nested layout issue Change-Id: Ic739aa8787aa972c3fd6752f394537d15c40eb66 --- .../src/dali-toolkit/utc-Dali-Layouting.cpp | 61 ++++++++++++++++++++++ .../devel-api/layouting/layout-group-impl.cpp | 28 ++++++++++ dali-toolkit/devel-api/layouting/layout-group.cpp | 5 ++ .../devel-api/layouting/layout-item-impl.cpp | 5 ++ .../devel-api/layouting/layout-item-impl.h | 5 ++ .../devel-api/layouting/layout-parent-impl.h | 5 ++ 6 files changed, 109 insertions(+) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp index 1be1e66..5fbe1e7 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp @@ -450,6 +450,67 @@ int UtcDaliLayouting_HboxLayout05(void) END_TEST; } +int UtcDaliLayouting_HboxLayout06(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliLayouting_HboxLayout06 - Test nested layouts"); + + 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 ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + // hbox centers elements vertically, it fills test harness stage, which is 480x800. + // hbox left justifies elements + 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 ); + + DALI_TEST_EQUALS( hbox.GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + // Change a layout + auto newHBoxLayout = LinearLayout::New(); + newHBoxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL ); + DevelControl::SetLayout( hbox, newHBoxLayout ); + + hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( hbox.GetProperty( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} + // Padding tests int UtcDaliLayouting_HboxLayout_Padding01(void) diff --git a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp index d6ab337..1f643cc 100644 --- a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp +++ b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp @@ -71,6 +71,8 @@ Toolkit::LayoutGroup::LayoutId LayoutGroup::Add( LayoutItem& child ) childLayout.child = &child; mImpl->mChildren.emplace_back( childLayout ); + child.SetParent( this ); + auto owner = child.GetOwner(); // If the owner does not have any LayoutItem child properties, add them @@ -406,6 +408,20 @@ void LayoutGroup::OnInitialize() DevelActor::ChildAddedSignal( control ).Connect( mSlotDelegate, &LayoutGroup::ChildAddedToOwner ); DevelActor::ChildRemovedSignal( control ).Connect( mSlotDelegate, &LayoutGroup::ChildRemovedFromOwner ); DevelHandle::PropertySetSignal( control ).Connect( mSlotDelegate, &LayoutGroup::OnOwnerPropertySet ); + + if( control.GetParent() ) + { + auto parent = Toolkit::Control::DownCast( control.GetParent() ); + if( parent ) + { + auto parentLayout = Toolkit::LayoutGroup::DownCast( DevelControl::GetLayout( parent ) ); + if( parentLayout ) + { + Internal::LayoutGroup& parentLayoutImpl = GetImplementation( parentLayout ); + parentLayoutImpl.Add( *this ); + } + } + } } } @@ -416,7 +432,19 @@ void LayoutGroup::OnRegisterChildProperties( const std::string& containerType ) void LayoutGroup::OnUnparent() { + // Remove children RemoveAll(); + + // Remove myself from parent + LayoutParent* parent = GetParent(); + if( parent ) + { + LayoutGroupPtr parentGroup( dynamic_cast< LayoutGroup* >( parent ) ); + if( parentGroup ) + { + parentGroup->Remove( *this ); + } + } } void LayoutGroup::ChildAddedToOwner( Actor child ) diff --git a/dali-toolkit/devel-api/layouting/layout-group.cpp b/dali-toolkit/devel-api/layouting/layout-group.cpp index dd36ddc..b13da31 100644 --- a/dali-toolkit/devel-api/layouting/layout-group.cpp +++ b/dali-toolkit/devel-api/layouting/layout-group.cpp @@ -27,6 +27,11 @@ LayoutGroup::LayoutGroup() { } +LayoutGroup LayoutGroup::DownCast( BaseHandle handle ) +{ + return LayoutGroup( dynamic_cast< Dali::Toolkit::Internal::LayoutGroup* >( handle.GetObjectPtr() ) ); +} + LayoutGroup::LayoutId LayoutGroup::Add( LayoutItem& child ) { return GetImplementation( *this ).Add( GetImplementation(child) ); diff --git a/dali-toolkit/devel-api/layouting/layout-item-impl.cpp b/dali-toolkit/devel-api/layouting/layout-item-impl.cpp index f7a6119..409ff46 100644 --- a/dali-toolkit/devel-api/layouting/layout-item-impl.cpp +++ b/dali-toolkit/devel-api/layouting/layout-item-impl.cpp @@ -284,6 +284,11 @@ void LayoutItem::OnLayout( bool changed, LayoutLength left, LayoutLength top, La { } +void LayoutItem::SetParent( LayoutParent* parent ) +{ + mImpl->mLayoutParent = parent; +} + LayoutParent* LayoutItem::GetParent() { return mImpl->mLayoutParent; diff --git a/dali-toolkit/devel-api/layouting/layout-item-impl.h b/dali-toolkit/devel-api/layouting/layout-item-impl.h index e59ca96..fe43f07 100644 --- a/dali-toolkit/devel-api/layouting/layout-item-impl.h +++ b/dali-toolkit/devel-api/layouting/layout-item-impl.h @@ -168,6 +168,11 @@ public: static LayoutLength GetDefaultSize( LayoutLength size, MeasureSpec measureSpec ); /** + * @copydoc LayoutParent::SetParent + */ + virtual void SetParent( LayoutParent* parent ) override; + + /** * @copydoc LayoutParent::GetParent */ virtual LayoutParent* GetParent() override; diff --git a/dali-toolkit/devel-api/layouting/layout-parent-impl.h b/dali-toolkit/devel-api/layouting/layout-parent-impl.h index 392a2ab..4ce1ab0 100644 --- a/dali-toolkit/devel-api/layouting/layout-parent-impl.h +++ b/dali-toolkit/devel-api/layouting/layout-parent-impl.h @@ -34,6 +34,11 @@ class DALI_IMPORT_API LayoutParent { public: /** + * Set the parent of this layout. + */ + virtual void SetParent( LayoutParent* parent ) = 0; + + /** * Get the parent of this layout. */ virtual LayoutParent* GetParent() = 0; -- 2.7.4