Fix to use width and height correctly in flex-layout-impl.cpp
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / layouting / flex-layout-impl.cpp
index ebbf330..648a7f6 100644 (file)
@@ -30,7 +30,7 @@
 #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
@@ -191,7 +191,7 @@ void FlexLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeas
   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() );
@@ -227,12 +227,12 @@ void FlexLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeas
     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 );
@@ -286,6 +286,8 @@ YGSize FlexLayout::OnChildMeasure( YGNodeRef node,
                               YGMeasureMode widthMode,
                               float innerHeight,
                               YGMeasureMode heightMode ) {
+  // TODO: this function should try to get use of LayoutGroup::GetChildMeasureSpec
+  // or LayoutGroup::MeasureChild somehow since it is fixed now
   LayoutItem* childLayout = static_cast<LayoutItem*>(node->getContext());
   auto childOwner = childLayout->GetOwner();
   auto desiredWidth = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
@@ -304,7 +306,7 @@ YGSize FlexLayout::OnChildMeasure( YGNodeRef node,
 
   if( desiredHeight == Toolkit::ChildLayoutData::MATCH_PARENT )
   {
-    if( innerWidth != YGUndefined)
+    if( innerHeight != YGUndefined)
     {
       desiredHeight = innerHeight;
     }
@@ -348,8 +350,20 @@ YGSize FlexLayout::OnChildMeasure( YGNodeRef node,
   }
 
   // Measure for Yoga
-  MeasureSpec ygWidthMeasureSpec = MeasureSpec( desiredWidth, static_cast<MeasureSpec::Mode>(widthMode) );
-  MeasureSpec ygHeightMeasureSpec = MeasureSpec( desiredHeight, static_cast<MeasureSpec::Mode>(heightMode) );
+  MeasureSpec::Mode ygWidthMode = static_cast<MeasureSpec::Mode>(widthMode);
+  if( measureWidthMode == MeasureSpec::Mode::EXACTLY )
+  {
+    ygWidthMode = MeasureSpec::Mode::EXACTLY;
+  }
+
+  MeasureSpec::Mode ygHeightMode = static_cast<MeasureSpec::Mode>(heightMode);
+  if( measureHeightMode == MeasureSpec::Mode::EXACTLY )
+  {
+    ygHeightMode = MeasureSpec::Mode::EXACTLY;
+  }
+
+  MeasureSpec ygWidthMeasureSpec = MeasureSpec( desiredWidth, ygWidthMode );
+  MeasureSpec ygHeightMeasureSpec = MeasureSpec( desiredHeight, ygHeightMode );
 #if defined(DEBUG_ENABLED)
   auto actor = Actor::DownCast(childOwner);
   std::ostringstream oss;