Tig 4 weeks ago
parent
commit
d7f56031bb

+ 7 - 4
Terminal.Gui/App/ApplicationImpl.Screen.cs

@@ -168,9 +168,12 @@ public partial class ApplicationImpl
             Driver?.ClearContents ();
         }
 
-        View.SetClipToScreen (Driver);
-        View.Draw (tops, neededLayout || forceRedraw);
-        View.SetClipToScreen (Driver);
-        Driver?.Refresh ();
+        if (Driver is { })
+        {
+            Driver.Clip = new (Screen);
+            View.Draw (tops, neededLayout || forceRedraw);
+            Driver.Clip = new (Screen);
+            Driver?.Refresh ();
+        }
     }
 }

+ 6 - 3
Terminal.Gui/App/PopoverBaseImpl.cs

@@ -99,14 +99,17 @@ public abstract class PopoverBaseImpl : View, IPopover
         {
             // Whenever visible is changing to true, we need to resize;
             // it's our only chance because we don't get laid out until we're visible
-            Layout (Application.Screen.Size);
+            if (App is { })
+            {
+                Layout (App.Screen.Size);
+            }
         }
         else
         {
             // Whenever visible is changing to false, we need to reset the focus
-            if (ApplicationNavigation.IsInHierarchy (this, Application.Navigation?.GetFocused ()))
+            if (ApplicationNavigation.IsInHierarchy (this, App?.Navigation?.GetFocused ()))
             {
-                Application.Navigation?.SetFocused (Application.Current?.MostFocused);
+                App?.Navigation?.SetFocused (App?.Current?.MostFocused);
             }
         }
 

+ 1 - 1
Terminal.Gui/Drawing/Ruler.cs

@@ -35,7 +35,7 @@ internal class Ruler
             return;
         }
 
-        driver ??= driver;
+        driver ??= Application.Driver;
 
         if (Orientation == Orientation.Horizontal)
         {

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

@@ -85,8 +85,10 @@ public class Adornment : View, IDesignable
     #region View Overrides
 
     /// <inheritdoc />
-    protected override IApplication? GetApp () { return Parent?.App; }
+    protected override IApplication? GetApp () => Parent?.App;
 
+    /// <inheritdoc />
+    protected override IDriver? GetDriver () => Parent?.Driver;
 
     // If a scheme is explicitly set, use that. Otherwise, use the scheme of the parent view.
     private Scheme? _scheme;

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

@@ -58,7 +58,7 @@ public class Margin : Adornment
         if (Thickness != Thickness.Empty /*&& ShadowStyle != ShadowStyle.None*/)
         {
             // PERFORMANCE: How expensive are these clones?
-            _cachedClip = GetClip (Driver)?.Clone ();
+            _cachedClip = GetClip ()?.Clone ();
         }
     }
 
@@ -80,10 +80,10 @@ public class Margin : Adornment
             if (view.Margin?.GetCachedClip () != null)
             {
                 view.Margin!.NeedsDraw = true;
-                Region? saved = GetClip (view.Driver);
-                View.SetClip (view.Driver, view.Margin!.GetCachedClip ());
-                view.Margin!.Draw ();
-                View.SetClip (view.Driver, saved);
+                Region? saved = view.GetClip ();
+                view.SetClip (view.Margin!.GetCachedClip ());
+                view.Margin!.Draw (); 
+                view.SetClip (saved);
                 view.Margin!.ClearCachedClip ();
             }
 

+ 13 - 15
Terminal.Gui/ViewBase/View.Drawing.Clipping.cs

@@ -15,7 +15,7 @@ public partial class View
     ///     </para>
     /// </remarks>
     /// <returns>The current Clip.</returns>
-    public static Region? GetClip (IDriver? driver) => driver?.Clip;
+    public Region? GetClip () => Driver?.Clip;
 
     /// <summary>
     ///     Sets the Clip to the specified region.
@@ -26,22 +26,20 @@ public partial class View
     ///         region.
     ///     </para>
     /// </remarks>
-    /// <param name="driver"></param>
     /// <param name="region"></param>
-    public static void SetClip (IDriver? driver, Region? region)
+    public void SetClip (Region? region)
     {
         // BUGBUG: If region is null we should set the clip to null.
         // BUGBUG: Fixing  this probably breaks other things.
         if (driver is { } && region is { })
         {
-            driver.Clip = region;
+            Driver.Clip = region;
         }
     }
 
     /// <summary>
     ///     Sets the Clip to be the rectangle of the screen.
     /// </summary>
-    /// <param name="driver"></param>
     /// <remarks>
     ///     <para>
     ///         There is a single clip region for the entire application. This method sets the clip region to the screen.
@@ -54,13 +52,13 @@ public partial class View
     /// <returns>
     ///     The current Clip, which can be then re-applied <see cref="View.SetClip"/>
     /// </returns>
-    public static Region? SetClipToScreen (IDriver? driver)
+    public Region? SetClipToScreen ()
     {
-        Region? previous = GetClip (driver);
+        Region? previous = GetClip ();
 
-        if (Application.Driver is { })
+        if (Driver is { })
         {
-            Application.Driver.Clip = new (driver!.Screen);
+            Driver.Clip = new (Driver!.Screen);
         }
 
         return previous;
@@ -75,7 +73,7 @@ public partial class View
     ///     </para>
     /// </remarks>
     /// <param name="rectangle"></param>
-    public static void ExcludeFromClip (Rectangle rectangle) { Application.Driver?.Clip?.Exclude (rectangle); }
+    public void ExcludeFromClip (Rectangle rectangle) { Driver?.Clip?.Exclude (rectangle); }
 
     /// <summary>
     ///     Removes the specified rectangle from the Clip.
@@ -86,7 +84,7 @@ public partial class View
     ///     </para>
     /// </remarks>
     /// <param name="region"></param>
-    public static void ExcludeFromClip (Region? region) { Application.Driver?.Clip?.Exclude (region); }
+    public void ExcludeFromClip (Region? region) { Driver?.Clip?.Exclude (region); }
 
     /// <summary>
     ///     Changes the Clip to the intersection of the current Clip and the <see cref="Frame"/> of this View.
@@ -107,7 +105,7 @@ public partial class View
             return null;
         }
 
-        Region previous = GetClip (Driver) ?? new (Application.Screen);
+        Region previous = GetClip () ?? new (Driver.Screen);
 
         Region frameRegion = previous.Clone ();
 
@@ -121,7 +119,7 @@ public partial class View
             frameRegion.Exclude (adornment.Thickness.GetInside (FrameToScreen()));
         }
 
-        SetClip (Driver, frameRegion);
+        SetClip (frameRegion);
 
         return previous;
     }
