Browse Source

Made more Driver APIs internal

Tig 9 months ago
parent
commit
55387d3c13

+ 11 - 11
Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs

@@ -57,13 +57,13 @@ public abstract class ConsoleDriver
     ///     Gets the column last set by <see cref="Move"/>. <see cref="Col"/> and <see cref="Row"/> are used by
     ///     <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content.
     /// </summary>
-    public int Col { get; internal set; }
+    internal int Col { get; private set; }
 
     /// <summary>The number of columns visible in the terminal.</summary>
-    public virtual int Cols
+    internal virtual int Cols
     {
         get => _cols;
-        internal set
+        set
         {
             _cols = value;
             ClearContents ();
@@ -75,22 +75,22 @@ public abstract class ConsoleDriver
     ///     <see cref="UpdateScreen"/> is called.
     ///     <remarks>The format of the array is rows, columns. The first index is the row, the second index is the column.</remarks>
     /// </summary>
-    public Cell [,]? Contents { get; internal set; }
+    internal Cell [,]? Contents { get; set; }
 
     /// <summary>The leftmost column in the terminal.</summary>
-    public virtual int Left { get; internal set; } = 0;
+    internal virtual int Left { get; set; } = 0;
 
     /// <summary>
     ///     Gets the row last set by <see cref="Move"/>. <see cref="Col"/> and <see cref="Row"/> are used by
     ///     <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content.
     /// </summary>
-    public int Row { get; internal set; }
+    internal int Row { get; private set; }
 
     /// <summary>The number of rows visible in the terminal.</summary>
-    public virtual int Rows
+    internal virtual int Rows
     {
         get => _rows;
-        internal set
+        set
         {
             _rows = value;
             ClearContents ();
@@ -98,7 +98,7 @@ public abstract class ConsoleDriver
     }
 
     /// <summary>The topmost row in the terminal.</summary>
-    public virtual int Top { get; internal set; } = 0;
+    internal virtual int Top { get; set; } = 0;
 
     /// <summary>
     ///     Set this to true in any unit tests that attempt to test drivers other than FakeDriver.
@@ -125,7 +125,7 @@ public abstract class ConsoleDriver
     ///     </para>
     /// </remarks>
     /// <param name="rune">Rune to add.</param>
-    public void AddRune (Rune rune)
+    internal void AddRune (Rune rune)
     {
         int runeWidth = -1;
         bool validLocation = IsValidLocation (rune, Col, Row);
@@ -300,7 +300,7 @@ public abstract class ConsoleDriver
     ///     convenience method that calls <see cref="AddRune(Rune)"/> with the <see cref="Rune"/> constructor.
     /// </summary>
     /// <param name="c">Character to add.</param>
-    public void AddRune (char c) { AddRune (new Rune (c)); }
+    internal void AddRune (char c) { AddRune (new Rune (c)); }
 
     /// <summary>Adds the <paramref name="str"/> to the display at the cursor position.</summary>
     /// <remarks>

+ 4 - 4
Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs

@@ -19,20 +19,20 @@ internal class CursesDriver : ConsoleDriver
     private UnixMainLoop _mainLoopDriver;
     private object _processInputToken;
 
-    public override int Cols
+    internal override int Cols
     {
         get => Curses.Cols;
-        internal set
+        set
         {
             Curses.Cols = value;
             ClearContents ();
         }
     }
 
-    public override int Rows
+    internal override int Rows
     {
         get => Curses.Lines;
-        internal set
+        set
         {
             Curses.Lines = value;
             ClearContents ();

+ 5 - 4
Terminal.Gui/Drawing/Ruler.cs

@@ -1,10 +1,11 @@
-namespace Terminal.Gui;
+#nullable enable
+namespace Terminal.Gui;
 
 /// <summary>Draws a ruler on the screen.</summary>
 /// <remarks>
 ///     <para></para>
 /// </remarks>
-public class Ruler
+internal class Ruler
 {
     /// <summary>Gets or sets the foreground and background color to use.</summary>
     public Attribute Attribute { get; set; } = new ();
@@ -36,7 +37,7 @@ public class Ruler
         if (Orientation == Orientation.Horizontal)
         {
             string hrule =
-                _hTemplate.Repeat ((int)Math.Ceiling (Length + 2 / (double)_hTemplate.Length)) [start..(Length + start)];
+                _hTemplate.Repeat ((int)Math.Ceiling (Length + 2 / (double)_hTemplate.Length))! [start..(Length + start)];
 
             // Top
             Application.Driver?.Move (location.X, location.Y);
@@ -45,7 +46,7 @@ public class Ruler
         else
         {
             string vrule =
-                _vTemplate.Repeat ((int)Math.Ceiling ((Length + 2) / (double)_vTemplate.Length))
+                _vTemplate.Repeat ((int)Math.Ceiling ((Length + 2) / (double)_vTemplate.Length))!
                     [start..(Length + start)];
 
             for (int r = location.Y; r < location.Y + Length; r++)

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

@@ -1,4 +1,6 @@
-namespace Terminal.Gui;
+using static Terminal.Gui.SpinnerStyle;
+
+namespace Terminal.Gui;
 
 public partial class View
 {
@@ -31,6 +33,21 @@ public partial class View
         return true;
     }
 
+    /// <summary>Draws the specified character at the current draw position.</summary>
+    /// <param name="rune">The Rune.</param>
+    public void AddRune (Rune rune)
+    {
+        Driver?.AddRune (rune);
+    }
+
+
+    /// <summary>
+    ///     Adds the specified <see langword="char"/> to the display at the current cursor position. This method is a
+    ///     convenience method that calls <see cref="AddRune(Rune)"/> with the <see cref="Rune"/> constructor.
+    /// </summary>
+    /// <param name="c">Character to add.</param>
+    public void AddRune (char c) { AddRune (new Rune (c)); }
+
     /// <summary>Draws the specified character in the specified viewport-relative column and row of the View.</summary>
     /// <para>
     ///     If the provided coordinates are outside the visible content area, this method does nothing.
@@ -49,6 +66,21 @@ public partial class View
         }
     }
 
+
+    /// <summary>Adds the <paramref name="str"/> to the display at the cursor position.</summary>
+    /// <remarks>
+    ///     <para>
+    ///         When the method returns, <see cref="Col"/> will be incremented by the number of columns
+    ///         <paramref name="str"/> required, unless the new column value is outside of the <see cref="Clip"/> or screen
+    ///         dimensions defined by <see cref="Cols"/>.
+    ///     </para>
+    ///     <para>If <paramref name="str"/> requires more columns than are available, the output will be clipped.</para>
+    /// </remarks>
+    /// <param name="str">String.</param>
+    public void AddStr (string str)
+    {
+        Driver?.AddStr (str);
+    }
     /// <summary>Utility function to draw strings that contain a hotkey.</summary>
     /// <param name="text">String to display, the hotkey specifier before a letter flags the next letter as the hotkey.</param>
     /// <param name="hotColor">Hot color.</param>
@@ -74,7 +106,7 @@ public partial class View
                 continue;
             }
 
-            Application.Driver?.AddRune (rune);
+            AddRune (rune);
             SetAttribute (normalColor);
         }
     }
@@ -121,4 +153,5 @@ public partial class View
         SetAttribute (prev);
         SetClip (prevClip);
     }
+
 }

+ 1 - 2
Terminal.Gui/Views/ColorPicker.16.cs

@@ -222,8 +222,7 @@ public class ColorPicker16 : View
         {
             for (var zoomedX = 0; zoomedX < BoxWidth; zoomedX++)
             {
-                Move (x * BoxWidth + zoomedX, y * BoxHeight + zoomedY);
-                Driver?.AddRune ((Rune)' ');
+                AddRune (x * BoxWidth + zoomedX, y * BoxHeight + zoomedY, (Rune)' ');
                 index++;
             }
         }

+ 5 - 6
Terminal.Gui/Views/ComboBox.cs

@@ -306,8 +306,7 @@ public class ComboBox : View, IDesignable
         {
             SetAttribute (ColorScheme.Focus);
         }
-        Move (Viewport.Right - 1, 0);
-        Driver?.AddRune (Glyphs.DownArrow);
+        AddRune (Viewport.Right - 1, 0, Glyphs.DownArrow);
 
         return true;
     }
@@ -932,7 +931,7 @@ public class ComboBox : View, IDesignable
                 {
                     for (var c = 0; c < f.Width; c++)
                     {
-                        Driver?.AddRune ((Rune)' ');
+                        AddRune (0, row, (Rune)' ');
                     }
                 }
                 else
@@ -948,14 +947,14 @@ public class ComboBox : View, IDesignable
 
                     if (AllowsMarking)
                     {
-                        Driver?.AddRune (
+                        AddRune (
                                         Source.IsMarked (item) ? AllowsMultipleSelection ? Glyphs.CheckStateChecked : Glyphs.Selected :
                                         AllowsMultipleSelection ? Glyphs.CheckStateUnChecked : Glyphs.UnSelected
                                        );
-                        Driver?.AddRune ((Rune)' ');
+                        AddRune ((Rune)' ');
                     }
 
-                    Source.Render (this, Driver, isSelected, item, col, row, f.Width - col, start);
+                    Source.Render (this, isSelected, item, col, row, f.Width - col, start);
                 }
             }
 

