[5.0] Add animation workaround in LayoutGroup.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / layouting / layout-group-impl.cpp
index 06305bd..d088a5a 100755 (executable)
@@ -59,6 +59,7 @@ LayoutGroup::~LayoutGroup()
 {
   // An object with a unique_ptr to an opaque structure must define it's destructor in the translation unit
   // where the opaque structure is defined. It cannot use the default method in the header file.
+  RemoveAll();
 }
 
 Toolkit::LayoutGroup::LayoutId LayoutGroup::Add( LayoutItem& child )
@@ -349,7 +350,7 @@ void LayoutGroup::MeasureChild( LayoutItemPtr child,
   // Get last stored width and height specifications for the child
   auto desiredWidth = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
   auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
-  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChild desiredWidth(%d) desiredHeight(%d)\n", desiredWidth, desiredHeight );
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChild child WIDTH_SPEC(%d) child HEIGHT SPEC(%d)\n", desiredWidth, desiredHeight );
 
   auto padding = GetPadding(); // Padding of this layout's owner, not of the child being measured.
 
@@ -373,13 +374,13 @@ void LayoutGroup::MeasureChildWithMargins( LayoutItemPtr child,
 
   auto padding = GetPadding(); // Padding of this layout's owner, not of the child being measured.
 
-  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins desiredWidth(%d)\n",  desiredWidth );
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins child WIDTH_SPEC(%d)\n",  desiredWidth );
 
   MeasureSpec childWidthMeasureSpec = GetChildMeasureSpec( parentWidthMeasureSpec,
                                                            LayoutLength( padding.start + padding.end ) +
                                                            widthUsed, desiredWidth );
 
-  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins desiredHeight(%d)\n",  desiredHeight );
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins child HEIGHT_SPEC(%d)\n",  desiredHeight );
 
   MeasureSpec childHeightMeasureSpec = GetChildMeasureSpec( parentHeightMeasureSpec,
                                                             LayoutLength( padding.top + padding.bottom )+
@@ -397,12 +398,14 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec(
   auto specMode = measureSpec.GetMode();
   LayoutLength specSize = measureSpec.GetSize();
 
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec childDimension(%f)\n", childDimension.AsInteger() );
+
   LayoutLength size = std::max( LayoutLength(0), specSize - padding ); // reduce available size by the owners padding
 
   LayoutLength resultSize = 0;
   MeasureSpec::Mode resultMode = MeasureSpec::Mode::UNSPECIFIED;
 
-  switch( specMode )
+  switch( specMode ) // Parents specMode
   {
     // Parent has imposed an exact size on us
     case MeasureSpec::Mode::EXACTLY:
@@ -512,7 +515,6 @@ 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() )
@@ -552,7 +554,7 @@ void LayoutGroup::OnInitialize()
       }
     }
 
-    RequestLayout( Dali::Toolkit::LayoutTransitionData::LayoutTransitionType::ON_OWNER_SET );
+    RequestLayout( Dali::Toolkit::LayoutTransitionData::Type::ON_OWNER_SET );
   }
 }
 
@@ -571,7 +573,6 @@ void LayoutGroup::OnUnparent()
   {
     DevelActor::ChildAddedSignal( control ).Disconnect( mSlotDelegate, &LayoutGroup::ChildAddedToOwner );
     DevelActor::ChildRemovedSignal( control ).Disconnect( mSlotDelegate, &LayoutGroup::ChildRemovedFromOwner );
-    DevelActor::ChildOrderChangedSignal( control ).Disconnect( mSlotDelegate, &LayoutGroup::ChildOrderChanged );
     DevelHandle::PropertySetSignal( control ).Disconnect( mSlotDelegate, &LayoutGroup::OnOwnerPropertySet );
   }
 }
@@ -585,7 +586,7 @@ void LayoutGroup::RemoveChild( LayoutItem& item )
 void LayoutGroup::ChildAddedToOwner( Actor child )
 {
   ChildAddedToOwnerImpl( child );
-  RequestLayout( Dali::Toolkit::LayoutTransitionData::LayoutTransitionType::ON_CHILD_ADD );
+  RequestLayout( Dali::Toolkit::LayoutTransitionData::Type::ON_CHILD_ADD, child, Actor() );
 }
 
 void LayoutGroup::ChildAddedToOwnerImpl( Actor child )
@@ -633,14 +634,21 @@ void LayoutGroup::ChildAddedToOwnerImpl( Actor child )
       Vector3 size = child.GetTargetSize();
       // If the size of the control is set explicitly make sure that the control size
       // stays the same after the layout except it is over written with match parent specs.
-      if ( size.x != 0 )
+
+      auto childControl = Toolkit::Control::DownCast(childLayout->GetOwner());
+
+      bool setWidthExplictly = ( childControl.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ) > 0  );
+      if ( size.x != 0 || setWidthExplictly )
       {
-        childLayout->SetMinimumWidth( size.x );
+        DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner SetTargetWidth(%f)\n", size.x );
+        childLayout->SetTargetWidth( size.x );
       }
 
-      if ( size.y != 0 )
+      bool setHeightExplcitly = ( childControl.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ) > 0 );
+      if ( size.y != 0 || setHeightExplcitly )
       {
-        childLayout->SetMinimumHeight( size.y );
+        DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner SetTargetHeight(%f)\n", size.y);
+        childLayout->SetTargetHeight( size.y );
       }
       // Default layout data will be generated by Add().
     }
@@ -670,7 +678,7 @@ void LayoutGroup::ChildRemovedFromOwner( Actor child )
     if( childLayout )
     {
       Remove( *childLayout.Get() );
-      RequestLayout( Dali::Toolkit::LayoutTransitionData::LayoutTransitionType::ON_CHILD_REMOVE );
+      RequestLayout( Dali::Toolkit::LayoutTransitionData::Type::ON_CHILD_REMOVE, child, Actor() );
     }
   }
 }
@@ -784,11 +792,13 @@ void LayoutGroup::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMea
         // Check below will be true for legacy containers and controls with layout required set.
         // Other layouts will have their own OnMeasure (a checked requirement) hence not execute LayoutGroup::OnMeasure.
         // Controls which have set layout required will not be legacy controls hence should not have a ResizePolicy set.
-        if( childControl.GetChildCount() > 0 )
+        // Only need to map the resize policy the first time as the Layouting system will then set it to FIXED.
+        if( childControl.GetChildCount() > 0 && ! mImpl->mResizePolicyMapped )
         {
           // First pass, Static mappings that are not dependant on parent
           SizeNegotiationMapper::SetLayoutParametersUsingResizePolicy( childControl, childLayout, Dimension::WIDTH );
           SizeNegotiationMapper::SetLayoutParametersUsingResizePolicy( childControl, childLayout, Dimension::HEIGHT );
+          mImpl->mResizePolicyMapped = true;
         }
 
         // Second pass, if any mappings were not possible due to parent size dependancies then calculate an exact desired size for child
@@ -890,6 +900,15 @@ void LayoutGroup::OnLayout( bool changed, LayoutLength left, LayoutLength top, L
     {
 
       auto childOwner = childLayout->GetOwner();
+      if( !childLayout->IsLayoutAnimated() )
+      {
+        Actor actor = Actor::DownCast( childOwner );
+        if ( actor && DevelActor::IsPositionOrSizeCurrentlyAnimating( actor ) )
+        {
+          continue;
+        }
+      }
+
       LayoutLength childWidth = childLayout->GetMeasuredWidth();
       LayoutLength childHeight = childLayout->GetMeasuredHeight();
       Extents childMargin = childLayout->GetMargin();