@@ -154,7 +152,7 @@ public partial class View
             return null;
         }
 
-        Region previous = GetClip (Driver) ?? new (Application.Screen);
+        Region previous = GetClip () ?? new (App!.Screen);
 
         Region viewportRegion = previous.Clone ();
 
@@ -174,7 +172,7 @@ public partial class View
             viewportRegion?.Exclude (adornment.Thickness.GetInside (viewport));
         }
 
-        SetClip (Driver, viewportRegion);
+        SetClip (viewportRegion);
 
         return previous;
     }

+ 2 - 2
Terminal.Gui/ViewBase/View.Drawing.Primitives.cs

@@ -142,7 +142,7 @@ public partial class View
         Attribute prev = SetAttribute (new (color ?? GetAttributeForRole (VisualRole.Normal).Background));
         Driver.FillRect (toClear);
         SetAttribute (prev);
-        SetClip (Driver, prevClip);
+        SetClip (prevClip);
     }
 
     /// <summary>Fills the specified <see cref="Viewport"/>-relative rectangle.</summary>
@@ -158,7 +158,7 @@ public partial class View
         Region? prevClip = AddViewportToClip ();
         Rectangle toClear = ViewportToScreen (rect);
         Driver.FillRect (toClear, rune);
-        SetClip (Driver, prevClip);
+        SetClip (prevClip);
     }
 
 }

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

@@ -51,7 +51,7 @@ public partial class View // Drawing APIs
         {
             return;
         }
-        Region? originalClip = GetClip (Driver);
+        Region? originalClip = GetClip ();
 
         // TODO: This can be further optimized by checking NeedsDraw below and only
         // TODO: clearing, drawing text, drawing content, etc. if it is true.
@@ -62,7 +62,7 @@ public partial class View // Drawing APIs
             // Note Margin with a Shadow is special-cased and drawn in a separate pass to support
             // transparent shadows.
             DoDrawAdornments (originalClip);
-            SetClip (Driver, originalClip);
+            SetClip (originalClip);
 
             // ------------------------------------
             // Clear the Viewport
@@ -98,7 +98,7 @@ public partial class View // Drawing APIs
             // Draw the line canvas
             // Restore the clip before rendering the line canvas and adornment subviews
             // because they may draw outside the viewport.
-            SetClip (Driver, originalClip);
+            SetClip (originalClip);
             originalClip = AddFrameToClip ();
             DoRenderLineCanvas ();
 
@@ -141,7 +141,7 @@ public partial class View // Drawing APIs
 
         // ------------------------------------
         // Reset the clip to what it was when we started
-        SetClip (Driver, originalClip);
+        SetClip (originalClip);
 
         // ------------------------------------
         // We're done drawing - The Clip is reset to what it was before we started.
@@ -169,7 +169,7 @@ public partial class View // Drawing APIs
 
             Region? saved = Border?.AddFrameToClip ();
             Border?.DoDrawSubViews ();
-            SetClip (Driver, saved);
+            SetClip (saved);
         }
 
         if (Padding?.SubViews is { } && Padding.Thickness != Thickness.Empty)
@@ -181,7 +181,7 @@ public partial class View // Drawing APIs
 
             Region? saved = Padding?.AddFrameToClip ();
             Padding?.DoDrawSubViews ();
-            SetClip (Driver, saved);
+            SetClip (saved);
         }
     }
 
@@ -199,7 +199,7 @@ public partial class View // Drawing APIs
             clipAdornments?.Combine (Border!.Thickness.AsRegion (Border!.FrameToScreen ()), RegionOp.Union);
             clipAdornments?.Combine (Padding!.Thickness.AsRegion (Padding!.FrameToScreen ()), RegionOp.Union);
             clipAdornments?.Combine (originalClip, RegionOp.Intersect);
-            SetClip (Driver, clipAdornments);
+            SetClip (clipAdornments);
         }
 
         if (Margin?.NeedsLayout == true)

+ 10 - 3
Terminal.Gui/ViewBase/View.cs

@@ -71,9 +71,9 @@ public partial class View : IDisposable, ISupportInitializeNotification
             DisposeAdornments ();
             DisposeScrollBars ();
 
-            if (Application.Mouse.MouseGrabView == this)
+            if (App?.Mouse.MouseGrabView == this)
             {
-                Application.Mouse.UngrabMouse ();
+                App.Mouse.UngrabMouse ();
             }
 
             for (int i = InternalSubViews.Count - 1; i >= 0; i--)
@@ -136,10 +136,17 @@ public partial class View : IDisposable, ISupportInitializeNotification
     /// </summary>
     internal IDriver? Driver
     {
-        get => _driver ?? App?.Driver ?? Application.Driver;
+        get => GetDriver ();
         set => _driver = value;
     }
 
+    /// <summary>
+    ///     Gets the <see cref="IDriver"/> instance for this view. Used internally to allow overrides by
+    ///     <see cref="Adornment"/>.
+    /// </summary>
+    /// <returns>If this view is at the top of the view hierarchy, returns <see langword="null"/>.</returns>
+    protected virtual IDriver? GetDriver () => _driver ?? App?.Driver ?? SuperView?.Driver ?? Application.Driver;
+
     /// <summary>
     ///     Gets the screen buffer contents. This is a convenience property for Views that need direct access to the
     ///     screen buffer.

+ 2 - 2
Terminal.Gui/Views/Menuv1/Menu.cs

@@ -836,7 +836,7 @@ internal sealed class Menu : View
         RenderLineCanvas ();
 
         // BUGBUG: Views should not change the clip. Doing so is an indcation of poor design or a bug in the framework.
-        Region? savedClip = SetClipToScreen (Driver);
+        Region? savedClip = SetClipToScreen ();
 
         SetAttribute (GetAttributeForRole (VisualRole.Normal));
 
@@ -1005,6 +1005,6 @@ internal sealed class Menu : View
             }
         }
 
-        SetClip (Driver, savedClip);
+        SetClip (savedClip);
     }
 }

+ 1 - 1
Tests/UnitTests/View/Adornment/AdornmentTests.cs

@@ -59,7 +59,7 @@ public class AdornmentTests (ITestOutputHelper output)
         Assert.Equal (6, view.Width);
         Assert.Equal (3, view.Height);
 
