From ba4139f5f6e9cf7df92715663db55765183258be Mon Sep 17 00:00:00 2001 From: Tig Date: Sun, 12 May 2024 21:55:43 -0600 Subject: [PATCH] WIP fixing 3469 --- Terminal.Gui/Text/TextFormatter.cs | 2 ++ Terminal.Gui/View/ViewText.cs | 4 ++-- UnitTests/View/Layout/Pos.AnchorEndTests.cs | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/Text/TextFormatter.cs b/Terminal.Gui/Text/TextFormatter.cs index af4a7b97b..775ff3f20 100644 --- a/Terminal.Gui/Text/TextFormatter.cs +++ b/Terminal.Gui/Text/TextFormatter.cs @@ -198,6 +198,8 @@ public class TextFormatter { _size = EnableNeedsFormat (value); } + Debug.Assert (Size.Width >= 0); + Debug.Assert (Size.Height >= 0); } } diff --git a/Terminal.Gui/View/ViewText.cs b/Terminal.Gui/View/ViewText.cs index 8d2548fa7..16b495a1c 100644 --- a/Terminal.Gui/View/ViewText.cs +++ b/Terminal.Gui/View/ViewText.cs @@ -191,12 +191,12 @@ public partial class View if (widthAuto is null || !widthAuto._style.HasFlag (Dim.DimAutoStyle.Text)) { - size.Width = _width.Anchor (0); + size.Width = ContentSize.Value.Width; } if (heightAuto is null || !heightAuto._style.HasFlag (Dim.DimAutoStyle.Text)) { - size.Height = _height.Anchor (0); + size.Height = ContentSize.Value.Height; } // Whenever DimAutoStyle.Text is set, ContentSize will match TextFormatter.Size. diff --git a/UnitTests/View/Layout/Pos.AnchorEndTests.cs b/UnitTests/View/Layout/Pos.AnchorEndTests.cs index 65f5583e7..7b8a7d218 100644 --- a/UnitTests/View/Layout/Pos.AnchorEndTests.cs +++ b/UnitTests/View/Layout/Pos.AnchorEndTests.cs @@ -303,4 +303,12 @@ public class PosAnchorEndTests (ITestOutputHelper output) Assert.Equal (5, result); } + [Fact] + public void PosAnchorEnd_MinusOne_Combine_Works () + { + var pos = AnchorEnd () - 1; + var result = pos.Calculate (10, new DimAbsolute (2), null, Dimension.None); + Assert.Equal (7, result); + + } }