浏览代码

Add ability to disable AutoSize

tznind 1 年之前
父节点
当前提交
aa72a97cd6

+ 7 - 0
Terminal.Gui/View/Layout/ViewLayout.cs

@@ -35,6 +35,13 @@ public enum LayoutStyle
 
 public partial class View
 {
+    /// <summary>
+    /// Determines the default usage of <see cref="View.AutoSize"/> in views
+    /// that support it (e.g. <see cref="Button"/>.  Set to false if you frequently
+    /// get Exceptions about changing Width when AutoSize is true.
+    /// </summary>
+    public static bool DefaultAutoSize = true;
+
     #region Frame
 
     private Rectangle _frame;

+ 1 - 1
Terminal.Gui/Views/Button.cs

@@ -52,7 +52,7 @@ public class Button : View
         Height = 1;
 
         CanFocus = true;
-        AutoSize = true;
+        AutoSize = View.DefaultAutoSize;
         HighlightStyle |= HighlightStyle.Pressed;
 #if HOVER
         HighlightStyle |= HighlightStyle.Hover;

+ 1 - 1
Terminal.Gui/Views/CheckBox.cs

@@ -24,7 +24,7 @@ public class CheckBox : View
         Height = 1;
 
         CanFocus = true;
-        AutoSize = true;
+        AutoSize = View.DefaultAutoSize;
 
         // Things this view knows how to do
         AddCommand (Command.Accept, OnToggled);

+ 1 - 1
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);