[NUI] Fixed svace issue
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Layouting / LayoutItem.cs
index 4a83d70..760d901 100755 (executable)
@@ -40,18 +40,17 @@ namespace Tizen.NUI
     public class LayoutItem : IDisposable
     {
         private bool disposed = false;
-        static bool LayoutDebugFrameData = false; // Debug flag
-        private MeasureSpecification OldWidthMeasureSpec; // Store measure specification to compare against later
-        private MeasureSpecification OldHeightMeasureSpec; // Store measure specification to compare against later
+        private MeasureSpecification oldWidthMeasureSpec; // Store measure specification to compare against later
+        private MeasureSpecification oldHeightMeasureSpec; // Store measure specification to compare against later
 
-        private LayoutFlags Flags = LayoutFlags.None;
+        private LayoutFlags flags = LayoutFlags.None;
 
-        private ILayoutParent Parent;
+        private ILayoutParent parent;
 
-        LayoutData _layoutPositionData;
+        LayoutData layoutPositionData;
 
-        private Extents _padding;
-        private Extents _margin;
+        private Extents padding;
+        private Extents margin;
 
         private bool parentReplacement = false;
         private bool setPositionByLayout = true;
@@ -103,11 +102,11 @@ namespace Tizen.NUI
         {
             get
             {
-                return _margin;
+                return margin;
             }
             set
             {
-                _margin = value;
+                margin = value;
                 RequestLayout();
             }
         }
@@ -120,11 +119,11 @@ namespace Tizen.NUI
         {
             get
             {
-                return _padding;
+                return padding;
             }
             set
             {
-                _padding = value;
+                padding = value;
                 RequestLayout();
             }
         }
@@ -144,7 +143,7 @@ namespace Tizen.NUI
         /// <param name="parent">Parent to set on this Layout.</param>
         internal void SetParent(ILayoutParent parent)
         {
-            Parent = parent as LayoutGroup;
+            this.parent = parent as LayoutGroup;
         }
 
         /// <summary>
@@ -156,10 +155,10 @@ namespace Tizen.NUI
             OnUnparent();
 
             // Remove myself from parent
-            Parent?.Remove(this);
+            parent?.Remove(this);
 
             // Remove parent reference
-            Parent = null;
+            parent = null;
 
             // Lastly, clear layout from owning View.
             Owner?.ResetLayout();
@@ -168,9 +167,9 @@ namespace Tizen.NUI
         private void Initialize()
         {
             LayoutWithTransition = false;
-            _layoutPositionData = new LayoutData(this, TransitionCondition.Unspecified, 0, 0, 0, 0);
-            _padding = new Extents(0, 0, 0, 0);
-            _margin = new Extents(0, 0, 0, 0);
+            layoutPositionData = new LayoutData(this, TransitionCondition.Unspecified, 0, 0, 0, 0);
+            padding = new Extents(0, 0, 0, 0);
+            margin = new Extents(0, 0, 0, 0);
         }
 
         /// <summary>
@@ -204,30 +203,34 @@ namespace Tizen.NUI
         /// <since_tizen> 6 </since_tizen>
         public void Measure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
         {
+            OnMeasure(widthMeasureSpec, heightMeasureSpec);
+            OnMeasureIndependentChildren(widthMeasureSpec, heightMeasureSpec);
+            flags = flags | LayoutFlags.LayoutRequired;
+            flags &= ~LayoutFlags.ForceLayout;
+
+            oldWidthMeasureSpec = widthMeasureSpec;
+            oldHeightMeasureSpec = heightMeasureSpec;
+        }
+
+        internal bool NeedsLayout(float widthSize, float heightSize, MeasureSpecification.ModeType widthMode, MeasureSpecification.ModeType heightMode)
+        {
+            if (LayoutRequested)
+            {
+                return true;
+            }
+
             // Check if relayouting is required.
-            bool specChanged = (widthMeasureSpec.Size != OldWidthMeasureSpec.Size) ||
-                (heightMeasureSpec.Size != OldHeightMeasureSpec.Size) ||
-                (widthMeasureSpec.Mode != OldWidthMeasureSpec.Mode) ||
-                (heightMeasureSpec.Mode != OldHeightMeasureSpec.Mode);
+            bool specChanged = (widthSize != oldWidthMeasureSpec.Size.AsDecimal()) || (widthMode != oldWidthMeasureSpec.Mode) ||
+                               (heightSize != oldHeightMeasureSpec.Size.AsDecimal()) || (heightMode != oldHeightMeasureSpec.Mode);
 
-            bool isSpecExactly = (widthMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly) &&
-                (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly);
+            bool isSpecExactly = (widthMode == MeasureSpecification.ModeType.Exactly) &&
+                                 (heightMode == MeasureSpecification.ModeType.Exactly);
 
-            bool matchesSpecSize = (MeasuredWidth.Size == widthMeasureSpec.Size) &&
-                (MeasuredHeight.Size == heightMeasureSpec.Size);
+            bool matchesSpecSize = (MeasuredWidth.Size.AsDecimal() == widthSize) && (MeasuredHeight.Size.AsDecimal() == heightSize);
 
             bool needsLayout = specChanged && (!isSpecExactly || !matchesSpecSize);
-            needsLayout = needsLayout || ((Flags & LayoutFlags.ForceLayout) == LayoutFlags.ForceLayout);
 
-            if (needsLayout)
-            {
-                OnMeasure(widthMeasureSpec, heightMeasureSpec);
-                OnMeasureIndependentChildren(widthMeasureSpec, heightMeasureSpec);
-                Flags = Flags | LayoutFlags.LayoutRequired;
-                Flags &= ~LayoutFlags.ForceLayout;
-            }
-            OldWidthMeasureSpec = widthMeasureSpec;
-            OldHeightMeasureSpec = heightMeasureSpec;
+            return needsLayout;
         }
 
         /// <summary>
@@ -266,12 +269,12 @@ namespace Tizen.NUI
                     bottom.AsRoundedValue(), independent);
 
             // Check if Measure needed before Layouting
