diff --git a/Terminal.Gui/Drawing/Thickness.cs b/Terminal.Gui/Drawing/Thickness.cs index 3748ac81f..956f8df13 100644 --- a/Terminal.Gui/Drawing/Thickness.cs +++ b/Terminal.Gui/Drawing/Thickness.cs @@ -100,6 +100,17 @@ public class Thickness : IEquatable return outside.Contains (x, y) && !inside.Contains (x, y); } + /// + /// Adds the thickness widths of another to the current , returning a new . + /// + /// + /// + public Thickness Add (Thickness other) + { + return new Thickness (Left + other.Left, Top + other.Top, Right + other.Right, Bottom + other.Bottom); + } + + /// Draws the rectangle with an optional diagnostics label. /// /// If is set to diff --git a/Terminal.Gui/View/Adornment/Adornment.cs b/Terminal.Gui/View/Adornment/Adornment.cs index bd273f583..7b632b03c 100644 --- a/Terminal.Gui/View/Adornment/Adornment.cs +++ b/Terminal.Gui/View/Adornment/Adornment.cs @@ -94,18 +94,6 @@ public class Adornment : View } } - ///// - //public override Rectangle BoundsToScreen (Rectangle bounds) - //{ - // // Adornments are *Children* of a View, not SubViews. Thus View.BoundsToScreen will not work. - // // To get the screen-relative coordinates of a Adornment, we need to know who - // // the Parent is - // Rectangle parentFrame = Parent?.Frame ?? Frame; - // bounds.Offset (parentFrame.X, parentFrame.Y); - - // return Parent?.SuperView?.BoundsToScreen (bounds) ?? bounds; - //} - /// public override Rectangle FrameToScreen () { diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 71af86d5e..c8cea4c3a 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -181,8 +181,9 @@ public partial class View return Rectangle.Empty with { Size = Frame.Size }; } - int width = Math.Max (0, Frame.Size.Width - Margin.Thickness.Horizontal - Border.Thickness.Horizontal - Padding.Thickness.Horizontal); - int height = Math.Max (0, Frame.Size.Height - Margin.Thickness.Vertical - Border.Thickness.Vertical - Padding.Thickness.Vertical); + Thickness totalThickness = Margin.Thickness.Add (Border.Thickness.Add (Padding.Thickness)); + int width = Math.Max (0, Frame.Size.Width - totalThickness.Horizontal); + int height = Math.Max (0, Frame.Size.Height - totalThickness.Vertical); return Rectangle.Empty with { Size = new (width, height) }; } @@ -198,18 +199,19 @@ public partial class View ); } #endif // DEBUG + Thickness totalThickness = Margin.Thickness.Add (Border.Thickness.Add (Padding.Thickness)); Frame = Frame with { Size = new ( - value.Size.Width - + Margin.Thickness.Horizontal - + Border.Thickness.Horizontal - + Padding.Thickness.Horizontal, - value.Size.Height - + Margin.Thickness.Vertical - + Border.Thickness.Vertical - + Padding.Thickness.Vertical + value.Size.Width + totalThickness.Horizontal, + //+ Margin.Thickness.Horizontal + //+ Border.Thickness.Horizontal + //+ Padding.Thickness.Horizontal, + value.Size.Height + totalThickness.Vertical + //+ Margin.Thickness.Vertical + //+ Border.Thickness.Vertical + //+ Padding.Thickness.Vertical ) }; } diff --git a/UnitTests/Drawing/ThicknessTests.cs b/UnitTests/Drawing/ThicknessTests.cs index 248a6979f..d52127ac1 100644 --- a/UnitTests/Drawing/ThicknessTests.cs +++ b/UnitTests/Drawing/ThicknessTests.cs @@ -785,4 +785,95 @@ public class ThicknessTests Assert.Equal (0, t.Bottom); Assert.Equal (0, t.Horizontal); } + + // Test Thickness.Add + [Theory] + [InlineData ( + 1, + 2, + 3, + 4, + 1, + 2, + 3, + 4, + 2, + 4, + 6, + 8)] + [InlineData ( + 1, + 2, + 3, + 4, + 0, + 0, + 0, + 0, + 1, + 2, + 3, + 4)] + [InlineData ( + 1, + 2, + 3, + 4, + -1, + -2, + -3, + -4, + 0, + 0, + 0, + 0)] + [InlineData ( + 1, + 2, + 3, + 4, + 1, + 1, + 1, + 1, + 2, + 3, + 4, + 5)] + [InlineData ( + 1, + 2, + 3, + 4, + 1, + 1, + 1, + 1, + 2, + 3, + 4, + 5)] + public void AddTest ( + int left, + int top, + int right, + int bottom, + int left2, + int top2, + int right2, + int bottom2, + int expectedLeft, + int expectedTop, + int expectedRight, + int expectedBottom + ) + { + var t = new Thickness (left, top, right, bottom); + var t2 = new Thickness (left2, top2, right2, bottom2); + var result = t.Add (t2); + Assert.Equal (expectedLeft, result.Left); + Assert.Equal (expectedTop, result.Top); + Assert.Equal (expectedRight, result.Right); + Assert.Equal (expectedBottom, result.Bottom); + } }