From: Kimmo Hoikka Date: Fri, 14 Sep 2018 10:57:29 +0000 (+0100) Subject: Removed dangerous implicit float conversion from LayoutLength and removed some of... X-Git-Tag: dali_1.3.42~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=94a17596be5c49de1bd7f19b997b6625a4407083 Removed dangerous implicit float conversion from LayoutLength and removed some of the related ambiguities caused by use of auto keyword Change-Id: Ibaaa17f98d7d9d77ca222b70211b162964b19552 --- diff --git a/automated-tests/src/dali-toolkit/custom-layout-impl.cpp b/automated-tests/src/dali-toolkit/custom-layout-impl.cpp index 115336a..30ebc29 100644 --- a/automated-tests/src/dali-toolkit/custom-layout-impl.cpp +++ b/automated-tests/src/dali-toolkit/custom-layout-impl.cpp @@ -41,7 +41,7 @@ CustomLayoutPtr CustomLayout::New() return layout; } -void CustomLayout::MeasureChildren( Dali::Toolkit::Internal::LayoutItemPtr childLayout, MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec, int resultingWidth, int resultingHeight ) +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; @@ -61,7 +61,7 @@ void CustomLayout::MeasureChildren( Dali::Toolkit::Internal::LayoutItemPtr child MeasureChild( childLayout, childWidthMeasureSpec, childHeightMeasureSpec ); resultingWidth += childLayout->GetMeasuredWidth(); - resultingHeight = std::max( childLayout->GetMeasuredHeight().mValue, resultingHeight ); + resultingHeight = std::max( childLayout->GetMeasuredHeight(), resultingHeight ); } void CustomLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec ) @@ -93,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++) { @@ -116,8 +116,8 @@ 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); childLayoutImpl.Layout( currentLeft, childTop, currentLeft + childWidth, childTop + childHeight ); diff --git a/automated-tests/src/dali-toolkit/custom-layout-impl.h b/automated-tests/src/dali-toolkit/custom-layout-impl.h index 7fb7be2..06c67e0 100644 --- a/automated-tests/src/dali-toolkit/custom-layout-impl.h +++ b/automated-tests/src/dali-toolkit/custom-layout-impl.h @@ -107,7 +107,7 @@ private: * @param[out] resultingWidth resulting width of layout after children are measured * @param[out] resultingHeight resulting height of layout after children are measured */ - void MeasureChildren( Dali::Toolkit::Internal::LayoutItemPtr childLayout, MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec, int resultingWidth, int resultingHeight ); + void MeasureChildren( Dali::Toolkit::Internal::LayoutItemPtr childLayout, MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec, LayoutLength resultingWidth, LayoutLength resultingHeight ); private: diff --git a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp index 8cdd8bc..4354909 100644 --- a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp +++ b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp @@ -374,13 +374,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 +395,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 +489,7 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec( } } - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec resultSize(%u)\n", resultSize ); - + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec resultSize(%u)\n", resultSize.mValue ); //noinspection ResourceType return MeasureSpec( resultSize, resultMode ); diff --git a/dali-toolkit/devel-api/layouting/layout-item-impl.cpp b/dali-toolkit/devel-api/layouting/layout-item-impl.cpp index 987b799..35b9997 100644 --- a/dali-toolkit/devel-api/layouting/layout-item-impl.cpp +++ b/dali-toolkit/devel-api/layouting/layout-item-impl.cpp @@ -347,9 +347,7 @@ void LayoutItem::SetLayoutRequested() void LayoutItem::SetMeasuredDimensions( MeasuredSize measuredWidth, MeasuredSize measuredHeight ) { DALI_LOG_INFO( gLayoutFilter, Debug::Verbose, "LayoutItem::SetMeasuredDimensions width(%d) height(%d) \n", - MeasureSpec::IntType( measuredWidth.GetSize() ), - MeasureSpec::IntType( measuredHeight.GetSize() ) - ); + measuredWidth.GetSize().mValue, measuredHeight.GetSize().mValue ); mImpl->SetPrivateFlag( Impl::PRIVATE_FLAG_MEASURED_DIMENSION_SET ); mImpl->mMeasuredWidth = measuredWidth; @@ -445,10 +443,10 @@ bool LayoutItem::SetFrame( LayoutLength left, LayoutLength top, LayoutLength rig { changed = true; - auto oldWidth = mImpl->mRight - mImpl->mLeft; - auto oldHeight = mImpl->mBottom - mImpl->mTop; - auto newWidth = right - left; - auto newHeight = bottom - top; + LayoutLength oldWidth = mImpl->mRight - mImpl->mLeft; + LayoutLength oldHeight = mImpl->mBottom - mImpl->mTop; + LayoutLength newWidth = right - left; + LayoutLength newHeight = bottom - top; bool sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight); mImpl->mLeft = left; @@ -469,11 +467,11 @@ bool LayoutItem::SetFrame( LayoutLength left, LayoutLength top, LayoutLength rig if( mImpl->mAnimated ) { auto animation = Animation::New( 0.5f ); - animation.AnimateTo( Property( actor, Actor::Property::POSITION_X ), float( left.mValue ) ); - animation.AnimateTo( Property( actor, Actor::Property::POSITION_Y ), float( top.mValue ) ); + animation.AnimateTo( Property( actor, Actor::Property::POSITION_X ), left.AsFloat() ); + animation.AnimateTo( Property( actor, Actor::Property::POSITION_Y ), top.AsFloat() ); - animation.AnimateTo( Property( actor, Actor::Property::SIZE_WIDTH ), float( newWidth ) ); - animation.AnimateTo( Property( actor, Actor::Property::SIZE_HEIGHT ), float( newHeight ) ); + animation.AnimateTo( Property( actor, Actor::Property::SIZE_WIDTH ), newWidth.AsFloat() ); + animation.AnimateTo( Property( actor, Actor::Property::SIZE_HEIGHT ), newHeight.AsFloat() ); animation.FinishedSignal().Connect( mSlotDelegate, &LayoutItem::OnLayoutAnimationFinished ); animation.Play(); @@ -481,10 +479,10 @@ bool LayoutItem::SetFrame( LayoutLength left, LayoutLength top, LayoutLength rig else { // @todo Collate into list of Property & Property::Value pairs. - actor.SetX( float( left.mValue ) ); - actor.SetY( float( top.mValue ) ); - actor.SetProperty( Actor::Property::SIZE_WIDTH, float( newWidth ) ); - actor.SetProperty( Actor::Property::SIZE_HEIGHT, float( newHeight ) ); + actor.SetX( left.AsFloat() ); + actor.SetY( top.AsFloat() ); + actor.SetProperty( Actor::Property::SIZE_WIDTH, newWidth.AsFloat() ); + actor.SetProperty( Actor::Property::SIZE_HEIGHT, newHeight.AsFloat() ); } } @@ -505,7 +503,7 @@ void LayoutItem::OnLayoutAnimationFinished( Animation& animation ) auto actor = Actor::DownCast(owner); if( actor ) { - actor.SetSize( Vector3( mImpl->mRight-mImpl->mLeft, mImpl->mBottom-mImpl->mTop, 0.0f ) ); + actor.SetSize( Vector3( mImpl->mRight.AsFloat() - mImpl->mLeft.AsFloat(), mImpl->mBottom.AsFloat() - mImpl->mTop.AsFloat(), 0.0f ) ); } } diff --git a/dali-toolkit/devel-api/layouting/layout-length.h b/dali-toolkit/devel-api/layouting/layout-length.h index 9953ed8..73c9b96 100644 --- a/dali-toolkit/devel-api/layouting/layout-length.h +++ b/dali-toolkit/devel-api/layouting/layout-length.h @@ -34,6 +34,11 @@ class LayoutLength public: using IntType = int; + LayoutLength() + : mValue( 0 ) + { + } + LayoutLength( IntType value ) : mValue( value ) { @@ -164,12 +169,16 @@ public: } LayoutLength operator*( float rhs ) { - return LayoutLength(LayoutLength::IntType(float(mValue) * rhs)); + return LayoutLength(LayoutLength::IntType(AsFloat() * rhs)); } - operator float() + /** + * @brief explicit method to return the value as float + * @return the LayoutLength as float + */ + float AsFloat() const { - return float( mValue ); + return static_cast( mValue ); } IntType mValue; diff --git a/dali-toolkit/devel-api/layouting/layout-size.h b/dali-toolkit/devel-api/layouting/layout-size.h index b7ec71e..b4802b3 100644 --- a/dali-toolkit/devel-api/layouting/layout-size.h +++ b/dali-toolkit/devel-api/layouting/layout-size.h @@ -42,6 +42,12 @@ public: { } + LayoutSize( LayoutLength anX, LayoutLength aY ) + : x( anX.mValue ), + y( aY.mValue ) + { + } + LayoutSize( const LayoutSize& layoutSize ) : x( layoutSize.x ), y( layoutSize.y ) diff --git a/dali-toolkit/devel-api/layouting/measure-spec.h b/dali-toolkit/devel-api/layouting/measure-spec.h index 04c4d01..2925724 100644 --- a/dali-toolkit/devel-api/layouting/measure-spec.h +++ b/dali-toolkit/devel-api/layouting/measure-spec.h @@ -36,7 +36,6 @@ namespace Toolkit class DALI_TOOLKIT_API MeasureSpec { public: - using IntType = LayoutLength::IntType; enum class Mode { @@ -48,12 +47,12 @@ public: }; MeasureSpec( LayoutLength measureSpec, MeasureSpec::Mode mode ) - : mSize( measureSpec.mValue ), + : mSize( measureSpec ), mMode( mode ) { } - MeasureSpec( IntType measureSpec ) + MeasureSpec( LayoutLength measureSpec ) : mSize( measureSpec ), mMode( Mode::UNSPECIFIED ) { @@ -82,6 +81,16 @@ public: } /** + * @brief Set the mode of the measure spec. + * + * @param mode The mode to set + */ + void SetMode( MeasureSpec::Mode mode ) + { + mMode = mode; + } + + /** * @brief Get the mode of the measure spec. * * @return The mode of the measure spec @@ -92,11 +101,21 @@ public: } /** + * @brief Set the size of the measure spec + * + * @param size the size to set + */ + void SetSize( LayoutLength size ) + { + mSize = size; + } + + /** * @brief Get the size of the measure spec * * @return the size of the measure spec */ - IntType GetSize() const + LayoutLength GetSize() const { return mSize; } @@ -121,7 +140,7 @@ public: return MeasureSpec( size, MeasureSpec::Mode::UNSPECIFIED ); } - if( delta < 0 && measureSpec.mSize < static_cast(abs(delta)) ) + if( delta < 0 && measureSpec.mSize < abs(delta) ) { size = 0; } @@ -132,9 +151,11 @@ public: return MeasureSpec( size, mode ); } -public: - IntType mSize; ///< The specified size +private: + + LayoutLength mSize; ///< The specified size Mode mMode; ///< The measure mode + }; inline std::ostream& operator<< (std::ostream& o, const MeasureSpec& measureSpec ) diff --git a/dali-toolkit/internal/layouting/absolute-layout-impl.cpp b/dali-toolkit/internal/layouting/absolute-layout-impl.cpp index 5c5989d..4cba410 100644 --- a/dali-toolkit/internal/layouting/absolute-layout-impl.cpp +++ b/dali-toolkit/internal/layouting/absolute-layout-impl.cpp @@ -78,8 +78,10 @@ void AbsoluteLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec height MeasuredSize::State heightState; } childState = { MeasuredSize::State::MEASURED_SIZE_OK, MeasuredSize::State::MEASURED_SIZE_OK }; - auto minPosition = Vector3( Vector3::ZERO ); - auto maxPosition = Vector3( Vector3::ZERO ); + LayoutLength minPositionX( 0 ); + LayoutLength minPositionY( 0 ); + LayoutLength maxPositionX( 0 ); + LayoutLength maxPositionY( 0 ); // measure children for( unsigned int i=0; iGetMeasuredWidth(); - auto childHeight = childLayout->GetMeasuredHeight(); + LayoutLength childWidth = childLayout->GetMeasuredWidth(); + LayoutLength childHeight = childLayout->GetMeasuredHeight(); // Determine the width and height needed by the children using their given position and size. // Children could overlap so find the left most and right most child. auto childPosition = childOwner.GetProperty< Vector3 >( Actor::Property::POSITION ); - minPosition.x = std::min( minPosition.x, childPosition.x ); - maxPosition.x = std::max( maxPosition.x, childPosition.x + childWidth ); + LayoutLength childLeft = childPosition.x; + LayoutLength childTop = childPosition.y; + + minPositionX = std::min( minPositionX, childLeft ); + maxPositionX = std::max( maxPositionX, childLeft + childWidth ); // Children could overlap so find the highest and lowest child. - minPosition.y = std::min( minPosition.y, childPosition.y ); - maxPosition.y = std::max( maxPosition.y, childPosition.y + childHeight ); + minPositionY = std::min( minPositionY, childTop ); + maxPositionY = std::max( maxPositionY, childTop + childHeight ); // Store current width and height needed to contain all children. - totalWidth = maxPosition.x - minPosition.x; - totalHeight = maxPosition.y - minPosition.y; - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "AbsoluteLayout::OnMeasure child width(%f) height(%f) \n", (float)totalWidth, (float)totalHeight ); + totalWidth = maxPositionX - minPositionX; + totalHeight = maxPositionY - minPositionY; + DALI_LOG_INFO( gLogFilter, Debug::Concise, "AbsoluteLayout::OnMeasure child width(%f) height(%f) \n", totalWidth.AsFloat(), totalHeight.AsFloat() ); if( childLayout->GetMeasuredWidthAndState().GetState() == MeasuredSize::State::MEASURED_SIZE_TOO_SMALL ) { @@ -149,13 +154,13 @@ void AbsoluteLayout::OnLayout( bool changed, LayoutLength left, LayoutLength top if( childLayout != nullptr ) { auto childOwner = childLayout->GetOwner(); - auto childWidth = childLayout->GetMeasuredWidth(); - auto childHeight = childLayout->GetMeasuredHeight(); + LayoutLength childWidth = childLayout->GetMeasuredWidth(); + LayoutLength childHeight = childLayout->GetMeasuredHeight(); auto childPosition = childOwner.GetProperty< Vector3 >( Actor::Property::POSITION ); - auto childTop = childPosition.y; - auto childLeft = childPosition.x; + LayoutLength childTop = childPosition.y; + LayoutLength childLeft = childPosition.x; DALI_LOG_INFO( gLogFilter, Debug::General, "AbsoluteLayout::OnLayout child[%s] position(%f,%f) child width[%d] height(%d)\n", Toolkit::Control::DownCast( childOwner ).GetName().c_str(), diff --git a/dali-toolkit/internal/layouting/flex-layout-impl.cpp b/dali-toolkit/internal/layouting/flex-layout-impl.cpp index bf5d084..1df4f5f 100644 --- a/dali-toolkit/internal/layouting/flex-layout-impl.cpp +++ b/dali-toolkit/internal/layouting/flex-layout-impl.cpp @@ -218,23 +218,23 @@ void FlexLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeas if( widthMeasureSpec.GetMode() == MeasureSpec::Mode::EXACTLY ) { - width = widthMeasureSpec.GetSize(); + width = widthMeasureSpec.GetSize().AsFloat(); YGNodeStyleSetWidth( mRoot, width ); } else if( widthMeasureSpec.GetMode() == MeasureSpec::Mode::AT_MOST ) { - width = widthMeasureSpec.GetSize(); + width = widthMeasureSpec.GetSize().AsFloat(); YGNodeStyleSetMaxWidth( mRoot, width ); } if ( heightMeasureSpec.GetMode() == MeasureSpec::Mode::EXACTLY ) { - height = heightMeasureSpec.GetSize(); + height = heightMeasureSpec.GetSize().AsFloat(); YGNodeStyleSetHeight( mRoot, height ); } else if ( heightMeasureSpec.GetMode() == MeasureSpec::Mode::AT_MOST ) { - height = heightMeasureSpec.GetSize(); + height = heightMeasureSpec.GetSize().AsFloat(); YGNodeStyleSetMaxHeight( mRoot, height ); } @@ -249,8 +249,8 @@ void FlexLayout::OnLayout( bool changed, LayoutLength left, LayoutLength top, La auto owner = GetOwner(); auto actor = Actor::DownCast(owner); bool isLayoutRtl = actor ? actor.GetProperty( Actor::Property::LAYOUT_DIRECTION ).Get() == LayoutDirection::RIGHT_TO_LEFT: false; - auto width = right - left; - auto height = bottom - top; + LayoutLength width = right - left; + LayoutLength height = bottom - top; #if defined(DEBUG_ENABLED) std::ostringstream oss; @@ -263,7 +263,7 @@ void FlexLayout::OnLayout( bool changed, LayoutLength left, LayoutLength top, La DALI_LOG_INFO( gLogFilter, Debug::Concise, oss.str().c_str() ); #endif - YGNodeCalculateLayout( mRoot, width, height, isLayoutRtl ? YGDirectionRTL : YGDirectionLTR ); + YGNodeCalculateLayout( mRoot, width.AsFloat(), height.AsFloat(), isLayoutRtl ? YGDirectionRTL : YGDirectionLTR ); auto count = GetChildCount(); for( unsigned int childIndex = 0; childIndex < count; childIndex++) @@ -272,10 +272,10 @@ void FlexLayout::OnLayout( bool changed, LayoutLength left, LayoutLength top, La if( childLayout != nullptr ) { YGNodeRef node = YGNodeGetChild(mRoot, childIndex); - auto childLeft = YGNodeLayoutGetLeft( node ) + left; - auto childTop = YGNodeLayoutGetTop( node ) + top; - auto childWidth = YGNodeLayoutGetWidth( node ); - auto childHeight = YGNodeLayoutGetHeight( node ); + LayoutLength childLeft = LayoutLength( YGNodeLayoutGetLeft( node ) ) + left; + LayoutLength childTop = LayoutLength( YGNodeLayoutGetTop( node ) ) + top; + LayoutLength childWidth = LayoutLength( YGNodeLayoutGetWidth( node ) ); + LayoutLength childHeight = LayoutLength( YGNodeLayoutGetHeight( node ) ); childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight ); } } @@ -332,12 +332,12 @@ YGSize FlexLayout::OnChildMeasure( YGNodeRef node, // Remove padding here since Yoga doesn't consider it as a part of the node size Extents padding = childLayout->GetPadding(); - auto measuredWidth = childLayout->GetMeasuredWidth() - padding.end - padding.start; - auto measuredHeight = childLayout->GetMeasuredHeight() - padding.bottom - padding.top; + LayoutLength measuredWidth = childLayout->GetMeasuredWidth() - padding.end - padding.start; + LayoutLength measuredHeight = childLayout->GetMeasuredHeight() - padding.bottom - padding.top; return YGSize{ - .width = measuredWidth, - .height = measuredHeight, + .width = measuredWidth.AsFloat(), + .height = measuredHeight.AsFloat(), }; } diff --git a/dali-toolkit/internal/layouting/grid-impl.cpp b/dali-toolkit/internal/layouting/grid-impl.cpp index af9b82e..3bb54a9 100644 --- a/dali-toolkit/internal/layouting/grid-impl.cpp +++ b/dali-toolkit/internal/layouting/grid-impl.cpp @@ -100,8 +100,8 @@ void Grid::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpe LayoutLength widthSize = widthMeasureSpec.GetSize(); LayoutLength heightSize = heightMeasureSpec.GetSize(); - int availableContentWidth(0); - int availableContentHeight(0); + LayoutLength availableContentWidth( 0 ); + LayoutLength availableContentHeight( 0 ); LayoutLength desiredChildHeight( 0 ); LayoutLength desiredChildWidth( 0 ); @@ -149,11 +149,11 @@ void Grid::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpe mTotalWidth = std::min( mTotalWidth, widthSize ); } - availableContentWidth = mTotalWidth - gridLayoutPadding.start - gridLayoutPadding.end; + availableContentWidth = mTotalWidth.mValue - gridLayoutPadding.start - gridLayoutPadding.end; widthSize = mTotalWidth; DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Grid::OnMeasure availableContentWidth(%d) mTotalWidth(%d) \n", - availableContentWidth, + availableContentWidth.mValue, mTotalWidth.mValue ); // HEIGHT SPECIFICATIONS @@ -196,10 +196,10 @@ void Grid::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpe } // If number of columns not defined - DetermineNumberOfColumns( availableContentWidth ); + DetermineNumberOfColumns( availableContentWidth.mValue ); // Locations define the start, end,top and bottom of each cell. - mLocations->CalculateLocations( mNumColumns, availableContentWidth, availableContentHeight, childCount, 0, 0 ); + mLocations->CalculateLocations( mNumColumns, availableContentWidth.mValue, availableContentHeight.mValue, childCount, 0, 0 ); SetMeasuredDimensions( ResolveSizeAndState( widthSize, widthMeasureSpec, MeasuredSize::State::MEASURED_SIZE_OK ), diff --git a/dali-toolkit/internal/layouting/linear-layout-impl.cpp b/dali-toolkit/internal/layouting/linear-layout-impl.cpp index fdba7e6..ecde6eb 100644 --- a/dali-toolkit/internal/layouting/linear-layout-impl.cpp +++ b/dali-toolkit/internal/layouting/linear-layout-impl.cpp @@ -192,7 +192,7 @@ void LinearLayout::MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec LayoutLength alternativeMaxHeight = 0; LayoutLength weightedMaxHeight = 0; float totalWeight = 0; - int usedExcessSpace = 0; + LayoutLength usedExcessSpace = 0; struct { MeasuredSize::State widthState; @@ -215,10 +215,10 @@ void LinearLayout::MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec if( childLayout ) { auto childOwner = childLayout->GetOwner(); - auto desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); - auto desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); - auto childWeight = childOwner.GetProperty( Toolkit::LinearLayout::ChildProperty::WEIGHT ); - auto childMargin = childLayout->GetMargin(); + LayoutLength desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); + LayoutLength desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); + float childWeight = childOwner.GetProperty( Toolkit::LinearLayout::ChildProperty::WEIGHT ); + Extents childMargin = childLayout->GetMargin(); totalWeight += childWeight; @@ -236,7 +236,7 @@ void LinearLayout::MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec // 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(); + Extents 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 ); @@ -249,16 +249,16 @@ void LinearLayout::MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec 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; + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LinearLayout::OnMeasure childWidth(%d)\n", childWidth.mValue ); + LayoutLength length = childWidth + LayoutLength::IntType( childMargin.start + childMargin.end ); + LayoutLength cellPadding = i < GetChildCount() - 1 ? mCellPadding.width : 0; if( isExactly ) { mTotalLength += length; } else { - auto totalLength = mTotalLength; + LayoutLength totalLength = mTotalLength; mTotalLength = std::max( totalLength, totalLength + length + cellPadding ); } } @@ -271,8 +271,8 @@ void LinearLayout::MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec matchHeightLocally = true; } - auto marginHeight = LayoutLength( childMargin.top + childMargin.bottom ); - auto childHeight = childLayout->GetMeasuredHeight() + marginHeight; + LayoutLength marginHeight = childMargin.top + childMargin.bottom; + LayoutLength childHeight = childLayout->GetMeasuredHeight() + marginHeight; if( childLayout->GetMeasuredWidthAndState().GetState() == MeasuredSize::State::MEASURED_SIZE_TOO_SMALL ) { @@ -302,7 +302,7 @@ void LinearLayout::MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec Extents padding = GetPadding(); mTotalLength += padding.start + padding.end; - auto widthSize = mTotalLength; + LayoutLength widthSize = mTotalLength; widthSize = std::max( widthSize, GetSuggestedMinimumWidth() ); MeasuredSize widthSizeAndState = ResolveSizeAndState( widthSize, widthMeasureSpec, MeasuredSize::State::MEASURED_SIZE_OK); widthSize = widthSizeAndState.GetSize(); @@ -312,7 +312,7 @@ void LinearLayout::MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec // 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; + LayoutLength remainingExcess = widthSize - mTotalLength + usedExcessSpace; if( remainingExcess != 0 && totalWeight > 0 ) { float remainingWeightSum = totalWeight; @@ -323,15 +323,15 @@ void LinearLayout::MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec { 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 desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); + LayoutLength desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); + float childWeight = childOwner.GetProperty( Toolkit::LinearLayout::ChildProperty::WEIGHT ); + Extents childMargin = childLayout->GetMargin(); LayoutLength childWidth = 0; if( childWeight > 0 ) { - int share = static_cast( childWeight * remainingExcess / remainingWeightSum ); + LayoutLength share = (childWeight * remainingExcess.mValue) / remainingWeightSum; remainingExcess -= share; remainingWeightSum -= childWeight; @@ -361,21 +361,21 @@ void LinearLayout::MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec } } - auto length = childLayout->GetMeasuredWidth() + LayoutLength::IntType( childMargin.start + childMargin.end ); - auto cellPadding = i < GetChildCount() - 1 ? mCellPadding.width : 0; + LayoutLength length = childLayout->GetMeasuredWidth() + LayoutLength( childMargin.start + childMargin.end ); + LayoutLength cellPadding = i < GetChildCount() - 1 ? mCellPadding.width : 0; if( isExactly ) { mTotalLength += length; } else { - auto totalLength = mTotalLength; + LayoutLength 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; + LayoutLength marginHeight = childMargin.top + childMargin.bottom; + LayoutLength childHeight = childLayout->GetMeasuredHeight() + marginHeight; maxHeight = std::max( maxHeight, childHeight ); alternativeMaxHeight = std::max( alternativeMaxHeight, matchHeightLocally ? marginHeight : childHeight ); @@ -412,26 +412,26 @@ void LinearLayout::ForceUniformHeight( int count, MeasureSpec widthMeasureSpec ) // Pretend that the linear layout has an exact size. This is the measured height of // ourselves. The measured height should be the max height of the children, changed // to accommodate the heightMeasureSpec from the parent - auto uniformMeasureSpec = MeasureSpec( GetMeasuredHeight(), MeasureSpec::Mode::EXACTLY ); + MeasureSpec uniformMeasureSpec( GetMeasuredHeight(), MeasureSpec::Mode::EXACTLY ); for (int i = 0; i < count; ++i) { LayoutItemPtr childLayout = GetChildAt(i); if( childLayout != nullptr ) { auto childOwner = childLayout->GetOwner(); - auto desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); - auto desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); + LayoutLength desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); + LayoutLength desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); if( desiredHeight == Toolkit::ChildLayoutData::MATCH_PARENT ) { // Temporarily force children to reuse their old measured width - int oldWidth = desiredWidth; + LayoutLength oldWidth = desiredWidth; childOwner.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, childLayout->GetMeasuredWidth().mValue ); // Remeasure with new dimensions - MeasureChildWithMargins( childLayout, widthMeasureSpec, 0, uniformMeasureSpec, 0); + MeasureChildWithMargins( childLayout, widthMeasureSpec, 0, uniformMeasureSpec, 0 ); - childOwner.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, oldWidth ); + childOwner.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, oldWidth.mValue ); } } } @@ -449,10 +449,10 @@ void LinearLayout::LayoutHorizontal( LayoutLength left, LayoutLength top, Layout LayoutLength childLeft( padding.start ); // Where bottom of child should go - auto height = bottom - top; + LayoutLength height = bottom - top; // Space available for child - auto childSpace = height - padding.top - padding.bottom; + LayoutLength childSpace = height - padding.top - padding.bottom; auto count = GetChildCount(); @@ -463,10 +463,12 @@ void LinearLayout::LayoutHorizontal( LayoutLength left, LayoutLength top, Layout { // mTotalLength contains the padding already // In case of RTL map BEGIN alignment to the right edge - if ( isLayoutRtl ) { + if ( isLayoutRtl ) + { childLeft = LayoutLength( padding.start ) + right - left - mTotalLength; } - else { + else + { childLeft = LayoutLength( padding.start ); } break; @@ -475,10 +477,12 @@ void LinearLayout::LayoutHorizontal( LayoutLength left, LayoutLength top, Layout { // mTotalLength contains the padding already // In case of RTL map END alignment to the left edge - if ( isLayoutRtl ) { + if ( isLayoutRtl ) + { childLeft = LayoutLength( padding.start ); } - else { + else + { childLeft = LayoutLength( padding.start ) + right - left - mTotalLength; } break; @@ -495,7 +499,8 @@ void LinearLayout::LayoutHorizontal( LayoutLength left, LayoutLength top, Layout int dir = 1; // In case of RTL, start drawing from the last child. - if( isLayoutRtl ) { + if( isLayoutRtl ) + { start = count - 1; dir = -1; } @@ -506,9 +511,9 @@ void LinearLayout::LayoutHorizontal( LayoutLength left, LayoutLength top, Layout LayoutItemPtr childLayout = GetChildAt( childIndex ); if( childLayout != nullptr ) { - auto childWidth = childLayout->GetMeasuredWidth(); - auto childHeight = childLayout->GetMeasuredHeight(); - auto childMargin = childLayout->GetMargin(); + LayoutLength childWidth = childLayout->GetMeasuredWidth(); + LayoutLength childHeight = childLayout->GetMeasuredHeight(); + Extents childMargin = childLayout->GetMargin(); switch ( mAlignment & VERTICAL_ALIGNMENT_MASK ) { @@ -548,7 +553,7 @@ void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec he LayoutLength alternativeMaxWidth = 0; LayoutLength weightedMaxWidth = 0; float totalWeight = 0; - int usedExcessSpace = 0; + LayoutLength usedExcessSpace = 0; struct { MeasuredSize::State widthState; @@ -571,10 +576,10 @@ void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec he if( childLayout ) { 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 desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); + LayoutLength desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); + float childWeight = childOwner.GetProperty( Toolkit::LinearLayout::ChildProperty::WEIGHT ); + Extents childMargin = childLayout->GetMargin(); totalWeight += childWeight; @@ -595,7 +600,7 @@ void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec he // 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(); + Extents 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 ); @@ -608,11 +613,11 @@ void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec he childHeight = childLayout->GetMeasuredHeight(); } - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LinearLayout::MeasureVertical childHeight(%d)\n", MeasureSpec::IntType( childHeight ) ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LinearLayout::MeasureVertical childHeight(%d)\n", childHeight.mValue ); - auto length = childHeight + LayoutLength::IntType( childMargin.top + childMargin.bottom ); - auto cellPadding = i < GetChildCount() - 1 ? mCellPadding.height : 0; - auto totalLength = mTotalLength; + LayoutLength length = childHeight + LayoutLength::IntType( childMargin.top + childMargin.bottom ); + LayoutLength cellPadding = i < GetChildCount() - 1 ? mCellPadding.height : 0; + LayoutLength totalLength = mTotalLength; mTotalLength = std::max( totalLength, totalLength + length + cellPadding ); } @@ -624,8 +629,8 @@ void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec he matchWidthLocally = true; } - auto marginWidth = LayoutLength( childMargin.start + childMargin.end ); - auto childWidth = childLayout->GetMeasuredWidth() + marginWidth; + LayoutLength marginWidth = childMargin.start + childMargin.end; + LayoutLength childWidth = childLayout->GetMeasuredWidth() + marginWidth; // was combineMeasuredStates() if( childLayout->GetMeasuredWidthAndState().GetState() == MeasuredSize::State::MEASURED_SIZE_TOO_SMALL ) @@ -656,7 +661,7 @@ void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec he Extents padding = GetPadding(); mTotalLength += padding.top + padding.bottom; - auto heightSize = mTotalLength; + LayoutLength heightSize = mTotalLength; heightSize = std::max( heightSize, GetSuggestedMinimumHeight() ); MeasuredSize heightSizeAndState = ResolveSizeAndState( heightSize, heightMeasureSpec, MeasuredSize::State::MEASURED_SIZE_OK); heightSize = heightSizeAndState.GetSize(); @@ -669,7 +674,7 @@ void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec he // 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; + LayoutLength remainingExcess = heightSize - mTotalLength + usedExcessSpace; if( remainingExcess != 0 && totalWeight > 0.0f ) { float remainingWeightSum = totalWeight; @@ -680,15 +685,15 @@ void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec he { 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 desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); + LayoutLength desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); + float childWeight = childOwner.GetProperty( Toolkit::LinearLayout::ChildProperty::WEIGHT ); + Extents childMargin = childLayout->GetMargin(); LayoutLength childHeight = 0; if( childWeight > 0 ) { - int share = static_cast( childWeight * remainingExcess / remainingWeightSum ); + LayoutLength share = (childWeight * remainingExcess.mValue) / remainingWeightSum; remainingExcess -= share; remainingWeightSum -= childWeight; @@ -726,16 +731,16 @@ void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec he matchWidthLocally = true; } - auto marginWidth = LayoutLength( childMargin.start + childMargin.end ); - auto childWidth = childLayout->GetMeasuredWidth() + marginWidth; + LayoutLength marginWidth = childMargin.start + childMargin.end; + LayoutLength 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; + LayoutLength length = childHeight + LayoutLength::IntType( childMargin.top + childMargin.bottom ); + LayoutLength cellPadding = i < GetChildCount() - 1 ? mCellPadding.height : 0; + LayoutLength totalLength = mTotalLength; mTotalLength = std::max( totalLength, totalLength + length + cellPadding ); } @@ -768,26 +773,26 @@ void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec he void LinearLayout::ForceUniformWidth( int count, MeasureSpec heightMeasureSpec ) { // Pretend that the linear layout has an exact size. - auto uniformMeasureSpec = MeasureSpec( GetMeasuredWidth(), MeasureSpec::Mode::EXACTLY ); + MeasureSpec uniformMeasureSpec( GetMeasuredWidth(), MeasureSpec::Mode::EXACTLY ); for (int i = 0; i < count; ++i) { LayoutItemPtr childLayout = GetChildAt(i); if( childLayout != nullptr ) { auto childOwner = childLayout->GetOwner(); - auto desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); - auto desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); + LayoutLength desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); + LayoutLength desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); if( desiredWidth == Toolkit::ChildLayoutData::MATCH_PARENT ) { // Temporarily force children to reuse their old measured height - int oldHeight = desiredHeight; + LayoutLength oldHeight = desiredHeight; childOwner.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, childLayout->GetMeasuredHeight().mValue ); // Remeasure with new dimensions MeasureChildWithMargins( childLayout, uniformMeasureSpec, 0, heightMeasureSpec, 0 ); - childOwner.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, oldHeight ); + childOwner.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, oldHeight.mValue ); } } } @@ -801,10 +806,10 @@ void LinearLayout::LayoutVertical( LayoutLength left, LayoutLength top, LayoutLe LayoutLength childLeft( padding.start ); // Where end of child should go - auto width = right - left; + LayoutLength width = right - left; // Space available for child - auto childSpace = width - padding.start - padding.end; + LayoutLength childSpace = width - padding.start - padding.end; auto count = GetChildCount(); switch ( mAlignment & VERTICAL_ALIGNMENT_MASK ) @@ -835,9 +840,9 @@ void LinearLayout::LayoutVertical( LayoutLength left, LayoutLength top, LayoutLe LayoutItemPtr childLayout = GetChildAt( childIndex ); if( childLayout != nullptr ) { - auto childWidth = childLayout->GetMeasuredWidth(); - auto childHeight = childLayout->GetMeasuredHeight(); - auto childMargin = childLayout->GetMargin(); + LayoutLength childWidth = childLayout->GetMeasuredWidth(); + LayoutLength childHeight = childLayout->GetMeasuredHeight(); + Extents childMargin = childLayout->GetMargin(); childTop += childMargin.top; switch ( mAlignment & HORIZONTAL_ALIGNMENT_MASK )