-        View.SetClipToScreen (Application.Driver);
+        view.SetClipToScreen ();
         view.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (

+ 1 - 1
Tests/UnitTests/View/Adornment/BorderTests.cs

@@ -39,7 +39,7 @@ public class BorderTests (ITestOutputHelper output)
 
         view.CanFocus = true;
         view.SetFocus ();
-        View.SetClipToScreen (Application.Driver);
+        view.SetClipToScreen ();
         view.Draw ();
         Assert.Equal (view.GetAttributeForRole (VisualRole.Focus), view.Border!.GetAttributeForRole (VisualRole.Focus));
         Assert.Equal (view.GetScheme ().Focus.Foreground, view.Border!.GetAttributeForRole (VisualRole.Focus).Foreground);

+ 4 - 4
Tests/UnitTests/View/Draw/ClearViewportTests.cs

@@ -133,7 +133,7 @@ public class ClearViewportTests (ITestOutputHelper output)
  └─┘",
                                                        output);
 
-        View.SetClipToScreen (Application.Driver);
+       view.SetClipToScreen ();
 
         view.ClearViewport ();
 
@@ -172,7 +172,7 @@ public class ClearViewportTests (ITestOutputHelper output)
  │X│
  └─┘",
                                                        output);
-        View.SetClipToScreen (Application.Driver);
+       view.SetClipToScreen ();
         view.ClearViewport ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -203,7 +203,7 @@ public class ClearViewportTests (ITestOutputHelper output)
                                        }
                                    }
 
-                                   View.SetClip (Application.Driver, savedClip);
+                                   view.SetClip (savedClip);
                                    e.Cancel = true;
                                };
         var top = new Toplevel ();
@@ -268,7 +268,7 @@ public class ClearViewportTests (ITestOutputHelper output)
                                        }
                                    }
 
-                                   View.SetClip (Application.Driver, savedClip);
+                                   view.SetClip (savedClip);
                                    e.Cancel = true;
                                };
         var top = new Toplevel ();

+ 9 - 9
Tests/UnitTests/View/Draw/ClipTests.cs

@@ -91,7 +91,7 @@ public class ClipTests (ITestOutputHelper _output)
                                                        _output);
 
         Rectangle toFill = new (x, y, width, height);
-        View.SetClipToScreen (Application.Driver);
+        superView.SetClipToScreen ();
         view.FillRect (toFill);
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -133,7 +133,7 @@ public class ClipTests (ITestOutputHelper _output)
                                                        _output);
         toFill = new (-1, -1, width + 1, height + 1);
 
-        View.SetClipToScreen (Application.Driver);
+        superView.SetClipToScreen ();
         view.FillRect (toFill);
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -154,7 +154,7 @@ public class ClipTests (ITestOutputHelper _output)
  └─┘",
                                                        _output);
         toFill = new (0, 0, width * 2, height * 2);
-        View.SetClipToScreen (Application.Driver);
+        superView.SetClipToScreen ();
         view.FillRect (toFill);
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -193,7 +193,7 @@ public class ClipTests (ITestOutputHelper _output)
         frameView.Border!.Thickness = new (1, 0, 0, 0);
 
         top.Add (frameView);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Layout ();
         top.Draw ();
 
@@ -217,7 +217,7 @@ public class ClipTests (ITestOutputHelper _output)
 
         top.Add (view);
         top.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
 
         //                            012345678901234567890123456789012345678
@@ -258,13 +258,13 @@ public class ClipTests (ITestOutputHelper _output)
         view.Border!.Thickness = new (1);
         view.BeginInit ();
         view.EndInit ();
-        Assert.Equal (view.Frame, View.GetClip (Application.Driver)!.GetBounds ());
+        Assert.Equal (view.Frame, view.GetClip ()!.GetBounds ());
 
         // Act
         view.AddViewportToClip ();
 
         // Assert
-        Assert.Equal (expectedClip, View.GetClip (Application.Driver)!.GetBounds ());
+        Assert.Equal (expectedClip, view.GetClip ()!.GetBounds ());
         view.Dispose ();
     }
 
@@ -292,14 +292,14 @@ public class ClipTests (ITestOutputHelper _output)
         view.Border!.Thickness = new (1);
         view.BeginInit ();
         view.EndInit ();
-        Assert.Equal (view.Frame, View.GetClip (Application.Driver)!.GetBounds ());
+        Assert.Equal (view.Frame, view.GetClip ()!.GetBounds ());
         view.Viewport = view.Viewport with { X = 1, Y = 1 };
 
         // Act
         view.AddViewportToClip ();
 
         // Assert
-        Assert.Equal (expectedClip, View.GetClip (Application.Driver)!.GetBounds ());
+        Assert.Equal (expectedClip, view.GetClip ()!.GetBounds ());
         view.Dispose ();
     }
 }

+ 2 - 2
Tests/UnitTests/View/Draw/DrawTests.cs

@@ -760,7 +760,7 @@ At 0,0
         Assert.Equal (new (3, 3, 10, 1), view.Frame);
         Assert.Equal (new (0, 0, 10, 1), view.Viewport);
         Assert.Equal (new (0, 0, 10, 1), view.NeedsDrawRect);
-        View.SetClipToScreen (Application.Driver);
+        view.SetClipToScreen ();
         top.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -859,7 +859,7 @@ At 0,0
         Assert.Equal (new (1, 1, 10, 1), view.Frame);
         Assert.Equal (new (0, 0, 10, 1), view.Viewport);
         Assert.Equal (new (0, 0, 10, 1), view.NeedsDrawRect);
-        View.SetClipToScreen (Application.Driver);
+        view.SetClipToScreen ();
 
         top.Draw ();
 

+ 2 - 2
Tests/UnitTests/View/TextTests.cs

@@ -40,7 +40,7 @@ Y
         Assert.Equal (new (0, 0, 10, 2), label.Frame);
 
         top.LayoutSubViews ();
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
 
         expected = @"
@@ -1077,7 +1077,7 @@ w ";
         verticalView.Width = 2;
         verticalView.TextFormatter.ConstrainToSize = new (2, 20);
         Assert.True (verticalView.TextFormatter.NeedsFormat);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         Assert.Equal (new (0, 3, 2, 20), verticalView.Frame);
 

+ 31 - 31
Tests/UnitTests/Views/AppendAutocompleteTests.cs

@@ -13,9 +13,9 @@ public class AppendAutocompleteTests (ITestOutputHelper output)
 
         // f is typed and suggestion is "fish"
         Application.RaiseKeyDownEvent ('f');
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.PositionCursor ();
         DriverAssert.AssertDriverContentsAre ("fish", output);
         Assert.Equal ("f", tf.Text);
@@ -25,7 +25,7 @@ public class AppendAutocompleteTests (ITestOutputHelper output)
 
         // Suggestion should disappear
         tf.Draw ();
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         DriverAssert.AssertDriverContentsAre ("f", output);
         Assert.Equal ("f", tf.Text);
 
