[NUI] separate layouting logic of the independent children
authorYeongjong Lee <cleanlyj@naver.com>
Thu, 19 Nov 2020 06:44:35 +0000 (15:44 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 15 Dec 2020 06:33:59 +0000 (15:33 +0900)
This patch introduces `IterateLayoutChildren()` method that return
an enumerable collection of the child layouts that affected by parent
layout.

Independent children will be measured in `OnMeasureIndependentChildren()`.

By using `IterateLayoutChildren()`, we can remove the codes that check
whether child layout exclude from layout flow in `OnMeasure`. and api
users don't need to check `View.ExcludeLayouting` property in custom layouts.

src/Tizen.NUI.Components/Controls/ScrollableBase.cs
src/Tizen.NUI/src/internal/Layouting/GridLocations.cs
src/Tizen.NUI/src/public/Layouting/AbsoluteLayout.cs
src/Tizen.NUI/src/public/Layouting/FlexLayout.cs
src/Tizen.NUI/src/public/Layouting/GridLayout.cs
src/Tizen.NUI/src/public/Layouting/LayoutGroup.cs
src/Tizen.NUI/src/public/Layouting/LayoutItem.cs
src/Tizen.NUI/src/public/Layouting/LinearLayout.cs

index 6ea4122..568e823 100755 (executable)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2020 Samsung Electronics Co., Ltd.
+/* Copyright (c) 2020 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -127,7 +127,7 @@ namespace Tizen.NUI.Components
         private float mPageFlickThreshold = 0.4f;
         private float mScrollingEventThreshold = 0.001f;
 
-        private class ScrollableBaseCustomLayout : LayoutGroup
+        private class ScrollableBaseCustomLayout : AbsoluteLayout
         {
             protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
             {
@@ -199,25 +199,6 @@ namespace Tizen.NUI.Components
                     scrollableBase.OnScrollingChildRelayout(null, null);
                 }
             }
-
-            protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
-            {
-                foreach (LayoutItem childLayout in LayoutChildren)
-                {
-                    if (childLayout != null && childLayout.Owner.Name == "ContentContainer")
-                    {
-                        LayoutLength childWidth = childLayout.MeasuredWidth.Size;
-                        LayoutLength childHeight = childLayout.MeasuredHeight.Size;
-
-                        Position2D childPosition = childLayout.Owner.Position2D;
-
-                        LayoutLength childLeft = new LayoutLength(childPosition.X);
-                        LayoutLength childTop = new LayoutLength(childPosition.Y);
-
-                        childLayout.Layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight, true);
-                    }
-                }
-            }
         } //  ScrollableBaseCustomLayout
 
         /// <summary>
@@ -621,7 +602,6 @@ namespace Tizen.NUI.Components
             ContentContainer = new View()
             {
                 Name = "ContentContainer",
-                ExcludeLayouting = false,
                 WidthSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.MatchParent : LayoutParamPolicies.WrapContent,
                 HeightSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.WrapContent : LayoutParamPolicies.MatchParent,
             };
index 0d92415..3e063bc 100755 (executable)
@@ -16,6 +16,7 @@
  */
 
 using System;
+using System.Collections.Generic;
 using Tizen.NUI.BaseComponents;
 
 namespace Tizen.NUI
@@ -32,7 +33,7 @@ namespace Tizen.NUI
         private int totalHorizontalExpand = 0;
         private int totalVerticalExpand = 0;
 
-        private GridChild[] gridChildren;
+        private List<GridChild> gridChildren;
 
         /// <summary>
         /// The nested class to represent a node of DAG.
@@ -146,46 +147,24 @@ namespace Tizen.NUI
 
         private void InitChildrenData(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
         {
-            int gridChildCount = 0;
-            for (int i = 0; i < LayoutChildren.Count; i++)
-            {
-                LayoutItem item = LayoutChildren[i];
-                View view = item?.Owner;
-                if (view == null) continue;
-                if (!item.Owner.ExcludeLayouting)
-                {
-                    gridChildCount++;
-                }
-            }
             bool isHorizontal = (GridOrientation == Orientation.Horizontal);
             int mainPivot = 0, subPivot = 0;
             int[] pivotStack = new int[isHorizontal ? Columns : Rows];
 
             vLocations = hLocations = null;
             vEdgeList = hEdgeList = null;
-            gridChildren = new GridChild[gridChildCount];
+            gridChildren = new List<GridChild>();
             maxColumnConut = Columns;
             maxRowCount = Rows;
 
             totalVerticalExpand = 0;
             totalHorizontalExpand = 0;
 
-            for (int i = 0, gridChildIndex = 0; i < LayoutChildren.Count; i++, gridChildIndex++)
+            foreach (LayoutItem item in IterateLayoutChildren())
             {
-                LayoutItem item = LayoutChildren[i];
-
-                View view = item?.Owner;
-                if (view == null) continue;
-
-                if (view.ExcludeLayouting)
-                {
-                    MeasureChildWithoutPadding(item, widthMeasureSpec, heightMeasureSpec);
-                    gridChildIndex--;
-                    continue;
-                }
-
                 int column, columnSpan, row, rowSpan;
                 StretchFlags verticalStretch, horizontalStretch;
+                View view = item.Owner;
 
                 column = GetColumn(view);
                 columnSpan = GetColumnSpan(view);
@@ -201,7 +180,7 @@ namespace Tizen.NUI
                     else
                         Tizen.Log.Error("NUI", "Row + RowSapn exceeds Grid Rows. Row + RowSapn (" + row + " + " + rowSpan + ") > Grid Rows(" + maxRowCount + ")");
 
-                    gridChildren[gridChildIndex] = new GridChild(null, new Node(0, 1, 0, 0), new Node(0, 1, 0, 0));
+                    gridChildren.Add(new GridChild(null, new Node(0, 1, 0, 0), new Node(0, 1, 0, 0)));
 
                     continue;
                 }
@@ -275,9 +254,9 @@ namespace Tizen.NUI
                     maxRowCount = row + rowSpan;
 
                 MeasureChildWithMargins(item, widthMeasureSpec, new LayoutLength(0), heightMeasureSpec, new LayoutLength(0));
-                gridChildren[gridChildIndex] = new GridChild(item,
-                                                new Node(column, columnSpan, item.MeasuredWidth.Size.AsDecimal() + item.Owner.Margin.Start + item.Owner.Margin.End, horizontalStretch),
-                                                new Node(row, rowSpan, item.MeasuredHeight.Size.AsDecimal() + item.Owner.Margin.Top + item.Owner.Margin.Bottom, verticalStretch));
+                gridChildren.Add(new GridChild(item,
+                                               new Node(column, columnSpan, item.MeasuredWidth.Size.AsDecimal() + item.Owner.Margin.Start + item.Owner.Margin.End, horizontalStretch),
+                                               new Node(row, rowSpan, item.MeasuredHeight.Size.AsDecimal() + item.Owner.Margin.Top + item.Owner.Margin.Bottom, verticalStretch)));
             }
         }
 
@@ -287,13 +266,13 @@ namespace Tizen.NUI
             bool isHorizontal = (edgeList == hEdgeList);
             int axisCount = isHorizontal ? Columns : Rows;
 
-            edgeList = new Node[gridChildren.Length + axisCount];
+            edgeList = new Node[gridChildren.Count + axisCount];
 
-            for (int i = 0; i < gridChildren.Length; i++)
+            for (int i = 0; i < gridChildren.Count; i++)
                 edgeList[i] = isHorizontal ? gridChildren[i].Column : gridChildren[i].Row;
 
             // Add virtual edge that have no edge for connecting adjacent cells.
-            for (int i = gridChildren.Length, end = gridChildren.Length + axisCount, v = 0; i < end; i++, v++)
+            for (int i = gridChildren.Count, end = gridChildren.Count + axisCount, v = 0; i < end; i++, v++)
                 edgeList[i] = new Node(v, 1, 0, 0);
 
             Array.Sort(edgeList, (a, b) => a.Start.CompareTo(b.Start));
index ecb04eb..fca6f14 100755 (executable)
@@ -46,39 +46,30 @@ namespace Tizen.NUI
             MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
             MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
 
-            for (int i = 0; i < LayoutChildren.Count; i++)
+            foreach (LayoutItem childLayout in IterateLayoutChildren())
             {
-                LayoutItem childLayout = LayoutChildren[i];
-                if (childLayout != null)
-                {
-                    // Get size of child with no padding, no margin. we won't support margin, padding for AbsolutLayout.
-                    MeasureChildWithoutPadding(childLayout, widthMeasureSpec, heightMeasureSpec);
-
-                    if (childLayout.Owner.ExcludeLayouting)
-                    {
-                        continue;
-                    }
+                // Get size of child with no padding, no margin. we won't support margin, padding for AbsolutLayout.
+                MeasureChildWithoutPadding(childLayout, widthMeasureSpec, heightMeasureSpec);
 
-                    // Determine the width and height needed by the children using their given position and size.
-                    // Children could overlap so find the right most child.
-                    Position2D childPosition = childLayout.Owner.Position2D;
-                    float childRight = childLayout.MeasuredWidth.Size.AsDecimal() + childPosition.X;
-                    float childBottom = childLayout.MeasuredHeight.Size.AsDecimal() + childPosition.Y;
+                // Determine the width and height needed by the children using their given position and size.
+                // Children could overlap so find the right most child.
+                Position2D childPosition = childLayout.Owner.Position2D;
+                float childRight = childLayout.MeasuredWidth.Size.AsDecimal() + childPosition.X;
+                float childBottom = childLayout.MeasuredHeight.Size.AsDecimal() + childPosition.Y;
 
-                    if (maxWidth < childRight)
-                        maxWidth = childRight;
+                if (maxWidth < childRight)
+                    maxWidth = childRight;
 
-                    if (maxHeight < childBottom)
-                        maxHeight = childBottom;
+                if (maxHeight < childBottom)
+                    maxHeight = childBottom;
 
-                    if (childLayout.MeasuredWidth.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
-                    {
-                        childWidthState = MeasuredSize.StateType.MeasuredSizeTooSmall;
-                    }
-                    if (childLayout.MeasuredHeight.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
-                    {
-                        childHeightState = MeasuredSize.StateType.MeasuredSizeTooSmall;
-                    }
+                if (childLayout.MeasuredWidth.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
+                {
+                    childWidthState = MeasuredSize.StateType.MeasuredSizeTooSmall;
+                }
+                if (childLayout.MeasuredHeight.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
+                {
+                    childHeightState = MeasuredSize.StateType.MeasuredSizeTooSmall;
                 }
             }
 
@@ -99,21 +90,17 @@ namespace Tizen.NUI
         {
             // Absolute layout positions it's children at their Actor positions.
             // Children could overlap or spill outside the parent, as is the nature of absolute positions.
-            for (int i = 0; i < LayoutChildren.Count; i++)
+            foreach (LayoutItem childLayout in IterateLayoutChildren())
             {
-                LayoutItem childLayout = LayoutChildren[i];
-                if (childLayout != null)
-                {
-                    LayoutLength childWidth = childLayout.MeasuredWidth.Size;
-                    LayoutLength childHeight = childLayout.MeasuredHeight.Size;
+                LayoutLength childWidth = childLayout.MeasuredWidth.Size;
+                LayoutLength childHeight = childLayout.MeasuredHeight.Size;
 
-                    Position2D childPosition = childLayout.Owner.Position2D;
+                Position2D childPosition = childLayout.Owner.Position2D;
 
-                    LayoutLength childLeft = new LayoutLength(childPosition.X);
-                    LayoutLength childTop = new LayoutLength(childPosition.Y);
+                LayoutLength childLeft = new LayoutLength(childPosition.X);
+                LayoutLength childTop = new LayoutLength(childPosition.Y);
 
-                    childLayout.Layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight, true);
-                }
+                childLayout.Layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight, true);
             }
         }
     }
index 53ac89d..faa9d68 100755 (executable)
@@ -585,7 +585,8 @@ namespace Tizen.NUI
         {
             // We need to measure child layout
             View child = Registry.GetManagedBaseHandleFromNativePtr(childPtr) as View;
-            if (child == null)
+            // independent child will be measured in LayoutGroup.OnMeasureIndependentChildren().
+            if (child?.ExcludeLayouting ?? true)
             {
                 measureSize.width = 0;
                 measureSize.height = 0;
@@ -693,12 +694,6 @@ namespace Tizen.NUI
                 if (childHandleRef.Handle == IntPtr.Zero || Child == null)
                     continue;
 
-                if (layoutItem.Owner.ExcludeLayouting)
-                {
-                    MeasureChildWithoutPadding(layoutItem, widthMeasureSpec, heightMeasureSpec);
-                    continue;
-                }
-
                 AlignmentType flexAlignemnt = GetFlexAlignmentSelf(Child);
                 PositionType positionType = GetFlexPositionType(Child);
                 float flexAspectRatio = GetFlexAspectRatio(Child);
@@ -748,21 +743,16 @@ namespace Tizen.NUI
             // Call to FlexLayout implementation to calculate layout values for later retrieval.
             Interop.FlexLayout.FlexLayout_CalculateLayout(swigCPtr, width.AsDecimal(), height.AsDecimal(), isLayoutRtl);
 
-            int count = LayoutChildren.Count;
-            for (int childIndex = 0; childIndex < count; childIndex++)
+            for (int childIndex = 0; childIndex < LayoutChildren.Count; childIndex++)
             {
                 LayoutItem childLayout = LayoutChildren[childIndex];
-                if (childLayout != null)
+                if (!childLayout?.Owner?.ExcludeLayouting ?? false)
                 {
-                    if (!childLayout.Owner.ExcludeLayouting)
-                    {
-                        // Get the frame for the child, start, top, end, bottom.
-                        Vector4 frame = new Vector4(Interop.FlexLayout.FlexLayout_GetNodeFrame(swigCPtr, childIndex), true);
-                        childLayout.Layout(new LayoutLength(frame.X), new LayoutLength(frame.Y), new LayoutLength(frame.Z), new LayoutLength(frame.W));
-                    }
+                    // Get the frame for the child, start, top, end, bottom.
+                    Vector4 frame = new Vector4(Interop.FlexLayout.FlexLayout_GetNodeFrame(swigCPtr, childIndex), true);
+                    childLayout.Layout(new LayoutLength(frame.X), new LayoutLength(frame.Y), new LayoutLength(frame.Z), new LayoutLength(frame.W));
                 }
             }
-            LayoutForIndependentChild();
         }
     } // FLexlayout
 } // namesspace Tizen.NUI
index 2fad169..22c753d 100755 (executable)
@@ -397,7 +397,7 @@ namespace Tizen.NUI
         {
             InitChildrenWithExpand(MeasuredWidth.Size - Padding.Start - Padding.End, MeasuredHeight.Size - Padding.Top - Padding.Bottom);
 
-            for (int i = 0; i < gridChildren.Length; i++)
+            for (int i = 0; i < gridChildren.Count; i++)
             {
                 GridChild child = gridChildren[i];
                 View view = child.LayoutItem?.Owner;
@@ -430,8 +430,6 @@ namespace Tizen.NUI
 
                 child.LayoutItem.Layout(new LayoutLength(l), new LayoutLength(t), new LayoutLength(l + width), new LayoutLength(t + height));
             }
-
-            LayoutForIndependentChild();
         }
 
         /// <summary>
index 5b6da9e..1973e05 100755 (executable)
@@ -46,6 +46,23 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// returns an enumerable collection of the child layouts that owner's <see cref="View.ExcludeLayouting"/> is false.
+        /// </summary>
+        /// <returns>An enumerable collection of the child layouts that affected by this layout.</returns>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected IEnumerable<LayoutItem> IterateLayoutChildren()
+        {
+            for (int i = 0; i < LayoutChildren.Count; i++)
+            {
+                LayoutItem childLayout = LayoutChildren[i];
+                if (!childLayout?.Owner?.ExcludeLayouting ?? false)
+                {
+                    yield return childLayout;
+                }
+            }
+        }
+
+        /// <summary>
         /// From ILayoutParent.<br />
         /// </summary>
         /// <exception cref="ArgumentNullException"> Thrown when childLayout is null. </exception>
@@ -400,6 +417,14 @@ namespace Tizen.NUI
                                    new MeasuredSize(measuredHeight, MeasuredSize.StateType.MeasuredSizeOK));
         }
 
