浏览代码

Ensured adornments layout

Tig 1 年之前
父节点
当前提交
e8c851631f

+ 2 - 1
Terminal.Gui/View/Adornment/Adornment.cs

@@ -88,7 +88,8 @@ public class Adornment : View
 
             if (prev != _thickness)
             {
-                Parent?.LayoutAdornments ();
+                Parent.SetNeedsLayout ();
+                Parent?.LayoutSubviews ();
                 OnThicknessChanged (prev);
             }
         }

+ 10 - 19
Terminal.Gui/View/Layout/ViewLayout.cs

@@ -570,13 +570,10 @@ public partial class View
             Margin.Y = 0;
             Margin.Width = Frame.Size.Width;
             Margin.Height = Frame.Size.Height;
-            Margin.SetNeedsLayout ();
-            Margin.SetNeedsDisplay ();
-            if (Margin.Subviews.Count > 0)
-            {
-                Margin.LayoutSubviews ();
-            }
         }
+        Margin.SetNeedsLayout ();
+        Margin.SetNeedsDisplay ();
+        Margin.LayoutSubviews ();
 
         Rectangle border = Margin.Thickness.GetInside (Margin.Frame);
 
@@ -587,13 +584,10 @@ public partial class View
             Border.Y = border.Location.Y;
             Border.Width = border.Size.Width;
             Border.Height = border.Size.Height;
-            Border.SetNeedsLayout ();
-            Border.SetNeedsDisplay ();
-            if (Border.Subviews.Count > 0)
-            {
-                Border.LayoutSubviews ();
-            }
         }
+        Border.SetNeedsLayout ();
+        Border.SetNeedsDisplay ();
+        Border.LayoutSubviews ();
 
         Rectangle padding = Border.Thickness.GetInside (Border.Frame);
 
@@ -604,13 +598,10 @@ public partial class View
             Padding.Y = padding.Location.Y;
             Padding.Width = padding.Size.Width;
             Padding.Height = padding.Size.Height;
-            Padding.SetNeedsLayout ();
-            Padding.SetNeedsDisplay ();
-            if (Padding.Subviews.Count > 0)
-            {
-                Padding.LayoutSubviews ();
-            }
         }
+        Padding.SetNeedsLayout ();
+        Padding.SetNeedsDisplay ();
+        Padding.LayoutSubviews ();
     }
 
     #endregion Adornments
@@ -1216,8 +1207,8 @@ public partial class View
             }
 
             LayoutAdornments ();
-            SetNeedsLayout ();
             SetNeedsDisplay ();
+            SetNeedsLayout ();
         }
     }
 

+ 53 - 0
UnitTests/View/Adornment/AdornmentSubViewTests.cs

@@ -0,0 +1,53 @@
+using Xunit.Abstractions;
+
+namespace Terminal.Gui.ViewTests;
+
+public class AdornmentSubViewTests (ITestOutputHelper output)
+{
+    private readonly ITestOutputHelper _output = output;
+
+    [Fact]
+    public void Adornment_WithSubView_FindDeepestView_Finds ()
+    {
+        var view = new View () {
+            Width = 10,
+            Height = 10
+
+        };
+        view.Padding.Thickness = new Thickness (1);
+
+        var subView = new View () {
+            X = 0,
+            Y =0,
+            Width = 1,
+            Height = 1
+        };
+        view.Padding.Add (subView);
+
+        Assert.Equal (subView, View.FindDeepestView (view, 0, 0));
+    }
+
+    [Fact]
+    public void Adornment_WithNonVisibleSubView_FindDeepestView_Finds_Adornment ()
+    {
+        var view = new View ()
+        {
+            Width = 10,
+            Height = 10
+
+        };
+        view.Padding.Thickness = new Thickness (1);
+
+        var subView = new View ()
+        {
+            X = 0,
+            Y = 0,
+            Width = 1,
+            Height = 1,
+            Visible = false
+        };
+        view.Padding.Add (subView);
+
+        Assert.Equal (view.Padding, View.FindDeepestView (view, 0, 0));
+    }
+}

+ 31 - 31
UnitTests/View/Adornment/AdornmentTests.cs

@@ -2,10 +2,9 @@
 
 namespace Terminal.Gui.ViewTests;
 
-public class AdornmentTests
+public class AdornmentTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public AdornmentTests (ITestOutputHelper output) { _output = output; }
+    private readonly ITestOutputHelper _output = output;
 
     [Fact]
     public void Bounds_Location_Always_Empty_Size_Correct ()
@@ -335,48 +334,49 @@ public class AdornmentTests
         Assert.True (raised);
     }
 
+
     [Fact]
-    public void Adornment_WithSubView_FindDeepestView_Finds ()
+    public void Setting_Thickness_Causes_Parent_Layout ()
     {
-        var view = new View () {
-            Width = 10,
-            Height = 10
+        var view = new View ();
+        var raised = false;
+        view.BeginInit();
+        view.EndInit();
 
-        };
-        view.Padding.Thickness = new Thickness (1);
+        view.LayoutStarted += LayoutStarted;
+        view.Margin.Thickness = new Thickness (1, 2, 3, 4);
+        Assert.True (raised);
 
-        var subView = new View () {
-            X = 0,
-            Y =0,
-            Width = 1,
-            Height = 1
-        };
-        view.Padding.Add (subView);
+        return;
+        void LayoutStarted (object sender, LayoutEventArgs e)
+        {
+            raised = true;
+        }
 
-        Assert.Equal (subView, View.FindDeepestView (view, 0, 0));
     }
 
     [Fact]
-    public void Adornment_WithNonVisibleSubView_FindDeepestView_Finds_Adornment ()
+    public void Setting_Thickness_Causes_Adornment_Layout ()
     {
         var view = new View ()
         {
-            Width = 10,
-            Height = 10
-
+            Width = 5,
+            Height = 5
         };
-        view.Padding.Thickness = new Thickness (1);
+        var raised = false;
+        view.BeginInit ();
+        view.EndInit ();
 
-        var subView = new View ()
+        view.Margin.LayoutStarted += LayoutStarted;
+        view.Margin.Thickness = new Thickness (1, 2, 3, 4);
+        Assert.True (raised);
+
+        return;
+        void LayoutStarted (object sender, LayoutEventArgs e)
         {
-            X = 0,
-            Y = 0,
-            Width = 1,
-            Height = 1,
-            Visible = false
-        };
-        view.Padding.Add (subView);
+            raised = true;
+        }
 
-        Assert.Equal (view.Padding, View.FindDeepestView (view, 0, 0));
     }
+
 }