+ 6 - 9
Terminal.Gui/Views/ListView.cs

@@ -33,7 +33,6 @@ public interface IListDataSource : IDisposable
     /// <summary>This method is invoked to render a specified item, the method should cover the entire provided width.</summary>
     /// <returns>The render.</returns>
     /// <param name="container">The list view to render.</param>
-    /// <param name="driver">The console driver to render.</param>
     /// <param name="selected">Describes whether the item being rendered is currently selected by the user.</param>
     /// <param name="item">The index of the item to render, zero for the first item and so on.</param>
     /// <param name="col">The column where the rendering will start</param>
@@ -46,7 +45,6 @@ public interface IListDataSource : IDisposable
     /// </remarks>
     void Render (
         ListView container,
-        ConsoleDriver driver,
         bool selected,
         int item,
         int col,
@@ -88,7 +86,7 @@ public interface IListDataSource : IDisposable
 ///     </para>
 ///     <para>
 ///         To change the contents of the ListView, set the <see cref="Source"/> property (when providing custom
-///         rendering via <see cref="IListDataSource"/>) or call <see cref="SetSource"/> an <see cref="IList"/> is being
+///         rendering via <see cref="IListDataSource"/>) or call <see cref="SetSource{T}"/> an <see cref="IList"/> is being
 ///         used.
 ///     </para>
 ///     <para>
@@ -822,7 +820,7 @@ public class ListView : View, IDesignable
                     Driver?.AddRune ((Rune)' ');
                 }
 
