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 for it.
592 childLayout = LayoutGroup::New( control );
593 childLayout->SetAnimateLayout( IsLayoutAnimated() ); // @todo this essentially forces animation inheritance. Bad?
594 #if defined(DEBUG_ENABLED)
595 auto desiredSize = control.GetNaturalSize();
596 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner desiredSize(%f,%f) (naturalSize)\n", desiredSize.width, desiredSize.height );
598 childControlDataImpl.SetLayout( *childLayout.Get() );
600 Vector3 size = child.GetTargetSize();
601 // If the size of the control is set explicitly make sure that the control size
602 // stays the same after the layout except it is over written with match parent specs.
605 childLayout->SetMinimumWidth( size.x );
610 childLayout->SetMinimumHeight( size.y );
612 // Default layout data will be generated by Add().
616 LayoutGroupPtr layoutGroup( dynamic_cast< LayoutGroup* >( childLayout.Get() ) );
619 // Set only in case of leaf children
620 childLayout->SetAnimateLayout( IsLayoutAnimated() );
624 Add( *childLayout.Get() );
628 void LayoutGroup::ChildRemovedFromOwner( Actor child )
630 Toolkit::Control control = Toolkit::Control::DownCast( child );
633 Internal::Control& childControlImpl = GetImplementation( control );
634 Internal::Control::Impl& childControlDataImpl = Internal::Control::Impl::Get( childControlImpl );
635 auto childLayout = childControlDataImpl.GetLayout();
638 Remove( *childLayout.Get() );
643 void LayoutGroup::ChildOrderChanged( Actor child )
645 Toolkit::Control childControl = Toolkit::Control::DownCast( child );
648 Internal::Control& childControlImpl = GetImplementation( childControl );
649 Internal::Control::Impl& childControlDataImpl = Internal::Control::Impl::Get( childControlImpl );
651 auto childLayout = childControlDataImpl.GetLayout();
654 Toolkit::Control control = Toolkit::Control::DownCast( GetOwner() );
655 unsigned int count = control.GetChildCount();
656 unsigned int index = static_cast< unsigned int >( childControl.GetProperty< int >( DevelActor::Property::SIBLING_ORDER ) );
658 // Find insertion position
659 while( ++index < count )
661 auto sibling = Toolkit::Control::DownCast( control.GetChildAt( index ) );
664 auto siblingLayout = DevelControl::GetLayout( sibling );
667 Internal::LayoutItem& siblingLayoutImpl = GetImplementation( siblingLayout );
668 Move( siblingLayoutImpl, *childLayout );
674 MoveBack( *childLayout );
679 void LayoutGroup::OnOwnerPropertySet( Handle& handle, Property::Index index, Property::Value value )
681 DALI_LOG_INFO( gLogFilter, Debug::Concise, "LayoutGroup::OnOwnerPropertySet\n");
682 auto actor = Actor::DownCast( handle );
685 index == Actor::Property::LAYOUT_DIRECTION ||
686 index == Toolkit::Control::Property::PADDING ||
687 index == Toolkit::Control::Property::MARGIN
695 void LayoutGroup::OnAnimationStateChanged( bool animateLayout )
697 // Change children's animation state
698 for( auto&& child : mImpl->mChildren )
700 LayoutGroupPtr parentGroup( dynamic_cast< LayoutGroup* >( child.child.Get() ) );
701 if( parentGroup && ( 0 == parentGroup->GetChildCount() ) ) // A leaf LayoutGroup will have no children.
703 // Change state only in case of leaf children
704 child.child->SetAnimateLayout( animateLayout );
709 void LayoutGroup::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec )
711 DALI_LOG_STREAM( gLogFilter, Debug::Verbose,
712 "LayoutGroup::OnMeasure Actor Id:" << Actor::DownCast(GetOwner()).GetId() <<
713 " Owner:" << Actor::DownCast(GetOwner()).GetName() <<
714 " MeasureSpecs( width:"<<widthMeasureSpec<<", height:"<<heightMeasureSpec );
716 auto childCount = GetChildCount();
717 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure child count(%u)\n", childCount);
719 auto widthMode = widthMeasureSpec.GetMode();
720 auto heightMode = heightMeasureSpec.GetMode();
721 LayoutLength widthSpecSize = widthMeasureSpec.GetSize();
722 LayoutLength heightSpecSize = heightMeasureSpec.GetSize();
724 bool exactWidth ( false );
725 bool exactHeight ( false );
727 // Default Layouting behaviour if not overridden
728 // EXACT, width and height as provided.
729 // MATCH_PARENT, width and hewidthSpecSizeight that of parent
731 // WRAP_CONTENT, take width of widest child and height size of longest child (within given limit)
732 // UNSPECIFIED, take width of widest child and height size of longest child.
734 LayoutLength layoutWidth( 0 );
735 LayoutLength layoutHeight( 0 );
737 // If LayoutGroup has children then measure children to get max dimensions
738 if ( childCount > 0 )
740 for( unsigned int i=0; i<childCount; ++i )
742 auto childLayout = GetChildAt( i );
745 auto childOwner = childLayout->GetOwner();
748 MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec );
749 auto childWidth = childLayout->GetMeasuredWidth();
750 auto childHeight = childLayout->GetMeasuredHeight();
751 auto childMargin = childLayout->GetMargin();
752 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure child width[%d] height(%d)\n", childWidth.mValue, childHeight.mValue );
754 layoutWidth = std::max( layoutWidth, childWidth + childMargin.start + childMargin.end );
755 layoutHeight = std::max( layoutHeight, childHeight + childMargin.top + childMargin.bottom );
756 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure calculated child width[%d] calculated height(%d)\n", layoutWidth.mValue, layoutHeight.mValue );
760 Extents padding = GetPadding();
761 layoutWidth += padding.start + padding.end;
762 layoutHeight += padding.top + padding.bottom;
766 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure Getting default size as a leaf\n" );
767 // LayoutGroup does not contain any children so must be a leaf
768 layoutWidth = GetDefaultSize( GetSuggestedMinimumWidth(), widthMeasureSpec );
769 layoutHeight = GetDefaultSize( GetSuggestedMinimumHeight(), heightMeasureSpec );
772 // Can't exceed specified width
773 if( widthMode == MeasureSpec::Mode::EXACTLY )
777 else if ( widthMode == MeasureSpec::Mode::AT_MOST )
779 layoutWidth = std::min( layoutWidth, widthSpecSize );
782 // Can't exceed specified height
783 if( heightMode == MeasureSpec::Mode::EXACTLY )
787 else if ( heightMode == MeasureSpec::Mode::AT_MOST )
789 layoutHeight = std::min( layoutHeight, heightSpecSize );
792 layoutWidth = std::max( layoutWidth, GetSuggestedMinimumWidth() );
793 layoutHeight = std::max( layoutHeight, GetSuggestedMinimumHeight() );
797 layoutWidth = widthSpecSize;
802 layoutHeight = heightSpecSize;
805 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure Measured size(%d,%d) for : %s \n", layoutWidth.mValue, layoutHeight.mValue, Actor::DownCast(GetOwner()).GetName().c_str() );
806 SetMeasuredDimensions( MeasuredSize( layoutWidth ), MeasuredSize( layoutHeight ) );
809 void LayoutGroup::OnLayout( bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom )
811 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnLayout\n");
813 auto count = GetChildCount();
815 for( unsigned int childIndex = 0; childIndex < count; childIndex++)
817 LayoutItemPtr childLayout = GetChildAt( childIndex );
818 if( childLayout != nullptr )
821 auto childOwner = childLayout->GetOwner();
822 auto childWidth = childLayout->GetMeasuredWidth();
823 auto childHeight = childLayout->GetMeasuredHeight();
824 auto childMargin = childLayout->GetMargin();
825 auto control = Toolkit::Control::DownCast( childOwner );
826 Extents padding = GetPadding();
828 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnLayout child width[%d] height(%d)\n", childWidth.mValue, childHeight.mValue );
830 auto childPosition = control.GetProperty< Vector3 >( Actor::Property::POSITION );
831 auto anchorPoint = control.GetProperty< Vector3 >( Actor::Property::ANCHOR_POINT );
833 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnLayout child[%s] position(%f,%f)\n", control.GetName().c_str(), childPosition.x, childPosition.y );
835 // Margin and Padding only supported when child anchor point is TOP_LEFT.
836 int paddingAndMarginOffsetX = ( AnchorPoint::TOP_LEFT == anchorPoint ) ? ( padding.top + childMargin.top ) : 0;
837 int paddingAndMarginOffsetY = ( AnchorPoint::TOP_LEFT == anchorPoint ) ? ( padding.start + childMargin.start ) : 0;
838 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnLayout paddingMargin offset(%d,%d)\n", paddingAndMarginOffsetX, paddingAndMarginOffsetY );
840 LayoutLength childLeft = childPosition.x + paddingAndMarginOffsetX;
841 LayoutLength childTop = childPosition.y + paddingAndMarginOffsetY;
843 childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight );
849 } // namespace Internal
850 } // namespace Toolkit