@@ -46,9 +46,9 @@ public class AppendAutocompleteTests (ITestOutputHelper output)
 
         // f is typed and suggestion is "fish"
         Application.RaiseKeyDownEvent ('f');
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.PositionCursor ();
         DriverAssert.AssertDriverContentsAre ("fish", output);
         Assert.Equal ("f", tf.Text);
@@ -63,9 +63,9 @@ public class AppendAutocompleteTests (ITestOutputHelper output)
 
         // Should reappear when you press next letter
         Application.RaiseKeyDownEvent (Key.I);
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.PositionCursor ();
         DriverAssert.AssertDriverContentsAre ("fish", output);
         Assert.Equal ("fi", tf.Text);
@@ -82,9 +82,9 @@ public class AppendAutocompleteTests (ITestOutputHelper output)
 
         // f is typed and suggestion is "fish"
         Application.RaiseKeyDownEvent ('f');
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.PositionCursor ();
         DriverAssert.AssertDriverContentsAre ("fish", output);
         Assert.Equal ("f", tf.Text);
@@ -92,18 +92,18 @@ public class AppendAutocompleteTests (ITestOutputHelper output)
         // When cycling autocomplete
         Application.RaiseKeyDownEvent (cycleKey);
 
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.PositionCursor ();
         DriverAssert.AssertDriverContentsAre ("friend", output);
         Assert.Equal ("f", tf.Text);
 
         // Should be able to cycle in circles endlessly
         Application.RaiseKeyDownEvent (cycleKey);
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.PositionCursor ();
         DriverAssert.AssertDriverContentsAre ("fish", output);
         Assert.Equal ("f", tf.Text);
@@ -118,9 +118,9 @@ public class AppendAutocompleteTests (ITestOutputHelper output)
 
         // f is typed and suggestion is "fish"
         Application.RaiseKeyDownEvent ('f');
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.PositionCursor ();
         DriverAssert.AssertDriverContentsAre ("fish", output);
         Assert.Equal ("f", tf.Text);
@@ -129,7 +129,7 @@ public class AppendAutocompleteTests (ITestOutputHelper output)
         Application.RaiseKeyDownEvent (' ');
         Application.RaiseKeyDownEvent (Key.CursorLeft);
 
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
         DriverAssert.AssertDriverContentsAre ("f", output);
         Assert.Equal ("f ", tf.Text);
@@ -144,16 +144,16 @@ public class AppendAutocompleteTests (ITestOutputHelper output)
 
         // f is typed and suggestion is "fish"
         Application.RaiseKeyDownEvent ('f');
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.PositionCursor ();
         DriverAssert.AssertDriverContentsAre ("fish", output);
         Assert.Equal ("f", tf.Text);
 
         // x is typed and suggestion should disappear
         Application.RaiseKeyDownEvent (Key.X);
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
         DriverAssert.AssertDriverContentsAre ("fx", output);
         Assert.Equal ("fx", tf.Text);
@@ -170,9 +170,9 @@ public class AppendAutocompleteTests (ITestOutputHelper output)
         var generator = (SingleWordSuggestionGenerator)tf.Autocomplete.SuggestionGenerator;
         generator.AllSuggestions = new() { "FISH" };
 
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.PositionCursor ();
         DriverAssert.AssertDriverContentsAre ("", output);
         tf.NewKeyDownEvent (Key.M);
@@ -182,16 +182,16 @@ public class AppendAutocompleteTests (ITestOutputHelper output)
         Assert.Equal ("my f", tf.Text);
 
         // Even though there is no match on case we should still get the suggestion
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.PositionCursor ();
         DriverAssert.AssertDriverContentsAre ("my fISH", output);
         Assert.Equal ("my f", tf.Text);
 
         // When tab completing the case of the whole suggestion should be applied
         Application.RaiseKeyDownEvent ('\t');
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
         DriverAssert.AssertDriverContentsAre ("my FISH", output);
         Assert.Equal ("my FISH", tf.Text);
@@ -208,24 +208,24 @@ public class AppendAutocompleteTests (ITestOutputHelper output)
         var generator = (SingleWordSuggestionGenerator)tf.Autocomplete.SuggestionGenerator;
         generator.AllSuggestions = new() { "fish" };
 
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.PositionCursor ();
         DriverAssert.AssertDriverContentsAre ("", output);
 
         tf.NewKeyDownEvent (new ('f'));
 
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.PositionCursor ();
         DriverAssert.AssertDriverContentsAre ("fish", output);
         Assert.Equal ("f", tf.Text);
 
         Application.RaiseKeyDownEvent ('\t');
 
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
         DriverAssert.AssertDriverContentsAre ("fish", output);
         Assert.Equal ("fish", tf.Text);
@@ -250,9 +250,9 @@ public class AppendAutocompleteTests (ITestOutputHelper output)
 
         // f is typed we should only see 'f' up to size of View (10)
         Application.RaiseKeyDownEvent ('f');
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.PositionCursor ();
         DriverAssert.AssertDriverContentsAre (expectRender, output);
         Assert.Equal ("f", tf.Text);

+ 7 - 7
Tests/UnitTests/Views/ComboBoxTests.cs

@@ -565,7 +565,7 @@ Three ",
         Assert.True (cb.IsShow);
         Assert.Equal (-1, cb.SelectedItem);
         Assert.Equal ("", cb.Text);