+        internal override void OnMeasureIndependentChildren(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
+        {
+            foreach (LayoutItem childLayout in LayoutChildren.Where(item => item?.Owner?.ExcludeLayouting ?? false))
+            {
+                MeasureChildWithoutPadding(childLayout, widthMeasureSpec, heightMeasureSpec);
+            }
+        }
+
         /// <summary>
         /// Called from Layout() when this layout should assign a size and position to each of its children.<br />
         /// Derived classes with children should override this method and call Layout() on each of their children.<br />
@@ -440,28 +465,19 @@ namespace Tizen.NUI
         /// Layout independent children those Owners have true ExcludeLayouting. <br />
         /// These children are required not to be affected by this layout. <br />
         /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected void LayoutForIndependentChild()
+        internal override void OnLayoutIndependentChildren(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
         {
-            int count = LayoutChildren.Count;
-            for (int childIndex = 0; childIndex < count; childIndex++)
+            foreach (LayoutItem childLayout in LayoutChildren.Where(item => item?.Owner?.ExcludeLayouting ?? false))
             {
-                LayoutItem childLayout = LayoutChildren[childIndex];
-                if (childLayout != null)
-                {
-                    if (childLayout.Owner.ExcludeLayouting)
-                    {
-                        LayoutLength childWidth = childLayout.MeasuredWidth.Size;
-                        LayoutLength childHeight = childLayout.MeasuredHeight.Size;
+                LayoutLength childWidth = childLayout.MeasuredWidth.Size;
+                LayoutLength childHeight = childLayout.MeasuredHeight.Size;
 
-                        Position2D childPosition = childLayout.Owner.Position2D;
+                Position2D childPosition = childLayout.Owner.Position2D;
 
-                        LayoutLength childPositionX = new LayoutLength(childPosition.X);
-                        LayoutLength childPositionY = new LayoutLength(childPosition.Y);
+                LayoutLength childPositionX = new LayoutLength(childPosition.X);
+                LayoutLength childPositionY = new LayoutLength(childPosition.Y);
 
-                        childLayout.Layout(childPositionX, childPositionY, childPositionX + childWidth, childPositionY + childHeight, true);
-                    }
-                }
+                childLayout.Layout(childPositionX, childPositionY, childPositionX + childWidth, childPositionY + childHeight, true);
             }
         }
 
index e9160fe..1bb7301 100755 (executable)
@@ -221,6 +221,7 @@ namespace Tizen.NUI
             if (needsLayout)
             {
                 OnMeasure(widthMeasureSpec, heightMeasureSpec);
+                OnMeasureIndependentChildren(widthMeasureSpec, heightMeasureSpec);
                 Flags = Flags | LayoutFlags.LayoutRequired;
                 Flags &= ~LayoutFlags.ForceLayout;
             }
@@ -280,6 +281,7 @@ namespace Tizen.NUI
             if (changed || ((Flags & LayoutFlags.LayoutRequired) == LayoutFlags.LayoutRequired))
             {
                 OnLayout(changed, left, top, right, bottom);
+                OnLayoutIndependentChildren(changed, left, top, right, bottom);
                 // Clear flag
                 Flags &= ~LayoutFlags.LayoutRequired;
             }
@@ -539,6 +541,8 @@ namespace Tizen.NUI
                                    GetDefaultSize(SuggestedMinimumHeight, heightMeasureSpec));
         }
 
