#include <dali-toolkit/third-party/yoga/YGNode.h>
#if defined(DEBUG_ENABLED)
-static Debug::Filter* gLogFilter = Debug::Filter::New( Debug::Concise, false, "LOG_LAYOUT" );
+static Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_LAYOUT" );
#endif
namespace Dali
oss << "FlexLayout::OnMeasure ";
if( actor )
{
- oss << "Actor Id:" << actor.GetId() << " Name:" << actor.GetName() << " Layout direction:" << actor.GetProperty( Actor::Property::LAYOUT_DIRECTION ).Get<int>() << " ";
+ oss << "Actor Id:" << actor.GetId() << " Name:" << actor.GetName() << " Layout direction:" << actor.GetProperty( Actor::Property::LAYOUT_DIRECTION ).Get<int>() << " ";
}
oss << "widthMeasureSpec:" << widthMeasureSpec << " heightMeasureSpec:" << heightMeasureSpec << std::endl;
DALI_LOG_INFO( gLogFilter, Debug::Concise, oss.str().c_str() );
YGNodeStyleSetMaxWidth( mRoot, width );
}
- if (heightMeasureSpec.GetMode() == MeasureSpec::Mode::EXACTLY)
+ if ( heightMeasureSpec.GetMode() == MeasureSpec::Mode::EXACTLY )
{
height = heightMeasureSpec.GetSize();
YGNodeStyleSetHeight( mRoot, height );
}
- else if (widthMeasureSpec.GetMode() == MeasureSpec::Mode::AT_MOST)
+ else if ( heightMeasureSpec.GetMode() == MeasureSpec::Mode::AT_MOST )
{
height = heightMeasureSpec.GetSize();
YGNodeStyleSetMaxHeight( mRoot, height );
auto childOwner = childLayout->GetOwner();
auto desiredWidth = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
-
- MeasureSpec::Mode measureWidthMode = MeasureSpec::Mode::AT_MOST;
- MeasureSpec::Mode measureHeightMode = MeasureSpec::Mode::AT_MOST;
- if( desiredWidth == Toolkit::ChildLayoutData::MATCH_PARENT )
- {
- if( innerWidth != YGUndefined)
- {
- desiredWidth = innerWidth;
- }
- measureWidthMode = MeasureSpec::Mode::EXACTLY;
- }
-
- if( desiredHeight == Toolkit::ChildLayoutData::MATCH_PARENT )
- {
- if( innerWidth != YGUndefined)
- {
- desiredHeight = innerHeight;
- }
- measureHeightMode = MeasureSpec::Mode::EXACTLY;
- }
-
- if( desiredWidth == Toolkit::ChildLayoutData::WRAP_CONTENT )
- {
- measureWidthMode = MeasureSpec::Mode::UNSPECIFIED;
- }
-
- if( desiredHeight == Toolkit::ChildLayoutData::WRAP_CONTENT )
+ auto parentWidthMeasureSpec = MeasureSpec( 0 );
+ if ( innerWidth != YGUndefined )
{
- measureHeightMode = MeasureSpec::Mode::UNSPECIFIED;
+ parentWidthMeasureSpec = MeasureSpec( innerWidth, static_cast<MeasureSpec::Mode>(widthMode) );
}
-
- MeasureSpec widthMeasureSpec = MeasureSpec( desiredWidth, measureWidthMode );
- MeasureSpec heightMeasureSpec = MeasureSpec( desiredHeight, measureHeightMode );
- if( measureWidthMode == MeasureSpec::Mode::UNSPECIFIED ||
- measureHeightMode == MeasureSpec::Mode::UNSPECIFIED )
+ auto parentHeightMeasureSpec = MeasureSpec( 0 );
+ if ( innerHeight != YGUndefined )
{
- // A measure just to get the size if the wrapped content
- childLayout->Measure( widthMeasureSpec, heightMeasureSpec );
- desiredWidth = childLayout->GetMeasuredWidth();
- desiredHeight = childLayout->GetMeasuredHeight();
- // Remove padding here since the second measure will add it back
- Extents padding = childLayout->GetPadding();
- desiredWidth = desiredWidth - padding.end - padding.start;
- desiredHeight = desiredHeight - padding.bottom - padding.top;
+ parentHeightMeasureSpec = MeasureSpec( innerHeight, static_cast<MeasureSpec::Mode>(heightMode) );
}
+ auto childWidthMeasureSpec = LayoutGroup::GetChildMeasureSpec( parentWidthMeasureSpec, 0, desiredWidth);
+ auto childHeightMeasureSpec = LayoutGroup::GetChildMeasureSpec( parentHeightMeasureSpec, 0, desiredHeight);
- // Safety check to avoid going out of boundary
- if( (innerWidth != YGUndefined && innerWidth != 0) && innerWidth < desiredWidth )
+ // Force to fill parent if a child wants to match parent even if GetChildMeasureSpec sets otherwise
+ if( desiredWidth == Toolkit::ChildLayoutData::MATCH_PARENT && innerWidth != YGUndefined )
{
- desiredWidth = innerWidth;
+ childWidthMeasureSpec = MeasureSpec( innerWidth, MeasureSpec::Mode::EXACTLY );
}
-
- if( (innerHeight != YGUndefined && innerHeight != 0) && innerHeight < desiredHeight )
+ if( desiredHeight == Toolkit::ChildLayoutData::MATCH_PARENT && innerHeight != YGUndefined )
{
- desiredHeight = innerHeight;
+ childHeightMeasureSpec = MeasureSpec( innerHeight, MeasureSpec::Mode::EXACTLY );
}
- // Measure for Yoga
- MeasureSpec ygWidthMeasureSpec = MeasureSpec( desiredWidth, static_cast<MeasureSpec::Mode>(widthMode) );
- MeasureSpec ygHeightMeasureSpec = MeasureSpec( desiredHeight, static_cast<MeasureSpec::Mode>(heightMode) );
#if defined(DEBUG_ENABLED)
auto actor = Actor::DownCast(childOwner);
std::ostringstream oss;
{
oss << "Actor Id:" << actor.GetId() << " Name:" << actor.GetName() << " ";
}
- oss << "innerWidth:" << ((innerWidth == YGUndefined) ? "YGUndefined " : "") << innerWidth <<
- " innerHeight:" << ((innerHeight == YGUndefined) ? "YGUndefined " : "") << innerHeight <<
+ oss << "innerWidth:" << ( ( innerWidth == YGUndefined ) ? "YGUndefined " : "" ) << innerWidth <<
+ " innerHeight:" << ( ( innerHeight == YGUndefined ) ? "YGUndefined " : "" ) << innerHeight <<
" desiredWidth:" << desiredWidth << " desiredHeight:" << desiredHeight <<
- " widthMeasureSpec:" << widthMeasureSpec << " heightMeasureSpec:" << heightMeasureSpec <<
- " ygWidthMeasureSpec:" << ygWidthMeasureSpec << " ygHeightMeasureSpec:" << ygHeightMeasureSpec << std::endl;
+ " childWidthMeasureSpec:" << childWidthMeasureSpec << " childHeightMeasureSpec:" << childHeightMeasureSpec << std::endl;
DALI_LOG_INFO( gLogFilter, Debug::Concise, oss.str().c_str() );
#endif
- if( measureWidthMode == MeasureSpec::Mode::UNSPECIFIED ||
- measureHeightMode == MeasureSpec::Mode::UNSPECIFIED )
- {
- if( ygWidthMeasureSpec == widthMeasureSpec && ygHeightMeasureSpec == heightMeasureSpec )
- {
- return YGSize{
- .width = childLayout->GetMeasuredWidth(),
- .height = childLayout->GetMeasuredHeight(),
- };
- }
- }
+ childLayout->Measure( childWidthMeasureSpec, childHeightMeasureSpec );
+
+ // 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;
- childLayout->Measure( ygWidthMeasureSpec, ygHeightMeasureSpec );
return YGSize{
- .width = childLayout->GetMeasuredWidth(),
- .height = childLayout->GetMeasuredHeight(),
+ .width = measuredWidth,
+ .height = measuredHeight,
};
}