From a916169b5eb1486758059050b35744d40d5e56e4 Mon Sep 17 00:00:00 2001 From: Tig Date: Tue, 23 Dec 2025 12:27:22 -0700 Subject: [PATCH] Update subview handling and use C# 12 collection exprs Refactor subview checks to use GetSubViews with padding, ensuring accurate layout calculations. Update button list initialization in MessageBoxes.cs to use the C# 12 collection expression for conciseness. Minor formatting cleanup in Dialog.cs. No functional changes to dialog padding logic. --- Examples/UICatalog/Scenarios/MessageBoxes.cs | 2 +- Terminal.Gui/ViewBase/View.Content.cs | 6 +++--- Terminal.Gui/Views/Dialog.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/UICatalog/Scenarios/MessageBoxes.cs b/Examples/UICatalog/Scenarios/MessageBoxes.cs index 6c691516d..56489cb08 100644 --- a/Examples/UICatalog/Scenarios/MessageBoxes.cs +++ b/Examples/UICatalog/Scenarios/MessageBoxes.cs @@ -240,7 +240,7 @@ public class MessageBoxes : Scenario int numButtons = int.Parse (numButtonsEdit.Text); int defaultButton = int.Parse (defaultButtonEdit.Text); - List btns = new (); + List btns = []; for (var i = 0; i < numButtons; i++) { diff --git a/Terminal.Gui/ViewBase/View.Content.cs b/Terminal.Gui/ViewBase/View.Content.cs index cc5947475..89416805f 100644 --- a/Terminal.Gui/ViewBase/View.Content.cs +++ b/Terminal.Gui/ViewBase/View.Content.cs @@ -88,7 +88,7 @@ public partial class View int max = GetContentSize ().Width; // If ContentSizeTracksViewport is false and there are no subviews, use the explicitly set ContentSize - if (!ContentSizeTracksViewport && InternalSubViews.Count == 0) + if (!ContentSizeTracksViewport && GetSubViews (includePadding: true).Count == 0) { return max; } @@ -117,7 +117,7 @@ public partial class View int max = GetContentSize ().Height; // If ContentSizeTracksViewport is false and there are no subviews, use the explicitly set ContentSize - if (!ContentSizeTracksViewport && InternalSubViews.Count == 0) + if (!ContentSizeTracksViewport && GetSubViews (includePadding: true).Count == 0) { return max; } @@ -128,7 +128,7 @@ public partial class View } // Iterate through all subviews to calculate the maximum height - foreach (View subView in InternalSubViews) + foreach (View subView in GetSubViews (includePadding: true)) { max = Math.Max (max, subView.Y.GetAnchor (0) + subView.Height.Calculate (0, max, subView, Dimension.Height)); } diff --git a/Terminal.Gui/Views/Dialog.cs b/Terminal.Gui/Views/Dialog.cs index e6f981d50..a34108d63 100644 --- a/Terminal.Gui/Views/Dialog.cs +++ b/Terminal.Gui/Views/Dialog.cs @@ -232,7 +232,7 @@ public class Dialog : Window, IDesignable // Update padding if buttons have been laid out (maxHeight > 1) if (maxHeight > 1 || Padding.Thickness.Bottom == 0) { - Padding.Thickness = Padding.Thickness with { Bottom = maxHeight }; + Padding.Thickness = Padding.Thickness with { Bottom = maxHeight }; } }