Fix crash when Layer added to LayoutGroup
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / layouting / layout-group-impl.cpp
index 1f643cc..7f8d9d0 100644 (file)
@@ -184,7 +184,7 @@ void LayoutGroup::DoRegisterChildProperties( const std::string& containerType )
 
 void LayoutGroup::OnSetChildProperties( Handle& handle, Property::Index index, Property::Value value )
 {
-  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnSetChildProperties\n");
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnSetChildProperties property(%s)\n", handle.GetPropertyName(index).c_str());
 
   if ( ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) &&
          ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
@@ -192,12 +192,11 @@ void LayoutGroup::OnSetChildProperties( Handle& handle, Property::Index index, P
        ( index == Toolkit::Control::Property::MARGIN || index == Toolkit::Control::Property::PADDING ) )
   {
     // If any child properties are set, must perform relayout
-    RequestLayout();
     for( auto&& child : mImpl->mChildren )
     {
       if( child.child->GetOwner() == handle )
       {
-        child.child->SetLayoutRequested();
+        child.child->RequestLayout();
         break;
       }
     }
@@ -407,6 +406,7 @@ void LayoutGroup::OnInitialize()
 
     DevelActor::ChildAddedSignal( control ).Connect( mSlotDelegate, &LayoutGroup::ChildAddedToOwner );
     DevelActor::ChildRemovedSignal( control ).Connect( mSlotDelegate, &LayoutGroup::ChildRemovedFromOwner );
+    DevelActor::ChildOrderChangedSignal( control ).Connect( mSlotDelegate, &LayoutGroup::ChildOrderChanged );
     DevelHandle::PropertySetSignal( control ).Connect( mSlotDelegate, &LayoutGroup::OnOwnerPropertySet );
 
     if( control.GetParent() )
@@ -451,7 +451,8 @@ void LayoutGroup::ChildAddedToOwner( Actor child )
 {
   LayoutItemPtr childLayout;
   Toolkit::Control control = Toolkit::Control::DownCast( child );
-  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner(%s)\n", control.GetName().c_str() );
+
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner control(%s)\n", control?control.GetName().c_str():"Invalid" );
 
   if( control ) // Can only support adding Controls, not Actors to layout
   {
@@ -472,6 +473,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() );
   }
@@ -492,6 +502,16 @@ void LayoutGroup::ChildRemovedFromOwner( Actor child )
   }
 }
 
+void LayoutGroup::ChildOrderChanged()
+{
+  RequestLayout();
+  // Force Children to be relaid out:
+  for( auto&& child : mImpl->mChildren )
+  {
+    child.child->SetLayoutRequested();
+  }
+}
+
 void LayoutGroup::OnOwnerPropertySet( Handle& handle, Property::Index index, Property::Value value )
 {
   DALI_LOG_INFO( gLogFilter, Debug::Concise, "LayoutGroup::OnOwnerPropertySet\n");
@@ -508,6 +528,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