X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Fcustom-layout-impl.cpp;h=37b6936abef11bec18a98b71ad09070a507bfb61;hb=943cc399b1f2fe70e166099cd66c635403bf9f0b;hp=97ded95ff0fd1086537d7f52fd1c06e2c06b51dc;hpb=07a1998795284bd9be338b7fb24e711d88f8bada;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit/custom-layout-impl.cpp b/automated-tests/src/dali-toolkit/custom-layout-impl.cpp index 97ded95..37b6936 100644 --- a/automated-tests/src/dali-toolkit/custom-layout-impl.cpp +++ b/automated-tests/src/dali-toolkit/custom-layout-impl.cpp @@ -30,12 +30,40 @@ namespace Internal using Dali::Actor; using Dali::Toolkit::MeasuredSize; +CustomLayout::CustomLayout() +: mBehaviourFlags( 0 ) +{ +} + CustomLayoutPtr CustomLayout::New() { CustomLayoutPtr layout( new CustomLayout() ); return layout; } +void CustomLayout::MeasureChildren( Dali::Toolkit::Internal::LayoutItemPtr childLayout, MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec, LayoutLength resultingWidth, LayoutLength resultingHeight ) +{ + // Initially use the measure spec of the child's parent + auto childWidthMeasureSpec = widthMeasureSpec; + auto childHeightMeasureSpec = heightMeasureSpec; + + if ( true == GetCustomBehaviourFlags( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_WIDTH ) ) + { + // Use unspecified width measure spec, child can be any width it desires + childWidthMeasureSpec = MeasureSpec( widthMeasureSpec.GetSize(), MeasureSpec::Mode::UNSPECIFIED ); + } + + if ( true == GetCustomBehaviourFlags( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_HEIGHT) ) + { + // Use unspecified height measure spec, child can be any height it desires + childHeightMeasureSpec = MeasureSpec( heightMeasureSpec.GetSize(), MeasureSpec::Mode::UNSPECIFIED ); + } + + MeasureChild( childLayout, childWidthMeasureSpec, childHeightMeasureSpec ); + resultingWidth += childLayout->GetMeasuredWidth(); + resultingHeight = std::max( childLayout->GetMeasuredHeight(), resultingHeight ); +} + void CustomLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec ) { auto accumulatedWidth = 0; @@ -51,9 +79,7 @@ void CustomLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMe auto childLayout = GetChildAt( i ); if( childLayout ) { - MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec ); - accumulatedWidth += childLayout->GetMeasuredWidth(); - maxHeight = std::max( childLayout->GetMeasuredHeight().mValue, maxHeight ); + MeasureChildren( childLayout, widthMeasureSpec, heightMeasureSpec, accumulatedWidth, maxHeight ); } } @@ -67,15 +93,15 @@ void CustomLayout::OnLayout( bool changed, LayoutLength left, LayoutLength top, LayoutLength childLeft( 0 ); // We want to vertically align the children to the middle - auto height = bottom - top; - auto middle = height / 2; + LayoutLength height = bottom - top; + LayoutLength middle = height / 2; auto owner = GetOwner(); auto actor = Actor::DownCast(owner); // Horizontally align the children to the left int count = actor.GetChildCount(); - int currentLeft = 0; + LayoutLength currentLeft = 0; for( int i = 0; i < count; i++) { @@ -90,16 +116,33 @@ void CustomLayout::OnLayout( bool changed, LayoutLength left, LayoutLength top, { Dali::Toolkit::Internal::LayoutItem& childLayoutImpl = GetImplementation( childLayout ); - auto childWidth = childLayoutImpl.GetMeasuredWidth(); - auto childHeight = childLayoutImpl.GetMeasuredHeight(); + LayoutLength childWidth = childLayoutImpl.GetMeasuredWidth(); + LayoutLength childHeight = childLayoutImpl.GetMeasuredHeight(); - childTop = middle - (childHeight / 2); + childTop = middle - childHeight / 2; childLayoutImpl.Layout( currentLeft, childTop, currentLeft + childWidth, childTop + childHeight ); currentLeft += childWidth; } } } +void CustomLayout::SetCustomBehaviourFlag( int flag ) +{ + mBehaviourFlags |= flag; + RequestLayout(); +} + +bool CustomLayout::GetCustomBehaviourFlags( int flagToCheck ) +{ + return ( mBehaviourFlags & flagToCheck ) != 0; +} + +void CustomLayout::ClearPrivateFlag( int flag ) +{ + mBehaviourFlags &= ~flag; + RequestLayout(); +} + } // namespace Internal } // namespace Test