-        View.SetClipToScreen (Application.Driver);
+        cb.SetClipToScreen ();
         cb.Draw ();
 
         DriverAssert.AssertDriverAttributesAre (
@@ -584,7 +584,7 @@ Three ",
         Assert.True (cb.IsShow);
         Assert.Equal (-1, cb.SelectedItem);
         Assert.Equal ("", cb.Text);
-        View.SetClipToScreen (Application.Driver);
+        cb.SetClipToScreen ();
         cb.Draw ();
 
         DriverAssert.AssertDriverAttributesAre (
@@ -609,7 +609,7 @@ Three ",
         Assert.True (cb.IsShow);
         Assert.Equal (2, cb.SelectedItem);
         Assert.Equal ("Three", cb.Text);
-        View.SetClipToScreen (Application.Driver);
+        cb.SetClipToScreen ();
         cb.Draw ();
 
         DriverAssert.AssertDriverAttributesAre (
@@ -628,7 +628,7 @@ Three ",
         Assert.True (cb.IsShow);
         Assert.Equal (2, cb.SelectedItem);
         Assert.Equal ("Three", cb.Text);
-        View.SetClipToScreen (Application.Driver);
+        cb.SetClipToScreen ();
         cb.Draw ();
 
         DriverAssert.AssertDriverAttributesAre (
@@ -647,7 +647,7 @@ Three ",
         Assert.True (cb.IsShow);
         Assert.Equal (2, cb.SelectedItem);
         Assert.Equal ("Three", cb.Text);
-        View.SetClipToScreen (Application.Driver);
+        cb.SetClipToScreen ();
         cb.Draw ();
 
         DriverAssert.AssertDriverAttributesAre (
@@ -928,7 +928,7 @@ One
         Assert.Equal (1, cb.SelectedItem);
         Assert.Equal ("Two", cb.Text);
 
-        View.SetClipToScreen (Application.Driver);
+        cb.SetClipToScreen ();
         cb.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -944,7 +944,7 @@ Two
         Assert.Equal (2, cb.SelectedItem);
         Assert.Equal ("Three", cb.Text);
 
-        View.SetClipToScreen (Application.Driver);
+        cb.SetClipToScreen ();
         cb.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (

+ 6 - 6
Tests/UnitTests/Views/GraphViewTests.cs

@@ -650,7 +650,7 @@ public class MultiBarSeriesTests
         fakeXAxis.LabelPoints.Clear ();
         gv.LayoutSubViews ();
         gv.SetNeedsDraw ();
-        View.SetClipToScreen (Application.Driver);
+        gv.SetClipToScreen ();
         gv.Draw ();
 
         Assert.Equal (3, fakeXAxis.LabelPoints.Count);
@@ -1125,7 +1125,7 @@ public class TextAnnotationTests
         // user scrolls up one unit of graph space
         gv.ScrollOffset = new PointF (0, 1f);
         gv.SetNeedsDraw ();
-        View.SetClipToScreen (Application.Driver);
+        gv.SetClipToScreen ();
         gv.Draw ();
 
         // we expect the text annotation to go down one line since
@@ -1222,7 +1222,7 @@ public class TextAnnotationTests
                             new TextAnnotation { Text = "hey!", ScreenPosition = new Point (3, 1) }
                            );
         gv.LayoutSubViews ();
-        View.SetClipToScreen (Application.Driver);
+        gv.SetClipToScreen ();
         gv.Draw ();
 
         var expected =
@@ -1238,7 +1238,7 @@ public class TextAnnotationTests
         // user scrolls up one unit of graph space
         gv.ScrollOffset = new PointF (0, 1f);
         gv.SetNeedsDraw ();
-        View.SetClipToScreen (Application.Driver);
+        gv.SetClipToScreen ();
         gv.Draw ();
 
         // we expect no change in the location of the annotation (only the axis label changes)
@@ -1257,7 +1257,7 @@ public class TextAnnotationTests
         // user scrolls up one unit of graph space
         gv.ScrollOffset = new PointF (0, 1f);
         gv.SetNeedsDraw ();
-        View.SetClipToScreen (Application.Driver);
+        gv.SetClipToScreen ();
         gv.Draw ();
 
         // we expect no change in the location of the annotation (only the axis label changes)
@@ -1528,7 +1528,7 @@ public class PathAnnotationTests
             // change the text and redraw
             view.Text = "ff1234";
             mount.SetNeedsDraw ();
-            View.SetClipToScreen (Application.Driver);
+            top.SetClipToScreen ();
             mount.Draw ();
 
             // should have the new text rendered

+ 24 - 24
Tests/UnitTests/Views/Menuv1/MenuBarv1Tests.cs

@@ -698,7 +698,7 @@ public class MenuBarv1Tests (ITestOutputHelper output)
         Dialog.DefaultShadow = ShadowStyle.None;
         Button.DefaultShadow = ShadowStyle.None;
 
-        Assert.Equal (new (0, 0, 40, 15), View.GetClip (Application.Driver)!.GetBounds ());
+        Assert.Equal (new (0, 0, 40, 15), Application.Current!.GetClip ()!.GetBounds ());
         DriverAssert.AssertDriverContentsWithFrameAre (@"", output);
 
         List<string> items = new ()
@@ -1594,7 +1594,7 @@ wo
 
         Assert.True (menu.NewMouseEvent (new () { Position = new (1, 0), Flags = MouseFlags.Button1Pressed, View = menu }));
         Assert.False (menu.IsMenuOpen);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ClosedMenuText, output);
         top.Dispose ();
@@ -1692,7 +1692,7 @@ wo
                                                      );
 
         Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorRight));
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -1804,7 +1804,7 @@ wo
                                                                );
 
                                                            Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorRight));
-                                                           View.SetClipToScreen (Application.Driver);
+                                                           top.SetClipToScreen ();
                                                            top.Draw ();
 
                                                            DriverAssert.AssertDriverContentsWithFrameAre (
@@ -2015,7 +2015,7 @@ wo
                                                            Assert.True (
                                                                         ((MenuBar)top.SubViews.ElementAt (0))._openMenu.NewKeyDownEvent (Key.CursorRight)
                                                                        );
-                                                           View.SetClipToScreen (Application.Driver);
+                                                           top.SetClipToScreen ();
                                                            top.Draw ();
 
                                                            DriverAssert.AssertDriverContentsWithFrameAre (
@@ -2092,14 +2092,14 @@ wo
         // Open second
         Assert.True (Application.Current.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorRight));
         Assert.True (menu.IsMenuOpen);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (1), output);
 
         // Close menu
         Assert.True (menu.NewKeyDownEvent (menu.Key));
         Assert.False (menu.IsMenuOpen);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ClosedMenuText, output);
 
@@ -2133,21 +2133,21 @@ wo
         // Open first
         Assert.True (menu.NewKeyDownEvent (menu.Key));
         Assert.True (menu.IsMenuOpen);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (0), output);
 
         // Open second
         Assert.True (top.SubViews.ElementAt (1).NewKeyDownEvent (Key.CursorRight));
         Assert.True (menu.IsMenuOpen);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         Application.Current.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (1), output);
 
         // Close menu
         Assert.True (menu.NewKeyDownEvent (menu.Key));
         Assert.False (menu.IsMenuOpen);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ClosedMenuText, output);
         top.Dispose ();
@@ -2216,7 +2216,7 @@ wo
         top.Add (menu);
         Application.Begin (top);
 
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ClosedMenuText, output);
 
@@ -2224,7 +2224,7 @@ wo
         {
             menu.OpenMenu (i);
             Assert.True (menu.IsMenuOpen);
-            View.SetClipToScreen (Application.Driver);
+            top.SetClipToScreen ();
             top.Draw ();
             DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (i), output);
         }
@@ -2483,7 +2483,7 @@ Edit
         Assert.True (menu.NewKeyDownEvent (menu.Key));
         Assert.True (menu.IsMenuOpen);
         Assert.False (isMenuClosed);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
 
         expected = @"
