diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 91660e08e..2804ef23c 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using System.IO.Compression; +using static Terminal.Gui.SpinnerStyle; namespace Terminal.Gui; @@ -894,7 +895,24 @@ public partial class View foreach (View v in ordered) { - LayoutSubview (v, ContentSize); + if (v.Width is Dim.DimAuto || v.Height is Dim.DimAuto) + { + // If the view is auto-sized... + Rectangle f = v.Frame; + v._frame = new (v.Frame.X, v.Frame.Y, 0, 0); + LayoutSubview (v, Viewport.Size); + + if (v.Frame != f) + { + // The subviews changed; do it again + v.LayoutNeeded = true; + LayoutSubview (v, Viewport.Size); + } + } + else + { + LayoutSubview (v, Viewport.Size); + } } // If the 'to' is rooted to 'from' and the layoutstyle is Computed it's a special-case. diff --git a/Terminal.Gui/View/ViewText.cs b/Terminal.Gui/View/ViewText.cs index ef3013dad..a9b1f3ab6 100644 --- a/Terminal.Gui/View/ViewText.cs +++ b/Terminal.Gui/View/ViewText.cs @@ -1,3 +1,5 @@ +using static Terminal.Gui.SpinnerStyle; + namespace Terminal.Gui; public partial class View @@ -171,6 +173,7 @@ public partial class View ? Math.Max (HotKeySpecifier.GetColumns (), 0) : 0; } + /// /// Gets the Frame dimensions required to fit within using the text /// specified by the property and accounting for any @@ -251,11 +254,37 @@ public partial class View return; } + + int w = Viewport.Size.Width + GetHotKeySpecifierLength (); - TextFormatter.Size = new ( - ContentSize.Width + GetHotKeySpecifierLength (), - ContentSize.Height + GetHotKeySpecifierLength (false) - ); + if (Width is Dim.DimAuto widthAuto && widthAuto._style != Dim.DimAutoStyle.Subviews) + { + if (Height is Dim.DimAuto) + { + // Both are auto. + TextFormatter.Size = new Size (SuperView?.Viewport.Width ?? 0, SuperView?.Viewport.Height ?? 0); + } + else + { + TextFormatter.Size = new Size (SuperView?.Viewport.Width ?? 0, Viewport.Size.Height + GetHotKeySpecifierLength ()); + } + + w = TextFormatter.FormatAndGetSize ().Width; + } + else + { + TextFormatter.Size = new Size (w, SuperView?.Viewport.Height ?? 0); + } + + int h = Viewport.Size.Height + GetHotKeySpecifierLength (); + + if (Height is Dim.DimAuto heightAuto && heightAuto._style != Dim.DimAutoStyle.Subviews) + { + TextFormatter.NeedsFormat = true; + h = TextFormatter.FormatAndGetSize ().Height; + } + + TextFormatter.Size = new Size (w, h); } private bool IsValidAutoSize (out Size autoSize)