[Tizen] Add codes for Dali Windows Backend
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / layouting / linear-layout-impl.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 9036731..64bee8c
@@ -61,7 +61,11 @@ LinearLayout::~LinearLayout()
 
 void LinearLayout::SetCellPadding( LayoutSize size )
 {
-  mCellPadding = size;
+  if ( mCellPadding != size )
+  {
+    mCellPadding = size;
+    RequestLayout();
+  }
 }
 
 LayoutSize LinearLayout::GetCellPadding()
@@ -71,7 +75,11 @@ LayoutSize LinearLayout::GetCellPadding()
 
 void LinearLayout::SetOrientation( Dali::Toolkit::LinearLayout::Orientation orientation )
 {
-  mOrientation = orientation;
+  if ( mOrientation != orientation )
+  {
+    mOrientation = orientation;
+    RequestLayout();
+  }
 }
 
 Dali::Toolkit::LinearLayout::Orientation LinearLayout::GetOrientation()
@@ -144,6 +152,9 @@ void LinearLayout::MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec
     MeasuredSize::State heightState;
   } childState = { MeasuredSize::State::MEASURED_SIZE_OK, MeasuredSize::State::MEASURED_SIZE_OK };
 
+  // Reset total length
+  mTotalLength = 0;
+
   // measure children, and determine if further resolution is required
   for( unsigned int i=0; i<GetChildCount(); ++i )
   {
@@ -262,26 +273,26 @@ void LinearLayout::LayoutHorizontal( LayoutLength left, LayoutLength top, Layout
 
   Extents padding = GetPadding();
 
-  LayoutLength childTop( 0 );
+  LayoutLength childTop( padding.top );
   LayoutLength childLeft( padding.start );
 
   // Where bottom of child should go
   auto height = bottom - top;
 
   // Space available for child
-  auto childSpace = height - padding.top - padding.bottom;
+  auto childSpace = height - (int)padding.top - (int)padding.bottom;
 
   auto count = GetChildCount();
 
   int start = 0;
   int dir = 1;
 
-  // In case of RTL, start drawing from the last child.
-  // @todo re-work to draw the first child from the right edge, and move leftwards.
-  // (Should have an alignment also)
+  // 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?
   if( isLayoutRtl ) {
     start = count - 1;
     dir = -1;
+    childLeft = padding.start + right - left - mTotalLength;
   }
 
   for( unsigned int i = 0; i < count; i++)
@@ -294,11 +305,11 @@ void LinearLayout::LayoutHorizontal( LayoutLength left, LayoutLength top, Layout
       auto childHeight = childLayout->GetMeasuredHeight();
       auto childMargin = childLayout->GetMargin();
 
-      childTop = LayoutLength(padding.top) + ((childSpace - childHeight) / 2) + childMargin.top - childMargin.bottom;
+      childTop = LayoutLength(padding.top) + (int)((childSpace - childHeight) / 2) + (int)childMargin.top - (int)childMargin.bottom;
 
       childLeft += childMargin.start;
       childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight );
-      childLeft += childWidth + childMargin.end + mCellPadding.width;
+      childLeft += childWidth + (int)childMargin.end + mCellPadding.width;
     }
   }
 }
@@ -318,6 +329,9 @@ void LinearLayout::MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec he
     MeasuredSize::State heightState;
   } childState = { MeasuredSize::State::MEASURED_SIZE_OK, MeasuredSize::State::MEASURED_SIZE_OK };
 
+  // Reset total length
+  mTotalLength = 0;
+
   // measure children, and determine if further resolution is required
   for( unsigned int i=0; i<GetChildCount(); ++i )
   {
@@ -419,14 +433,14 @@ void LinearLayout::LayoutVertical( LayoutLength left, LayoutLength top, LayoutLe
 {
   Extents padding = GetPadding();
 
-  LayoutLength childTop( 0 );
+  LayoutLength childTop( padding.top );
   LayoutLength childLeft( padding.start );
 
   // Where bottom of child should go
   auto width = right - left;
 
   // Space available for child
-  auto childSpace = width - padding.start - padding.end;
+  auto childSpace = width - (int)padding.start - (int)padding.end;
   auto count = GetChildCount();
 
   for( unsigned int childIndex = 0; childIndex < count; childIndex++)
@@ -439,10 +453,10 @@ void LinearLayout::LayoutVertical( LayoutLength left, LayoutLength top, LayoutLe
       auto childMargin = childLayout->GetMargin();
 
       childTop += childMargin.top;
-      childLeft = ( childSpace - childWidth ) / 2 + childMargin.start - childMargin.end;
+      childLeft = LayoutLength( padding.start ) + ( childSpace - childWidth ) / 2 + childMargin.start - childMargin.end;
 
       childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight );
-      childTop += childHeight + childMargin.bottom + mCellPadding.height;
+      childTop += childHeight + (int)childMargin.bottom + mCellPadding.height;
     }
   }
 }