Fix possible error if negative grid columns set
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / custom-layout-impl.cpp
index 97ded95..115336a 100644 (file)
@@ -30,12 +30,40 @@ namespace Internal
 using Dali::Actor;
 using Dali::Toolkit::MeasuredSize;
 
+CustomLayout::CustomLayout()
+: mBehaviourFlags( 0 )
+{
+}
+
 CustomLayoutPtr CustomLayout::New()
 {
   CustomLayoutPtr layout( new CustomLayout() );
   return layout;
 }
 
+void CustomLayout::MeasureChildren( Dali::Toolkit::Internal::LayoutItemPtr childLayout, MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec, int resultingWidth, int resultingHeight )
+{
+  // Initially use the measure spec of the child's parent
+  auto childWidthMeasureSpec = widthMeasureSpec;
+  auto childHeightMeasureSpec = heightMeasureSpec;
+
+  if ( true == GetCustomBehaviourFlags( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_WIDTH ) )
+  {
+    // Use unspecified width measure spec, child can be any width it desires
+    childWidthMeasureSpec = MeasureSpec( widthMeasureSpec.GetSize(), MeasureSpec::Mode::UNSPECIFIED );
+  }
+
+  if ( true == GetCustomBehaviourFlags( Test::CustomLayout::BEHAVIOUR_FLAG_UNCONSTRAINED_CHILD_HEIGHT) )
+  {
+    // Use unspecified height measure spec, child can be any height it desires
+    childHeightMeasureSpec = MeasureSpec( heightMeasureSpec.GetSize(), MeasureSpec::Mode::UNSPECIFIED );
+  }
+
+  MeasureChild( childLayout, childWidthMeasureSpec, childHeightMeasureSpec );
+  resultingWidth += childLayout->GetMeasuredWidth();
+  resultingHeight = std::max( childLayout->GetMeasuredHeight().mValue, resultingHeight );
+}
+
 void CustomLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec )
 {
   auto accumulatedWidth = 0;
@@ -51,9 +79,7 @@ void CustomLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMe
     auto childLayout = GetChildAt( i );
     if( childLayout )
     {
-      MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec );
-      accumulatedWidth += childLayout->GetMeasuredWidth();
-      maxHeight = std::max( childLayout->GetMeasuredHeight().mValue, maxHeight );
+        MeasureChildren( childLayout, widthMeasureSpec, heightMeasureSpec, accumulatedWidth, maxHeight );
     }
   }
 
@@ -100,6 +126,23 @@ void CustomLayout::OnLayout( bool changed, LayoutLength left, LayoutLength top,
   }
 }
 
+void CustomLayout::SetCustomBehaviourFlag( int flag )
+{
+  mBehaviourFlags |= flag;
+  RequestLayout();
+}
+
+bool CustomLayout::GetCustomBehaviourFlags( int flagToCheck )
+{
+  return ( mBehaviourFlags & flagToCheck ) != 0;
+}
+
+void CustomLayout::ClearPrivateFlag( int flag )
+{
+    mBehaviourFlags &= ~flag;
+    RequestLayout();
+}
+
 } // namespace Internal
 
 } // namespace Test