-            if (changed || ((Flags & LayoutFlags.LayoutRequired) == LayoutFlags.LayoutRequired))
+            if (changed || ((flags & LayoutFlags.LayoutRequired) == LayoutFlags.LayoutRequired))
             {
                 OnLayout(changed, left, top, right, bottom);
                 OnLayoutIndependentChildren(changed, left, top, right, bottom);
                 // Clear flag
-                Flags &= ~LayoutFlags.LayoutRequired;
+                flags &= ~LayoutFlags.LayoutRequired;
             }
         }
 
@@ -330,7 +333,7 @@ namespace Tizen.NUI
         /// <since_tizen> 6 </since_tizen>
         public ILayoutParent GetParent()
         {
-            return Parent;
+            return parent;
         }
 
         /// <summary>
@@ -340,10 +343,10 @@ namespace Tizen.NUI
         /// <since_tizen> 6 </since_tizen>
         public void RequestLayout()
         {
-            Flags = Flags | LayoutFlags.ForceLayout;
-            if (Parent != null)
+            flags = flags | LayoutFlags.ForceLayout;
+            if (parent != null)
             {
-                LayoutGroup layoutGroup = Parent as LayoutGroup;
+                LayoutGroup layoutGroup = parent as LayoutGroup;
                 if (layoutGroup != null && !layoutGroup.LayoutRequested)
                 {
                     layoutGroup.RequestLayout();
@@ -360,7 +363,7 @@ namespace Tizen.NUI
         {
             get
             {
-                return (Flags & LayoutFlags.ForceLayout) == LayoutFlags.ForceLayout;
+                return (flags & LayoutFlags.ForceLayout) == LayoutFlags.ForceLayout;
             }
         }
 
@@ -402,16 +405,7 @@ namespace Tizen.NUI
         {
             get
             {
-                float maximumWidth = Owner.MaximumSize.Width;
-                float minimumWidth = Owner.MinimumSize.Width;
-
-                float baseHeight = Owner.MaximumSize.Height > 0 ? Math.Min(Owner.MaximumSize.Height, Owner.NaturalSize.Height) : Owner.NaturalSize.Height;
-                float baseWidth = Owner.GetWidthForHeight(baseHeight);
-
-                float result = minimumWidth > 0 ? Math.Max(baseWidth, minimumWidth) : baseWidth;
-                result = maximumWidth > 0 ? Math.Min(result, maximumWidth) : result;
-
-                return new LayoutLength(result);
+                return Owner.SuggestedMinimumWidth;
             }
         }
 
@@ -424,16 +418,7 @@ namespace Tizen.NUI
         {
             get
             {
-                float maximumHeight = Owner.MaximumSize.Height;
-                float minimumHeight = Owner.MinimumSize.Height;
-
-                float baseWidth = Owner.MaximumSize.Width > 0 ? Math.Min(Owner.MaximumSize.Width, Owner.NaturalSize.Width) : Owner.NaturalSize.Width;
-                float baseHeight = Owner.GetHeightForWidth(baseWidth);
-
-                float result = minimumHeight > 0 ? Math.Max(baseHeight, minimumHeight) : baseHeight;
-                result = maximumHeight > 0 ? Math.Min(result, maximumHeight) : result;
-
-                return new LayoutLength(result);
+                return Owner.SuggestedMinimumHeight;
             }
         }
 
@@ -507,7 +492,7 @@ namespace Tizen.NUI
         {
             MeasuredWidth = measuredWidth;
             MeasuredHeight = measuredHeight;
-            Flags = Flags | LayoutFlags.MeasuredDimensionSet;
+            flags = flags | LayoutFlags.MeasuredDimensionSet;
         }
 
         /// <summary>
@@ -563,19 +548,13 @@ namespace Tizen.NUI
         {
             bool changed = false;
 
-            if (_layoutPositionData.Left != left ||
-                 _layoutPositionData.Right != right ||
-                 _layoutPositionData.Top != top ||
-                 _layoutPositionData.Bottom != bottom)
+            if (layoutPositionData.Left != left ||
+                 layoutPositionData.Right != right ||
+                 layoutPositionData.Top != top ||
+                 layoutPositionData.Bottom != bottom)
             {
                 changed = true;
 
-                float oldWidth = _layoutPositionData.Right - _layoutPositionData.Left;
-                float oldHeight = _layoutPositionData.Bottom - _layoutPositionData.Top;
-                float newWidth = right - left;
-                float newHeight = bottom - top;
-                bool sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight);
-
                 // Set condition to layout changed as currently unspecified. Add, Remove would have specified a condition.
                 if (ConditionForAnimation.Equals(TransitionCondition.Unspecified))
                 {
@@ -583,40 +562,36 @@ namespace Tizen.NUI
                 }
 
                 // Store new layout position data
-                _layoutPositionData = new LayoutData(this, ConditionForAnimation, left, top, right, bottom);
+                layoutPositionData = new LayoutData(this, ConditionForAnimation, left, top, right, bottom);
 
-                Debug.WriteLineIf(LayoutDebugFrameData, "LayoutItem FramePositionData View:" + _layoutPositionData.Item.Owner.Name +
-                                                         " left:" + _layoutPositionData.Left +
-                                                         " top:" + _layoutPositionData.Top +
-                                                         " right:" + _layoutPositionData.Right +
-                                                         " bottom:" + _layoutPositionData.Bottom);
+                NUILog.Debug("LayoutItem FramePositionData View:" + layoutPositionData.Item?.Owner?.Name +
+                                                         " left:" + layoutPositionData.Left +
+                                                         " top:" + layoutPositionData.Top +
+                                                         " right:" + layoutPositionData.Right +
+                                                         " bottom:" + layoutPositionData.Bottom);
 
-                Container onwerContainer = Owner.GetParent();
-                View onwerView = onwerContainer is Layer ? new View(Layer.getCPtr(onwerContainer).Handle, false) : onwerContainer as View;
+                View ownerView = Owner.GetParent() as View;
 
-                if (onwerView != null && onwerView.Layout != null && onwerView.Layout.LayoutWithTransition)
+                if (ownerView?.Layout?.LayoutWithTransition ?? false)
                 {
-                    NUIApplication.GetDefaultWindow().LayoutController.AddTransitionDataEntry(_layoutPositionData);
+                    NUIApplication.GetDefaultWindow().LayoutController.AddTransitionDataEntry(layoutPositionData);
                 }
                 else
                 {
-                    if (Owner.Position != null)
+                    if (independent)
                     {
-                        if(independent)
-                        {
-                            // If height or width specification is not explicitly defined,
-                            // the size of the owner view must be reset even the ExcludeLayouting is true.
-                            if (Owner.HeightSpecification < 0 || Owner.WidthSpecification < 0)
-                            {
-                                Owner.SetSize(right - left, bottom - top);
-                            }
-                        }
-                        else
+                        // If height or width specification is not explicitly defined,
+                        // the size of the owner view must be reset even the ExcludeLayouting is true.
+                        if (Owner.HeightSpecification < 0 || Owner.WidthSpecification < 0)
                         {
                             Owner.SetSize(right - left, bottom - top);
-                            Owner.SetPosition(left, top);
                         }
                     }
+                    else
+                    {
+                        Owner.SetSize(right - left, bottom - top);
+                        Owner.SetPosition(left, top);
+                    }
                 }
 
                 // Reset condition for animation ready for next transition when required.
@@ -630,15 +605,15 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected virtual void Dispose(bool disposing)
         {
-            if(disposed)
+            if (disposed)
             {
                 return;
             }
 
             if (disposing)
             {
-                _margin?.Dispose();
-                _padding?.Dispose();
+                margin?.Dispose();
+                padding?.Dispose();
             }
             disposed = true;
         }