-                Source.Render (this, Driver, isSelected, item, col, row, f.Width - col, start);
+                Source.Render (this, isSelected, item, col, row, f.Width - col, start);
             }
         }
         return true;
@@ -1116,7 +1114,6 @@ public class ListWrapper<T> : IListDataSource, IDisposable
     /// <inheritdoc/>
     public void Render (
         ListView container,
-        ConsoleDriver driver,
         bool marked,
         int item,
         int col,
@@ -1133,17 +1130,17 @@ public class ListWrapper<T> : IListDataSource, IDisposable
 
             if (t is null)
             {
-                RenderUstr (driver, "", col, line, width);
+                RenderUstr (container, "", col, line, width);
             }
             else
             {
                 if (t is string s)
                 {
-                    RenderUstr (driver, s, col, line, width, start);
+                    RenderUstr (container, s, col, line, width, start);
                 }
                 else
                 {
-                    RenderUstr (driver, t.ToString (), col, line, width, start);
+                    RenderUstr (container, t.ToString (), col, line, width, start);
                 }
             }
         }
@@ -1239,7 +1236,7 @@ public class ListWrapper<T> : IListDataSource, IDisposable
         return maxLength;
     }
 
-    private void RenderUstr (ConsoleDriver driver, string ustr, int col, int line, int width, int start = 0)
+    private void RenderUstr (View driver, string ustr, int col, int line, int width, int start = 0)
     {
         string str = start > ustr.GetColumns () ? string.Empty : ustr.Substring (Math.Min (start, ustr.ToRunes ().Length - 1));
         string u = TextFormatter.ClipAndJustify (str, width, Alignment.Start);

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

@@ -141,7 +141,7 @@ public class ProgressBar : View, IDesignable
         {
             for (var i = 0; i < Viewport.Width; i++)
             {
-                if (Array.IndexOf (_activityPos, i) != -1)
+                if (Array.IndexOf (_activityPos!, i) != -1)
                 {
                     Driver?.AddRune (SegmentCharacter);
                 }

+ 5 - 1
Terminal.Gui/Views/Shortcut.cs

@@ -495,7 +495,11 @@ public class Shortcut : View, IOrientation, IDesignable
 
     private void SetCommandViewDefaultLayout ()
     {
-        CommandView.Margin.Thickness = GetMarginThickness ();
+        if (CommandView.Margin is { })
+        {
+            CommandView.Margin.Thickness = GetMarginThickness ();
+        }
+
         CommandView.X = Pos.Align (Alignment.End, AlignmentModes);
 
         CommandView.VerticalTextAlignment = Alignment.Center;

+ 41 - 45
UICatalog/Scenarios/AnimationScenario/AnimationScenario.cs

@@ -32,7 +32,7 @@ public class AnimationScenario : Scenario
             Height = Dim.Fill (),
         };
 
-        _imageView = new ImageView { Width = Dim.Fill (), Height = Dim.Fill () - 2 };
+        _imageView = new ImageView { Width = Dim.Fill (), Height = Dim.Fill ()! - 2 };
 
         win.Add (_imageView);
 
@@ -63,7 +63,7 @@ public class AnimationScenario : Scenario
 
         if (!string.IsNullOrEmpty (assemblyLocation))
         {
-            dir = new DirectoryInfo (Path.GetDirectoryName (assemblyLocation));
+            dir = new DirectoryInfo (Path.GetDirectoryName (assemblyLocation) ?? string.Empty);
         }
         else
         {
@@ -105,7 +105,7 @@ public class AnimationScenario : Scenario
     // This is a C# port of https://github.com/andraaspar/bitmap-to-braille by Andraaspar
 
     /// <summary>Renders an image as unicode Braille.</summary>
-    public class BitmapToBraille
+    public class BitmapToBraille (int widthPixels, int heightPixels, Func<int, int, bool> pixelIsLit)
     {
         public const int CHAR_HEIGHT = 4;
         public const int CHAR_WIDTH = 2;
@@ -113,16 +113,9 @@ public class AnimationScenario : Scenario
         private const string CHARS =
             " ⠁⠂⠃⠄⠅⠆⠇⡀⡁⡂⡃⡄⡅⡆⡇⠈⠉⠊⠋⠌⠍⠎⠏⡈⡉⡊⡋⡌⡍⡎⡏⠐⠑⠒⠓⠔⠕⠖⠗⡐⡑⡒⡓⡔⡕⡖⡗⠘⠙⠚⠛⠜⠝⠞⠟⡘⡙⡚⡛⡜⡝⡞⡟⠠⠡⠢⠣⠤⠥⠦⠧⡠⡡⡢⡣⡤⡥⡦⡧⠨⠩⠪⠫⠬⠭⠮⠯⡨⡩⡪⡫⡬⡭⡮⡯⠰⠱⠲⠳⠴⠵⠶⠷⡰⡱⡲⡳⡴⡵⡶⡷⠸⠹⠺⠻⠼⠽⠾⠿⡸⡹⡺⡻⡼⡽⡾⡿⢀⢁⢂⢃⢄⢅⢆⢇⣀⣁⣂⣃⣄⣅⣆⣇⢈⢉⢊⢋⢌⢍⢎⢏⣈⣉⣊⣋⣌⣍⣎⣏⢐⢑⢒⢓⢔⢕⢖⢗⣐⣑⣒⣓⣔⣕⣖⣗⢘⢙⢚⢛⢜⢝⢞⢟⣘⣙⣚⣛⣜⣝⣞⣟⢠⢡⢢⢣⢤⢥⢦⢧⣠⣡⣢⣣⣤⣥⣦⣧⢨⢩⢪⢫⢬⢭⢮⢯⣨⣩⣪⣫⣬⣭⣮⣯⢰⢱⢲⢳⢴⢵⢶⢷⣰⣱⣲⣳⣴⣵⣶⣷⢸⢹⢺⢻⢼⢽⢾⢿⣸⣹⣺⣻⣼⣽⣾⣿";
 
-        public BitmapToBraille (int widthPixels, int heightPixels, Func<int, int, bool> pixelIsLit)
-        {
-            WidthPixels = widthPixels;
-            HeightPixels = heightPixels;
-            PixelIsLit = pixelIsLit;
-        }
-
-        public int HeightPixels { get; }
-        public Func<int, int, bool> PixelIsLit { get; }
-        public int WidthPixels { get; }
+        public int HeightPixels { get; } = heightPixels;
+        public Func<int, int, bool> PixelIsLit { get; } = pixelIsLit;
+        public int WidthPixels { get; } = widthPixels;
 
         public string GenerateImage ()
         {
@@ -171,55 +164,58 @@ public class AnimationScenario : Scenario
 
     private class ImageView : View
     {
-        private string [] brailleCache;
-        private int currentFrame;
-        private int frameCount;
-        private Image<Rgba32> [] fullResImages;
-        private Image<Rgba32> [] matchSizes;
-        private Rectangle oldSize = Rectangle.Empty;
-        public void NextFrame () { currentFrame = (currentFrame + 1) % frameCount; }
+        private string []? _brailleCache;
+        private int _currentFrame;
+        private int _frameCount;
+        private Image<Rgba32> []? _fullResImages;
+        private Image<Rgba32> []? _matchSizes;
+        private Rectangle _oldSize = Rectangle.Empty;
+        public void NextFrame () { _currentFrame = (_currentFrame + 1) % _frameCount; }
 
         protected override bool OnDrawingContent ()
         {
-            if (frameCount == 0)
+            if (_frameCount == 0)
             {
                 return false;
             }
-            if (oldSize != Viewport)
+            if (_oldSize != Viewport)
             {
                 // Invalidate cached images now size has changed
-                matchSizes = new Image<Rgba32> [frameCount];
-                brailleCache = new string [frameCount];
-                oldSize = Viewport;
+                _matchSizes = new Image<Rgba32> [_frameCount];
+                _brailleCache = new string [_frameCount];
+                _oldSize = Viewport;
             }
 
-            Image<Rgba32> imgScaled = matchSizes [currentFrame];
-            string braille = brailleCache [currentFrame];
+            Image<Rgba32>? imgScaled = _matchSizes? [_currentFrame];
+            string? braille = _brailleCache? [_currentFrame];
 
             if (imgScaled == null)
             {
-                Image<Rgba32> imgFull = fullResImages [currentFrame];
+                Image<Rgba32>? imgFull = _fullResImages? [_currentFrame];
 
                 // keep aspect ratio
                 int newSize = Math.Min (Viewport.Width, Viewport.Height);
 
                 // generate one
-                matchSizes [currentFrame] = imgScaled = imgFull.Clone (
-                                                                       x => x.Resize (
-                                                                                      newSize * BitmapToBraille.CHAR_HEIGHT,
-                                                                                      newSize * BitmapToBraille.CHAR_HEIGHT
-                                                                                     )
-                                                                      );
+                if (_matchSizes is { } && imgFull is { })
+                {
+                    _matchSizes [_currentFrame] = imgScaled = imgFull.Clone (
+                                                                             x => x.Resize (
+                                                                                            newSize * BitmapToBraille.CHAR_HEIGHT,
+                                                                                            newSize * BitmapToBraille.CHAR_HEIGHT
+                                                                                           )
+                                                                            );
+                }
             }
 
-            if (braille == null)
+            if (braille == null && _brailleCache is { })
             {
-                brailleCache [currentFrame] = braille = GetBraille (matchSizes [currentFrame]);
+                _brailleCache [_currentFrame] = braille = GetBraille (_matchSizes? [_currentFrame]!);
             }
 
-            string [] lines = braille.Split ('\n');
+            string []? lines = braille?.Split ('\n');
 
-            for (var y = 0; y < lines.Length; y++)
+            for (var y = 0; y < lines!.Length; y++)
             {
                 string line = lines [y];
 
@@ -234,18 +230,18 @@ public class AnimationScenario : Scenario
 
         internal void SetImage (Image<Rgba32> image)
         {
-            frameCount = image.Frames.Count;
+            _frameCount = image.Frames.Count;
 
-            fullResImages = new Image<Rgba32> [frameCount];
-            matchSizes = new Image<Rgba32> [frameCount];
-            brailleCache = new string [frameCount];
+            _fullResImages = new Image<Rgba32> [_frameCount];
+            _matchSizes = new Image<Rgba32> [_frameCount];
+            _brailleCache = new string [_frameCount];
 
-            for (var i = 0; i < frameCount - 1; i++)
+            for (var i = 0; i < _frameCount - 1; i++)
             {
-                fullResImages [i] = image.Frames.ExportFrame (0);
+                _fullResImages [i] = image.Frames.ExportFrame (0);
             }
 
-            fullResImages [frameCount - 1] = image;
+            _fullResImages [_frameCount - 1] = image;
 
             SetNeedsDraw ();
         }

+ 3 - 3
UICatalog/Scenarios/CharacterMap.cs

@@ -765,7 +765,7 @@ internal class CharMap : View, IDesignable
                     // Draw the rune
                     if (width > 0)
                     {
-                        Driver.AddRune (rune);
+                        AddRune (rune);
                     }
                     else
                     {
@@ -786,11 +786,11 @@ internal class CharMap : View, IDesignable
 
                             if (normal.Length == 1)
                             {
-                                Driver.AddRune (normal [0]);
+                                AddRune ((Rune)normal [0]);
                             }
                             else
                             {
-                                Driver.AddRune (Rune.ReplacementChar);
+                                AddRune (Rune.ReplacementChar);
                             }
                         }
                     }

+ 14 - 14
UICatalog/Scenarios/CombiningMarks.cs

@@ -13,20 +13,20 @@ public class CombiningMarks : Scenario
 
         top.DrawComplete += (s, e) =>
                                    {
-                                       Application.Driver?.Move (0, 0);
-                                       Application.Driver?.AddStr ("Terminal.Gui only supports combining marks that normalize. See Issue #2616.");
-                                       Application.Driver?.Move (0, 2);
-                                       Application.Driver?.AddStr ("\u0301\u0301\u0328<- \"\\u301\\u301\\u328]\" using AddStr.");
-                                       Application.Driver?.Move (0, 3);
-                                       Application.Driver?.AddStr ("[a\u0301\u0301\u0328]<- \"[a\\u301\\u301\\u328]\" using AddStr.");
-                                       Application.Driver?.Move (0, 4);
-                                       Application.Driver?.AddRune ('[');
-                                       Application.Driver?.AddRune ('a');
-                                       Application.Driver?.AddRune ('\u0301');
-                                       Application.Driver?.AddRune ('\u0301');
-                                       Application.Driver?.AddRune ('\u0328');
-                                       Application.Driver?.AddRune (']');
-                                       Application.Driver?.AddStr ("<- \"[a\\u301\\u301\\u328]\" using AddRune for each.");
+                                       top.Move (0, 0);
+                                       top.AddStr ("Terminal.Gui only supports combining marks that normalize. See Issue #2616.");
+                                       top.Move (0, 2);
+                                       top.AddStr ("\u0301\u0301\u0328<- \"\\u301\\u301\\u328]\" using AddStr.");
+                                       top.Move (0, 3);
+                                       top.AddStr ("[a\u0301\u0301\u0328]<- \"[a\\u301\\u301\\u328]\" using AddStr.");
+                                       top.Move (0, 4);
+                                       top.AddRune ('[');
+                                       top.AddRune ('a');
+                                       top.AddRune ('\u0301');
+                                       top.AddRune ('\u0301');
+                                       top.AddRune ('\u0328');
+                                       top.AddRune (']');
+                                       top.AddStr ("<- \"[a\\u301\\u301\\u328]\" using AddRune for each.");
                                    };
 
         Application.Run (top);

+ 1 - 1
UICatalog/Scenarios/DynamicMenuBar.cs

@@ -414,7 +414,7 @@ public class DynamicMenuBar : Scenario
                                 };
 
             var dialog = new Dialog
-                { Title = "Enter the menu details.", Buttons = [btnOk, btnCancel], Height = Dim.Auto (DimAutoStyle.Content, 22, Driver.Rows) };
+                { Title = "Enter the menu details.", Buttons = [btnOk, btnCancel], Height = Dim.Auto (DimAutoStyle.Content, 22, Application.Screen.Height) };
 
             Width = Dim.Fill ();
             Height = Dim.Fill () - 1;

+ 1 - 1
UICatalog/Scenarios/DynamicStatusBar.cs

@@ -201,7 +201,7 @@ public class DynamicStatusBar : Scenario
                                       TextTitle.Text = string.Empty;
                                       Application.RequestStop ();
                                   };
-            var dialog = new Dialog { Title = "Enter the menu details.", Buttons = [btnOk, btnCancel], Height = Dim.Auto (DimAutoStyle.Content, 17, Driver.Rows) };
+            var dialog = new Dialog { Title = "Enter the menu details.", Buttons = [btnOk, btnCancel], Height = Dim.Auto (DimAutoStyle.Content, 17, Application.Screen.Height) };
 
             Width = Dim.Fill ();
             Height = Dim.Fill () - 1;

+ 9 - 8
UICatalog/Scenarios/Editors/AdornmentsEditor.cs

@@ -42,7 +42,10 @@ public class AdornmentsEditor : EditorBase
             PaddingEditor.AdornmentToEdit = ViewToEdit?.Padding ?? null;
         }
 
-        Padding.Text = $"View: {GetIdentifyingString (ViewToEdit)}";
+        if (Padding is { })
+        {
+            Padding.Text = $"View: {GetIdentifyingString (ViewToEdit)}";
+        }
     }
 
     private string GetIdentifyingString (View? view)
@@ -72,17 +75,15 @@ public class AdornmentsEditor : EditorBase
 
     public bool ShowViewIdentifier
     {
-        get => Padding.Thickness != Thickness.Empty;
+        get => Padding is { } && Padding.Thickness != Thickness.Empty;
         set
         {
-            if (value)
+            if (Padding is null)
             {
-                Padding.Thickness = new (0, 2, 0, 0);
-            }
-            else
-            {
-                Padding.Thickness = Thickness.Empty;
+                return;
             }
+
+            Padding.Thickness = value ? new (0, 2, 0, 0) : Thickness.Empty;
         }
     }
 

+ 3 - 10
UICatalog/Scenarios/Editors/DimEditor.cs

@@ -29,19 +29,12 @@ public class DimEditor : EditorBase
             return;
         }
 
-        Dim dim;
-        if (Dimension == Dimension.Width)
-        {
-            dim = ViewToEdit.Width;
-        }
-        else
-        {
-            dim = ViewToEdit.Height;
-        }
+        Dim? dim;
+        dim = Dimension == Dimension.Width ? ViewToEdit.Width : ViewToEdit.Height;
 
         try
         {
-            _dimRadioGroup!.SelectedItem = _dimNames.IndexOf (Enumerable.First<string> (_dimNames, s => dim!.ToString ().StartsWith (s)));
+            _dimRadioGroup!.SelectedItem = _dimNames.IndexOf (_dimNames.First (s => dim!.ToString ().StartsWith (s)));
         }
         catch (InvalidOperationException e)
         {

+ 1 - 1
UICatalog/Scenarios/Editors/EventLog.cs

@@ -93,7 +93,7 @@ public class EventLog : ListView
     private void EventLog_Initialized (object? _, EventArgs e)
     {
 
-        Border.Add (ExpandButton!);
+        Border?.Add (ExpandButton!);
         Source = new ListWrapper<string> (_eventSource);
 
     }

+ 3 - 3
UICatalog/Scenarios/LineDrawing.cs

@@ -114,7 +114,7 @@ public class LineDrawing : Scenario
 
         var tools = new ToolsView { Title = "Tools", X = Pos.Right (canvas) - 20, Y = 2 };
 
-        tools.ColorChanged += (s, e) => canvas.SetAttribute (e);
+        tools.ColorChanged += (s, e) => canvas.SetCurrentAttribute (e);
         tools.SetStyle += b => canvas.CurrentTool = new DrawLineTool { LineStyle = b };
         tools.AddLayer += () => canvas.AddLayer ();
 
@@ -276,7 +276,7 @@ public class DrawingArea : View
             {
                 if (c.Value is { })
                 {
-                    SetAttribute (c.Value.Value.Attribute ?? ColorScheme.Normal);
+                    SetCurrentAttribute (c.Value.Value.Attribute ?? ColorScheme.Normal);
 
                     // TODO: #2616 - Support combining sequences that don't normalize
                     AddRune (c.Key.X, c.Key.Y, c.Value.Value.Rune);
@@ -336,7 +336,7 @@ public class DrawingArea : View
         Layers.Add (CurrentLayer);
     }
 
-    internal void SetAttribute (Attribute a) { CurrentAttribute = a; }
+    internal void SetCurrentAttribute (Attribute a) { CurrentAttribute = a; }
 
     public void ClearUndo () { _undoHistory.Clear (); }
 }

+ 4 - 5
UICatalog/Scenarios/ListViewWithSelection.cs

@@ -250,7 +250,6 @@ public class ListViewWithSelection : Scenario
 
         public void Render (
             ListView container,
-            ConsoleDriver driver,
             bool selected,
             int item,
             int col,
@@ -266,7 +265,7 @@ public class ListViewWithSelection : Scenario
                                       string.Format ("{{0,{0}}}", -_nameColumnWidth),
                                       Scenarios [item].GetName ()
                                      );
-            RenderUstr (driver, $"{s} ({Scenarios [item].GetDescription ()})", col, line, width, start);
+            RenderUstr (container, $"{s} ({Scenarios [item].GetDescription ()})", col, line, width, start);
         }
 
         public void SetMark (int item, bool value)
@@ -307,7 +306,7 @@ public class ListViewWithSelection : Scenario
         }
 
         // A slightly adapted method from: https://github.com/gui-cs/Terminal.Gui/blob/fc1faba7452ccbdf49028ac49f0c9f0f42bbae91/Terminal.Gui/Views/ListView.cs#L433-L461
-        private void RenderUstr (ConsoleDriver driver, string ustr, int col, int line, int width, int start = 0)
+        private void RenderUstr (View view, string ustr, int col, int line, int width, int start = 0)
         {
             var used = 0;
             int index = start;
@@ -322,14 +321,14 @@ public class ListViewWithSelection : Scenario
                     break;
                 }
 
-                driver.AddRune (rune);
+                view.AddRune (rune);
                 used += count;
                 index += size;
             }
 
             while (used < width)
             {
-                driver.AddRune ((Rune)' ');
+                view.AddRune ((Rune)' ');
                 used++;
             }
         }

+ 1 - 1
UICatalog/Scenarios/MultiColouredTable.cs

@@ -210,7 +210,7 @@ public class MultiColouredTable : Scenario
                     }
                 }
 
-                Driver.AddRune ((Rune)render [i]);
+                AddRune ((Rune)render [i]);
                 SetAttribute (cellColor);
             }
         }

+ 5 - 3
UICatalog/UICatalog.cs

@@ -485,7 +485,11 @@ public class UICatalogApp
             {
                 Title = "Benchmark Results",
             };
-            benchmarkWindow.Border.Thickness = new (0, 0, 0, 0);
+
+            if (benchmarkWindow.Border is { })
+            {
+                benchmarkWindow.Border.Thickness = new (0, 0, 0, 0);
+            }
 
             TableView resultsTableView = new ()
             {
@@ -1362,8 +1366,6 @@ public class UICatalogApp
 
     private struct Options
     {
-        public bool Version;
-
         public string Driver;
 
         public string Scenario;

+ 0 - 1
UnitTests/Views/ListViewTests.cs

@@ -686,7 +686,6 @@ Item 6",
 
         public void Render (
             ListView container,
-            ConsoleDriver driver,
             bool selected,
             int item,
             int col,