X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Fdevel-api%2Flayouting%2Flayout-group-impl.cpp;h=d088a5ac77396e85e645a071c3d55b21fce13670;hb=9921868a204bf0132f7d5ddacae75c47b7550e80;hp=856ca18c632eb1604bf4dc98dcbcd1107678197e;hpb=2b6baa7ad447110327e4ac22e7b3c3b6524c14da;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp old mode 100644 new mode 100755 index 856ca18..d088a5a --- 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 { @@ -58,6 +59,7 @@ LayoutGroup::~LayoutGroup() { // An object with a unique_ptr to an opaque structure must define it's destructor in the translation unit // where the opaque structure is defined. It cannot use the default method in the header file. + RemoveAll(); } Toolkit::LayoutGroup::LayoutId LayoutGroup::Add( LayoutItem& child ) @@ -344,10 +346,11 @@ 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 ); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChild desiredWidth(%d) desiredHeight(%d)\n", desiredWidth, desiredHeight ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChild child WIDTH_SPEC(%d) child HEIGHT SPEC(%d)\n", desiredWidth, desiredHeight ); auto padding = GetPadding(); // Padding of this layout's owner, not of the child being measured. @@ -371,13 +374,13 @@ void LayoutGroup::MeasureChildWithMargins( LayoutItemPtr child, auto padding = GetPadding(); // Padding of this layout's owner, not of the child being measured. - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins desiredWidth(%d)\n", desiredWidth ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins child WIDTH_SPEC(%d)\n", desiredWidth ); MeasureSpec childWidthMeasureSpec = GetChildMeasureSpec( parentWidthMeasureSpec, LayoutLength( padding.start + padding.end ) + widthUsed, desiredWidth ); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins desiredHeight(%d)\n", desiredHeight ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins child HEIGHT_SPEC(%d)\n", desiredHeight ); MeasureSpec childHeightMeasureSpec = GetChildMeasureSpec( parentHeightMeasureSpec, LayoutLength( padding.top + padding.bottom )+ @@ -395,12 +398,14 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec( auto specMode = measureSpec.GetMode(); LayoutLength specSize = measureSpec.GetSize(); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec childDimension(%f)\n", childDimension.AsInteger() ); + LayoutLength size = std::max( LayoutLength(0), specSize - padding ); // reduce available size by the owners padding LayoutLength resultSize = 0; MeasureSpec::Mode resultMode = MeasureSpec::Mode::UNSPECIFIED; - switch( specMode ) + switch( specMode ) // Parents specMode { // Parent has imposed an exact size on us case MeasureSpec::Mode::EXACTLY: @@ -505,12 +510,11 @@ 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 ); DevelActor::ChildRemovedSignal( control ).Connect( mSlotDelegate, &LayoutGroup::ChildRemovedFromOwner ); - DevelActor::ChildOrderChangedSignal( control ).Connect( mSlotDelegate, &LayoutGroup::ChildOrderChanged ); DevelHandle::PropertySetSignal( control ).Connect( mSlotDelegate, &LayoutGroup::OnOwnerPropertySet ); if( control.GetParent() ) @@ -549,6 +553,8 @@ void LayoutGroup::OnInitialize() } } } + + RequestLayout( Dali::Toolkit::LayoutTransitionData::Type::ON_OWNER_SET ); } } @@ -561,6 +567,14 @@ 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 ); + DevelHandle::PropertySetSignal( control ).Disconnect( mSlotDelegate, &LayoutGroup::OnOwnerPropertySet ); + } } void LayoutGroup::RemoveChild( LayoutItem& item ) @@ -571,12 +585,20 @@ void LayoutGroup::RemoveChild( LayoutItem& item ) void LayoutGroup::ChildAddedToOwner( Actor child ) { + ChildAddedToOwnerImpl( child ); + RequestLayout( Dali::Toolkit::LayoutTransitionData::Type::ON_CHILD_ADD, child, Actor() ); +} + +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 @@ -591,37 +613,48 @@ 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() << - " desiredWidth: " << control.GetNaturalSize().width << " desiredHeight:" << control.GetNaturalSize().height ); + DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner child control:" << control.GetName() << + " desiredWidth: " << control.GetNaturalSize().width << + " desiredHeight:" << control.GetNaturalSize().height ); childControlDataImpl.SetLayout( *childLayout.Get() ); Vector3 size = child.GetTargetSize(); // If the size of the control is set explicitly make sure that the control size // stays the same after the layout except it is over written with match parent specs. - if ( size.x != 0 ) + + auto childControl = Toolkit::Control::DownCast(childLayout->GetOwner()); + + bool setWidthExplictly = ( childControl.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ) > 0 ); + if ( size.x != 0 || setWidthExplictly ) { - childLayout->SetMinimumWidth( size.x ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner SetTargetWidth(%f)\n", size.x ); + childLayout->SetTargetWidth( size.x ); } - if ( size.y != 0 ) + bool setHeightExplcitly = ( childControl.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ) > 0 ); + if ( size.y != 0 || setHeightExplcitly ) { - childLayout->SetMinimumHeight( size.y ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner SetTargetHeight(%f)\n", size.y); + childLayout->SetTargetHeight( size.y ); } // Default layout data will be generated by Add(). } 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 ) { @@ -645,6 +678,7 @@ void LayoutGroup::ChildRemovedFromOwner( Actor child ) if( childLayout ) { Remove( *childLayout.Get() ); + RequestLayout( Dali::Toolkit::LayoutTransitionData::Type::ON_CHILD_REMOVE, child, Actor() ); } } } @@ -733,10 +767,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. @@ -751,14 +784,49 @@ 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. + // 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( 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 ); 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" ); + 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 ); @@ -766,7 +834,7 @@ void LayoutGroup::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMea } 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" ); } } @@ -832,6 +900,15 @@ void LayoutGroup::OnLayout( bool changed, LayoutLength left, LayoutLength top, L { 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();