Browse Source

Refactored Thickness.Draw to require driver.

Tig 4 weeks ago
parent
commit
db737f98c4

+ 1 - 3
Terminal.Gui/Drawing/Thickness.cs

@@ -89,15 +89,13 @@ public record struct Thickness
     /// <param name="label">The diagnostics label to draw on the bottom of the <see cref="Bottom"/>.</param>
     /// <param name="driver">Optional driver. If not specified, <see cref="Application.Driver"/> will be used.</param>
     /// <returns>The inner rectangle remaining to be drawn.</returns>
-    public Rectangle Draw (Rectangle rect, ViewDiagnosticFlags diagnosticFlags = ViewDiagnosticFlags.Off, string? label = null, IDriver? driver = null)
+    public Rectangle Draw (IDriver? driver, Rectangle rect, ViewDiagnosticFlags diagnosticFlags = ViewDiagnosticFlags.Off, string? label = null)
     {
         if (rect.Size.Width < 1 || rect.Size.Height < 1)
         {
             return Rectangle.Empty;
         }
 
-        driver ??= Application.Driver;
-
         var clearChar = (Rune)' ';
         Rune leftChar = clearChar;
         Rune rightChar = clearChar;

+ 1 - 1
Terminal.Gui/ViewBase/Adornment/Adornment.cs

@@ -182,7 +182,7 @@ public class Adornment : View, IDesignable
         }
 
         // This just draws/clears the thickness, not the insides.
-        Thickness.Draw (ViewportToScreen (Viewport), Diagnostics, ToString ());
+        Thickness.Draw (Driver, ViewportToScreen (Viewport), Diagnostics, ToString ());
 
         NeedsDraw = true;
 

+ 1 - 1
Terminal.Gui/ViewBase/Adornment/Margin.cs

@@ -128,7 +128,7 @@ public class Margin : Adornment
             // This just draws/clears the thickness, not the insides.
             // TODO: This is a hack. See https://github.com/gui-cs/Terminal.Gui/issues/4016
             //SetAttribute (GetAttributeForRole (VisualRole.Normal));
-            Thickness.Draw (screen, Diagnostics, ToString ());
+            Thickness.Draw (Driver, screen, Diagnostics, ToString ());
         }
 
         if (ShadowStyle != ShadowStyle.None)

+ 1 - 1
Terminal.Gui/ViewBase/View.Drawing.cs

@@ -205,7 +205,7 @@ public partial class View // Drawing APIs
         if (Margin?.NeedsLayout == true)
         {
             Margin.NeedsLayout = false;
-            Margin?.Thickness.Draw (FrameToScreen ());
+            Margin?.Thickness.Draw (Driver, FrameToScreen ());
             Margin?.Parent?.SetSubViewNeedsDraw ();
         }
 

+ 9 - 8
Tests/UnitTestsParallelizable/Drawing/ThicknessTests.cs

@@ -1,4 +1,5 @@
 using System.Text;
+using Terminal.Gui.Drivers;
 using UnitTests;
 using Xunit.Abstractions;
 
@@ -634,7 +635,7 @@ public class ThicknessTests (ITestOutputHelper output) : FakeDriverBase
                                       new (0, 0, driver!.Cols, driver!.Rows),
                                       (Rune)' '
                                      );
-        t.Draw (r, ViewDiagnosticFlags.Thickness, "Test", driver);
+        t.Draw (driver, r, ViewDiagnosticFlags.Thickness, "Test");
 
         DriverAssert.AssertDriverContentsWithFrameAre (
                                                        @"
@@ -650,7 +651,7 @@ public class ThicknessTests (ITestOutputHelper output) : FakeDriverBase
                         new (0, 0, driver!.Cols, driver!.Rows),
                         (Rune)' '
                        );
-        t.Draw (r, ViewDiagnosticFlags.Thickness, "Test", driver);
+        t.Draw (driver, r, ViewDiagnosticFlags.Thickness, "Test");
 
         DriverAssert.AssertDriverContentsWithFrameAre (
                                                        @"
@@ -680,7 +681,7 @@ public class ThicknessTests (ITestOutputHelper output) : FakeDriverBase
                                       new (0, 0, driver!.Cols, driver!.Rows),
                                       (Rune)' '
                                      );
-        t.Draw (r, ViewDiagnosticFlags.Thickness, "Test", driver);
+        t.Draw (driver, r, ViewDiagnosticFlags.Thickness, "Test");
 
         DriverAssert.AssertDriverContentsWithFrameAre (
                                                        @"
@@ -710,7 +711,7 @@ public class ThicknessTests (ITestOutputHelper output) : FakeDriverBase
                                       new (0, 0, driver!.Cols, driver!.Rows),
                                       (Rune)' '
                                      );
-        t.Draw (r, ViewDiagnosticFlags.Thickness, "Test", driver);
+        t.Draw (driver, r, ViewDiagnosticFlags.Thickness, "Test");
 
         DriverAssert.AssertDriverContentsWithFrameAre (
                                                        @"
@@ -755,7 +756,7 @@ public class ThicknessTests (ITestOutputHelper output) : FakeDriverBase
 
         top.Draw ();
         top.SetClipToScreen ();
-        t.Draw (r, ViewDiagnosticFlags.Ruler, "Test", driver);
+        t.Draw (driver, r, ViewDiagnosticFlags.Ruler, "Test");
 
         DriverAssert.AssertDriverContentsAre (
                                               @"
@@ -788,7 +789,7 @@ public class ThicknessTests (ITestOutputHelper output) : FakeDriverBase
         top.SetNeedsDraw ();
         top.Draw ();
         top.SetClipToScreen ();
-        t.Draw (r, ViewDiagnosticFlags.Ruler, "Test", driver);
+        t.Draw (driver, r, ViewDiagnosticFlags.Ruler, "Test");
 
         DriverAssert.AssertDriverContentsAre (
                                               @"
@@ -821,7 +822,7 @@ public class ThicknessTests (ITestOutputHelper output) : FakeDriverBase
         top.SetNeedsDraw ();
         top.Draw ();
         top.SetClipToScreen ();
-        t.Draw (r, ViewDiagnosticFlags.Ruler, "Test", driver);
+        t.Draw (driver, r, ViewDiagnosticFlags.Ruler, "Test");
 
         DriverAssert.AssertDriverContentsWithFrameAre (
                                                        @"
@@ -854,7 +855,7 @@ public class ThicknessTests (ITestOutputHelper output) : FakeDriverBase
         top.SetNeedsDraw ();
         top.Draw ();
         top.SetClipToScreen ();
-        t.Draw (r, ViewDiagnosticFlags.Ruler, "Test", driver);
+        t.Draw (driver, r, ViewDiagnosticFlags.Ruler, "Test");
 
         DriverAssert.AssertDriverContentsWithFrameAre (
                                                        @"