From aa72a97cd677fa818d38ebb01268471479249a3b Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 13 Apr 2024 15:04:30 +0100 Subject: [PATCH 1/3] Add ability to disable AutoSize --- Terminal.Gui/View/Layout/ViewLayout.cs | 7 +++++++ Terminal.Gui/Views/Button.cs | 2 +- Terminal.Gui/Views/CheckBox.cs | 2 +- Terminal.Gui/Views/Label.cs | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 2d1c3224b3..dd68c4f8de 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -35,6 +35,13 @@ public enum LayoutStyle public partial class View { + /// + /// Determines the default usage of in views + /// that support it (e.g. . Set to false if you frequently + /// get Exceptions about changing Width when AutoSize is true. + /// + public static bool DefaultAutoSize = true; + #region Frame private Rectangle _frame; diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index a710bc2d92..058a254835 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -52,7 +52,7 @@ public Button () Height = 1; CanFocus = true; - AutoSize = true; + AutoSize = View.DefaultAutoSize; HighlightStyle |= HighlightStyle.Pressed; #if HOVER HighlightStyle |= HighlightStyle.Hover; diff --git a/Terminal.Gui/Views/CheckBox.cs b/Terminal.Gui/Views/CheckBox.cs index 7b8dc08a8c..d9aa9048fc 100644 --- a/Terminal.Gui/Views/CheckBox.cs +++ b/Terminal.Gui/Views/CheckBox.cs @@ -24,7 +24,7 @@ public CheckBox () Height = 1; CanFocus = true; - AutoSize = true; + AutoSize = View.DefaultAutoSize; // Things this view knows how to do AddCommand (Command.Accept, OnToggled); diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index 7b7b331c14..ec62a68023 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -16,7 +16,7 @@ public class Label : View public Label () { Height = 1; - AutoSize = true; + AutoSize = View.DefaultAutoSize; // Things this view knows how to do AddCommand (Command.HotKey, FocusNext); From 7d4d77ca6499f760f3c6a1e4746ce5f63271296c Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 14 Apr 2024 09:40:31 +0100 Subject: [PATCH 2/3] Force AutoSize false instead of throw Exception when setting Width/Height --- Terminal.Gui/View/Layout/ViewLayout.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index dd68c4f8de..aed51b3278 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -228,7 +228,8 @@ public Dim Height if (AutoSize) { - throw new InvalidOperationException (@$"Must set AutoSize to false before setting {nameof (Height)}."); + Debug.WriteLine (@$"Must set AutoSize to false before setting {nameof (Height)}."); + AutoSize = false; } //if (ValidatePosDim) { @@ -236,9 +237,10 @@ public Dim Height if (IsAdded && AutoSize && !isValidNewAutoSize) { - throw new InvalidOperationException ( + Debug.WriteLine ( @$"Must set AutoSize to false before setting the {nameof (Height)}." ); + AutoSize = false; } //} @@ -275,14 +277,16 @@ public Dim Width if (AutoSize) { - throw new InvalidOperationException (@$"Must set AutoSize to false before setting {nameof (Width)}."); + Debug.WriteLine($@"Must set AutoSize to false before setting {nameof(Width)}."); + AutoSize = false; } bool isValidNewAutoSize = AutoSize && IsValidAutoSizeWidth (_width); if (IsAdded && AutoSize && !isValidNewAutoSize) { - throw new InvalidOperationException (@$"Must set AutoSize to false before setting {nameof (Width)}."); + Debug.WriteLine($@"Must set AutoSize to false before setting {nameof(Width)}."); + AutoSize = false; } OnResizeNeeded (); From fadecc150ab5811c954bbcef9d0f2ae37588057e Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 14 Apr 2024 09:41:05 +0100 Subject: [PATCH 3/3] Revert "Add ability to disable AutoSize" This reverts commit aa72a97cd677fa818d38ebb01268471479249a3b. --- Terminal.Gui/View/Layout/ViewLayout.cs | 7 ------- Terminal.Gui/Views/Button.cs | 2 +- Terminal.Gui/Views/CheckBox.cs | 2 +- Terminal.Gui/Views/Label.cs | 2 +- 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index aed51b3278..dcfce11103 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -35,13 +35,6 @@ public enum LayoutStyle public partial class View { - /// - /// Determines the default usage of in views - /// that support it (e.g. . Set to false if you frequently - /// get Exceptions about changing Width when AutoSize is true. - /// - public static bool DefaultAutoSize = true; - #region Frame private Rectangle _frame; diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index 058a254835..a710bc2d92 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -52,7 +52,7 @@ public Button () Height = 1; CanFocus = true; - AutoSize = View.DefaultAutoSize; + AutoSize = true; HighlightStyle |= HighlightStyle.Pressed; #if HOVER HighlightStyle |= HighlightStyle.Hover; diff --git a/Terminal.Gui/Views/CheckBox.cs b/Terminal.Gui/Views/CheckBox.cs index d9aa9048fc..7b8dc08a8c 100644 --- a/Terminal.Gui/Views/CheckBox.cs +++ b/Terminal.Gui/Views/CheckBox.cs @@ -24,7 +24,7 @@ public CheckBox () Height = 1; CanFocus = true; - AutoSize = View.DefaultAutoSize; + AutoSize = true; // Things this view knows how to do AddCommand (Command.Accept, OnToggled); diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index ec62a68023..7b7b331c14 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -16,7 +16,7 @@ public class Label : View public Label () { Height = 1; - AutoSize = View.DefaultAutoSize; + AutoSize = true; // Things this view knows how to do AddCommand (Command.HotKey, FocusNext);