From 6e19027ba207adc974995d39b17197915f60d92e Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Thu, 21 Jun 2018 16:01:11 +0900 Subject: [PATCH] Inherit parent's layout animation Change-Id: I049b087506c4aa1ed286b8aaf797709256b78e8e --- .../src/dali-toolkit/utc-Dali-Layouting.cpp | 46 ++++++++++++++++++++++ .../devel-api/layouting/layout-group-impl.cpp | 23 +++++++++++ .../devel-api/layouting/layout-group-impl.h | 5 +++ .../devel-api/layouting/layout-item-impl.cpp | 2 + .../devel-api/layouting/layout-item-impl.h | 5 +++ 5 files changed, 81 insertions(+) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp index b15a2e8..4246d16 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp @@ -593,6 +593,52 @@ int UtcDaliLayouting_HboxLayout07(void) END_TEST; } +int UtcDaliLayouting_HboxLayout08(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliLayouting_HboxLayout08 - Test layout animation"); + + Stage stage = Stage::GetCurrent(); + + auto rootControl = Control::New(); + auto absoluteLayout = AbsoluteLayout::New(); + absoluteLayout.SetAnimateLayout( true ); + DevelControl::SetLayout( rootControl, absoluteLayout ); + rootControl.SetName( "AbsoluteLayout" ); + stage.Add( rootControl ); + + Control control1 = CreateLeafControl( 40, 40 ); + rootControl.Add( control1 ); + + auto hbox = Control::New(); + auto hboxLayout = LinearLayout::New(); + hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL ); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "HBox" ); + + Control control2 = CreateLeafControl( 40, 40 ); + hbox.Add( control2 ); + + hbox.SetParentOrigin( ParentOrigin::CENTER ); + hbox.SetAnchorPoint( AnchorPoint::CENTER ); + rootControl.Add( hbox ); + + DALI_TEST_EQUALS( absoluteLayout.IsLayoutAnimated(), true, TEST_LOCATION ); + DALI_TEST_EQUALS( DevelControl::GetLayout( control1 ).IsLayoutAnimated(), true, TEST_LOCATION ); + DALI_TEST_EQUALS( hboxLayout.IsLayoutAnimated(), false, TEST_LOCATION ); + DALI_TEST_EQUALS( DevelControl::GetLayout( control2 ).IsLayoutAnimated(), false, TEST_LOCATION ); + + hboxLayout.SetAnimateLayout( true ); + absoluteLayout.SetAnimateLayout( false ); + + DALI_TEST_EQUALS( absoluteLayout.IsLayoutAnimated(), false, TEST_LOCATION ); + DALI_TEST_EQUALS( DevelControl::GetLayout( control1 ).IsLayoutAnimated(), false, TEST_LOCATION ); + DALI_TEST_EQUALS( hboxLayout.IsLayoutAnimated(), true, TEST_LOCATION ); + DALI_TEST_EQUALS( DevelControl::GetLayout( control2 ).IsLayoutAnimated(), true, 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 fd30091..428ac89 100644 --- a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp +++ b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp @@ -471,6 +471,15 @@ void LayoutGroup::ChildAddedToOwner( Actor child ) // Default layout data will be generated by Add(). } + else + { + LayoutGroupPtr layoutGroup( dynamic_cast< LayoutGroup* >( childLayout.Get() ) ); + if( !layoutGroup ) + { + // Set only in case of leaf children + childLayout->SetAnimateLayout( IsLayoutAnimated() ); + } + } Add( *childLayout.Get() ); } @@ -507,6 +516,20 @@ void LayoutGroup::OnOwnerPropertySet( Handle& handle, Property::Index index, Pro } } +void LayoutGroup::OnAnimationStateChanged( bool animateLayout ) +{ + // Change children's animation state + for( auto&& child : mImpl->mChildren ) + { + LayoutGroupPtr parentGroup( dynamic_cast< LayoutGroup* >( child.child.Get() ) ); + if( !parentGroup ) + { + // Change state only in case of leaf children + child.child->SetAnimateLayout( animateLayout ); + } + } +} + } // namespace Internal } // namespace Toolkit } // namespace Dali diff --git a/dali-toolkit/devel-api/layouting/layout-group-impl.h b/dali-toolkit/devel-api/layouting/layout-group-impl.h index f827c30..27363aa 100644 --- a/dali-toolkit/devel-api/layouting/layout-group-impl.h +++ b/dali-toolkit/devel-api/layouting/layout-group-impl.h @@ -267,6 +267,11 @@ private: */ void OnSetChildProperties( Handle& handle, Property::Index index, Property::Value value ); + /** + * @brief Called when a layer animation state is changed. + */ + void OnAnimationStateChanged( bool animateLayout ) override final; + public: class Impl; // Class declaration is public so we can add devel API's in the future diff --git a/dali-toolkit/devel-api/layouting/layout-item-impl.cpp b/dali-toolkit/devel-api/layouting/layout-item-impl.cpp index 409ff46..4213cd8 100644 --- a/dali-toolkit/devel-api/layouting/layout-item-impl.cpp +++ b/dali-toolkit/devel-api/layouting/layout-item-impl.cpp @@ -85,6 +85,8 @@ void LayoutItem::Unparent() void LayoutItem::SetAnimateLayout( bool animateLayout ) { mImpl->mAnimated = animateLayout; + + OnAnimationStateChanged( animateLayout ); } bool LayoutItem::IsLayoutAnimated() const diff --git a/dali-toolkit/devel-api/layouting/layout-item-impl.h b/dali-toolkit/devel-api/layouting/layout-item-impl.h index 8e4cdf3..ce5250a 100644 --- a/dali-toolkit/devel-api/layouting/layout-item-impl.h +++ b/dali-toolkit/devel-api/layouting/layout-item-impl.h @@ -419,6 +419,11 @@ protected: */ virtual void OnInitialize(); + /** + * @brief Called when a layer animation state is changed. + */ + virtual void OnAnimationStateChanged( bool animateLayout ) {} + private: /** * @brief Called to change the size of the layout. -- 2.7.4