Browse Source

Identified and worked around Issue #3469

Tig 1 year ago
parent
commit
bea82a2be6

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

@@ -20,7 +20,7 @@ public class CheckBox : View
         _charChecked = Glyphs.Checked;
         _charUnChecked = Glyphs.UnChecked;
 
-        Height = 1;
+        Height = 1;//Dim.Auto (Dim.DimAutoStyle.Text);
         Width = Dim.Auto (Dim.DimAutoStyle.Text);
 
         CanFocus = true;

+ 0 - 2
Terminal.Gui/Views/DatePicker.cs

@@ -216,7 +216,6 @@ public class DatePicker : View
         {
             X = Pos.Center () - 2,
             Y = Pos.Bottom (_calendar) - 1,
-            Height = 1,
             Width = 2,
             Text = GetBackButtonText (),
             WantContinuousButtonPressed = true,
@@ -235,7 +234,6 @@ public class DatePicker : View
         {
             X = Pos.Right (_previousMonthButton) + 2,
             Y = Pos.Bottom (_calendar) - 1,
-            Height = 1,
             Width = 2,
             Text = GetForwardButtonText(),
             WantContinuousButtonPressed = true,

+ 1 - 0
Terminal.Gui/Views/TextField.cs

@@ -33,6 +33,7 @@ public class TextField : View
         CaptionColor = new Color (Color.DarkGray);
         ReadOnly = false;
         Autocomplete = new TextFieldAutocomplete ();
+
         Height = 1;
 
         CanFocus = true;

+ 28 - 24
UICatalog/Scenarios/PosAlign.cs

@@ -78,7 +78,8 @@ public sealed class PosAlign : Scenario
             X = Pos.Align (_horizAligner.Alignment),
             Y = Pos.Top (alignRadioGroup),
             ColorScheme = colorScheme,
-            Text = "Spaces"
+            Text = "Spaces",
+            Checked = true
         };
 
         putSpaces.Toggled += (s, e) =>
@@ -115,20 +116,18 @@ public sealed class PosAlign : Scenario
                                       view.Margin.Thickness = new (_leftMargin, 0, 0, 0);
                                   }
                               }
-
-                              appWindow.LayoutSubviews ();
                           };
         appWindow.Add (margin);
 
-        List<Button> addedViews = new List<Button> ();
-
-        addedViews.Add (
-                        new()
-                        {
-                            X = Pos.Align (_horizAligner.Alignment),
-                            Y = Pos.Center (),
-                            Text = NumberToWords.Convert (0)
-                        });
+        List<Button> addedViews =
+        [
+            new ()
+            {
+                X = Pos.Align (_horizAligner.Alignment),
+                Y = Pos.Center (),
+                Text = NumberToWords.Convert (0)
+            }
+        ];
 
         Buttons.NumericUpDown<int> addedViewsUpDown = new Buttons.NumericUpDown<int>
         {
@@ -224,7 +223,8 @@ public sealed class PosAlign : Scenario
             X = 0,
             Y = Pos.Align (_vertAligner.Alignment),
             ColorScheme = colorScheme,
-            Text = "Spaces"
+            Text = "Spaces",
+            Checked = true
         };
 
         putSpaces.Toggled += (s, e) =>
@@ -258,23 +258,27 @@ public sealed class PosAlign : Scenario
                                   // Skip the justification radio group
                                   if (view != alignRadioGroup)
                                   {
+                                      // BUGBUG: This is a hack to work around #3469
+                                      if (view is CheckBox)
+                                      {
+                                          view.Height = 1 + _topMargin;
+                                      }
+
                                       view.Margin.Thickness = new (0, _topMargin, 0, 0);
                                   }
                               }
-
-                              appWindow.LayoutSubviews ();
                           };
         appWindow.Add (margin);
 
-        List<CheckBox> addedViews = new List<CheckBox> ();
-
-        addedViews.Add (
-                        new()
-                        {
-                            X = 0,
-                            Y = Pos.Align (_vertAligner.Alignment),
-                            Text = NumberToWords.Convert (0)
-                        });
+        List<CheckBox> addedViews =
+        [
+            new ()
+            {
+                X = 0,
+                Y = Pos.Align (_vertAligner.Alignment),
+                Text = NumberToWords.Convert (0)
+            }
+        ];
 
         Buttons.NumericUpDown<int> addedViewsUpDown = new Buttons.NumericUpDown<int>
         {

+ 0 - 1
UnitTests/View/Layout/Dim.AutoTests.cs

@@ -665,7 +665,6 @@ public class DimAutoTests (ITestOutputHelper output)
         super.Dispose ();
     }
 
-
     // Test that changing TextFormatter does not impact View dimensions if Dim.Auto is not in play
     [Fact]
     public void DimAuto_Not_Used_TextFormatter_Does_Not_Change_View_Size ()

+ 20 - 0
UnitTests/View/Text/TextTests.cs

@@ -130,6 +130,26 @@ public class TextTests (ITestOutputHelper output)
         Assert.Equal (new Rectangle (0, 0, 5, 1), view.Viewport);
     }
 
+    // BUGBUG: this is a temporary test that helped identify #3469 - It needs to be expanded upon (and renamed)
+    [Fact]
+    public void TextDirection_Horizontal_Dims_Correct_WidthAbsolute ()
+    {
+        var view = new View
+        {
+            Text = "01234",
+            TextDirection = TextDirection.LeftRight_TopBottom,
+            TextAlignment = Alignment.Centered,
+            Width = 10,
+            Height = Dim.Auto (Dim.DimAutoStyle.Text)
+        };
+        view.BeginInit ();
+        view.EndInit ();
+        Assert.Equal (new Rectangle (0, 0, 10, 1), view.Frame);
+        Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
+
+        Assert.Equal (new (5, 1), view.TextFormatter.Size);  // BUGBUG: should be 10, 1
+    }
+
     [Fact]
     public void TextDirection_Vertical_Dims_Correct ()
     {