@@ -2498,7 +2498,7 @@ Edit
         Assert.True (menu.NewKeyDownEvent (menu.Key));
         Assert.False (menu.IsMenuOpen);
         Assert.True (isMenuClosed);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
 
         expected = @"
@@ -2655,7 +2655,7 @@ Edit
         Assert.Equal (1, menu._selected);
         Assert.Equal (-1, menu._selectedSub);
         Assert.Null (menu._openSubMenu);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (1), output);
 
@@ -2663,7 +2663,7 @@ Edit
         Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorRight));
         Assert.True (menu.IsMenuOpen);
         Assert.False (tf.HasFocus);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (2), output);
 
@@ -2671,21 +2671,21 @@ Edit
         Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorLeft));
         Assert.True (menu.IsMenuOpen);
         Assert.False (tf.HasFocus);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (1), output);
 
         Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorLeft));
         Assert.True (menu.IsMenuOpen);
         Assert.False (tf.HasFocus);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (0), output);
 
         Assert.True (Application.RaiseKeyDownEvent (menu.Key));
         Assert.False (menu.IsMenuOpen);
         Assert.True (tf.HasFocus);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ClosedMenuText, output);
         top.Dispose ();
@@ -2756,7 +2756,7 @@ Edit
                     );
         Assert.True (menu.IsMenuOpen);
         Assert.False (tf.HasFocus);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (1), output);
 
@@ -2767,7 +2767,7 @@ Edit
                     );
         Assert.True (menu.IsMenuOpen);
         Assert.False (tf.HasFocus);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (2), output);
 
@@ -2778,7 +2778,7 @@ Edit
                     );
         Assert.True (menu.IsMenuOpen);
         Assert.False (tf.HasFocus);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ClosedMenuText, output);
 
@@ -2789,14 +2789,14 @@ Edit
                     );
         Assert.True (menu.IsMenuOpen);
         Assert.False (tf.HasFocus);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (0), output);
 
         Assert.True (menu.NewMouseEvent (new () { Position = new (8, 0), Flags = MouseFlags.Button1Pressed, View = menu }));
         Assert.False (menu.IsMenuOpen);
         Assert.True (tf.HasFocus);
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         top.Draw ();
         DriverAssert.AssertDriverContentsAre (expectedMenu.ClosedMenuText, output);
         top.Dispose ();

+ 3 - 3
Tests/UnitTests/Views/ProgressBarTests.cs

@@ -37,7 +37,7 @@ public class ProgressBarTests
         for (var i = 0; i <= pb.Frame.Width; i++)
         {
             pb.Fraction += 0.2F;
-            View.SetClipToScreen (Application.Driver);
+            pb.SetClipToScreen ();
             pb.Draw ();
 
             if (i == 0)
@@ -175,7 +175,7 @@ public class ProgressBarTests
         for (var i = 0; i < 38; i++)
         {
             pb.Pulse ();
-            View.SetClipToScreen (Application.Driver);
+            pb.SetClipToScreen ();
             pb.Draw ();
 
             if (i == 0)
@@ -880,7 +880,7 @@ public class ProgressBarTests
         for (var i = 0; i < 38; i++)
         {
             pb.Pulse ();
-            View.SetClipToScreen (Application.Driver);
+            pb.SetClipToScreen ();
             pb.Draw ();
 
             if (i == 0)

+ 1 - 1
Tests/UnitTests/Views/SpinnerViewTests.cs

@@ -57,7 +57,7 @@ public class SpinnerViewTests (ITestOutputHelper output)
         DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
 
         view.AdvanceAnimation ();
-        View.SetClipToScreen (Application.Driver);
+        view.SetClipToScreen ();
         view.Draw ();
 
         expected = "/";

+ 22 - 22
Tests/UnitTests/Views/TabViewTests.cs

@@ -664,7 +664,7 @@ public class TabViewTests (ITestOutputHelper output)
         Assert.Equal (tab2, tv.SubViews.First (v => v.Id.Contains ("tabRow")).MostFocused);
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -683,7 +683,7 @@ public class TabViewTests (ITestOutputHelper output)
         tab1.DisplayText = "12345678910";
         tab2.DisplayText = "13";
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -700,7 +700,7 @@ public class TabViewTests (ITestOutputHelper output)
         tv.SelectedTab = tab2;
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
         DriverAssert.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -717,7 +717,7 @@ public class TabViewTests (ITestOutputHelper output)
         tab2.DisplayText = "abcdefghijklmnopq";
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
         DriverAssert.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -810,7 +810,7 @@ public class TabViewTests (ITestOutputHelper output)
         Assert.Equal (tab2, tv.SubViews.First (v => v.Id.Contains ("tabRow")).MostFocused);
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -830,7 +830,7 @@ public class TabViewTests (ITestOutputHelper output)
         tab2.DisplayText = "13";
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -847,7 +847,7 @@ public class TabViewTests (ITestOutputHelper output)
         tv.SelectedTab = tab2;
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -865,7 +865,7 @@ public class TabViewTests (ITestOutputHelper output)
         tab2.DisplayText = "abcdefghijklmnopq";
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -910,7 +910,7 @@ public class TabViewTests (ITestOutputHelper output)
         tv.Height = 5;
         tv.Layout ();
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -952,7 +952,7 @@ public class TabViewTests (ITestOutputHelper output)
         tv.SelectedTab = tab2;
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -972,7 +972,7 @@ public class TabViewTests (ITestOutputHelper output)
         tab2.DisplayText = "13";
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -989,7 +989,7 @@ public class TabViewTests (ITestOutputHelper output)
         tv.SelectedTab = tab2;
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -1007,7 +1007,7 @@ public class TabViewTests (ITestOutputHelper output)
         tab2.DisplayText = "abcdefghijklmnopq";
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -1049,7 +1049,7 @@ public class TabViewTests (ITestOutputHelper output)
         tv.SelectedTab = tab2;
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -1144,7 +1144,7 @@ public class TabViewTests (ITestOutputHelper output)
         tab2.DisplayText = "13";
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -1161,7 +1161,7 @@ public class TabViewTests (ITestOutputHelper output)
         tv.SelectedTab = tab2;
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -1179,7 +1179,7 @@ public class TabViewTests (ITestOutputHelper output)
         tab2.DisplayText = "abcdefghijklmnopq";
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -1223,7 +1223,7 @@ public class TabViewTests (ITestOutputHelper output)
         tv.SelectedTab = tab2;
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -1337,7 +1337,7 @@ public class TabViewTests (ITestOutputHelper output)
         tv.SelectedTab = tab2;
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -1354,7 +1354,7 @@ public class TabViewTests (ITestOutputHelper output)
         tv.SelectedTab = tab3;
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -1404,7 +1404,7 @@ public class TabViewTests (ITestOutputHelper output)
         tv.SelectedTab = tab2;
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (
@@ -1421,7 +1421,7 @@ public class TabViewTests (ITestOutputHelper output)
         tv.SelectedTab = tab3;
 
         tv.Layout ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (

+ 27 - 27
Tests/UnitTests/Views/TableViewTests.cs

@@ -722,7 +722,7 @@ public class TableViewTests (ITestOutputHelper output)
 
         // since A is now pushed off screen we get indicator showing
         // that user can scroll left to see first column
-        View.SetClipToScreen (Application.Driver);
+        tableView.SetClipToScreen ();
         tableView.Draw ();
 
         expected =
@@ -737,7 +737,7 @@ public class TableViewTests (ITestOutputHelper output)
         tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight });
         tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight });
 
-        View.SetClipToScreen (Application.Driver);
+        tableView.SetClipToScreen ();
         tableView.Draw ();
 
         expected =
@@ -796,7 +796,7 @@ public class TableViewTests (ITestOutputHelper output)
 
         // Scroll right
         tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight });
