+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 );
+ }
+ }
+}
+
+void LayoutGroup::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec )
+{
+ auto childCount = GetChildCount();
+
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose,
+ "LayoutGroup::OnMeasure Actor Id:" << Actor::DownCast(GetOwner()).GetId() <<
+ " Owner:" << Actor::DownCast(GetOwner()).GetName() <<
+ " Child Count:" << childCount <<
+ " MeasureSpecs( width:"<<widthMeasureSpec<<", height:"<<heightMeasureSpec );
+
+ auto widthMode = widthMeasureSpec.GetMode();
+ auto heightMode = heightMeasureSpec.GetMode();
+ LayoutLength widthSpecSize = widthMeasureSpec.GetSize();
+ LayoutLength heightSpecSize = heightMeasureSpec.GetSize();
+
+ bool exactWidth ( false );
+ bool exactHeight ( false );
+
+ // Layouting behaviour
+ // EXACT, width and height as provided.
+ // MATCH_PARENT, width and height that of parent
+ // WRAP_CONTENT, take width of widest child and height size of longest child (within given limit)
+ // UNSPECIFIED, take width of widest child and height size of longest child.
+
+ LayoutLength layoutWidth( 0 );
+ LayoutLength layoutHeight( 0 );
+
+ // If LayoutGroup has children then measure children to get max dimensions
+ if ( childCount > 0 )
+ {
+ for( unsigned int i=0; i<childCount; ++i )
+ {
+ auto childLayout = GetChildAt( i );
+ if( childLayout )
+ {
+ auto childControl = Toolkit::Control::DownCast(childLayout->GetOwner());
+
+ // If child control has children check if a ResizePolicy is set on it. A LayoutItem could be a legacy container.
+ // A legacy container would need it's ResizePolicy to be applied as a MeasureSpec.
+
+ // 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.
+ // 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
+ if( true == childLayout->IsResizePolicyRequired() ) // No need to test child count as this flag would only be set if control had children.
+ {
+ // Get last stored width and height specifications for the child
+ LayoutLength desiredWidth = childControl.GetProperty<float>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
+ LayoutLength desiredHeight = childControl.GetProperty<float>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
+
+ DALI_LOG_INFO( gLogFilter, Debug::General, "LayoutGroup::MeasureChild Initial desired size pre ResizePolicy(%f,%f)\n", desiredWidth.AsInteger(), desiredHeight.AsInteger() );
+
+ childLayout->SetResizePolicyRequired( false ); // clear flag incase in case of changes before next Measure
+ SizeNegotiationMapper::GetSizeofChildForParentDependentResizePolicy( childControl, widthMeasureSpec, heightMeasureSpec, desiredWidth, desiredHeight );
+
+ // Parent dependant ResizePolicies become exact sizes so are now set on the child before it's measured.
+ childControl.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, desiredWidth.AsInteger() );
+ childControl.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, desiredHeight.AsInteger() );
+
+ DALI_LOG_INFO( gLogFilter, Debug::General, " LayoutGroup::OnMeasure ResizePolicy Required resulting size(%f,%f)\n", desiredWidth.AsInteger(), desiredHeight.AsInteger() );
+ }
+
+ // Get size of child
+ MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec );
+ LayoutLength childWidth = childLayout->GetMeasuredWidth();
+ LayoutLength childHeight = childLayout->GetMeasuredHeight();
+
+ Extents childMargin = childLayout->GetMargin();
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure child " << childControl.GetName().c_str() << " width[" << childWidth << "] height[" << childHeight << "]\n" );
+
+ layoutWidth = std::max( layoutWidth, childWidth + childMargin.start + childMargin.end );
+ layoutHeight = std::max( layoutHeight, childHeight + childMargin.top + childMargin.bottom );
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure calculated child width[" << layoutWidth << "] height[" << layoutHeight << "]\n" );
+ }
+ else
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure Not a layout\n" );
+ }
+ }
+
+ Extents padding = GetPadding();
+ layoutWidth += padding.start + padding.end;
+ layoutHeight += padding.top + padding.bottom;
+ }
+ else
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure Getting default size as a leaf\n" );
+ // LayoutGroup does not contain any children so must be a leaf
+ layoutWidth = GetDefaultSize( GetSuggestedMinimumWidth(), widthMeasureSpec );
+ layoutHeight = GetDefaultSize( GetSuggestedMinimumHeight(), heightMeasureSpec );
+ }
+
+ // Can't exceed specified width
+ if( widthMode == MeasureSpec::Mode::EXACTLY )
+ {
+ exactWidth = true;
+ }
+ else if ( widthMode == MeasureSpec::Mode::AT_MOST )
+ {
+ layoutWidth = std::min( layoutWidth, widthSpecSize );
+ }
+
+ // Can't exceed specified height
+ if( heightMode == MeasureSpec::Mode::EXACTLY )
+ {
+ exactHeight = true;
+ }
+ else if ( heightMode == MeasureSpec::Mode::AT_MOST )
+ {
+ layoutHeight = std::min( layoutHeight, heightSpecSize );
+ }
+
+ layoutWidth = std::max( layoutWidth, GetSuggestedMinimumWidth() );
+ layoutHeight = std::max( layoutHeight, GetSuggestedMinimumHeight() );
+
+ if( exactWidth )
+ {
+ layoutWidth = widthSpecSize;
+ }
+
+ if( exactHeight )
+ {
+ layoutHeight = heightSpecSize;
+ }
+
+ DALI_LOG_STREAM( gLogFilter, Debug::General, "LayoutGroup::OnMeasure Measured size(" << layoutWidth << "," << layoutHeight << ") for : " << Actor::DownCast(GetOwner()).GetName() << " \n" );
+ SetMeasuredDimensions( MeasuredSize( layoutWidth ), MeasuredSize( layoutHeight ) );
+}
+
+void LayoutGroup::OnLayout( bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom )
+{
+ auto count = GetChildCount();
+
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup OnLayout owner:" << ( ( Toolkit::Control::DownCast(GetOwner())) ? Toolkit::Control::DownCast(GetOwner()).GetName() : "invalid" ) << " childCount:" << count );
+
+ for( unsigned int childIndex = 0; childIndex < count; childIndex++)
+ {
+ LayoutItemPtr childLayout = GetChildAt( childIndex );
+ if( childLayout != nullptr )
+ {
+
+ 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();
+ auto control = Toolkit::Control::DownCast( childOwner );
+ Extents padding = GetPadding();
+
+ auto childPosition = control.GetProperty< Vector3 >( Actor::Property::POSITION );
+ auto anchorPoint = control.GetProperty< Vector3 >( Actor::Property::ANCHOR_POINT );
+
+ DALI_LOG_STREAM( gLogFilter, Debug::General, "LayoutGroup::OnLayout child[" << control.GetName() <<
+ "] position(" << childPosition << ") child width[" << childWidth << "] height[" << childHeight << "]\n" );
+
+ // Margin and Padding only supported when child anchor point is TOP_LEFT.
+ int paddingAndMarginOffsetX = ( AnchorPoint::TOP_LEFT == anchorPoint ) ? ( padding.top + childMargin.top ) : 0;
+ int paddingAndMarginOffsetY = ( AnchorPoint::TOP_LEFT == anchorPoint ) ? ( padding.start + childMargin.start ) : 0;
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnLayout paddingMargin offset(%d,%d)\n", paddingAndMarginOffsetX, paddingAndMarginOffsetY );
+
+ LayoutLength childLeft = childPosition.x + paddingAndMarginOffsetX;
+ LayoutLength childTop = childPosition.y + paddingAndMarginOffsetY;
+
+ childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight );
+ }
+ }
+}
+
+