2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
21 #include <dali/public-api/object/type-registry-helper.h>
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/object/handle-devel.h>
24 #include <dali/integration-api/debug.h>
27 #include <dali-toolkit/internal/layouting/layout-group-data-impl.h>
28 #include <dali-toolkit/public-api/controls/control-impl.h>
29 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
33 #if defined(DEBUG_ENABLED)
34 Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_LAYOUT" );
45 LayoutGroup::LayoutGroup()
46 : mImpl( new LayoutGroup::Impl() ),
51 LayoutGroupPtr LayoutGroup::New( Handle& owner )
53 LayoutGroupPtr layoutPtr = new LayoutGroup();
57 LayoutGroup::~LayoutGroup()
59 // An object with a unique_ptr to an opaque structure must define it's destructor in the translation unit
60 // where the opaque structure is defined. It cannot use the default method in the header file.
63 Toolkit::LayoutGroup::LayoutId LayoutGroup::Add( LayoutItem& child )
65 LayoutParent* oldParent = child.GetParent();
68 LayoutGroupPtr parentGroup( dynamic_cast< LayoutGroup* >( oldParent ) );
71 parentGroup->Remove( child );
75 Impl::ChildLayout childLayout;
76 childLayout.layoutId = mImpl->mNextLayoutId++;
77 childLayout.child = &child;
78 mImpl->mChildren.emplace_back( childLayout );
80 child.SetParent( this );
82 auto owner = child.GetOwner();
84 // If the owner does not have any LayoutItem child properties, add them
85 if( ! DevelHandle::DoesCustomPropertyExist( owner, Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ) )
87 // Set default properties for LayoutGroup and LayoutItem.
88 // Deriving classes can override OnChildAdd() to add their own default properties
89 GenerateDefaultChildPropertyValues( owner );
92 // Inform deriving classes that this child has been added
93 OnChildAdd( *childLayout.child.Get() );
95 // Now listen to future changes to the child properties.
96 DevelHandle::PropertySetSignal(owner).Connect( this, &LayoutGroup::OnSetChildProperties );
100 return childLayout.layoutId;
103 void LayoutGroup::Remove( Toolkit::LayoutGroup::LayoutId childId )
105 for( auto iter = mImpl->mChildren.begin() ; iter != mImpl->mChildren.end() ; ++iter )
107 if( iter->layoutId == childId )
109 RemoveChild( *iter->child.Get() );
110 mImpl->mChildren.erase(iter);
117 void LayoutGroup::Remove( LayoutItem& child )
119 for( auto iter = mImpl->mChildren.begin() ; iter != mImpl->mChildren.end() ; ++iter )
121 if( iter->child.Get() == &child )
123 RemoveChild( *iter->child.Get() );
124 mImpl->mChildren.erase(iter);
131 Toolkit::LayoutGroup::LayoutId LayoutGroup::Insert( LayoutItem& target, LayoutItem& child )
133 LayoutParent* oldParent = child.GetParent();
136 LayoutGroupPtr parentGroup( dynamic_cast< LayoutGroup* >( oldParent ) );
139 parentGroup->Remove( child );
143 // Find target position
144 std::vector< Impl::ChildLayout >::iterator position;
145 for( auto iter = mImpl->mChildren.begin(); iter != mImpl->mChildren.end(); ++iter )
147 if( iter->child.Get() == &target )
154 Impl::ChildLayout childLayout;
155 childLayout.layoutId = mImpl->mNextLayoutId++;
156 childLayout.child = &child;
157 mImpl->mChildren.insert( position, childLayout );
159 child.SetParent( this );
161 auto owner = child.GetOwner();
163 // Inform deriving classes that this child has been added
164 OnChildAdd( *childLayout.child.Get() );
166 // Now listen to future changes to the child properties.
167 DevelHandle::PropertySetSignal(owner).Connect( this, &LayoutGroup::OnSetChildProperties );
171 return childLayout.layoutId;
174 Toolkit::LayoutGroup::LayoutId LayoutGroup::Move( LayoutItem& target, LayoutItem& child )
176 // Remove child from the previous position
177 for( auto iter = mImpl->mChildren.begin() ; iter != mImpl->mChildren.end() ; ++iter )
179 if( iter->child.Get() == &child )
181 mImpl->mChildren.erase( iter );
186 // Find target position
187 std::vector< Impl::ChildLayout >::iterator position;
188 for( auto iter = mImpl->mChildren.begin(); iter != mImpl->mChildren.end(); ++iter )
190 if( iter->child.Get() == &target )
197 Impl::ChildLayout childLayout;
198 childLayout.layoutId = mImpl->mNextLayoutId++;
199 childLayout.child = &child;
200 mImpl->mChildren.insert( position, childLayout );
204 return childLayout.layoutId;
207 Toolkit::LayoutGroup::LayoutId LayoutGroup::MoveBack( LayoutItem& child )
209 // Remove child from the previous position
210 for( auto iter = mImpl->mChildren.begin() ; iter != mImpl->mChildren.end() ; ++iter )
212 if( iter->child.Get() == &child )
214 mImpl->mChildren.erase( iter );
219 Impl::ChildLayout childLayout;
220 childLayout.layoutId = mImpl->mNextLayoutId++;
221 childLayout.child = &child;
222 mImpl->mChildren.emplace_back( childLayout );
226 return childLayout.layoutId;
229 void LayoutGroup::RemoveAll()
231 for( auto iter = mImpl->mChildren.begin() ; iter != mImpl->mChildren.end() ; )
233 RemoveChild( *iter->child.Get() );
234 iter = mImpl->mChildren.erase(iter);
238 unsigned int LayoutGroup::GetChildCount() const
240 return mImpl->mChildren.size();
243 LayoutItemPtr LayoutGroup::GetChildAt( unsigned int index ) const
245 DALI_ASSERT_ALWAYS( index < mImpl->mChildren.size() );
246 return mImpl->mChildren[ index ].child;
249 LayoutItemPtr LayoutGroup::GetChild( Toolkit::LayoutGroup::LayoutId childId ) const
251 for( auto&& childLayout : mImpl->mChildren )
253 if( childLayout.layoutId == childId )
255 return childLayout.child;
261 Toolkit::LayoutGroup::LayoutId LayoutGroup::GetChildId( LayoutItem& child ) const
263 for( auto&& childLayout : mImpl->mChildren )
265 if( childLayout.child.Get() == &child )
267 return childLayout.layoutId;
270 return Toolkit::LayoutGroup::UNKNOWN_ID;
273 void LayoutGroup::OnChildAdd( LayoutItem& child )
277 void LayoutGroup::OnChildRemove( LayoutItem& child )
281 void LayoutGroup::DoInitialize()
285 void LayoutGroup::DoRegisterChildProperties( const std::string& containerType )
289 void LayoutGroup::OnSetChildProperties( Handle& handle, Property::Index index, Property::Value value )
291 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnSetChildProperties property(%s)\n", handle.GetPropertyName(index).c_str());
293 if ( ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) &&
294 ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
296 ( index == Toolkit::Control::Property::MARGIN || index == Toolkit::Control::Property::PADDING ) )
298 // If any child properties are set, must perform relayout
299 for( auto&& child : mImpl->mChildren )
301 if( child.child->GetOwner() == handle )
303 child.child->RequestLayout();
310 void LayoutGroup::GenerateDefaultChildPropertyValues( Handle child )
312 child.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION,
313 Toolkit::ChildLayoutData::WRAP_CONTENT );
314 child.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,
315 Toolkit::ChildLayoutData::WRAP_CONTENT );
318 void LayoutGroup::MeasureChildren( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec)
320 for( auto&& child : mImpl->mChildren )
322 //if( (child.mViewFlags & Impl::VISIBILITY_MASK) != Impl::GONE ) // Use owner visibility/enabled/ready
324 MeasureChild( child.child, widthMeasureSpec, heightMeasureSpec );
329 void LayoutGroup::MeasureChild( LayoutItemPtr child,
330 MeasureSpec parentWidthMeasureSpec,
331 MeasureSpec parentHeightMeasureSpec )
333 DALI_LOG_TRACE_METHOD( gLogFilter );
335 auto childOwner = child->GetOwner();
337 auto control = Toolkit::Control::DownCast( childOwner );
339 #if defined( DEBUG_ENABLED )
342 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChild(%s) natural size(%f, %f)\n",
343 control.GetName().c_str(), control.GetNaturalSize().width, control.GetNaturalSize().height );
347 // Get last stored width and height specifications for the child
348 auto desiredWidth = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
349 auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
350 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChild desiredWidth(%d) desiredHeight(%d)\n", desiredWidth, desiredHeight );
352 auto padding = GetPadding(); // Padding of this layout's owner, not of the child being measured.
354 const MeasureSpec childWidthMeasureSpec = GetChildMeasureSpec( parentWidthMeasureSpec,
355 padding.start + padding.end,
357 const MeasureSpec childHeightMeasureSpec = GetChildMeasureSpec( parentHeightMeasureSpec,
358 padding.top + padding.bottom,
361 child->Measure( childWidthMeasureSpec, childHeightMeasureSpec );
364 void LayoutGroup::MeasureChildWithMargins( LayoutItemPtr child,
365 MeasureSpec parentWidthMeasureSpec, LayoutLength widthUsed,
366 MeasureSpec parentHeightMeasureSpec, LayoutLength heightUsed)
368 auto childOwner = child->GetOwner();
369 auto desiredWidth = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
370 auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
372 auto padding = GetPadding(); // Padding of this layout's owner, not of the child being measured.
374 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins desiredWidth(%d)\n", desiredWidth );
376 MeasureSpec childWidthMeasureSpec = GetChildMeasureSpec( parentWidthMeasureSpec,
377 padding.start + padding.end +
378 widthUsed, desiredWidth );
380 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins desiredHeight(%d)\n", desiredHeight );
382 MeasureSpec childHeightMeasureSpec = GetChildMeasureSpec( parentHeightMeasureSpec,
383 padding.top + padding.bottom +
384 heightUsed, desiredHeight );
386 child->Measure( childWidthMeasureSpec, childHeightMeasureSpec );
390 MeasureSpec LayoutGroup::GetChildMeasureSpec(
391 MeasureSpec measureSpec,
392 LayoutLength padding,
393 LayoutLength childDimension )
395 auto specMode = measureSpec.GetMode();
396 LayoutLength specSize = measureSpec.GetSize();
398 auto size = std::max( LayoutLength(0), specSize - padding ); // reduce available size by the owners padding
400 MeasureSpec::IntType resultSize = 0;
401 MeasureSpec::Mode resultMode = MeasureSpec::Mode::UNSPECIFIED;
405 // Parent has imposed an exact size on us
406 case MeasureSpec::Mode::EXACTLY:
408 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec MeasureSpec::Mode::EXACTLY\n");
409 if (childDimension == Toolkit::ChildLayoutData::MATCH_PARENT)
411 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec childDimension MATCH_PARENT\n");
413 // Child wants to be our size. So be it.
415 resultMode = MeasureSpec::Mode::EXACTLY;
417 else if (childDimension == Toolkit::ChildLayoutData::WRAP_CONTENT)
419 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec childDimension WRAP_CONTENT\n");
421 // Child wants to determine its own size. It can't be
424 resultMode = MeasureSpec::Mode::AT_MOST;
428 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec childDimension UNSPECIFIED\n");
429 resultSize = childDimension;
430 resultMode = MeasureSpec::Mode::EXACTLY;
436 // Parent has imposed a maximum size on us
437 case MeasureSpec::Mode::AT_MOST:
439 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec MeasureSpec::Mode::AT_MOST\n");
440 if (childDimension == Toolkit::ChildLayoutData::MATCH_PARENT)
442 // Child wants to be our size, but our size is not fixed.
443 // Constrain child to not be bigger than us.
445 resultMode = MeasureSpec::Mode::AT_MOST;
447 else if (childDimension == Toolkit::ChildLayoutData::WRAP_CONTENT)
449 // Child wants to determine its own size. It can't be
452 resultMode = MeasureSpec::Mode::AT_MOST;
456 // Child wants a specific size... so be it
457 resultSize = childDimension + padding;
458 resultMode = MeasureSpec::Mode::EXACTLY;
464 // Parent asked to see how big we want to be
465 case MeasureSpec::Mode::UNSPECIFIED:
467 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec MeasureSpec::Mode::UNSPECIFIED\n");
469 if (childDimension == Toolkit::ChildLayoutData::MATCH_PARENT)
471 // Child wants to be our size... find out how big it should be
472 resultSize = LayoutItem::Impl::sUseZeroUnspecifiedMeasureSpec ? LayoutLength(0) : size;
473 resultMode = MeasureSpec::Mode::UNSPECIFIED;
475 else if (childDimension == Toolkit::ChildLayoutData::WRAP_CONTENT)
477 // Child wants to determine its own size.... find out how big
479 resultSize = LayoutItem::Impl::sUseZeroUnspecifiedMeasureSpec ? LayoutLength(0) : size;
480 resultMode = MeasureSpec::Mode::UNSPECIFIED;
484 // Child wants a specific size... let him have it
485 resultSize = childDimension + padding;
486 resultMode = MeasureSpec::Mode::EXACTLY;
492 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec resultSize(%u)\n", resultSize );
495 //noinspection ResourceType
496 return MeasureSpec( resultSize, resultMode );
500 void LayoutGroup::OnInitialize()
502 auto control = Toolkit::Control::DownCast( GetOwner() );
506 // Take ownership of existing children
507 for( unsigned int childIndex = 0 ; childIndex < control.GetChildCount(); ++childIndex )
509 ChildAddedToOwner( control.GetChildAt( childIndex ) );
512 DevelActor::ChildAddedSignal( control ).Connect( mSlotDelegate, &LayoutGroup::ChildAddedToOwner );
513 DevelActor::ChildRemovedSignal( control ).Connect( mSlotDelegate, &LayoutGroup::ChildRemovedFromOwner );
514 DevelActor::ChildOrderChangedSignal( control ).Connect( mSlotDelegate, &LayoutGroup::ChildOrderChanged );
515 DevelHandle::PropertySetSignal( control ).Connect( mSlotDelegate, &LayoutGroup::OnOwnerPropertySet );
517 if( control.GetParent() )
519 auto parent = Toolkit::Control::DownCast( control.GetParent() );
522 auto parentLayout = Toolkit::LayoutGroup::DownCast( DevelControl::GetLayout( parent ) );
525 Internal::LayoutGroup& parentLayoutImpl = GetImplementation( parentLayout );
527 unsigned int count = parent.GetChildCount();
528 unsigned int index = static_cast< unsigned int >( control.GetProperty< int >( DevelActor::Property::SIBLING_ORDER ) );
530 // Find insertion position
531 while( ++index < count )
533 auto sibling = Toolkit::Control::DownCast( parent.GetChildAt( index ) );
536 auto siblingLayout = DevelControl::GetLayout( sibling );
539 Internal::LayoutItem& siblingLayoutImpl = GetImplementation( siblingLayout );
540 parentLayoutImpl.Insert( siblingLayoutImpl, *this );
548 parentLayoutImpl.Add( *this );
556 void LayoutGroup::OnRegisterChildProperties( const std::string& containerType )
558 DoRegisterChildProperties( containerType );
561 void LayoutGroup::OnUnparent()
567 void LayoutGroup::RemoveChild( LayoutItem& item )
569 item.SetParent( nullptr );
570 OnChildRemove( item );
573 void LayoutGroup::ChildAddedToOwner( Actor child )
575 LayoutItemPtr childLayout;
576 Toolkit::Control control = Toolkit::Control::DownCast( child );
578 #if defined(DEBUG_ENABLED)
579 auto parent = Toolkit::Control::DownCast( GetOwner() );
580 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner control(%s) owner(%s)\n", control?control.GetName().c_str():"Invalid", parent?parent.GetName().c_str():"Invalid" );
583 if( control ) // Can only support adding Controls, not Actors to layout
585 Internal::Control& childControlImpl = GetImplementation( control );
586 Internal::Control::Impl& childControlDataImpl = Internal::Control::Impl::Get( childControlImpl );
587 childLayout = childControlDataImpl.GetLayout();
591 // If the child doesn't already have a layout, then create a LayoutItem or LayoutGroup for it.
592 // If control behaviour flag set to Layout then set a LayoutGroup.
593 if( DevelControl::IsLayoutingRequired( control ) )
595 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner Creating default LayoutGroup for control:%s\n", control?control.GetName().c_str():"Invalid" );
596 childLayout = LayoutGroup::New( control );
600 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner Creating default LayoutItem for control:%s\n", control?control.GetName().c_str():"Invalid" );
601 childLayout = LayoutItem::New( control );
603 childLayout->SetAnimateLayout( IsLayoutAnimated() ); // @todo this essentially forces animation inheritance. Bad?
605 DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner control:" << control.GetName().c_str() <<
606 " desiredWidth: " << control.GetNaturalSize().width <<
607 " desiredHeight:" << control.GetNaturalSize().height
610 childControlDataImpl.SetLayout( *childLayout.Get() );
612 Vector3 size = child.GetTargetSize();
613 // If the size of the control is set explicitly make sure that the control size
614 // stays the same after the layout except it is over written with match parent specs.
617 childLayout->SetMinimumWidth( size.x );
622 childLayout->SetMinimumHeight( size.y );
624 // Default layout data will be generated by Add().
628 LayoutGroupPtr layoutGroup( dynamic_cast< LayoutGroup* >( childLayout.Get() ) );
631 // Set only in case of leaf children
632 childLayout->SetAnimateLayout( IsLayoutAnimated() );
636 Add( *childLayout.Get() );
640 void LayoutGroup::ChildRemovedFromOwner( Actor child )
642 Toolkit::Control control = Toolkit::Control::DownCast( child );
645 Internal::Control& childControlImpl = GetImplementation( control );
646 Internal::Control::Impl& childControlDataImpl = Internal::Control::Impl::Get( childControlImpl );
647 auto childLayout = childControlDataImpl.GetLayout();
650 Remove( *childLayout.Get() );
655 void LayoutGroup::ChildOrderChanged( Actor child )
657 Toolkit::Control childControl = Toolkit::Control::DownCast( child );
660 Internal::Control& childControlImpl = GetImplementation( childControl );
661 Internal::Control::Impl& childControlDataImpl = Internal::Control::Impl::Get( childControlImpl );
663 auto childLayout = childControlDataImpl.GetLayout();
666 Toolkit::Control control = Toolkit::Control::DownCast( GetOwner() );
667 unsigned int count = control.GetChildCount();
668 unsigned int index = static_cast< unsigned int >( childControl.GetProperty< int >( DevelActor::Property::SIBLING_ORDER ) );
670 // Find insertion position
671 while( ++index < count )
673 auto sibling = Toolkit::Control::DownCast( control.GetChildAt( index ) );
676 auto siblingLayout = DevelControl::GetLayout( sibling );
679 Internal::LayoutItem& siblingLayoutImpl = GetImplementation( siblingLayout );
680 Move( siblingLayoutImpl, *childLayout );
686 MoveBack( *childLayout );
691 void LayoutGroup::OnOwnerPropertySet( Handle& handle, Property::Index index, Property::Value value )
693 DALI_LOG_INFO( gLogFilter, Debug::Concise, "LayoutGroup::OnOwnerPropertySet\n");
694 auto actor = Actor::DownCast( handle );
697 index == Actor::Property::LAYOUT_DIRECTION ||
698 index == Toolkit::Control::Property::PADDING ||
699 index == Toolkit::Control::Property::MARGIN
707 void LayoutGroup::OnAnimationStateChanged( bool animateLayout )
709 // Change children's animation state
710 for( auto&& child : mImpl->mChildren )
712 LayoutGroupPtr parentGroup( dynamic_cast< LayoutGroup* >( child.child.Get() ) );
715 // Change state only in case of leaf children
716 child.child->SetAnimateLayout( animateLayout );
721 void LayoutGroup::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec )
723 auto childCount = GetChildCount();
725 DALI_LOG_STREAM( gLogFilter, Debug::Verbose,
726 "LayoutGroup::OnMeasure Actor Id:" << Actor::DownCast(GetOwner()).GetId() <<
727 " Owner:" << Actor::DownCast(GetOwner()).GetName() <<
728 " Child Count:" << childCount <<
729 " MeasureSpecs( width:"<<widthMeasureSpec<<", height:"<<heightMeasureSpec );
731 auto widthMode = widthMeasureSpec.GetMode();
732 auto heightMode = heightMeasureSpec.GetMode();
733 LayoutLength widthSpecSize = widthMeasureSpec.GetSize();
734 LayoutLength heightSpecSize = heightMeasureSpec.GetSize();
736 bool exactWidth ( false );
737 bool exactHeight ( false );
739 // Default Layouting behaviour if not overridden
740 // EXACT, width and height as provided.
741 // MATCH_PARENT, width and hewidthSpecSizeight that of parent
743 // WRAP_CONTENT, take width of widest child and height size of longest child (within given limit)
744 // UNSPECIFIED, take width of widest child and height size of longest child.
746 LayoutLength layoutWidth( 0 );
747 LayoutLength layoutHeight( 0 );
749 // If LayoutGroup has children then measure children to get max dimensions
750 if ( childCount > 0 )
752 for( unsigned int i=0; i<childCount; ++i )
754 auto childLayout = GetChildAt( i );
757 auto childOwner = childLayout->GetOwner();
760 MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec );
761 auto childWidth = childLayout->GetMeasuredWidth();
762 auto childHeight = childLayout->GetMeasuredHeight();
763 auto childMargin = childLayout->GetMargin();
764 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure child width[%d] height(%d)\n", childWidth.mValue, childHeight.mValue );
766 layoutWidth = std::max( layoutWidth, childWidth + childMargin.start + childMargin.end );
767 layoutHeight = std::max( layoutHeight, childHeight + childMargin.top + childMargin.bottom );
768 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure calculated child width[%d] calculated height(%d)\n", layoutWidth.mValue, layoutHeight.mValue );
772 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure Not a layout\n" );
776 Extents padding = GetPadding();
777 layoutWidth += padding.start + padding.end;
778 layoutHeight += padding.top + padding.bottom;
782 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure Getting default size as a leaf\n" );
783 // LayoutGroup does not contain any children so must be a leaf
784 layoutWidth = GetDefaultSize( GetSuggestedMinimumWidth(), widthMeasureSpec );
785 layoutHeight = GetDefaultSize( GetSuggestedMinimumHeight(), heightMeasureSpec );
788 // Can't exceed specified width
789 if( widthMode == MeasureSpec::Mode::EXACTLY )
793 else if ( widthMode == MeasureSpec::Mode::AT_MOST )
795 layoutWidth = std::min( layoutWidth, widthSpecSize );
798 // Can't exceed specified height
799 if( heightMode == MeasureSpec::Mode::EXACTLY )
803 else if ( heightMode == MeasureSpec::Mode::AT_MOST )
805 layoutHeight = std::min( layoutHeight, heightSpecSize );
808 layoutWidth = std::max( layoutWidth, GetSuggestedMinimumWidth() );
809 layoutHeight = std::max( layoutHeight, GetSuggestedMinimumHeight() );
813 layoutWidth = widthSpecSize;
818 layoutHeight = heightSpecSize;
821 DALI_LOG_INFO( gLogFilter, Debug::General, "LayoutGroup::OnMeasure Measured size(%d,%d) for : %s \n", layoutWidth.mValue, layoutHeight.mValue, Actor::DownCast(GetOwner()).GetName().c_str() );
822 SetMeasuredDimensions( MeasuredSize( layoutWidth ), MeasuredSize( layoutHeight ) );
825 void LayoutGroup::OnLayout( bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom )
827 auto count = GetChildCount();
829 DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup OnLayout owner:" << ( ( Toolkit::Control::DownCast(GetOwner())) ? Toolkit::Control::DownCast(GetOwner()).GetName() : "invalid" ) << " childCount:" << count );
831 for( unsigned int childIndex = 0; childIndex < count; childIndex++)
833 LayoutItemPtr childLayout = GetChildAt( childIndex );
834 if( childLayout != nullptr )
837 auto childOwner = childLayout->GetOwner();
838 auto childWidth = childLayout->GetMeasuredWidth();
839 auto childHeight = childLayout->GetMeasuredHeight();
840 auto childMargin = childLayout->GetMargin();
841 auto control = Toolkit::Control::DownCast( childOwner );
842 Extents padding = GetPadding();
844 auto childPosition = control.GetProperty< Vector3 >( Actor::Property::POSITION );
845 auto anchorPoint = control.GetProperty< Vector3 >( Actor::Property::ANCHOR_POINT );
847 DALI_LOG_INFO( gLogFilter, Debug::General, "LayoutGroup::OnLayout child[%s] position(%f,%f) child width[%d] height(%d)\n",
848 control.GetName().c_str(),
849 childPosition.x, childPosition.y,
850 childWidth.mValue, childHeight.mValue
853 // Margin and Padding only supported when child anchor point is TOP_LEFT.
854 int paddingAndMarginOffsetX = ( AnchorPoint::TOP_LEFT == anchorPoint ) ? ( padding.top + childMargin.top ) : 0;
855 int paddingAndMarginOffsetY = ( AnchorPoint::TOP_LEFT == anchorPoint ) ? ( padding.start + childMargin.start ) : 0;
856 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnLayout paddingMargin offset(%d,%d)\n", paddingAndMarginOffsetX, paddingAndMarginOffsetY );
858 LayoutLength childLeft = childPosition.x + paddingAndMarginOffsetX;
859 LayoutLength childTop = childPosition.y + paddingAndMarginOffsetY;
861 childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight );
867 } // namespace Internal
868 } // namespace Toolkit