X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Fdevel-api%2Flayouting%2Flayout-group-impl.cpp;h=06305bdfd62cd1e019e95749714d39cd1a52b3b7;hp=8cdd8bcffd647755dc250541035f31acbbfaa278;hb=4fcbbea5dc1fb7667607f663f04e898f0e4086ae;hpb=57974024e1401e657866df3afabf53676a5892b6 diff --git a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp index 8cdd8bc..06305bd 100644 --- a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp +++ b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace { @@ -288,7 +289,7 @@ void LayoutGroup::DoRegisterChildProperties( const std::string& containerType ) 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 ) ) @@ -344,6 +345,7 @@ void LayoutGroup::MeasureChild( LayoutItemPtr child, } #endif + // Get last stored width and height specifications for the child auto desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); auto desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); @@ -374,13 +376,13 @@ void LayoutGroup::MeasureChildWithMargins( LayoutItemPtr child, 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 ); @@ -395,9 +397,9 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec( 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 ) @@ -489,8 +491,7 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec( } } - 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 ); @@ -506,7 +507,7 @@ void LayoutGroup::OnInitialize() // Take ownership of existing children for( unsigned int childIndex = 0 ; childIndex < control.GetChildCount(); ++childIndex ) { - ChildAddedToOwner( control.GetChildAt( childIndex ) ); + ChildAddedToOwnerImpl( control.GetChildAt( childIndex ) ); } DevelActor::ChildAddedSignal( control ).Connect( mSlotDelegate, &LayoutGroup::ChildAddedToOwner ); @@ -550,6 +551,8 @@ void LayoutGroup::OnInitialize() } } } + + RequestLayout( Dali::Toolkit::LayoutTransitionData::LayoutTransitionType::ON_OWNER_SET ); } } @@ -562,6 +565,15 @@ void LayoutGroup::OnUnparent() { // Remove children RemoveAll(); + + auto control = Toolkit::Control::DownCast( GetOwner() ); + if( control ) + { + 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 ); + } } void LayoutGroup::RemoveChild( LayoutItem& item ) @@ -572,12 +584,20 @@ void LayoutGroup::RemoveChild( LayoutItem& item ) void LayoutGroup::ChildAddedToOwner( Actor child ) { + ChildAddedToOwnerImpl( child ); + RequestLayout( Dali::Toolkit::LayoutTransitionData::LayoutTransitionType::ON_CHILD_ADD ); +} + +void LayoutGroup::ChildAddedToOwnerImpl( Actor child ) +{ LayoutItemPtr childLayout; Toolkit::Control control = Toolkit::Control::DownCast( child ); #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" ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner child control(%s) owner control(%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 @@ -592,20 +612,21 @@ void LayoutGroup::ChildAddedToOwner( Actor child ) // 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" ); + 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" ); + 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() ); // forces animation inheritance. } - childLayout->SetAnimateLayout( IsLayoutAnimated() ); // @todo this essentially forces animation inheritance. Bad? - DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner control:" << control.GetName().c_str() << + DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner child control:" << control.GetName() << " desiredWidth: " << control.GetNaturalSize().width << - " desiredHeight:" << control.GetNaturalSize().height - ); + " desiredHeight:" << control.GetNaturalSize().height ); childControlDataImpl.SetLayout( *childLayout.Get() ); @@ -625,6 +646,7 @@ void LayoutGroup::ChildAddedToOwner( Actor child ) } else { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner child(%s) already has a Layout\n", control.GetName().c_str() ); LayoutGroupPtr layoutGroup( dynamic_cast< LayoutGroup* >( childLayout.Get() ) ); if( !layoutGroup ) { @@ -648,6 +670,7 @@ void LayoutGroup::ChildRemovedFromOwner( Actor child ) if( childLayout ) { Remove( *childLayout.Get() ); + RequestLayout( Dali::Toolkit::LayoutTransitionData::LayoutTransitionType::ON_CHILD_REMOVE ); } } } @@ -736,10 +759,9 @@ void LayoutGroup::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMea bool exactWidth ( false ); bool exactHeight ( false ); - // Default Layouting behaviour if not overridden + // Layouting behaviour // EXACT, width and height as provided. - // MATCH_PARENT, width and hewidthSpecSizeight that of parent - + // 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. @@ -754,22 +776,55 @@ void LayoutGroup::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMea auto childLayout = GetChildAt( i ); if( childLayout ) { - auto childOwner = childLayout->GetOwner(); + 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. + if( childControl.GetChildCount() > 0 ) + { + // First pass, Static mappings that are not dependant on parent + SizeNegotiationMapper::SetLayoutParametersUsingResizePolicy( childControl, childLayout, Dimension::WIDTH ); + SizeNegotiationMapper::SetLayoutParametersUsingResizePolicy( childControl, childLayout, Dimension::HEIGHT ); + } + + // 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( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); + LayoutLength desiredHeight = childControl.GetProperty( 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 ); - auto childWidth = childLayout->GetMeasuredWidth(); - auto childHeight = childLayout->GetMeasuredHeight(); - auto childMargin = childLayout->GetMargin(); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure child width[%d] height(%d)\n", childWidth.mValue, childHeight.mValue ); + 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_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure calculated child width[%d] calculated height(%d)\n", layoutWidth.mValue, layoutHeight.mValue ); + 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" ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure Not a layout\n" ); } } @@ -818,7 +873,7 @@ void LayoutGroup::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMea layoutHeight = heightSpecSize; } - 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() ); + DALI_LOG_STREAM( gLogFilter, Debug::General, "LayoutGroup::OnMeasure Measured size(" << layoutWidth << "," << layoutHeight << ") for : " << Actor::DownCast(GetOwner()).GetName() << " \n" ); SetMeasuredDimensions( MeasuredSize( layoutWidth ), MeasuredSize( layoutHeight ) ); } @@ -835,20 +890,17 @@ void LayoutGroup::OnLayout( bool changed, LayoutLength left, LayoutLength top, L { auto childOwner = childLayout->GetOwner(); - auto childWidth = childLayout->GetMeasuredWidth(); - auto childHeight = childLayout->GetMeasuredHeight(); - auto childMargin = childLayout->GetMargin(); + 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_INFO( gLogFilter, Debug::General, "LayoutGroup::OnLayout child[%s] position(%f,%f) child width[%d] height(%d)\n", - control.GetName().c_str(), - childPosition.x, childPosition.y, - childWidth.mValue, childHeight.mValue - ); + 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;