{
}
+LayoutGroupPtr LayoutGroup::New( Handle& owner )
+{
+ LayoutGroupPtr layoutPtr = new LayoutGroup();
+ return layoutPtr;
+}
+
LayoutGroup::~LayoutGroup()
{
// An object with a unique_ptr to an opaque structure must define it's destructor in the translation unit
void LayoutGroup::OnSetChildProperties( Handle& handle, Property::Index index, Property::Value value )
{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnSetChildProperties property(%s)\n", handle.GetPropertyName(index).c_str());
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::OnSetChildProperties property(" << handle.GetPropertyName(index) << ")\n" );
if ( ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) &&
( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
#if defined( DEBUG_ENABLED )
if ( control )
{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChild natural size(%f, %f)\n", control.GetNaturalSize().width, control.GetNaturalSize().height );
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChild(%s) natural size(%f, %f)\n",
+ control.GetName().c_str(), control.GetNaturalSize().width, control.GetNaturalSize().height );
}
#endif
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins desiredWidth(%d)\n", desiredWidth );
MeasureSpec childWidthMeasureSpec = GetChildMeasureSpec( parentWidthMeasureSpec,
- padding.start + padding.end +
+ LayoutLength( padding.start + padding.end ) +
widthUsed, desiredWidth );
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins desiredHeight(%d)\n", desiredHeight );
MeasureSpec childHeightMeasureSpec = GetChildMeasureSpec( parentHeightMeasureSpec,
- padding.top + padding.bottom +
+ LayoutLength( padding.top + padding.bottom )+
heightUsed, desiredHeight );
child->Measure( childWidthMeasureSpec, childHeightMeasureSpec );
auto specMode = measureSpec.GetMode();
LayoutLength specSize = measureSpec.GetSize();
- auto size = std::max( LayoutLength(0), specSize - padding ); // reduce available size by the owners padding
+ LayoutLength size = std::max( LayoutLength(0), specSize - padding ); // reduce available size by the owners padding
- MeasureSpec::IntType resultSize = 0;
+ LayoutLength resultSize = 0;
MeasureSpec::Mode resultMode = MeasureSpec::Mode::UNSPECIFIED;
switch( specMode )
}
}
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec resultSize(%u)\n", resultSize );
-
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec resultSize(" << resultSize << ")\n" );
//noinspection ResourceType
return MeasureSpec( resultSize, resultMode );
LayoutItemPtr childLayout;
Toolkit::Control control = Toolkit::Control::DownCast( child );
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner control(%s)\n", control?control.GetName().c_str():"Invalid" );
+#if defined(DEBUG_ENABLED)
+ auto parent = Toolkit::Control::DownCast( GetOwner() );
+ 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" );
+#endif
if( control ) // Can only support adding Controls, not Actors to layout
{
if( ! childLayout )
{
- // If the child doesn't already have a layout, then create a LayoutItem for it.
- childLayout = LayoutItem::New( control );
+ // If the child doesn't already have a layout, then create a LayoutItem or LayoutGroup for it.
+ // If control behaviour flag set to Layout then set a LayoutGroup.
+ if( DevelControl::IsLayoutingRequired( control ) )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner Creating default LayoutGroup for control:%s\n", control?control.GetName().c_str():"Invalid" );
+ childLayout = LayoutGroup::New( control );
+ }
+ else
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner Creating default LayoutItem for control:%s\n", control?control.GetName().c_str():"Invalid" );
+ childLayout = LayoutItem::New( control );
+ }
childLayout->SetAnimateLayout( IsLayoutAnimated() ); // @todo this essentially forces animation inheritance. Bad?
-#if defined(DEBUG_ENABLED)
- auto desiredSize = control.GetNaturalSize();
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner desiredSize(%f,%f) (naturalSize)\n", desiredSize.width, desiredSize.height );
-#endif
+
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner control:" << control.GetName() <<
+ " desiredWidth: " << control.GetNaturalSize().width << " desiredHeight:" << control.GetNaturalSize().height );
+
childControlDataImpl.SetLayout( *childLayout.Get() );
Vector3 size = child.GetTargetSize();
for( auto&& child : mImpl->mChildren )
{
LayoutGroupPtr parentGroup( dynamic_cast< LayoutGroup* >( child.child.Get() ) );
- if( !parentGroup )
+ 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 );
+
+ // Default Layouting behaviour if not overridden
+ // EXACT, width and height as provided.
+ // MATCH_PARENT, width and hewidthSpecSizeight 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 childOwner = childLayout->GetOwner();
+
+ // 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 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();
+ 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 );
+ }
+ }
+}
+
+
} // namespace Internal
} // namespace Toolkit
} // namespace Dali