+        internal virtual void OnMeasureIndependentChildren(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec) { }
+
         /// <summary>
         /// Called from Layout() when this layout should assign a size and position to each of its children. <br />
         /// Derived classes with children should override this method and call Layout() on each of their children. <br />
@@ -551,6 +555,8 @@ namespace Tizen.NUI
         /// <since_tizen> 6 </since_tizen>
         protected virtual void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom) { }
 
+        internal virtual void OnLayoutIndependentChildren(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom) { }
+
         /// <summary>
         /// Virtual method to allow derived classes to remove any children before it is removed from
         /// its parent.
index a7bedc0..584f235 100755 (executable)
@@ -17,6 +17,7 @@
 using System;
 using Tizen.NUI.BaseComponents;
 using System.Collections.Generic;
+using System.Linq;
 
 namespace Tizen.NUI
 {
@@ -179,7 +180,6 @@ namespace Tizen.NUI
             {
                 LayoutVertical(left, top, right, bottom);
             }
-            LayoutForIndependentChild();
         }
 
 
@@ -274,7 +274,7 @@ namespace Tizen.NUI
             float alternativeMaxHeight = 0.0f;
             float weightedMaxHeight = 0.0f;
             float totalWeight = 0.0f;
-            int childrenCount = 0;
+            int childrenCount = IterateLayoutChildren().Count();
 
             // Reset measure variables
             _totalLength = 0.0f;