-        View.SetClipToScreen (Application.Driver);
+        tableView.SetClipToScreen ();
         tableView.Draw ();
 
         // Note that with SmoothHorizontalScrolling only a single new column
@@ -844,7 +844,7 @@ public class TableViewTests (ITestOutputHelper output)
 
         // select last visible column
         tableView.SelectedColumn = 2; // column C
-        View.SetClipToScreen (Application.Driver);
+        tableView.SetClipToScreen ();
         tableView.Draw ();
 
         var expected =
@@ -856,7 +856,7 @@ public class TableViewTests (ITestOutputHelper output)
 
         // Scroll right
         tableView.NewKeyDownEvent (new () { KeyCode = KeyCode.CursorRight });
-        View.SetClipToScreen (Application.Driver);
+        tableView.SetClipToScreen ();
         tableView.Draw ();
 
         // notice that without smooth scrolling we just update the first column
@@ -1974,7 +1974,7 @@ public class TableViewTests (ITestOutputHelper output)
 ◄─┼─┼─┤
 │2│3│4│";
         tableView.SetNeedsDraw ();
-        View.SetClipToScreen (Application.Driver);
+        tableView.SetClipToScreen ();
         tableView.Draw ();
 
         DriverAssert.AssertDriverContentsAre (expected, output);
@@ -1988,7 +1988,7 @@ public class TableViewTests (ITestOutputHelper output)
 ├─┼─┼─┤
 │2│3│4│";
         tableView.SetNeedsDraw ();
-        View.SetClipToScreen (Application.Driver);
+        tableView.SetClipToScreen ();
         tableView.Draw ();
 
         DriverAssert.AssertDriverContentsAre (expected, output);
@@ -2004,7 +2004,7 @@ public class TableViewTests (ITestOutputHelper output)
         tableView.Style.ShowHorizontalHeaderUnderline = true;
         tableView.LayoutSubViews ();
         tableView.SetNeedsDraw ();
-        View.SetClipToScreen (Application.Driver);
+        tableView.SetClipToScreen ();
         tableView.Draw ();
 
         // normally we should have scroll indicators because DEF are of screen
@@ -2027,7 +2027,7 @@ public class TableViewTests (ITestOutputHelper output)
 ├─┼─┼─┤
 │1│2│3│";
         tableView.SetNeedsDraw ();
-        View.SetClipToScreen (Application.Driver);
+        tableView.SetClipToScreen ();
         tableView.Draw ();
         DriverAssert.AssertDriverContentsAre (expected, output);
     }
@@ -2600,7 +2600,7 @@ A B C
 
         Assert.True (pets.First ().IsPicked);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2620,7 +2620,7 @@ A B C
         Assert.True (pets.ElementAt (0).IsPicked);
         Assert.True (pets.ElementAt (1).IsPicked);
         Assert.False (pets.ElementAt (2).IsPicked);
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2640,7 +2640,7 @@ A B C
         Assert.False (pets.ElementAt (0).IsPicked);
         Assert.True (pets.ElementAt (1).IsPicked);
         Assert.False (pets.ElementAt (2).IsPicked);
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2668,7 +2668,7 @@ A B C
         wrapper.CheckedRows.Add (0);
         wrapper.CheckedRows.Add (2);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         var expected =
@@ -2692,7 +2692,7 @@ A B C
         Assert.Contains (2, wrapper.CheckedRows);
         Assert.Equal (3, wrapper.CheckedRows.Count);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2708,7 +2708,7 @@ A B C
         // Untoggle the top 2
         tv.NewKeyDownEvent (Key.Space);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2737,7 +2737,7 @@ A B C
         tv.NewKeyDownEvent (Key.A.WithCtrl);
         tv.NewKeyDownEvent (Key.Space);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         var expected =
@@ -2757,7 +2757,7 @@ A B C
         // Untoggle all again
         tv.NewKeyDownEvent (Key.Space);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2798,7 +2798,7 @@ A B C
 
         Assert.True (pets.All (p => p.IsPicked));
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         var expected =
@@ -2818,7 +2818,7 @@ A B C
         Assert.Empty (pets.Where (p => p.IsPicked));
 #pragma warning restore xUnit2029
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2845,7 +2845,7 @@ A B C
         var wrapper = new CheckBoxTableSourceWrapperByIndex (tv, tv.Table);
         tv.Table = wrapper;
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         var expected =
@@ -2865,7 +2865,7 @@ A B C
 
         Assert.Single (wrapper.CheckedRows, 0);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2885,7 +2885,7 @@ A B C
         Assert.Contains (1, wrapper.CheckedRows);
         Assert.Equal (2, wrapper.CheckedRows.Count);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2904,7 +2904,7 @@ A B C
 
         Assert.Single (wrapper.CheckedRows, 1);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2936,7 +2936,7 @@ A B C
         wrapper.UseRadioButtons = true;
 
         tv.Table = wrapper;
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         var expected =
@@ -2959,7 +2959,7 @@ A B C
 
         Assert.True (pets.First ().IsPicked);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -2980,7 +2980,7 @@ A B C
         Assert.True (pets.ElementAt (1).IsPicked);
         Assert.False (pets.ElementAt (2).IsPicked);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -3001,7 +3001,7 @@ A B C
         Assert.False (pets.ElementAt (1).IsPicked);
         Assert.False (pets.ElementAt (2).IsPicked);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =

+ 8 - 8
Tests/UnitTests/Views/TextFieldTests.cs

