Inherit parent's layout animation 96/182196/2
authorHeeyong Song <heeyong.song@samsung.com>
Thu, 21 Jun 2018 07:01:11 +0000 (16:01 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Thu, 21 Jun 2018 07:16:13 +0000 (16:16 +0900)
Change-Id: I049b087506c4aa1ed286b8aaf797709256b78e8e

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

index b15a2e8..4246d16 100644 (file)
@@ -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)
index fd30091..428ac89 100644 (file)
@@ -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
index f827c30..27363aa 100644 (file)
@@ -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
 
index 409ff46..4213cd8 100644 (file)
@@ -85,6 +85,8 @@ void LayoutItem::Unparent()
 void LayoutItem::SetAnimateLayout( bool animateLayout )
 {
   mImpl->mAnimated = animateLayout;
+
+  OnAnimationStateChanged( animateLayout );
 }
 
 bool LayoutItem::IsLayoutAnimated() const
index 8e4cdf3..ce5250a 100644 (file)
@@ -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.