#include <dali/integration-api/debug.h>
#include <dali/public-api/common/extents.h>
#include <dali/public-api/actors/actor.h>
+#include <dali/devel-api/object/handle-devel.h>
//INTERNAL INCLUDES
#include <dali-toolkit/devel-api/layouting/layout-item.h>
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() );
: LayoutGroup(),
mCellPadding( 0, 0 ),
mOrientation( Dali::Toolkit::LinearLayout::Orientation::HORIZONTAL ),
+ mAlignment( Dali::Toolkit::LinearLayout::Alignment::BEGIN | Dali::Toolkit::LinearLayout::Alignment::CENTER_VERTICAL ),
mTotalLength( 0 )
{
}
{
}
+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 )
{
- mCellPadding = size;
+ if ( mCellPadding != size )
+ {
+ mCellPadding = size;
+ RequestLayout();
+ }
}
-LayoutSize LinearLayout::GetCellPadding()
+LayoutSize LinearLayout::GetCellPadding() const
{
return mCellPadding;
}
void LinearLayout::SetOrientation( Dali::Toolkit::LinearLayout::Orientation orientation )
{
- mOrientation = orientation;
+ if ( mOrientation != orientation )
+ {
+ mOrientation = orientation;
+ RequestLayout();
+ }
}
-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)
{
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;
mTotalLength = 0;
// measure children, and determine if further resolution is required
- for( unsigned int i=0; i<GetChildCount(); ++i )
+
+ // 1st phase:
+ // We cycle through all children and measure children with weight 0 (non weighted children) according to their specs
+ // to accumulate total used space in mTotalLength based on measured sizes and margins.
+ // Weighted children are not measured at this phase.
+ // Available space for weighted children will be calculated in the phase 2 based on mTotalLength value.
+ for( unsigned int i = 0; i < GetChildCount(); ++i )
{
auto childLayout = GetChildAt( i );
if( childLayout )
{
auto childOwner = childLayout->GetOwner();
auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
-
- MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec );
- auto childWidth = childLayout->GetMeasuredWidth();
+ auto desiredWidth = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
+ auto childWeight = childOwner.GetProperty<float>( 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<GetChildCount()-1 ? mCellPadding.width: 0;
-
- if( isExactly )
+ const bool useExcessSpace = desiredWidth == 0 && childWeight > 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;
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 );
+ }
}
}
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<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
+ auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
+ auto childWeight = childOwner.GetProperty<float>( Toolkit::LinearLayout::ChildProperty::WEIGHT );
+ auto childMargin = childLayout->GetMargin();
+
+ LayoutLength childWidth = 0;
+ if( childWeight > 0 )
+ {
+ int share = static_cast<int>( 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;
Extents padding = GetPadding();
- LayoutLength childTop( 0 );
+ LayoutLength childTop( padding.top );
LayoutLength childLeft( padding.start );
// Where bottom of child should go
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++)
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;
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;
mTotalLength = 0;
// measure children, and determine if further resolution is required
- for( unsigned int i=0; i<GetChildCount(); ++i )
+
+ // 1st phase:
+ // We cycle through all children and measure children with weight 0 (non weighted children) according to their specs
+ // to accumulate total used space in mTotalLength based on measured sizes and margins.
+ // Weighted children are not measured at this phase.
+ // Available space for weighted children will be calculated in the phase 2 based on mTotalLength value.
+ for( unsigned int i = 0; i < GetChildCount(); ++i )
{
auto childLayout = GetChildAt( i );
if( childLayout )
{
auto childOwner = childLayout->GetOwner();
auto desiredWidth = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
-
- MeasureChildWithMargins( childLayout, widthMeasureSpec, 0, heightMeasureSpec, 0 );
- auto childHeight = childLayout->GetMeasuredHeight();
+ auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
+ auto childWeight = childOwner.GetProperty<float>( Toolkit::LinearLayout::ChildProperty::WEIGHT );
auto childMargin = childLayout->GetMargin();
- 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);
+ totalWeight += childWeight;
+
+ bool useExcessSpace = desiredHeight == 0 && childWeight > 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 )
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;
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<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
+ auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
+ auto childWeight = childOwner.GetProperty<float>( Toolkit::LinearLayout::ChildProperty::WEIGHT );
+ auto childMargin = childLayout->GetMargin();
+
+ LayoutLength childHeight = 0;
+ if( childWeight > 0 )
+ {
+ int share = static_cast<int>( 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;
{
Extents padding = GetPadding();
- LayoutLength childTop( 0 );
+ 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 );
auto childMargin = childLayout->GetMargin();
childTop += childMargin.top;
- childLeft = ( 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;
}