@@ -123,13 +123,13 @@ public class TextFieldTests (ITestOutputHelper output)
 
         // Caption should appear when not focused and no text
         Assert.False (tf.HasFocus);
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
         DriverAssert.AssertDriverContentsAre ("Enter txt", output);
 
         // but disapear when text is added
         tf.Text = content;
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
         DriverAssert.AssertDriverContentsAre (content, output);
         Application.Current.Dispose ();
@@ -147,14 +147,14 @@ public class TextFieldTests (ITestOutputHelper output)
         // Caption has no effect when focused
         tf.Title = "Enter txt";
         Assert.True (tf.HasFocus);
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
         DriverAssert.AssertDriverContentsAre ("", output);
 
         Application.RaiseKeyDownEvent ('\t');
 
         Assert.False (tf.HasFocus);
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
         DriverAssert.AssertDriverContentsAre ("Enter txt", output);
         Application.Current.Dispose ();
@@ -173,7 +173,7 @@ public class TextFieldTests (ITestOutputHelper output)
         Application.RaiseKeyDownEvent ('\t');
         Assert.False (tf.HasFocus);
 
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
         
         // Verify the caption text is rendered
@@ -203,7 +203,7 @@ public class TextFieldTests (ITestOutputHelper output)
         Application.RaiseKeyDownEvent ('\t');
         Assert.False (tf.HasFocus);
 
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
         
         // The hotkey character 'F' should be rendered (without the underscore in the actual text)
@@ -237,7 +237,7 @@ public class TextFieldTests (ITestOutputHelper output)
         Application.RaiseKeyDownEvent ('\t');
         Assert.False (tf.HasFocus);
 
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
         
         // The underscore should not be rendered, 'T' should be underlined
@@ -1641,7 +1641,7 @@ Les Misérables",
 
         // incorrect order will result with a wrong accent place
         tf.Text = "Les Mis" + char.ConvertFromUtf32 (int.Parse ("0301", NumberStyles.HexNumber)) + "erables";
-        View.SetClipToScreen (Application.Driver);
+        tf.SetClipToScreen ();
         tf.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (

+ 1 - 1
Tests/UnitTests/Views/TextViewTests.cs

@@ -6827,7 +6827,7 @@ line.
         tv.CursorPosition = new (6, 2);
         Assert.Equal (new (5, 2), tv.CursorPosition);
         top.LayoutSubViews ();
-        View.SetClipToScreen (Application.Driver);
+        top.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsWithFrameAre (

+ 7 - 7
Tests/UnitTests/Views/TreeTableSourceTests.cs

@@ -55,7 +55,7 @@ public class TreeTableSourceTests : IDisposable
         // when pressing right we should expand the top route
         tv.NewKeyDownEvent (Key.CursorRight);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -73,7 +73,7 @@ public class TreeTableSourceTests : IDisposable
         // when pressing left we should collapse the top route again
         tv.NewKeyDownEvent (Key.CursorLeft);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -97,7 +97,7 @@ public class TreeTableSourceTests : IDisposable
 
         tv.Style.GetOrCreateColumnStyle (1).MinAcceptableWidth = 1;
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         var expected =
@@ -117,7 +117,7 @@ public class TreeTableSourceTests : IDisposable
 
         Assert.True (tv.NewMouseEvent (new MouseEventArgs { Position = new (2, 2), Flags = MouseFlags.Button1Clicked }));
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -142,7 +142,7 @@ public class TreeTableSourceTests : IDisposable
 
         // Clicking on the + again should collapse
         tv.NewMouseEvent (new MouseEventArgs { Position = new (2, 2), Flags = MouseFlags.Button1Clicked });
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -195,7 +195,7 @@ public class TreeTableSourceTests : IDisposable
 
         Application.RaiseKeyDownEvent (Key.CursorRight);
 
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =
@@ -213,7 +213,7 @@ public class TreeTableSourceTests : IDisposable
 
         tv.NewKeyDownEvent (Key.CursorDown);
         tv.NewKeyDownEvent (Key.Space);
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         expected =

+ 13 - 13
Tests/UnitTests/Views/TreeViewTests.cs

@@ -718,7 +718,7 @@ public class TreeViewTests (ITestOutputHelper output)
                                             );
         tv.MaxDepth = 3;
         tv.ExpandAll ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         // Normal drawing of the tree view
@@ -757,7 +757,7 @@ public class TreeViewTests (ITestOutputHelper output)
                                             );
         tv.MaxDepth = 5;
         tv.ExpandAll ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
 
         tv.Draw ();
 
@@ -785,7 +785,7 @@ public class TreeViewTests (ITestOutputHelper output)
 
         Assert.True (tv.CanExpand ("5"));
         Assert.False (tv.IsExpanded ("5"));
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
 
         tv.Draw ();
 
@@ -840,7 +840,7 @@ public class TreeViewTests (ITestOutputHelper output)
         Assert.Null (tv.GetObjectOnRow (4));
 
         tv.Collapse (n1);
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
 
         tv.Draw ();
 
@@ -877,7 +877,7 @@ public class TreeViewTests (ITestOutputHelper output)
 
         tv.SetScheme (new Scheme ());
         tv.LayoutSubViews ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsAre (
@@ -897,7 +897,7 @@ public class TreeViewTests (ITestOutputHelper output)
         tv.Collapse (n1);
 
         tv.LayoutSubViews ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsAre (
@@ -915,7 +915,7 @@ public class TreeViewTests (ITestOutputHelper output)
         tv.ScrollOffsetVertical = 1;
 
         tv.LayoutSubViews ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsAre (
@@ -952,7 +952,7 @@ public class TreeViewTests (ITestOutputHelper output)
 
         tv.SetScheme (new Scheme ());
         tv.LayoutSubViews ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         // Normal drawing of the tree view
@@ -1141,7 +1141,7 @@ oot two
 
         // matches nothing
         filter.Text = "asdfjhasdf";
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         // Normal drawing of the tree view
@@ -1152,7 +1152,7 @@ oot two
 
         // Matches everything
         filter.Text = "root";
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsAre (
@@ -1167,7 +1167,7 @@ oot two
 
         // Matches 2 leaf nodes
         filter.Text = "leaf";
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsAre (
@@ -1181,7 +1181,7 @@ oot two
 
         // Matches 1 leaf nodes
         filter.Text = "leaf 1";
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         DriverAssert.AssertDriverContentsAre (
@@ -1253,7 +1253,7 @@ oot two
         // redraw now that the custom color
         // delegate is registered
         tv.SetNeedsDraw ();
-        View.SetClipToScreen (Application.Driver);
+        tv.SetClipToScreen ();
         tv.Draw ();
 
         // Same text