[NUI] Restore AbsoluteLayout not to apply margin/padding without bounds
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Tue, 18 Mar 2025 10:21:43 +0000 (19:21 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 25 Mar 2025 06:44:47 +0000 (15:44 +0900)
AbsoluteLayout is restored not to apply margin and padding if bounds are
not set by calling SetLayoutBounds().

It is because position is updated according to margin and padding.
If margin and padding is applied only with position instead of bounds,
position will be increased unexpectedly in OnLayout() each time.

src/Tizen.NUI/src/public/Layouting/AbsoluteLayout.cs

index 39ebb85b6410410aff1abdd6c228e730e0c6fecb..5efa67e85f84dd4c6267ba06a4bae23be54204a3 100755 (executable)
@@ -147,12 +147,14 @@ namespace Tizen.NUI
                     continue;
                 }
 
+                var isBoundsSet = childLayout.Owner.GetAttached<LayoutParams>() != null;
+
                 Extents childMargin = childLayout.Margin;
                 var rect = GetLayoutBounds(childLayout.Owner);
                 var flags = GetLayoutFlags(childLayout.Owner);
 
-                // If child view positions with using pivot point, then padding and margin are not used.
-                if (childLayout.Owner.PositionUsesPivotPoint)
+                // If child view does not use bounds, then padding and margin are not used.
+                if (!isBoundsSet)
                 {
                     MeasureChildWithoutPadding(childLayout, widthMeasureSpec, heightMeasureSpec);
                 }
@@ -206,8 +208,8 @@ namespace Tizen.NUI
                 float childRight;
                 float childBottom;
 
-                // If child view positions with using pivot point, then padding and margin are not used.
-                if (childLayout.Owner.PositionUsesPivotPoint)
+                // If child view does not use bounds, then padding and margin are not used.
+                if (!isBoundsSet)
                 {
                     childRight = childLayout.MeasuredWidth.Size.AsDecimal() + childLayout.Owner.PositionX;
                     childBottom = childLayout.MeasuredHeight.Size.AsDecimal() + childLayout.Owner.PositionY;
@@ -267,6 +269,8 @@ namespace Tizen.NUI
                     continue;
                 }
 
+                var isBoundsSet = childLayout.Owner.GetAttached<LayoutParams>() != null;
+
                 Extents childMargin = childLayout.Margin;
 
                 LayoutLength childWidth = childLayout.MeasuredWidth.Size;
@@ -275,8 +279,8 @@ namespace Tizen.NUI
                 LayoutLength childLeft;
                 LayoutLength childTop;
 
-                // If child view positions with using pivot point, then padding and margin are not used.
-                if (childLayout.Owner.PositionUsesPivotPoint)
+                // If child view does not use bounds, then padding and margin are not used.
+                if (!isBoundsSet)
                 {
                     childLeft = new LayoutLength(childLayout.Owner.PositionX);
                     childTop = new LayoutLength(childLayout.Owner.PositionY);
@@ -284,18 +288,17 @@ namespace Tizen.NUI
                 }
                 else
                 {
-                    var isBoundsSet = childLayout.Owner.GetAttached<LayoutParams>() != null;
                     var rect = GetLayoutBounds(childLayout.Owner);
                     var flags = GetLayoutFlags(childLayout.Owner);
                     var isXProportional = flags.HasFlag(AbsoluteLayoutFlags.XProportional);
                     var isYProportional = flags.HasFlag(AbsoluteLayoutFlags.YProportional);
 
-                    var childX = MeasurePosition(isBoundsSet, childLayout.Owner.PositionX, rect.X, isXProportional,
+                    var childX = MeasureBoundsPosition(rect.X, isXProportional,
                                 MeasuredWidth.Size.AsDecimal() - (Padding.Start + Padding.End),
                                 childWidth.AsDecimal() + (childMargin.Start + childMargin.End),
                                 Padding.Start, childMargin.Start);
 
-                    var childY = MeasurePosition(isBoundsSet, childLayout.Owner.PositionY, rect.Y, isYProportional,
+                    var childY = MeasureBoundsPosition(rect.Y, isYProportional,
                                 MeasuredHeight.Size.AsDecimal() - (Padding.Top + Padding.Bottom),
                                 childHeight.AsDecimal() + (childMargin.Top + childMargin.Bottom),
                                 Padding.Top, childMargin.Bottom);
@@ -337,19 +340,6 @@ namespace Tizen.NUI
             }
         }
 
-        private float MeasurePosition(bool isBoundsSet, float position, float boundsValue, bool proportional, float constraint, float sizeWithMargin, float paddingBegin, float marginBegin)
-        {
-            // If user sets LayoutBounds, use LayoutBounds. Otherwise, use Position property.
-            if (isBoundsSet)
-            {
-                return MeasureBoundsPosition(boundsValue, proportional, constraint, sizeWithMargin, paddingBegin, marginBegin);
-            }
-            else
-            {
-                return paddingBegin + position + marginBegin;
-            }
-        }
-
         private class LayoutParams
         {
             /// <summary>