Просмотр исходного кода

Removed bad Checkbox code.
Fixed colorpicker

Tig 1 год назад
Родитель
Сommit
9766ee0516

+ 2 - 12
Terminal.Gui/Views/CheckBox.cs

@@ -158,11 +158,11 @@ public class CheckBox : View
             case TextAlignment.Left:
             case TextAlignment.Centered:
             case TextAlignment.Justified:
-                TextFormatter.Text = $"{GetCheckedState ()} {GetFormatterText ()}";
+                TextFormatter.Text = $"{GetCheckedState ()} {Text}";
 
                 break;
             case TextAlignment.Right:
-                TextFormatter.Text = $"{GetFormatterText ()} {GetCheckedState ()}";
+                TextFormatter.Text = $"{Text} {GetCheckedState ()}";
 
                 break;
         }
@@ -177,14 +177,4 @@ public class CheckBox : View
             var _ => _charNullChecked
         };
     }
-
-    private string GetFormatterText ()
-    {
-        if (string.IsNullOrEmpty (Title) || ContentSize.Width <= 2)
-        {
-            return Text;
-        }
-
-        return Text [..Math.Min (ContentSize.Width - 2, Text.GetRuneCount ())];
-    }
 }

+ 11 - 8
Terminal.Gui/Views/ColorPicker.cs

@@ -37,12 +37,9 @@ public class ColorPicker : View
         AddCommands ();
         AddKeyBindings ();
 
-        LayoutStarted += (o, a) =>
-                         {
-                             Thickness thickness = GetAdornmentsThickness ();
-                             Width = _cols * BoxWidth + thickness.Vertical;
-                             Height = _rows * BoxHeight + thickness.Horizontal;
-                         };
+        Width = Dim.Auto (minimumContentDim: _boxWidth * _cols);
+        Height = Dim.Auto (minimumContentDim: _boxHeight * _rows);
+        SetContentSize(new (_boxWidth * _cols, _boxHeight * _rows));
 
         MouseClick += ColorPicker_MouseClick;
     }
@@ -68,6 +65,9 @@ public class ColorPicker : View
             if (_boxHeight != value)
             {
                 _boxHeight = value;
+                Width = Dim.Auto (minimumContentDim: _boxWidth * _cols);
+                Height = Dim.Auto (minimumContentDim: _boxHeight * _rows);
+                SetContentSize (new (_boxWidth * _cols, _boxHeight * _rows));
                 SetNeedsLayout ();
             }
         }
@@ -82,6 +82,9 @@ public class ColorPicker : View
             if (_boxWidth != value)
             {
                 _boxWidth = value;
+                Width = Dim.Auto (minimumContentDim: _boxWidth * _cols);
+                Height = Dim.Auto (minimumContentDim: _boxHeight * _rows);
+                SetContentSize (new (_boxWidth * _cols, _boxHeight * _rows));
                 SetNeedsLayout ();
             }
         }
@@ -175,9 +178,9 @@ public class ColorPicker : View
         Driver.SetAttribute (HasFocus ? ColorScheme.Focus : GetNormalColor ());
         var colorIndex = 0;
 
-        for (var y = 0; y < Viewport.Height / BoxHeight; y++)
+        for (var y = 0; y < Math.Max(2, viewport.Height / BoxHeight); y++)
         {
-            for (var x = 0; x < Viewport.Width / BoxWidth; x++)
+            for (var x = 0; x < Math.Max(8, viewport.Width / BoxWidth); x++)
             {
                 int foregroundColorIndex = y == 0 ? colorIndex + _cols : colorIndex - _cols;
                 Driver.SetAttribute (new Attribute ((ColorName)foregroundColorIndex, (ColorName)colorIndex));

+ 6 - 4
UICatalog/Scenarios/Adornments.cs

@@ -102,7 +102,7 @@ public class Adornments : Scenario
                                   window.Padding.Add (labelInPadding);
 
                                   var textFieldInPadding = new TextField
-                                      { X = Pos.Right (labelInPadding) + 1, Y = Pos.Top (labelInPadding), Width = 15, Text = "some text" };
+                                  { X = Pos.Right (labelInPadding) + 1, Y = Pos.Top (labelInPadding), Width = 15, Text = "some text" };
                                   textFieldInPadding.Accept += (s, e) => MessageBox.Query (20, 7, "TextField", textFieldInPadding.Text, "Ok");
                                   window.Padding.Add (textFieldInPadding);
 
@@ -282,9 +282,11 @@ public class Adornments : Scenario
             _rightEdit.Value = Thickness.Right;
             _bottomEdit.Value = Thickness.Bottom;
 
+            // TODO: Use Dim.Auto(subviews) when ready
+            Width = Dim.Auto ();// GetAdornmentsThickness ().Horizontal + _foregroundColorPicker.Frame.Width * 2 - 3;
+            Height = Dim.Auto (); //GetAdornmentsThickness ().Vertical + 4 + 3;
             LayoutSubviews ();
-            Height = GetAdornmentsThickness ().Vertical + 4 + 3;
-            Width = GetAdornmentsThickness ().Horizontal + _foregroundColorPicker.Frame.Width * 2 - 3;
+            SetContentSize (new (_foregroundColorPicker.Frame.Width * 2 + 1, 4 + 3 ));
         }
 
         private void Top_ValueChanging (object sender, StateEventArgs<int> e)
@@ -470,7 +472,7 @@ public class Adornments : Scenario
                 _paddingEditor.AttributeChanged += Editor_AttributeChanged;
                 Add (_paddingEditor);
 
-                _diagCheckBox = new() { Text = "_Diagnostics", Y = Pos.Bottom (_paddingEditor) };
+                _diagCheckBox = new () { Text = "_Diagnostics", Y = Pos.Bottom (_paddingEditor) };
                 _diagCheckBox.Checked = Diagnostics != ViewDiagnosticFlags.Off;
 
                 _diagCheckBox.Toggled += (s, e) =>