@@ -288,16 +288,8 @@ namespace Tizen.NUI
             // Weighted children are not measured at this phase.
             // Available space for weighted children will be calculated in the phase 2 based on totalLength value.
             // Max height of children is stored.
-            for (int i = 0; i < LayoutChildren.Count; i++)
+            foreach (LayoutItem childLayout in IterateLayoutChildren())
             {
-                LayoutItem childLayout = LayoutChildren[i];
-                if (childLayout.Owner.ExcludeLayouting)
-                {
-                    MeasureChildWithoutPadding(childLayout, widthMeasureSpec, heightMeasureSpec);
-                    continue;
-                }
-
-                childrenCount++;
                 int childDesiredHeight = childLayout.Owner.HeightSpecification;
                 float childWeight = childLayout.Owner.Weight;
                 Extents childMargin = childLayout.Margin;
@@ -399,15 +391,8 @@ namespace Tizen.NUI
                 maxHeight = 0;
                 _totalLength = 0;
 
-                int numberOfChildren = LayoutChildren.Count;
-                for (int i = 0; i < numberOfChildren; ++i)
+                foreach (LayoutItem childLayout in IterateLayoutChildren())
                 {
-                    LayoutItem childLayout = LayoutChildren[i];
-                    if (childLayout.Owner.ExcludeLayouting)
-                    {
-                        continue;
-                    }
-
                     float desiredChildHeight = childLayout.Owner.HeightSpecification;
 
                     float childWeight = childLayout.Owner.Weight;
@@ -472,7 +457,7 @@ namespace Tizen.NUI
             float alternativeMaxWidth = 0.0f;
             float weightedMaxWidth = 0.0f;
             float totalWeight = 0.0f;
-            int childrenCount = 0;
+            int childrenCount = IterateLayoutChildren().Count();
 
             // Reset total length
             _totalLength = 0.0f;
@@ -488,15 +473,8 @@ namespace Tizen.NUI
             // to accumulate total used space in _totalLength.
             // Weighted children are not measured in this phase.
             // Available space for weighted children will be calculated in the phase 2 based on _totalLength value.
-            for (int i = 0; i < LayoutChildren.Count; i++)
+            foreach (LayoutItem childLayout in IterateLayoutChildren())
             {
-                LayoutItem childLayout = LayoutChildren[i];
-                if (childLayout.Owner.ExcludeLayouting)
-                {
-                    MeasureChildWithoutPadding(childLayout, widthMeasureSpec, heightMeasureSpec);
-                    continue;
-                }
-
                 childrenCount++;
                 int childDesiredWidth = childLayout.Owner.WidthSpecification;
                 float childWeight = childLayout.Owner.Weight;
@@ -596,15 +574,8 @@ namespace Tizen.NUI
                 maxWidth = 0;
                 _totalLength = 0;
 
-                int numberOfChildren = LayoutChildren.Count;
-                for (int i = 0; i < numberOfChildren; ++i)
+                foreach (LayoutItem childLayout in IterateLayoutChildren())
                 {
-                    LayoutItem childLayout = LayoutChildren[i];
-                    if (childLayout.Owner.ExcludeLayouting)
-                    {
-                        continue;
-                    }
-
                     float desiredChildWidth = childLayout.Owner.WidthSpecification;
 
                     float childWeight = childLayout.Owner.Weight;
@@ -667,7 +638,8 @@ namespace Tizen.NUI
             // Space available for child
             LayoutLength childSpace = new LayoutLength(height - Padding.Top - Padding.Bottom);
 
-            int count = LayoutChildren.Count;
+            List<LayoutItem> LinearChildren = IterateLayoutChildren().ToList();
+            int count = LinearChildren.Count;
 
             switch (LinearAlignment)
             {
@@ -717,34 +689,29 @@ namespace Tizen.NUI
             {
                 int childIndex = start + dir * i;
                 // Get a reference to the childLayout at the given index
-                LayoutItem childLayout = LayoutChildren[childIndex];
-                if (childLayout != null)
-                {
-                    if (!childLayout.Owner.ExcludeLayouting)
-                    {
-                        LayoutLength childWidth = childLayout.MeasuredWidth.Size;
-                        LayoutLength childHeight = childLayout.MeasuredHeight.Size;
-                        Extents childMargin = childLayout.Margin;
+                LayoutItem childLayout = LinearChildren[childIndex];
 
-                        switch (LinearAlignment)
-                        {
-                            case Alignment.Bottom:
-                                childTop = new LayoutLength(height - Padding.Bottom - childHeight - childMargin.Bottom);
-                                break;
-                            case Alignment.CenterVertical:
-                            case Alignment.Center: // FALLTHROUGH
-                                childTop = new LayoutLength(Padding.Top + ((childSpace - childHeight).AsDecimal() / 2.0f) + childMargin.Top - childMargin.Bottom);
-                                break;
-                            case Alignment.Top: // FALLTHROUGH default
-                            default:
-                                childTop = new LayoutLength(Padding.Top + childMargin.Top);
-                                break;
-                        }
-                        childLeft += childMargin.Start;
-                        childLayout.Layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
-                        childLeft += childWidth + childMargin.End + ((i < count - 1) ? CellPadding.Width : 0);
-                    }
+                LayoutLength childWidth = childLayout.MeasuredWidth.Size;
+                LayoutLength childHeight = childLayout.MeasuredHeight.Size;
+                Extents childMargin = childLayout.Margin;
+
+                switch (LinearAlignment)
+                {
+                    case Alignment.Bottom:
+                        childTop = new LayoutLength(height - Padding.Bottom - childHeight - childMargin.Bottom);
+                        break;
+                    case Alignment.CenterVertical:
+                    case Alignment.Center: // FALLTHROUGH
+                        childTop = new LayoutLength(Padding.Top + ((childSpace - childHeight).AsDecimal() / 2.0f) + childMargin.Top - childMargin.Bottom);
+                        break;
+                    case Alignment.Top: // FALLTHROUGH default
+                    default:
+                        childTop = new LayoutLength(Padding.Top + childMargin.Top);
+                        break;
                 }
+                childLeft += childMargin.Start;
+                childLayout.Layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
+                childLeft += childWidth + childMargin.End + ((i < count - 1) ? CellPadding.Width : 0);
             }
         } // LayoutHorizontally
 
@@ -759,7 +726,8 @@ namespace Tizen.NUI
             // Space available for child
             LayoutLength childSpace = new LayoutLength(width - Padding.Start - Padding.End);
 
-            int count = LayoutChildren.Count;
+            List<LayoutItem> LinearChildren = IterateLayoutChildren().ToList();
+            int count = LinearChildren.Count;
 
             switch (LinearAlignment)
             {
@@ -781,40 +749,35 @@ namespace Tizen.NUI
 
             for (int i = 0; i < count; i++)
             {
-                LayoutItem childLayout = LayoutChildren[i];
-                if (childLayout != null)
-                {
-                    if (!childLayout.Owner.ExcludeLayouting)
-                    {
-                        LayoutLength childWidth = childLayout.MeasuredWidth.Size;
-                        LayoutLength childHeight = childLayout.MeasuredHeight.Size;
-                        Extents childMargin = childLayout.Margin;
+                LayoutItem childLayout = LinearChildren[i];
 
-                        childTop += childMargin.Top;
-                        switch (LinearAlignment)
+                LayoutLength childWidth = childLayout.MeasuredWidth.Size;
+                LayoutLength childHeight = childLayout.MeasuredHeight.Size;
+                Extents childMargin = childLayout.Margin;
+
+                childTop += childMargin.Top;
+                switch (LinearAlignment)
+                {
+                    case Alignment.Begin:
+                    default:
                         {
-                            case Alignment.Begin:
-                            default:
-                                {
-                                    childLeft = new LayoutLength(Padding.Start + childMargin.Start);
-                                    break;
-                                }
-                            case Alignment.End:
-                                {
-                                    childLeft = new LayoutLength(width - Padding.End - childWidth - childMargin.End);
-                                    break;
-                                }
-                            case Alignment.CenterHorizontal:
-                            case Alignment.Center: // FALL THROUGH
-                                {
-                                    childLeft = new LayoutLength(Padding.Start + ((childSpace - childWidth).AsDecimal() / 2.0f) + childMargin.Start - childMargin.End);
-                                    break;
-                                }
+                            childLeft = new LayoutLength(Padding.Start + childMargin.Start);
+                            break;
+                        }
+                    case Alignment.End:
+                        {
+                            childLeft = new LayoutLength(width - Padding.End - childWidth - childMargin.End);
+                            break;
+                        }
+                    case Alignment.CenterHorizontal:
+                    case Alignment.Center: // FALL THROUGH
+                        {
+                            childLeft = new LayoutLength(Padding.Start + ((childSpace - childWidth).AsDecimal() / 2.0f) + childMargin.Start - childMargin.End);
+                            break;
                         }
-                        childLayout.Layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
-                        childTop += childHeight + childMargin.Bottom + ((i < count - 1) ? CellPadding.Height : 0);
-                    }
                 }
+                childLayout.Layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
+                childTop += childHeight + childMargin.Bottom + ((i < count - 1) ? CellPadding.Height : 0);
             }
         } // LayoutVertical
 
@@ -824,12 +787,8 @@ namespace Tizen.NUI
             // ourselves. The measured height should be the max height of the children, changed
             // to accommodate the heightMeasureSpec from the parent
             MeasureSpecification uniformMeasureSpec = new MeasureSpecification(MeasuredHeight.Size, MeasureSpecification.ModeType.Exactly);
-            foreach (LayoutItem childLayout in LayoutChildren)
+            foreach (LayoutItem childLayout in IterateLayoutChildren())
             {
-                if (childLayout.Owner.ExcludeLayouting)
-                {
-                    continue;
-                }
                 int desiredChildHeight = childLayout.Owner.HeightSpecification;
                 int desiredChildWidth = childLayout.Owner.WidthSpecification;
 
@@ -851,13 +810,8 @@ namespace Tizen.NUI
         {
             // Pretend that the linear layout has an exact size.
             MeasureSpecification uniformMeasureSpec = new MeasureSpecification(MeasuredWidth.Size, MeasureSpecification.ModeType.Exactly);
-            foreach (LayoutItem childLayout in LayoutChildren)
+            foreach (LayoutItem childLayout in IterateLayoutChildren())
             {
-                if (childLayout.Owner.ExcludeLayouting)
-                {
-                    continue;
-                }
-
                 int desiredChildWidth = childLayout.Owner.WidthSpecification;
                 int desiredChildHeight = childLayout.Owner.WidthSpecification;