X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Flayouting%2Flinear-layout-impl.cpp;h=fdba7e63c8c950b2199df641954302f4d4a41f0f;hb=70ca72bbf8864314c389eb0268406dd68a811da1;hp=f989a541801a786f63b16636fafd26f260af6751;hpb=d14c633f5dfb1b3ca03175480ee4992b7773cbf1;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/layouting/linear-layout-impl.cpp b/dali-toolkit/internal/layouting/linear-layout-impl.cpp index f989a54..fdba7e6 100644 --- a/dali-toolkit/internal/layouting/linear-layout-impl.cpp +++ b/dali-toolkit/internal/layouting/linear-layout-impl.cpp @@ -21,6 +21,7 @@ #include #include #include +#include //INTERNAL INCLUDES #include @@ -41,6 +42,9 @@ namespace Toolkit namespace Internal { +const int HORIZONTAL_ALIGNMENT_MASK = ( Dali::Toolkit::LinearLayout::Alignment::BEGIN | Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL | Dali::Toolkit::LinearLayout::Alignment::END ); +const int VERTICAL_ALIGNMENT_MASK = ( Dali::Toolkit::LinearLayout::Alignment::TOP | Dali::Toolkit::LinearLayout::Alignment::CENTER_VERTICAL | Dali::Toolkit::LinearLayout::Alignment::BOTTOM ); + LinearLayoutPtr LinearLayout::New() { LinearLayoutPtr layout( new LinearLayout() ); @@ -51,6 +55,7 @@ LinearLayout::LinearLayout() : LayoutGroup(), mCellPadding( 0, 0 ), mOrientation( Dali::Toolkit::LinearLayout::Orientation::HORIZONTAL ), + mAlignment( Dali::Toolkit::LinearLayout::Alignment::BEGIN | Dali::Toolkit::LinearLayout::Alignment::CENTER_VERTICAL ), mTotalLength( 0 ) { } @@ -59,6 +64,31 @@ LinearLayout::~LinearLayout() { } +void LinearLayout::DoRegisterChildProperties( const std::string& containerType ) +{ + auto typeInfo = Dali::TypeRegistry::Get().GetTypeInfo( containerType ); + if( typeInfo ) + { + Property::IndexContainer indices; + typeInfo.GetChildPropertyIndices( indices ); + + if( std::find( indices.Begin(), indices.End(), Toolkit::LinearLayout::ChildProperty::WEIGHT ) == + indices.End() ) + { + ChildPropertyRegistration( typeInfo.GetName(), "weight", Toolkit::LinearLayout::ChildProperty::WEIGHT, Property::FLOAT ); + } + } +} + +void LinearLayout::OnChildAdd( LayoutItem& child ) +{ + auto owner = child.GetOwner(); + if( !DevelHandle::DoesCustomPropertyExist( owner, Toolkit::LinearLayout::ChildProperty::WEIGHT ) ) + { + owner.SetProperty( Toolkit::LinearLayout::ChildProperty::WEIGHT, 0.0f ); + } +} + void LinearLayout::SetCellPadding( LayoutSize size ) { if ( mCellPadding != size ) @@ -68,7 +98,7 @@ void LinearLayout::SetCellPadding( LayoutSize size ) } } -LayoutSize LinearLayout::GetCellPadding() +LayoutSize LinearLayout::GetCellPadding() const { return mCellPadding; } @@ -82,11 +112,25 @@ void LinearLayout::SetOrientation( Dali::Toolkit::LinearLayout::Orientation orie } } -Dali::Toolkit::LinearLayout::Orientation LinearLayout::GetOrientation() +Dali::Toolkit::LinearLayout::Orientation LinearLayout::GetOrientation() const { return mOrientation; } +void LinearLayout::SetAlignment( unsigned int alignment ) +{ + if ( mAlignment != alignment ) + { + mAlignment = alignment; + RequestLayout(); + } +} + +unsigned int LinearLayout::GetAlignment() const +{ + return mAlignment; +} + void LinearLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec ) { #if defined(DEBUG_ENABLED) @@ -141,11 +185,14 @@ void LinearLayout::MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec { auto widthMode = widthMeasureSpec.GetMode(); auto heightMode = heightMeasureSpec.GetMode(); - bool isExactly = (widthMode == MeasureSpec::Mode::EXACTLY); + bool isExactly = ( widthMode == MeasureSpec::Mode::EXACTLY ); bool matchHeight = false; bool allFillParent = true; LayoutLength maxHeight = 0; LayoutLength alternativeMaxHeight = 0; + LayoutLength weightedMaxHeight = 0; + float totalWeight = 0; + int usedExcessSpace = 0; struct { MeasuredSize::State widthState; @@ -156,32 +203,64 @@ void LinearLayout::MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec mTotalLength = 0; // measure children, and determine if further resolution is required - for( unsigned int i=0; iGetOwner(); auto desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); - - MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec ); - auto childWidth = childLayout->GetMeasuredWidth(); + auto desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); + auto childWeight = childOwner.GetProperty( Toolkit::LinearLayout::ChildProperty::WEIGHT ); auto childMargin = childLayout->GetMargin(); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LinearLayout::OnMeasure childWidth(%d)\n", MeasureSpec::IntType( childWidth ) ); - - auto length = childWidth + LayoutLength::IntType(childMargin.start + childMargin.end); + totalWeight += childWeight; - auto cellPadding = i 0; + if( isExactly && useExcessSpace ) { - mTotalLength += length; + mTotalLength += childMargin.start + childMargin.end; } else { - auto totalLength = mTotalLength; - mTotalLength = std::max( totalLength, totalLength + length + cellPadding ); + LayoutLength childWidth = 0; + if( useExcessSpace ) + { + // The widthMode is either UNSPECIFIED or AT_MOST, and + // this child is only laid out using excess space. Measure + // using WRAP_CONTENT so that we can find out the view's + // optimal width. + auto padding = GetPadding(); + const MeasureSpec childWidthMeasureSpec = GetChildMeasureSpec( widthMeasureSpec, padding.start + padding.end, Toolkit::ChildLayoutData::WRAP_CONTENT ); + const MeasureSpec childHeightMeasureSpec = GetChildMeasureSpec( heightMeasureSpec, padding.top + padding.bottom, desiredHeight ); + childLayout->Measure( childWidthMeasureSpec, childHeightMeasureSpec ); + childWidth = childLayout->GetMeasuredWidth(); + usedExcessSpace += childWidth; + } + else + { + MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec ); + childWidth = childLayout->GetMeasuredWidth(); + } + + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LinearLayout::OnMeasure childWidth(%d)\n", MeasureSpec::IntType( childWidth ) ); + auto length = childWidth + LayoutLength::IntType( childMargin.start + childMargin.end ); + auto cellPadding = i < GetChildCount() - 1 ? mCellPadding.width : 0; + if( isExactly ) + { + mTotalLength += length; + } + else + { + auto totalLength = mTotalLength; + mTotalLength = std::max( totalLength, totalLength + length + cellPadding ); + } } bool matchHeightLocally = false; @@ -206,7 +285,18 @@ void LinearLayout::MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec maxHeight = std::max( maxHeight, childHeight ); allFillParent = ( allFillParent && desiredHeight == Toolkit::ChildLayoutData::MATCH_PARENT ); - alternativeMaxHeight = std::max( alternativeMaxHeight, matchHeightLocally ? marginHeight : childHeight ); + if( childWeight > 0 ) + { + /* + * Heights of weighted Views are bogus if we end up + * remeasuring, so keep them separate. + */ + weightedMaxHeight = std::max( weightedMaxHeight, matchHeightLocally ? marginHeight : childHeight ); + } + else + { + alternativeMaxHeight = std::max( alternativeMaxHeight, matchHeightLocally ? marginHeight : childHeight ); + } } } @@ -217,6 +307,88 @@ void LinearLayout::MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec MeasuredSize widthSizeAndState = ResolveSizeAndState( widthSize, widthMeasureSpec, MeasuredSize::State::MEASURED_SIZE_OK); widthSize = widthSizeAndState.GetSize(); + // Expand children with weight to take up available space + // 2nd phase: + // We cycle through weighted children now (children with weight > 0). + // The children are measured with exact size equal to their share of the available space based on their weights. + // mTotalLength is updated to include weighted children measured sizes. + int remainingExcess = widthSize - mTotalLength + usedExcessSpace; + if( remainingExcess != 0 && totalWeight > 0 ) + { + float remainingWeightSum = totalWeight; + maxHeight = 0; + mTotalLength = 0; + + for( unsigned int i = 0; i < GetChildCount(); ++i ) + { + auto childLayout = GetChildAt( i ); + auto childOwner = childLayout->GetOwner(); + auto desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); + auto desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); + auto childWeight = childOwner.GetProperty( Toolkit::LinearLayout::ChildProperty::WEIGHT ); + auto childMargin = childLayout->GetMargin(); + + LayoutLength childWidth = 0; + if( childWeight > 0 ) + { + int share = static_cast( childWeight * remainingExcess / remainingWeightSum ); + remainingExcess -= share; + remainingWeightSum -= childWeight; + + // Always lay out weighted elements with intrinsic size regardless of the parent spec. + // for consistency between specs. + if( desiredWidth == 0 ) + { + // This child needs to be laid out from scratch using + // only its share of excess space. + childWidth = share; + } + else + { + // This child had some intrinsic width to which we + // need to add its share of excess space. + childWidth = childLayout->GetMeasuredWidth() + share; + } + + const MeasureSpec childWidthMeasureSpec = MeasureSpec( childWidth, MeasureSpec::Mode::EXACTLY ); + const MeasureSpec childHeightMeasureSpec = GetChildMeasureSpec( heightMeasureSpec, padding.top + padding.bottom, desiredHeight ); + childLayout->Measure( childWidthMeasureSpec, childHeightMeasureSpec ); + + // Child may now not fit in horizontal dimension. + if( childLayout->GetMeasuredWidthAndState().GetState() == MeasuredSize::State::MEASURED_SIZE_TOO_SMALL ) + { + childState.widthState = MeasuredSize::State::MEASURED_SIZE_TOO_SMALL; + } + } + + auto length = childLayout->GetMeasuredWidth() + LayoutLength::IntType( childMargin.start + childMargin.end ); + auto cellPadding = i < GetChildCount() - 1 ? mCellPadding.width : 0; + if( isExactly ) + { + mTotalLength += length; + } + else + { + auto totalLength = mTotalLength; + mTotalLength = std::max( totalLength, totalLength + length + cellPadding ); + } + + bool matchHeightLocally = heightMode != MeasureSpec::Mode::EXACTLY && desiredHeight == Toolkit::ChildLayoutData::MATCH_PARENT; + auto marginHeight = LayoutLength( childMargin.top + childMargin.bottom ); + auto childHeight = childLayout->GetMeasuredHeight() + marginHeight; + + maxHeight = std::max( maxHeight, childHeight ); + alternativeMaxHeight = std::max( alternativeMaxHeight, matchHeightLocally ? marginHeight : childHeight ); + allFillParent = (allFillParent && desiredHeight == Toolkit::ChildLayoutData::MATCH_PARENT); + + mTotalLength += padding.start + padding.end; + } + } + else + { + alternativeMaxHeight = std::max( alternativeMaxHeight, weightedMaxHeight ); + } + if( !allFillParent && heightMode != MeasureSpec::Mode::EXACTLY ) { maxHeight = alternativeMaxHeight; @@ -284,15 +456,48 @@ void LinearLayout::LayoutHorizontal( LayoutLength left, LayoutLength top, Layout auto count = GetChildCount(); + switch ( mAlignment & HORIZONTAL_ALIGNMENT_MASK ) + { + case Dali::Toolkit::LinearLayout::Alignment::BEGIN: + default: + { + // mTotalLength contains the padding already + // In case of RTL map BEGIN alignment to the right edge + if ( isLayoutRtl ) { + childLeft = LayoutLength( padding.start ) + right - left - mTotalLength; + } + else { + childLeft = LayoutLength( padding.start ); + } + break; + } + case Dali::Toolkit::LinearLayout::Alignment::END: + { + // mTotalLength contains the padding already + // In case of RTL map END alignment to the left edge + if ( isLayoutRtl ) { + childLeft = LayoutLength( padding.start ); + } + else { + childLeft = LayoutLength( padding.start ) + right - left - mTotalLength; + } + break; + } + case Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL: + { + // mTotalLength contains the padding already + childLeft = LayoutLength( padding.start ) + ( right - left - mTotalLength ) / 2; + break; + } + } + int start = 0; int dir = 1; - // In case of RTL, start drawing from the last child and apply right alignment. - // @TODO Should we have also support Actor HorizontalAlignment|VerticalAlignment in general for LinearLayout? + // In case of RTL, start drawing from the last child. if( isLayoutRtl ) { start = count - 1; dir = -1; - childLeft = padding.start + right - left - mTotalLength; } for( unsigned int i = 0; i < count; i++) @@ -305,8 +510,25 @@ void LinearLayout::LayoutHorizontal( LayoutLength left, LayoutLength top, Layout auto childHeight = childLayout->GetMeasuredHeight(); auto childMargin = childLayout->GetMargin(); - childTop = LayoutLength(padding.top) + ((childSpace - childHeight) / 2) + childMargin.top - childMargin.bottom; - + switch ( mAlignment & VERTICAL_ALIGNMENT_MASK ) + { + case Dali::Toolkit::LinearLayout::Alignment::TOP: + { + childTop = LayoutLength( padding.top ) + childMargin.top; + break; + } + case Dali::Toolkit::LinearLayout::Alignment::BOTTOM: + { + childTop = height - padding.bottom - childHeight - childMargin.bottom; + break; + } + case Dali::Toolkit::LinearLayout::Alignment::CENTER_VERTICAL: + default: + { + childTop = LayoutLength( padding.top ) + ( ( childSpace - childHeight ) / 2 ) + childMargin.top - childMargin.bottom; + break; + } + } childLeft += childMargin.start; childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight ); childLeft += childWidth + childMargin.end + mCellPadding.width; @@ -317,12 +539,16 @@ void LinearLayout::LayoutHorizontal( LayoutLength left, LayoutLength top, Layout void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec ) { auto widthMode = widthMeasureSpec.GetMode(); + auto heightMode = heightMeasureSpec.GetMode(); + bool isExactly = ( heightMode == MeasureSpec::Mode::EXACTLY ); bool matchWidth = false; bool allFillParent = true; LayoutLength maxWidth = 0; LayoutLength alternativeMaxWidth = 0; - + LayoutLength weightedMaxWidth = 0; + float totalWeight = 0; + int usedExcessSpace = 0; struct { MeasuredSize::State widthState; @@ -333,22 +559,62 @@ void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec he mTotalLength = 0; // measure children, and determine if further resolution is required - for( unsigned int i=0; iGetOwner(); auto desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); - - MeasureChildWithMargins( childLayout, widthMeasureSpec, 0, heightMeasureSpec, 0 ); - auto childHeight = childLayout->GetMeasuredHeight(); + auto desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); + auto childWeight = childOwner.GetProperty( Toolkit::LinearLayout::ChildProperty::WEIGHT ); auto childMargin = childLayout->GetMargin(); - auto length = childHeight + LayoutLength::IntType(childMargin.top + childMargin.bottom ); - auto cellPadding = i 0; + + if( isExactly && useExcessSpace ) + { + LayoutLength totalLength = mTotalLength; + mTotalLength = std::max( totalLength, totalLength + childMargin.top + childMargin.bottom ); + } + else + { + LayoutLength childHeight = 0; + if( useExcessSpace ) + { + // The heightMode is either UNSPECIFIED or AT_MOST, and + // this child is only laid out using excess space. Measure + // using WRAP_CONTENT so that we can find out the view's + // optimal height. We'll restore the original height of 0 + // after measurement. + auto padding = GetPadding(); + const MeasureSpec childWidthMeasureSpec = GetChildMeasureSpec( widthMeasureSpec, padding.start + padding.end, desiredWidth ); + const MeasureSpec childHeightMeasureSpec = GetChildMeasureSpec( heightMeasureSpec, padding.top + padding.bottom, Toolkit::ChildLayoutData::WRAP_CONTENT ); + childLayout->Measure( childWidthMeasureSpec, childHeightMeasureSpec ); + childHeight = childLayout->GetMeasuredHeight(); + usedExcessSpace += childHeight; + } + else + { + MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec ); + childHeight = childLayout->GetMeasuredHeight(); + } + + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LinearLayout::MeasureVertical childHeight(%d)\n", MeasureSpec::IntType( childHeight ) ); + + auto length = childHeight + LayoutLength::IntType( childMargin.top + childMargin.bottom ); + auto cellPadding = i < GetChildCount() - 1 ? mCellPadding.height : 0; + auto totalLength = mTotalLength; + mTotalLength = std::max( totalLength, totalLength + length + cellPadding ); + } bool matchWidthLocally = false; if( widthMode != MeasureSpec::Mode::EXACTLY && desiredWidth == Toolkit::ChildLayoutData::MATCH_PARENT ) @@ -373,9 +639,21 @@ void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec he maxWidth = std::max( maxWidth, childWidth ); allFillParent = ( allFillParent && desiredWidth == Toolkit::ChildLayoutData::MATCH_PARENT ); - alternativeMaxWidth = std::max( alternativeMaxWidth, matchWidthLocally ? marginWidth : childWidth ); + if( childWeight > 0 ) + { + /* + * Widths of weighted Views are bogus if we end up + * remeasuring, so keep them separate. + */ + weightedMaxWidth = std::max( weightedMaxWidth, matchWidthLocally ? marginWidth : childWidth ); + } + else + { + alternativeMaxWidth = std::max( alternativeMaxWidth, matchWidthLocally ? marginWidth : childWidth ); + } } } + Extents padding = GetPadding(); mTotalLength += padding.top + padding.bottom; auto heightSize = mTotalLength; @@ -383,6 +661,92 @@ void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec he MeasuredSize heightSizeAndState = ResolveSizeAndState( heightSize, heightMeasureSpec, MeasuredSize::State::MEASURED_SIZE_OK); heightSize = heightSizeAndState.GetSize(); + // Either expand children with weight to take up available space or + // shrink them if they extend beyond our current bounds. If we skipped + // measurement on any children, we need to measure them now. + + // 2nd phase: + // We cycle through weighted children now (children with weight > 0). + // The children are measured with exact size equal to their share of the available space based on their weights. + // mTotalLength is updated to include weighted children measured sizes. + int remainingExcess = heightSize - mTotalLength + usedExcessSpace; + if( remainingExcess != 0 && totalWeight > 0.0f ) + { + float remainingWeightSum = totalWeight; + + mTotalLength = 0; + + for( unsigned int i = 0; i < GetChildCount(); ++i ) + { + auto childLayout = GetChildAt( i ); + auto childOwner = childLayout->GetOwner(); + auto desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); + auto desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); + auto childWeight = childOwner.GetProperty( Toolkit::LinearLayout::ChildProperty::WEIGHT ); + auto childMargin = childLayout->GetMargin(); + + LayoutLength childHeight = 0; + if( childWeight > 0 ) + { + int share = static_cast( childWeight * remainingExcess / remainingWeightSum ); + remainingExcess -= share; + remainingWeightSum -= childWeight; + + // Always lay out weighted elements with intrinsic size regardless of the parent spec + // for consistency between specs. + if( desiredHeight == 0 ) + { + // This child needs to be laid out from scratch using + // only its share of excess space. + childHeight = share; + } + else + { + // This child had some intrinsic width to which we + // need to add its share of excess space. + childHeight = childLayout->GetMeasuredHeight() + share; + } + + const MeasureSpec childWidthMeasureSpec = GetChildMeasureSpec( widthMeasureSpec, padding.start + padding.end, desiredWidth ); + const MeasureSpec childHeightMeasureSpec = MeasureSpec( childHeight, MeasureSpec::Mode::EXACTLY ); + childLayout->Measure( childWidthMeasureSpec, childHeightMeasureSpec ); + + // Child may now not fit in vertical dimension. + if( childLayout->GetMeasuredHeightAndState().GetState() == MeasuredSize::State::MEASURED_SIZE_TOO_SMALL ) + { + childState.heightState = MeasuredSize::State::MEASURED_SIZE_TOO_SMALL; + } + } + + bool matchWidthLocally = false; + if( widthMode != MeasureSpec::Mode::EXACTLY && desiredWidth == Toolkit::ChildLayoutData::MATCH_PARENT ) + { + // Will have to re-measure at least this child when we know exact height. + matchWidth = true; + matchWidthLocally = true; + } + + auto marginWidth = LayoutLength( childMargin.start + childMargin.end ); + auto childWidth = childLayout->GetMeasuredWidth() + marginWidth; + maxWidth = std::max( maxWidth, childWidth ); + allFillParent = allFillParent && desiredWidth == Toolkit::ChildLayoutData::MATCH_PARENT; + alternativeMaxWidth = std::max( alternativeMaxWidth, matchWidthLocally ? marginWidth : childWidth ); + + childHeight = childLayout->GetMeasuredHeight(); + auto length = childHeight + LayoutLength::IntType( childMargin.top + childMargin.bottom ); + auto cellPadding = i < GetChildCount() - 1 ? mCellPadding.height : 0; + auto totalLength = mTotalLength; + mTotalLength = std::max( totalLength, totalLength + length + cellPadding ); + } + + // Add in our padding + mTotalLength += padding.top + padding.bottom; + } + else + { + alternativeMaxWidth = std::max( alternativeMaxWidth, weightedMaxWidth ); + } + if( !allFillParent && widthMode != MeasureSpec::Mode::EXACTLY ) { maxWidth = alternativeMaxWidth; @@ -436,13 +800,36 @@ void LinearLayout::LayoutVertical( LayoutLength left, LayoutLength top, LayoutLe LayoutLength childTop( padding.top ); LayoutLength childLeft( padding.start ); - // Where bottom of child should go + // Where end of child should go auto width = right - left; // Space available for child auto childSpace = width - padding.start - padding.end; auto count = GetChildCount(); + switch ( mAlignment & VERTICAL_ALIGNMENT_MASK ) + { + case Dali::Toolkit::LinearLayout::Alignment::TOP: + { + // mTotalLength contains the padding already + childTop = LayoutLength( padding.top ); + break; + } + case Dali::Toolkit::LinearLayout::Alignment::BOTTOM: + { + // mTotalLength contains the padding already + childTop = LayoutLength( padding.top ) + bottom - top - mTotalLength; + break; + } + case Dali::Toolkit::LinearLayout::Alignment::CENTER_VERTICAL: + default: + { + // mTotalLength contains the padding already + childTop = LayoutLength( padding.top ) + ( bottom - top - mTotalLength ) / 2; + break; + } + } + for( unsigned int childIndex = 0; childIndex < count; childIndex++) { LayoutItemPtr childLayout = GetChildAt( childIndex ); @@ -453,8 +840,25 @@ void LinearLayout::LayoutVertical( LayoutLength left, LayoutLength top, LayoutLe auto childMargin = childLayout->GetMargin(); childTop += childMargin.top; - childLeft = LayoutLength( padding.start ) + ( childSpace - childWidth ) / 2 + childMargin.start - childMargin.end; - + switch ( mAlignment & HORIZONTAL_ALIGNMENT_MASK ) + { + case Dali::Toolkit::LinearLayout::Alignment::BEGIN: + default: + { + childLeft = LayoutLength( padding.start ) + childMargin.start; + break; + } + case Dali::Toolkit::LinearLayout::Alignment::END: + { + childLeft = width - padding.end - childWidth - childMargin.end; + break; + } + case Dali::Toolkit::LinearLayout::Alignment::CENTER_HORIZONTAL: + { + childLeft = LayoutLength( padding.start ) + ( childSpace - childWidth ) / 2 + childMargin.start - childMargin.end; + break; + } + } childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight ); childTop += childHeight + childMargin.bottom + mCellPadding.height; }