2
0
Эх сурвалжийг харах

Added View.Set/GetAtribute. Made Driver.Set/GetAttribute internal

Tig 9 сар өмнө
parent
commit
606bdf16a6
41 өөрчлөгдсөн 279 нэмэгдсэн , 217 устгасан
  1. 2 2
      Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs
  2. 6 6
      Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs
  3. 2 2
      Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs
  4. 1 1
      Terminal.Gui/View/Adornment/Adornment.cs
  5. 3 3
      Terminal.Gui/View/Adornment/Border.cs
  6. 2 2
      Terminal.Gui/View/Adornment/ShadowView.cs
  7. 28 1
      Terminal.Gui/View/View.Attribute.cs
  8. 5 5
      Terminal.Gui/View/View.Drawing.Primitives.cs
  9. 5 5
      Terminal.Gui/View/View.Drawing.cs
  10. 11 2
      Terminal.Gui/View/View.Hierarchy.cs
  11. 3 3
      Terminal.Gui/Views/ColorBar.cs
  12. 2 2
      Terminal.Gui/Views/ColorPicker.16.cs
  13. 1 1
      Terminal.Gui/Views/ColorPicker.cs
  14. 7 4
      Terminal.Gui/Views/ComboBox.cs
  15. 1 1
      Terminal.Gui/Views/FileDialog.cs
  16. 2 2
      Terminal.Gui/Views/GraphView/Annotations.cs
  17. 1 1
      Terminal.Gui/Views/GraphView/GraphView.cs
  18. 2 2
      Terminal.Gui/Views/GraphView/Series.cs
  19. 4 4
      Terminal.Gui/Views/HexView.cs
  20. 1 1
      Terminal.Gui/Views/LineView.cs
  21. 3 3
      Terminal.Gui/Views/ListView.cs
  22. 3 3
      Terminal.Gui/Views/Menu/Menu.cs
  23. 1 1
      Terminal.Gui/Views/ProgressBar.cs
  24. 8 8
      Terminal.Gui/Views/RadioGroup.cs
  25. 2 2
      Terminal.Gui/Views/ScrollBarView.cs
  26. 8 8
      Terminal.Gui/Views/Slider.cs
  27. 2 2
      Terminal.Gui/Views/TabView.cs
  28. 23 11
      Terminal.Gui/Views/TableView/TableView.cs
  29. 8 8
      Terminal.Gui/Views/TextField.cs
  30. 3 3
      Terminal.Gui/Views/TextValidateField.cs
  31. 12 12
      Terminal.Gui/Views/TextView.cs
  32. 1 1
      Terminal.Gui/Views/Tile.cs
  33. 82 71
      Terminal.Gui/Views/TileView.cs
  34. 1 1
      Terminal.Gui/Views/TreeView/TreeView.cs
  35. 9 9
      UICatalog/Scenarios/CharacterMap.cs
  36. 5 5
      UICatalog/Scenarios/GraphViewExample.cs
  37. 1 1
      UICatalog/Scenarios/Images.cs
  38. 3 3
      UICatalog/Scenarios/LineDrawing.cs
  39. 10 10
      UICatalog/Scenarios/MultiColouredTable.cs
  40. 3 3
      UICatalog/Scenarios/Snake.cs
  41. 2 2
      UICatalog/Scenarios/TextEffectsScenario.cs

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

@@ -549,7 +549,7 @@ public abstract class ConsoleDriver
     /// <summary>Selects the specified attribute as the attribute to use for future calls to AddRune and AddString.</summary>
     /// <remarks>Implementations should call <c>base.SetAttribute(c)</c>.</remarks>
     /// <param name="c">C.</param>
-    public Attribute SetAttribute (Attribute c)
+    internal Attribute SetAttribute (Attribute c)
     {
         Attribute prevAttribute = CurrentAttribute;
         CurrentAttribute = c;
@@ -559,7 +559,7 @@ public abstract class ConsoleDriver
 
     /// <summary>Gets the current <see cref="Attribute"/>.</summary>
     /// <returns>The current attribute.</returns>
-    public Attribute GetAttribute () { return CurrentAttribute; }
+    internal Attribute GetAttribute () { return CurrentAttribute; }
 
     // TODO: This is only overridden by CursesDriver. Once CursesDriver supports 24-bit color, this virtual method can be
     // removed (and Attribute can lose the platformColor property).

+ 6 - 6
Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs

@@ -106,12 +106,12 @@ public class AppendAutocomplete : AutocompleteBase
         }
 
         // draw it like it's selected, even though it's not
-        Application.Driver?.SetAttribute (
-                                         new Attribute (
-                                                        ColorScheme.Normal.Foreground,
-                                                        textField.ColorScheme.Focus.Background
-                                                       )
-                                        );
+        textField.SetAttribute (
+                               new Attribute (
+                                              ColorScheme.Normal.Foreground,
+                                              textField.ColorScheme.Focus.Background
+                                             )
+                              );
         textField.Move (textField.Text.Length, 0);
 
         Suggestion suggestion = Suggestions.ElementAt (SelectedIdx);

+ 2 - 2
Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs

@@ -395,11 +395,11 @@ public abstract partial class PopupAutocomplete : AutocompleteBase
         {
             if (i == SelectedIdx - ScrollOffset)
             {
-                Application.Driver?.SetAttribute (ColorScheme.Focus);
+                _popup.SetAttribute (ColorScheme.Focus);
             }
             else
             {
-                Application.Driver?.SetAttribute (ColorScheme.Normal);
+                _popup.SetAttribute (ColorScheme.Normal);
             }
 
             _popup.Move (0, i);

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

@@ -170,7 +170,7 @@ public class Adornment : View, IDesignable
         }
 
         Attribute normalAttr = GetNormalColor ();
-        Driver?.SetAttribute (normalAttr);
+        SetAttribute (normalAttr);
 
         // This just draws/clears the thickness, not the insides.
         Thickness.Draw (ViewportToScreen (viewport), Diagnostics, ToString ());

+ 3 - 3
Terminal.Gui/View/Adornment/Border.cs

@@ -705,11 +705,11 @@ public class Border : Adornment
 
             if (ColorScheme is { })
             {
-                Driver?.SetAttribute (GetNormalColor ());
+                SetAttribute (GetNormalColor ());
             }
             else
             {
-                Driver?.SetAttribute (Parent!.GetNormalColor ());
+                SetAttribute (Parent!.GetNormalColor ());
             }
 
             if (drawTop)
@@ -852,7 +852,7 @@ public class Border : Adornment
                             );
             }
 
-            Driver?.SetAttribute (prevAttr);
+            SetAttribute (prevAttr);
 
             // TODO: This should be moved to LineCanvas as a new BorderStyle.Ruler
             if (Diagnostics.HasFlag (ViewDiagnosticFlags.Ruler))

+ 2 - 2
Terminal.Gui/View/Adornment/ShadowView.cs

@@ -63,7 +63,7 @@ internal class ShadowView : View
             case ShadowStyle.Transparent:
                 //Attribute prevAttr = Driver.GetAttribute ();
                 //var attr = new Attribute (prevAttr.Foreground, prevAttr.Background);
-                //Driver.SetAttribute (attr);
+                //SetAttribute (attr);
 
                 if (Orientation == Orientation.Vertical)
                 {
@@ -74,7 +74,7 @@ internal class ShadowView : View
                     DrawHorizontalShadowTransparent (viewport);
                 }
 
-                //Driver.SetAttribute (prevAttr);
+                //SetAttribute (prevAttr);
 
                 break;
         }

+ 28 - 1
Terminal.Gui/View/View.Color.cs → Terminal.Gui/View/View.Attribute.cs

@@ -1,7 +1,14 @@
-namespace Terminal.Gui;
+using System;
+
+namespace Terminal.Gui;
 
 public partial class View
 {
+    // TODO: Rename "Color"->"Attribute" given we'll soon have non-color information in Attributes?
+    // TODO: See https://github.com/gui-cs/Terminal.Gui/issues/457
+
+    #region ColorScheme
+    
     private ColorScheme _colorScheme;
 
     /// <summary>The color scheme for this view, if it is not defined, it returns the <see cref="SuperView"/>'s color scheme.</summary>
@@ -117,4 +124,24 @@ public partial class View
 
         return attr;
     }
+
+    #endregion ColorScheme
+
+    #region Attribute
+
+    /// <summary>Selects the specified attribute as the attribute to use for future calls to AddRune and AddString.</summary>
+    /// <remarks></remarks>
+    /// <param name="attribute">THe Attribute to set.</param>
+    public Attribute SetAttribute (Attribute attribute)
+    {
+        return Driver?.SetAttribute (attribute) ?? Attribute.Default;
+    }
+
+    /// <summary>Gets the current <see cref="Attribute"/>.</summary>
+    /// <returns>The current attribute.</returns>
+    public Attribute GetAttribute ()
+    {
+        return Driver?.GetAttribute () ?? Attribute.Default;
+    }
+    #endregion Attribute
 }

+ 5 - 5
Terminal.Gui/View/View.Drawing.Primitives.cs

@@ -65,19 +65,19 @@ public partial class View
     public void DrawHotString (string text, Attribute hotColor, Attribute normalColor)
     {
         Rune hotkeySpec = HotKeySpecifier == (Rune)0xffff ? (Rune)'_' : HotKeySpecifier;
-        Application.Driver?.SetAttribute (normalColor);
+        SetAttribute (normalColor);
 
         foreach (Rune rune in text.EnumerateRunes ())
         {
             if (rune == new Rune (hotkeySpec.Value))
             {
-                Application.Driver?.SetAttribute (hotColor);
+                SetAttribute (hotColor);
 
                 continue;
             }
 
             Application.Driver?.AddRune (rune);
-            Application.Driver?.SetAttribute (normalColor);
+            SetAttribute (normalColor);
         }
     }
 
@@ -123,9 +123,9 @@ public partial class View
 
         Driver.Clip = Rectangle.Intersect (prevClip, ViewportToScreen (Viewport with { Location = new (0, 0) }));
 
-        Attribute prev = Driver.SetAttribute (new (color ?? GetNormalColor ().Background));
+        Attribute prev = SetAttribute (new (color ?? GetNormalColor ().Background));
         Driver.FillRect (toClear);
-        Driver.SetAttribute (prev);
+        SetAttribute (prev);
 
         Driver.Clip = prevClip;
     }

+ 5 - 5
Terminal.Gui/View/View.Drawing.cs

@@ -166,7 +166,7 @@ public partial class View // Drawing APIs
     {
         if (ColorScheme is { })
         {
-            Driver?.SetAttribute (GetNormalColor ());
+            SetAttribute (GetNormalColor ());
         }
     }
 
@@ -241,9 +241,9 @@ public partial class View // Drawing APIs
             toClear = Rectangle.Intersect (toClear, visibleContent);
         }
 
-        Attribute prev = Driver.SetAttribute (GetNormalColor ());
+        Attribute prev = SetAttribute (GetNormalColor ());
         Driver.FillRect (toClear);
-        Driver.SetAttribute (prev);
+        SetAttribute (prev);
 
         Driver.Clip = prevClip;
         SetNeedsDisplay ();
@@ -467,7 +467,7 @@ public partial class View // Drawing APIs
                 // Get the entire map
                 if (p.Value is { })
                 {
-                    Driver.SetAttribute (p.Value.Value.Attribute ?? ColorScheme!.Normal);
+                    SetAttribute (p.Value.Value.Attribute ?? ColorScheme!.Normal);
                     Driver.Move (p.Key.X, p.Key.Y);
 
                     // TODO: #2616 - Support combining sequences that don't normalize
@@ -492,7 +492,7 @@ public partial class View // Drawing APIs
                 // Get the entire map
                 if (p.Value is { })
                 {
-                    Driver.SetAttribute (p.Value.Value.Attribute ?? ColorScheme!.Normal);
+                    SetAttribute (p.Value.Value.Attribute ?? ColorScheme!.Normal);
                     Driver.Move (p.Key.X, p.Key.Y);
 
                     // TODO: #2616 - Support combining sequences that don't normalize

+ 11 - 2
Terminal.Gui/View/View.Hierarchy.cs

@@ -47,8 +47,12 @@ public partial class View // SuperView/SubView hierarchy management (SuperView,
     /// </remarks>
     /// <param name="view">The view to add.</param>
     /// <returns>The view that was added.</returns>
-    public virtual View Add (View view)
+    public virtual View? Add (View? view)
     {
+        if (view is null)
+        {
+            return null;
+        }
         if (_subviews is null)
         {
             _subviews = [];
@@ -148,8 +152,13 @@ public partial class View // SuperView/SubView hierarchy management (SuperView,
     /// <returns>
     ///     The removed View. <see langword="null"/> if the View could not be removed.
     /// </returns>
-    public virtual View? Remove (View view)
+    public virtual View? Remove (View? view)
     {
+        if (view is null)
+        {
+            return null;
+        }
+
         if (_subviews is null)
         {
             return view;

+ 3 - 3
Terminal.Gui/Views/ColorBar.cs

@@ -89,7 +89,7 @@ internal abstract class ColorBar : View, IColorBar
         if (!string.IsNullOrWhiteSpace (Text))
         {
             Move (0, 0);
-            Driver?.SetAttribute (HasFocus ? GetFocusColor () : GetNormalColor ());
+            SetAttribute (HasFocus ? GetFocusColor () : GetNormalColor ());
             Driver?.AddStr (Text);
 
             // TODO: is there a better method than this? this is what it is in TableView
@@ -198,7 +198,7 @@ internal abstract class ColorBar : View, IColorBar
             if (isSelectedCell)
             {
                 // Draw the triangle at the closest position
-                Application.Driver?.SetAttribute (new (triangleColor, color));
+                SetAttribute (new (triangleColor, color));
                 AddRune (x + xOffset, yOffset, new ('▲'));
 
                 // Record for tests
@@ -206,7 +206,7 @@ internal abstract class ColorBar : View, IColorBar
             }
             else
             {
-                Application.Driver?.SetAttribute (new (color, color));
+                SetAttribute (new (color, color));
                 AddRune (x + xOffset, yOffset, new ('█'));
             }
         }

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

@@ -135,7 +135,7 @@ public class ColorPicker16 : View
     {
         base.OnDrawingContent (viewport);
 
-        Driver?.SetAttribute (HasFocus ? ColorScheme.Focus : GetNormalColor ());
+        SetAttribute (HasFocus ? ColorScheme.Focus : GetNormalColor ());
         var colorIndex = 0;
 
         for (var y = 0; y < Math.Max (2, viewport.Height / BoxHeight); y++)
@@ -149,7 +149,7 @@ public class ColorPicker16 : View
                     continue;
                 }
 
-                Driver?.SetAttribute (new ((ColorName16)foregroundColorIndex, (ColorName16)colorIndex));
+                SetAttribute (new ((ColorName16)foregroundColorIndex, (ColorName16)colorIndex));
                 bool selected = x == Cursor.X && y == Cursor.Y;
                 DrawColorBox (x, y, selected);
                 colorIndex++;

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

@@ -102,7 +102,7 @@ public partial class ColorPicker : View
     protected override bool OnDrawingContent (Rectangle viewport)
     {
         Attribute normal = GetNormalColor ();
-        Driver?.SetAttribute (new (SelectedColor, normal.Background));
+        SetAttribute (new (SelectedColor, normal.Background));
         int y = _bars.Count + (Style.ShowColorName ? 1 : 0);
         AddRune (13, y, (Rune)'■');
 

+ 7 - 4
Terminal.Gui/Views/ComboBox.cs

@@ -302,7 +302,10 @@ public class ComboBox : View, IDesignable
             return true;
         }
 
-        Driver?.SetAttribute (ColorScheme.Focus);
+        if (ColorScheme != null)
+        {
+            SetAttribute (ColorScheme.Focus);
+        }
         Move (Viewport.Right - 1, 0);
         Driver?.AddRune (Glyphs.DownArrow);
 
@@ -889,7 +892,7 @@ public class ComboBox : View, IDesignable
         protected override bool OnDrawingContent (Rectangle viewport)
         {
             Attribute current = ColorScheme?.Focus ?? Attribute.Default;
-            Driver?.SetAttribute (current);
+            SetAttribute (current);
             Move (0, 0);
             Rectangle f = Frame;
             int item = TopItem;
@@ -919,7 +922,7 @@ public class ComboBox : View, IDesignable
 
                 if (newcolor != current)
                 {
-                    Driver?.SetAttribute (newcolor);
+                    SetAttribute (newcolor);
                     current = newcolor;
                 }
 
@@ -940,7 +943,7 @@ public class ComboBox : View, IDesignable
                     if (rowEventArgs.RowAttribute is { } && current != rowEventArgs.RowAttribute)
                     {
                         current = (Attribute)rowEventArgs.RowAttribute;
-                        Driver?.SetAttribute (current);
+                        SetAttribute (current);
                     }
 
                     if (AllowsMarking)

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

@@ -384,7 +384,7 @@ public class FileDialog : Dialog
 
             Move (0, Viewport.Height / 2);
 
-            Driver.SetAttribute (new Attribute (Color.Red, ColorScheme.Normal.Background));
+            SetAttribute (new Attribute (Color.Red, ColorScheme.Normal.Background));
             Driver.AddStr (new string (' ', feedbackPadLeft));
             Driver.AddStr (_feedback);
             Driver.AddStr (new string (' ', feedbackPadRight));

+ 2 - 2
Terminal.Gui/Views/GraphView/Annotations.cs

@@ -160,7 +160,7 @@ public class LegendAnnotation : View, IAnnotation
         {
             if (entry.Item1.Color.HasValue)
             {
-                Application.Driver?.SetAttribute (entry.Item1.Color.Value);
+                SetAttribute (entry.Item1.Color.Value);
             }
             else
             {
@@ -217,7 +217,7 @@ public class PathAnnotation : IAnnotation
     /// <param name="graph"></param>
     public void Render (GraphView graph)
     {
-        View.Driver.SetAttribute (LineColor ?? graph.ColorScheme.Normal);
+        graph.SetAttribute (LineColor ?? graph.ColorScheme.Normal);
 
         foreach (LineF line in PointsToLines ())
         {

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

@@ -345,7 +345,7 @@ public class GraphView : View, IDesignable
     ///     Sets the color attribute of <see cref="Application.Driver"/> to the <see cref="GraphColor"/> (if defined) or
     ///     <see cref="ColorScheme"/> otherwise.
     /// </summary>
-    public void SetDriverColorToGraphColor () { Driver?.SetAttribute (GraphColor ?? GetNormalColor ()); }
+    public void SetDriverColorToGraphColor () { SetAttribute (GraphColor ?? GetNormalColor ()); }
 
     bool IDesignable.EnableForDesign ()
     {

+ 2 - 2
Terminal.Gui/Views/GraphView/Series.cs

@@ -33,7 +33,7 @@ public class ScatterSeries : ISeries
     {
         if (Fill.Color.HasValue)
         {
-            Application.Driver?.SetAttribute (Fill.Color.Value);
+            graph.SetAttribute (Fill.Color.Value);
         }
 
         foreach (PointF p in Points.Where (p => graphBounds.Contains (p)))
@@ -261,7 +261,7 @@ public class BarSeries : ISeries
 
         if (adjusted.Color.HasValue)
         {
-            Application.Driver?.SetAttribute (adjusted.Color.Value);
+            graph.SetAttribute (adjusted.Color.Value);
         }
 
         graph.DrawLine (start, end, adjusted.Rune);

+ 4 - 4
Terminal.Gui/Views/HexView.cs

@@ -428,9 +428,9 @@ public class HexView : View, IDesignable
             return true;
         }
 
-        Attribute currentAttribute;
+        Attribute currentAttribute = Attribute.Default;
         Attribute current = GetFocusColor ();
-        Driver?.SetAttribute (current);
+        SetAttribute (current);
         Move (0, 0);
 
         int nBlocks = BytesPerLine / NUM_BYTES_PER_HEX_COLUMN;
@@ -452,7 +452,7 @@ public class HexView : View, IDesignable
 
             Move (0, line);
             currentAttribute = new Attribute (GetNormalColor ().Foreground.GetHighlightColor (), GetNormalColor ().Background);
-            Driver?.SetAttribute (currentAttribute);
+            SetAttribute (currentAttribute);
             var address = $"{_displayStart + line * nBlocks * NUM_BYTES_PER_HEX_COLUMN:x8}";
             Driver?.AddStr ($"{address.Substring (8 - AddressWidth)}");
 
@@ -555,7 +555,7 @@ public class HexView : View, IDesignable
             if (currentAttribute != attribute)
             {
                 currentAttribute = attribute;
-                Driver?.SetAttribute (attribute);
+                SetAttribute (attribute);
             }
         }
     }

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

@@ -57,7 +57,7 @@ public class LineView : View
     protected override bool OnDrawingContent (Rectangle viewport)
     {
         Move (0, 0);
-        Driver?.SetAttribute (GetNormalColor ());
+        SetAttribute (GetNormalColor ());
 
         int hLineWidth = Math.Max (1, Glyphs.HLine.GetColumns ());
 

+ 3 - 3
Terminal.Gui/Views/ListView.cs

@@ -772,7 +772,7 @@ public class ListView : View, IDesignable
     protected override bool OnDrawingContent (Rectangle viewport)
     {
         Attribute current = ColorScheme?.Focus ?? Attribute.Default;
-        Driver?.SetAttribute (current);
+        SetAttribute (current);
         Move (0, 0);
         Rectangle f = Viewport;
         int item = Viewport.Y;
@@ -789,7 +789,7 @@ public class ListView : View, IDesignable
 
             if (newcolor != current)
             {
-                Driver?.SetAttribute (newcolor);
+                SetAttribute (newcolor);
                 current = newcolor;
             }
 
@@ -810,7 +810,7 @@ public class ListView : View, IDesignable
                 if (rowEventArgs.RowAttribute is { } && current != rowEventArgs.RowAttribute)
                 {
                     current = (Attribute)rowEventArgs.RowAttribute;
-                    Driver?.SetAttribute (current);
+                    SetAttribute (current);
                 }
 
                 if (_allowsMarking)

+ 3 - 3
Terminal.Gui/Views/Menu/Menu.cs

@@ -411,7 +411,7 @@ internal sealed class Menu : View
 
         Rectangle savedClip = Driver.Clip;
         Driver.Clip = new (0, 0, Driver.Cols, Driver.Rows);
-        Driver.SetAttribute (GetNormalColor ());
+        SetAttribute (GetNormalColor ());
 
         for (int i = Viewport.Y; i < _barItems!.Children.Length; i++)
         {
@@ -427,7 +427,7 @@ internal sealed class Menu : View
 
             MenuItem? item = _barItems.Children [i];
 
-            Driver.SetAttribute (
+            SetAttribute (
                                  // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
                                  item is null ? GetNormalColor () :
                                  i == _currentChild ? GetFocusColor () : GetNormalColor ()
@@ -444,7 +444,7 @@ internal sealed class Menu : View
                 Move (0, i);
             }
 
-            Driver.SetAttribute (DetermineColorSchemeFor (item, i));
+            SetAttribute (DetermineColorSchemeFor (item, i));
 
             for (int p = Viewport.X; p < Frame.Width - 2; p++)
             {

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

@@ -141,7 +141,7 @@ public class ProgressBar : View, IDesignable
     ///<inheritdoc/>
     protected override bool OnDrawingContent (Rectangle viewport)
     {
-        Driver?.SetAttribute (GetHotNormalColor ());
+        SetAttribute (GetHotNormalColor ());
 
         Move (0, 0);
 

+ 8 - 8
Terminal.Gui/Views/RadioGroup.cs

@@ -362,7 +362,7 @@ public class RadioGroup : View, IDesignable, IOrientation
     /// <inheritdoc/>
     protected override bool OnDrawingContent (Rectangle viewport)
     {
-        Driver?.SetAttribute (GetNormalColor ());
+        SetAttribute (GetNormalColor ());
 
         for (var i = 0; i < _radioLabels.Count; i++)
         {
@@ -379,7 +379,7 @@ public class RadioGroup : View, IDesignable, IOrientation
             }
 
             string rl = _radioLabels [i];
-            Driver?.SetAttribute (GetNormalColor ());
+            SetAttribute (GetNormalColor ());
             Driver?.AddStr ($"{(i == _selected ? Glyphs.Selected : Glyphs.UnSelected)} ");
             TextFormatter.FindHotKey (rl, HotKeySpecifier, out int hotPos, out Key hotKey);
 
@@ -393,7 +393,7 @@ public class RadioGroup : View, IDesignable, IOrientation
 
                     if (j == hotPos && i == Cursor)
                     {
-                        Application.Driver?.SetAttribute (
+                        SetAttribute (
                                                           HasFocus
                                                               ? ColorScheme!.HotFocus
                                                               : GetHotNormalColor ()
@@ -401,11 +401,11 @@ public class RadioGroup : View, IDesignable, IOrientation
                     }
                     else if (j == hotPos && i != Cursor)
                     {
-                        Application.Driver?.SetAttribute (GetHotNormalColor ());
+                        SetAttribute (GetHotNormalColor ());
                     }
                     else if (HasFocus && i == Cursor)
                     {
-                        Application.Driver?.SetAttribute (GetFocusColor ());
+                        SetAttribute (GetFocusColor ());
                     }
 
                     if (rune == HotKeySpecifier && j + 1 < rlRunes.Length)
@@ -415,7 +415,7 @@ public class RadioGroup : View, IDesignable, IOrientation
 
                         if (i == Cursor)
                         {
-                            Application.Driver?.SetAttribute (
+                            SetAttribute (
                                                               HasFocus
                                                                   ? ColorScheme!.HotFocus
                                                                   : GetHotNormalColor ()
@@ -423,12 +423,12 @@ public class RadioGroup : View, IDesignable, IOrientation
                         }
                         else if (i != Cursor)
                         {
-                            Application.Driver?.SetAttribute (GetHotNormalColor ());
+                            SetAttribute (GetHotNormalColor ());
                         }
                     }
 
                     Application.Driver?.AddRune (rune);
-                    Driver?.SetAttribute (GetNormalColor ());
+                    SetAttribute (GetNormalColor ());
                 }
             }
             else

+ 2 - 2
Terminal.Gui/Views/ScrollBarView.cs

@@ -463,7 +463,7 @@ public class ScrollBarView : View
             return false;
         }
 
-        Driver.SetAttribute (Host.HasFocus ? ColorScheme.Focus : GetNormalColor ());
+        SetAttribute (Host.HasFocus ? ColorScheme.Focus : GetNormalColor ());
 
         if (_vertical)
         {
@@ -765,7 +765,7 @@ public class ScrollBarView : View
 
     private void ContentBottomRightCorner_DrawContent (object sender, DrawEventArgs e)
     {
-        Driver.SetAttribute (Host.HasFocus ? ColorScheme.Focus : GetNormalColor ());
+        SetAttribute (Host.HasFocus ? ColorScheme.Focus : GetNormalColor ());
 
         // I'm forced to do this here because the Clear method is
         // changing the color attribute and is different of this one

+ 8 - 8
Terminal.Gui/Views/Slider.cs

@@ -866,7 +866,7 @@ public class Slider<T> : View, IOrientation
         // Left Spacing
         if (_config._showEndSpacing && _config._startSpacing > 0)
         {
-            Driver?.SetAttribute (
+            SetAttribute (
                                   isSet && _config._type == SliderType.LeftRange
                                       ? Style.RangeChar.Attribute ?? normalAttr
                                       : Style.SpaceChar.Attribute ?? normalAttr
@@ -889,7 +889,7 @@ public class Slider<T> : View, IOrientation
         }
         else
         {
-            Driver?.SetAttribute (Style.EmptyChar.Attribute ?? normalAttr);
+            SetAttribute (Style.EmptyChar.Attribute ?? normalAttr);
 
             for (var i = 0; i < _config._startSpacing; i++)
             {
@@ -942,7 +942,7 @@ public class Slider<T> : View, IOrientation
                 }
 
                 // Draw Option
-                Driver?.SetAttribute (
+                SetAttribute (
                                       isSet && _setOptions.Contains (i) ? Style.SetChar.Attribute ?? setAttr :
                                       drawRange ? Style.RangeChar.Attribute ?? setAttr : Style.OptionChar.Attribute ?? normalAttr
                                      );
@@ -980,7 +980,7 @@ public class Slider<T> : View, IOrientation
                 if (_config._showEndSpacing || i < _options.Count - 1)
                 {
                     // Skip if is the Last Spacing.
-                    Driver?.SetAttribute (
+                    SetAttribute (
                                           drawRange && isSet
                                               ? Style.RangeChar.Attribute ?? setAttr
                                               : Style.SpaceChar.Attribute ?? normalAttr
@@ -1008,7 +1008,7 @@ public class Slider<T> : View, IOrientation
         // Right Spacing
         if (_config._showEndSpacing)
         {
-            Driver?.SetAttribute (
+            SetAttribute (
                                   isSet && _config._type == SliderType.RightRange
                                       ? Style.RangeChar.Attribute ?? normalAttr
                                       : Style.SpaceChar.Attribute ?? normalAttr
@@ -1031,7 +1031,7 @@ public class Slider<T> : View, IOrientation
         }
         else
         {
-            Driver?.SetAttribute (Style.EmptyChar.Attribute ?? normalAttr);
+            SetAttribute (Style.EmptyChar.Attribute ?? normalAttr);
 
             for (var i = 0; i < remaining; i++)
             {
@@ -1223,7 +1223,7 @@ public class Slider<T> : View, IOrientation
             }
 
             // Legend
-            Driver?.SetAttribute (isOptionSet ? setAttr : normalAttr);
+            SetAttribute (isOptionSet ? setAttr : normalAttr);
 
             foreach (Rune c in text.EnumerateRunes ())
             {
@@ -1249,7 +1249,7 @@ public class Slider<T> : View, IOrientation
             }
 
             // Option Right Spacing of Option
-            Driver?.SetAttribute (spaceAttr);
+            SetAttribute (spaceAttr);
 
             if (isTextVertical)
             {

+ 2 - 2
Terminal.Gui/Views/TabView.cs

@@ -655,7 +655,7 @@ public class TabView : View
             RenderTabLine ();
 
             RenderUnderline ();
-            Driver?.SetAttribute (HasFocus ? GetFocusColor () : GetNormalColor ());
+            SetAttribute (HasFocus ? GetFocusColor () : GetNormalColor ());
 
             return true;
         }
@@ -1308,7 +1308,7 @@ public class TabView : View
                 tab.DrawAdornments ();
 
 
-                Driver?.SetAttribute (GetNormalColor ());
+                SetAttribute (GetNormalColor ());
             }
         }
 

+ 23 - 11
Terminal.Gui/Views/TableView/TableView.cs

@@ -921,7 +921,7 @@ public class TableView : View, IDesignable
         // What columns to render at what X offset in viewport
         ColumnToRender [] columnsToRender = CalculateViewport (Viewport).ToArray ();
 
-        Driver?.SetAttribute (GetNormalColor ());
+        SetAttribute (GetNormalColor ());
 
         //invalidate current row (prevents scrolling around leaving old characters in the frame
         Driver?.AddStr (new string (' ', Viewport.Width));
@@ -1281,19 +1281,19 @@ public class TableView : View, IDesignable
             if (render.Length > 0)
             {
                 // invert the color of the current cell for the first character
-                Driver.SetAttribute (new Attribute (cellColor.Background, cellColor.Foreground));
+                SetAttribute (new Attribute (cellColor.Background, cellColor.Foreground));
                 Driver.AddRune ((Rune)render [0]);
 
                 if (render.Length > 1)
                 {
-                    Driver.SetAttribute (cellColor);
+                    SetAttribute (cellColor);
                     Driver.AddStr (render.Substring (1));
                 }
             }
         }
         else
         {
-            Driver.SetAttribute (cellColor);
+            SetAttribute (cellColor);
             Driver.AddStr (render);
         }
     }
@@ -1321,7 +1321,7 @@ public class TableView : View, IDesignable
     /// <returns></returns>
     internal int GetHeaderHeightIfAny () { return ShouldRenderHeaders () ? GetHeaderHeight () : 0; }
 
-    private void AddRuneAt (ConsoleDriver? d, int col, int row, Rune ch)
+    private void AddRuneAt (ConsoleDriver d, int col, int row, Rune ch)
     {
         Move (col, row);
         d?.AddRune (ch);
@@ -1511,7 +1511,7 @@ public class TableView : View, IDesignable
             return;
         }
         Move (0, row);
-        Driver.SetAttribute (GetNormalColor ());
+        SetAttribute (GetNormalColor ());
         Driver.AddStr (new string (' ', width));
     }
 
@@ -1904,7 +1904,10 @@ public class TableView : View, IDesignable
             color = Enabled ? rowScheme?.Normal : rowScheme?.Disabled;
         }
 
-        Driver?.SetAttribute (color.Value);
+        if (color is { })
+        {
+            SetAttribute (color.Value);
+        }
         Driver?.AddStr (new string (' ', Viewport.Width));
 
         // Render cells for each visible header for the current row
@@ -1989,18 +1992,24 @@ public class TableView : View, IDesignable
                     color = Enabled ? rowScheme.Normal : rowScheme.Disabled;
                 }
 
-                Driver?.SetAttribute (color.Value);
+                SetAttribute (color.Value);
             }
 
             // If not in full row select mode always, reset color scheme to normal and render the vertical line (or space) at the end of the cell
             if (!FullRowSelect)
             {
-                Driver?.SetAttribute (Enabled ? rowScheme.Normal : rowScheme.Disabled);
+                if (rowScheme is { })
+                {
+                    SetAttribute (Enabled ? rowScheme.Normal : rowScheme.Disabled);
+                }
             }
 
             if (style.AlwaysUseNormalColorForVerticalCellLines && style.ShowVerticalCellLines)
             {
-                Driver?.SetAttribute (rowScheme.Normal);
+                if (rowScheme is { })
+                {
+                    SetAttribute (rowScheme.Normal);
+                }
             }
 
             RenderSeparator (current.X - 1, row, false);
@@ -2013,7 +2022,10 @@ public class TableView : View, IDesignable
 
         if (style.ShowVerticalCellLines)
         {
-            Driver?.SetAttribute (rowScheme.Normal);
+            if (rowScheme is { })
+            {
+                SetAttribute (rowScheme.Normal);
+            }
 
             //render start and end of line
             AddRune (0, row, Glyphs.VLine);

+ 8 - 8
Terminal.Gui/Views/TextField.cs

@@ -938,7 +938,7 @@ public class TextField : View
         var selColor = new Attribute (GetFocusColor ().Background, GetFocusColor ().Foreground);
         SetSelectedStartSelectedLength ();
 
-        Driver?.SetAttribute (GetNormalColor ());
+        SetAttribute (GetNormalColor ());
         Move (0, 0);
 
         int p = ScrollOffset;
@@ -954,11 +954,11 @@ public class TextField : View
 
             if (idx == _cursorPosition && HasFocus && !Used && SelectedLength == 0 && !ReadOnly)
             {
-                Driver?.SetAttribute (selColor);
+                SetAttribute (selColor);
             }
             else if (ReadOnly)
             {
-                Driver?.SetAttribute (
+                SetAttribute (
                                       idx >= _start && SelectedLength > 0 && idx < _start + SelectedLength
                                           ? selColor
                                           : roc
@@ -966,15 +966,15 @@ public class TextField : View
             }
             else if (!HasFocus && Enabled)
             {
-                Driver?.SetAttribute (GetFocusColor ());
+                SetAttribute (GetFocusColor ());
             }
             else if (!Enabled)
             {
-                Driver?.SetAttribute (roc);
+                SetAttribute (roc);
             }
             else
             {
-                Driver?.SetAttribute (
+                SetAttribute (
                                       idx >= _start && SelectedLength > 0 && idx < _start + SelectedLength
                                           ? selColor
                                           : ColorScheme.Focus
@@ -997,7 +997,7 @@ public class TextField : View
             }
         }
 
-        Driver?.SetAttribute (GetFocusColor ());
+        SetAttribute (GetFocusColor ());
 
         for (int i = col; i < width; i++)
         {
@@ -1769,7 +1769,7 @@ public class TextField : View
         }
 
         var color = new Attribute (CaptionColor, GetNormalColor ().Background);
-        Driver.SetAttribute (color);
+        SetAttribute (color);
 
         Move (0, 0);
         string render = Caption;

+ 3 - 3
Terminal.Gui/Views/TextValidateField.cs

@@ -571,7 +571,7 @@ namespace Terminal.Gui
             Move (0, 0);
 
             // Left Margin
-            Driver?.SetAttribute (textColor);
+            SetAttribute (textColor);
 
             for (var i = 0; i < margin_left; i++)
             {
@@ -579,7 +579,7 @@ namespace Terminal.Gui
             }
 
             // Content
-            Driver?.SetAttribute (textColor);
+            SetAttribute (textColor);
 
             // Content
             for (var i = 0; i < _provider.DisplayText.Length; i++)
@@ -588,7 +588,7 @@ namespace Terminal.Gui
             }
 
             // Right Margin
-            Driver?.SetAttribute (textColor);
+            SetAttribute (textColor);
 
             for (var i = 0; i < margin_right; i++)
             {

+ 12 - 12
Terminal.Gui/Views/TextView.cs

@@ -3962,7 +3962,7 @@ public class TextView : View
     /// <summary>
     ///     Sets the <see cref="View.Driver"/> to an appropriate color for rendering the given <paramref name="idxCol"/>
     ///     of the current <paramref name="line"/>. Override to provide custom coloring by calling
-    ///     <see cref="ConsoleDriver?.SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.Normal"/>.
+    ///     <see cref="SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.Normal"/>.
     /// </summary>
     /// <param name="line">The line.</param>
     /// <param name="idxCol">The col index.</param>
@@ -3976,18 +3976,18 @@ public class TextView : View
         if (line [idxCol].Attribute is { })
         {
             Attribute? attribute = line [idxCol].Attribute;
-            Driver?.SetAttribute ((Attribute)attribute!);
+            SetAttribute ((Attribute)attribute!);
         }
         else
         {
-            Driver?.SetAttribute (GetNormalColor ());
+            SetAttribute (GetNormalColor ());
         }
     }
 
     /// <summary>
     ///     Sets the <see cref="View.Driver"/> to an appropriate color for rendering the given <paramref name="idxCol"/>
     ///     of the current <paramref name="line"/>. Override to provide custom coloring by calling
-    ///     <see cref="ConsoleDriver?.SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.Focus"/>.
+    ///     <see cref="SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.Focus"/>.
     /// </summary>
     /// <param name="line">The line.</param>
     /// <param name="idxCol">The col index.</param>
@@ -4011,13 +4011,13 @@ public class TextView : View
             attribute = new (cellAttribute.Value.Foreground, ColorScheme!.Focus.Background);
         }
 
-        Driver?.SetAttribute (attribute);
+        SetAttribute (attribute);
     }
 
     /// <summary>
     ///     Sets the <see cref="View.Driver"/> to an appropriate color for rendering the given <paramref name="idxCol"/>
     ///     of the current <paramref name="line"/>. Override to provide custom coloring by calling
-    ///     <see cref="ConsoleDriver?.SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.Focus"/>.
+    ///     <see cref="SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.Focus"/>.
     /// </summary>
     /// <param name="line">The line.</param>
     /// <param name="idxCol">The col index.</param>
@@ -4033,13 +4033,13 @@ public class TextView : View
         {
             Attribute? attribute = line [idxCol].Attribute;
 
-            Driver?.SetAttribute (
+            SetAttribute (
                                  new (attribute!.Value.Background, attribute.Value.Foreground)
                                 );
         }
         else
         {
-            Driver?.SetAttribute (
+            SetAttribute (
                                  new (
                                       ColorScheme!.Focus.Background,
                                       ColorScheme!.Focus.Foreground
@@ -4051,7 +4051,7 @@ public class TextView : View
     /// <summary>
     ///     Sets the <see cref="View.Driver"/> to an appropriate color for rendering the given <paramref name="idxCol"/>
     ///     of the current <paramref name="line"/>. Override to provide custom coloring by calling
-    ///     <see cref="ConsoleDriver?.SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.HotFocus"/>.
+    ///     <see cref="SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.HotFocus"/>.
     /// </summary>
     /// <param name="line">The line.</param>
     /// <param name="idxCol">The col index.</param>
@@ -4078,7 +4078,7 @@ public class TextView : View
     ///     Sets the driver to the default color for the control where no text is being rendered. Defaults to
     ///     <see cref="ColorScheme.Normal"/>.
     /// </summary>
-    protected virtual void SetNormalColor () { Driver?.SetAttribute (GetNormalColor ()); }
+    protected virtual void SetNormalColor () { SetAttribute (GetNormalColor ()); }
 
     private void Adjust ()
     {
@@ -6361,11 +6361,11 @@ public class TextView : View
         DoNeededAction ();
     }
 
-    private static void SetValidUsedColor (Attribute? attribute)
+    private void SetValidUsedColor (Attribute? attribute)
     {
         // BUGBUG: (v2 truecolor) This code depends on 8-bit color names; disabling for now
         //if ((colorScheme!.HotNormal.Foreground & colorScheme.Focus.Background) == colorScheme.Focus.Foreground) {
-        Driver?.SetAttribute (new (attribute!.Value.Background, attribute!.Value.Foreground));
+        SetAttribute (new (attribute!.Value.Background, attribute!.Value.Foreground));
     }
 
     /// <summary>Restore from original model.</summary>

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

@@ -31,7 +31,7 @@ public class Tile
     ///     The <see cref="ContentView"/> that is contained in this <see cref="TileView"/>. Add new child views to this
     ///     member for multiple <see cref="ContentView"/>s within the <see cref="Tile"/>.
     /// </summary>
-    public View ContentView { get; internal set; }
+    public View? ContentView { get; internal set; }
 
     /// <summary>
     ///     Gets or Sets the minimum size you to allow when splitter resizing along parent

+ 82 - 71
Terminal.Gui/Views/TileView.cs

@@ -1,4 +1,5 @@
-namespace Terminal.Gui;
+#nullable enable
+namespace Terminal.Gui;
 
 /// <summary>
 ///     A <see cref="View"/> consisting of a moveable bar that divides the display area into resizeable
@@ -7,10 +8,10 @@
 public class TileView : View
 {
     private Orientation _orientation = Orientation.Vertical;
-    private List<Pos> _splitterDistances;
-    private List<TileViewLineView> _splitterLines;
-    private List<Tile> _tiles;
-    private TileView _parentTileView;
+    private List<Pos>? _splitterDistances;
+    private List<TileViewLineView>? _splitterLines;
+    private List<Tile>? _tiles;
+    private TileView? _parentTileView;
 
     /// <summary>Creates a new instance of the <see cref="TileView"/> class with 2 tiles (i.e. left and right).</summary>
     public TileView () : this (2) { }
@@ -63,10 +64,10 @@ public class TileView : View
     }
 
     /// <summary>The splitter locations. Note that there will be N-1 splitters where N is the number of <see cref="Tiles"/>.</summary>
-    public IReadOnlyCollection<Pos> SplitterDistances => _splitterDistances.AsReadOnly ();
+    public IReadOnlyCollection<Pos> SplitterDistances => _splitterDistances!.AsReadOnly ();
 
     /// <summary>The sub sections hosted by the view</summary>
-    public IReadOnlyCollection<Tile> Tiles => _tiles.AsReadOnly ();
+    public IReadOnlyCollection<Tile> Tiles => _tiles!.AsReadOnly ();
 
     // TODO: Update to use Key instead of KeyCode
     /// <summary>
@@ -82,7 +83,7 @@ public class TileView : View
     /// </summary>
     /// <remarks>Use <see cref="IsRootTileView"/> to determine if the returned value is the root.</remarks>
     /// <returns></returns>
-    public TileView GetParentTileView () { return _parentTileView; }
+    public TileView? GetParentTileView () { return _parentTileView; }
 
     /// <summary>
     ///     Returns the index of the first <see cref="Tile"/> in <see cref="Tiles"/> which contains
@@ -90,9 +91,9 @@ public class TileView : View
     /// </summary>
     public int IndexOf (View toFind, bool recursive = false)
     {
-        for (var i = 0; i < _tiles.Count; i++)
+        for (var i = 0; i < _tiles!.Count; i++)
         {
-            View v = _tiles [i].ContentView;
+            View v = _tiles [i].ContentView!;
 
             if (v == toFind)
             {
@@ -121,14 +122,14 @@ public class TileView : View
     ///     line
     /// </summary>
     /// <param name="idx"></param>
-    public Tile InsertTile (int idx)
+    public Tile? InsertTile (int idx)
     {
         Tile [] oldTiles = Tiles.ToArray ();
         RebuildForTileCount (oldTiles.Length + 1);
 
-        Tile toReturn = null;
+        Tile? toReturn = null;
 
-        for (var i = 0; i < _tiles.Count; i++)
+        for (var i = 0; i < _tiles?.Count; i++)
         {
             if (i != idx)
             {
@@ -136,12 +137,12 @@ public class TileView : View
 
                 // remove the new empty View
                 Remove (_tiles [i].ContentView);
-                _tiles [i].ContentView.Dispose ();
+                _tiles [i].ContentView?.Dispose ();
                 _tiles [i].ContentView = null;
 
                 // restore old Tile and View
                 _tiles [i] = oldTile;
-                _tiles [i].ContentView.TabStop = TabStop;
+                _tiles [i].ContentView!.TabStop = TabStop;
                 Add (_tiles [i].ContentView);
             }
             else
@@ -182,7 +183,10 @@ public class TileView : View
     /// <inheritdoc/>
     protected override void OnDrawComplete ()
     {
-        Driver?.SetAttribute (ColorScheme.Normal);
+        if (ColorScheme is { })
+        {
+            SetAttribute (ColorScheme.Normal);
+        }
 
         var lc = new LineCanvas ();
 
@@ -213,7 +217,7 @@ public class TileView : View
 
             foreach (TileViewLineView line in allLines)
             {
-                bool isRoot = _splitterLines.Contains (line);
+                bool isRoot = _splitterLines!.Contains (line);
 
                 Rectangle screen = line.ViewportToScreen (Rectangle.Empty);
                 Point origin = ScreenToFrame (screen.Location);
@@ -237,7 +241,10 @@ public class TileView : View
             }
         }
 
-        Driver?.SetAttribute (ColorScheme.Normal);
+        if (ColorScheme is { })
+        {
+            SetAttribute (ColorScheme.Normal);
+        }
 
         foreach (KeyValuePair<Point, Rune> p in lc.GetMap (Viewport))
         {
@@ -284,7 +291,7 @@ public class TileView : View
 
         if (key.KeyCode == ToggleResizable)
         {
-            foreach (TileViewLineView l in _splitterLines)
+            foreach (TileViewLineView l in _splitterLines!)
             {
                 bool iniBefore = l.IsInitialized;
                 l.IsInitialized = false;
@@ -328,7 +335,7 @@ public class TileView : View
 
         foreach (Tile tile in _tiles)
         {
-            tile.ContentView.Dispose ();
+            tile.ContentView?.Dispose ();
             tile.ContentView = null;
         }
 
@@ -353,7 +360,7 @@ public class TileView : View
 
             var tile = new Tile ();
             _tiles.Add (tile);
-            tile.ContentView.Id = $"Tile.ContentView {i}";
+            tile.ContentView!.Id = $"Tile.ContentView {i}";
             Add (tile.ContentView);
 
             // BUGBUG: This should not be needed:
@@ -369,7 +376,7 @@ public class TileView : View
     /// </summary>
     /// <param name="idx"></param>
     /// <returns></returns>
-    public Tile RemoveTile (int idx)
+    public Tile? RemoveTile (int idx)
     {
         Tile [] oldTiles = Tiles.ToArray ();
 
@@ -382,14 +389,14 @@ public class TileView : View
 
         RebuildForTileCount (oldTiles.Length - 1);
 
-        for (var i = 0; i < _tiles.Count; i++)
+        for (var i = 0; i < _tiles?.Count; i++)
         {
             int oldIdx = i >= idx ? i + 1 : i;
             Tile oldTile = oldTiles [oldIdx];
 
             // remove the new empty View
             Remove (_tiles [i].ContentView);
-            _tiles [i].ContentView.Dispose ();
+            _tiles [i].ContentView?.Dispose ();
             _tiles [i].ContentView = null;
 
             // restore old Tile and View
@@ -427,7 +434,11 @@ public class TileView : View
             return false;
         }
 
-        _splitterDistances [idx] = value;
+        if (_splitterDistances is { })
+        {
+            _splitterDistances [idx] = value;
+        }
+
         OnSplitterMoved (idx);
         SetNeedsDisplay ();
         SetNeedsLayout ();
@@ -436,7 +447,7 @@ public class TileView : View
     }
 
     /// <summary>Invoked when any of the <see cref="SplitterDistances"/> is changed.</summary>
-    public event SplitterEventHandler SplitterMoved;
+    public event SplitterEventHandler? SplitterMoved;
 
     /// <summary>
     ///     Converts of <see cref="Tiles"/> element <paramref name="idx"/> from a regular <see cref="View"/> to a new
@@ -458,10 +469,10 @@ public class TileView : View
     {
         // when splitting a view into 2 sub views we will need to migrate
         // the title too
-        Tile tile = _tiles [idx];
+        Tile tile = _tiles! [idx];
 
         string title = tile.Title;
-        View toMove = tile.ContentView;
+        View? toMove = tile.ContentView;
 
         if (toMove is TileView existing)
         {
@@ -476,7 +487,7 @@ public class TileView : View
         };
 
         // Take everything out of the View we are moving
-        View [] childViews = toMove.Subviews.ToArray ();
+        View [] childViews = toMove!.Subviews.ToArray ();
         toMove.RemoveAll ();
 
         // Remove the view itself and replace it with the new TileView
@@ -488,16 +499,16 @@ public class TileView : View
 
         tile.ContentView = newContainer;
 
-        View newTileView1 = newContainer._tiles [0].ContentView;
+        View newTileView1 = newContainer!._tiles? [0].ContentView!;
 
         // Add the original content into the first view of the new container
         foreach (View childView in childViews)
         {
-            newTileView1.Add (childView);
+            newTileView1!.Add (childView);
         }
 
         // Move the title across too
-        newContainer._tiles [0].Title = title;
+        newContainer._tiles! [0].Title = title;
         tile.Title = string.Empty;
 
         result = newContainer;
@@ -511,14 +522,14 @@ public class TileView : View
         foreach (Tile tile in Tiles)
         {
             Remove (tile.ContentView);
-            tile.ContentView.Dispose ();
+            tile.ContentView?.Dispose ();
         }
 
         base.Dispose (disposing);
     }
 
     /// <summary>Raises the <see cref="SplitterMoved"/> event</summary>
-    protected virtual void OnSplitterMoved (int idx) { SplitterMoved?.Invoke (this, new (this, idx, _splitterDistances [idx])); }
+    protected virtual void OnSplitterMoved (int idx) { SplitterMoved?.Invoke (this, new (this, idx, _splitterDistances! [idx])); }
 
     private List<TileViewLineView> GetAllLineViewsRecursively (View v)
     {
@@ -545,14 +556,14 @@ public class TileView : View
         return lines;
     }
 
-    private List<TileTitleToRender> GetAllTitlesToRenderRecursively (TileView v, int depth = 0)
+    private List<TileTitleToRender> GetAllTitlesToRenderRecursively (TileView? v, int depth = 0)
     {
         List<TileTitleToRender> titles = new ();
 
-        foreach (Tile sub in v.Tiles)
+        foreach (Tile sub in v!.Tiles)
         {
             // Don't render titles for invisible stuff!
-            if (!sub.ContentView.Visible)
+            if (!sub.ContentView!.Visible)
             {
                 continue;
             }
@@ -588,20 +599,20 @@ public class TileView : View
         return root;
     }
 
-    private Dim GetTileWidthOrHeight (int i, int space, Tile [] visibleTiles, TileViewLineView [] visibleSplitterLines)
+    private Dim GetTileWidthOrHeight (int i, int space, Tile? [] visibleTiles, TileViewLineView? [] visibleSplitterLines)
     {
         // last tile
         if (i + 1 >= visibleTiles.Length)
         {
-            return Dim.Fill (HasBorder () ? 1 : 0);
+            return Dim.Fill (HasBorder () ? 1 : 0)!;
         }
 
-        TileViewLineView nextSplitter = visibleSplitterLines [i];
-        Pos nextSplitterPos = Orientation == Orientation.Vertical ? nextSplitter.X : nextSplitter.Y;
+        TileViewLineView? nextSplitter = visibleSplitterLines [i];
+        Pos? nextSplitterPos = Orientation == Orientation.Vertical ? nextSplitter!.X : nextSplitter!.Y;
         int nextSplitterDistance = nextSplitterPos.GetAnchor (space);
 
-        TileViewLineView lastSplitter = i >= 1 ? visibleSplitterLines [i - 1] : null;
-        Pos lastSplitterPos = Orientation == Orientation.Vertical ? lastSplitter?.X : lastSplitter?.Y;
+        TileViewLineView? lastSplitter = i >= 1 ? visibleSplitterLines [i - 1] : null;
+        Pos? lastSplitterPos = Orientation == Orientation.Vertical ? lastSplitter?.X : lastSplitter?.Y;
         int lastSplitterDistance = lastSplitterPos?.GetAnchor (space) ?? 0;
 
         int distance = nextSplitterDistance - lastSplitterDistance;
@@ -618,19 +629,19 @@ public class TileView : View
 
     private void HideSplittersBasedOnTileVisibility ()
     {
-        if (_splitterLines.Count == 0)
+        if (_splitterLines is { Count: 0 })
         {
             return;
         }
 
-        foreach (TileViewLineView line in _splitterLines)
+        foreach (TileViewLineView line in _splitterLines!)
         {
             line.Visible = true;
         }
 
-        for (var i = 0; i < _tiles.Count; i++)
+        for (var i = 0; i < _tiles!.Count; i++)
         {
-            if (!_tiles [i].ContentView.Visible)
+            if (!_tiles [i].ContentView!.Visible)
             {
                 // when a tile is not visible, prefer hiding
                 // the splitter on it's left
@@ -654,7 +665,7 @@ public class TileView : View
     private bool IsValidNewSplitterPos (int idx, Pos value, int fullSpace)
     {
         int newSize = value.GetAnchor (fullSpace);
-        bool isGettingBigger = newSize > _splitterDistances [idx].GetAnchor (fullSpace);
+        bool isGettingBigger = newSize > _splitterDistances! [idx].GetAnchor (fullSpace);
         int lastSplitterOrBorder = HasBorder () ? 1 : 0;
         int nextSplitterOrBorder = HasBorder () ? fullSpace - 1 : fullSpace;
 
@@ -713,7 +724,7 @@ public class TileView : View
             }
 
             // don't grow if it would take us below min size of right panel
-            if (spaceForNext < _tiles [idx + 1].MinSize)
+            if (spaceForNext < _tiles! [idx + 1].MinSize)
             {
                 return false;
             }
@@ -729,7 +740,7 @@ public class TileView : View
             }
 
             // don't shrink if it would take us below min size of left panel
-            if (spaceForLast < _tiles [idx].MinSize)
+            if (spaceForLast < _tiles! [idx].MinSize)
             {
                 return false;
             }
@@ -763,7 +774,7 @@ public class TileView : View
             return;
         }
 
-        for (var i = 0; i < _splitterLines.Count; i++)
+        for (var i = 0; i < _splitterLines!.Count; i++)
         {
             TileViewLineView line = _splitterLines [i];
 
@@ -780,19 +791,19 @@ public class TileView : View
 
             if (_orientation == Orientation.Vertical)
             {
-                line.X = _splitterDistances [i];
+                line.X = _splitterDistances! [i];
                 line.Y = 0;
             }
             else
             {
-                line.Y = _splitterDistances [i];
+                line.Y = _splitterDistances! [i];
                 line.X = 0;
             }
         }
 
         HideSplittersBasedOnTileVisibility ();
 
-        Tile [] visibleTiles = _tiles.Where (t => t.ContentView.Visible).ToArray ();
+        Tile [] visibleTiles = _tiles!.Where (t => t.ContentView!.Visible).ToArray ();
         TileViewLineView [] visibleSplitterLines = _splitterLines.Where (l => l.Visible).ToArray ();
 
         for (var i = 0; i < visibleTiles.Length; i++)
@@ -801,14 +812,14 @@ public class TileView : View
 
             if (Orientation == Orientation.Vertical)
             {
-                tile.ContentView.X = i == 0 ? viewport.X : Pos.Right (visibleSplitterLines [i - 1]);
+                tile.ContentView!.X = i == 0 ? viewport.X : Pos.Right (visibleSplitterLines [i - 1]);
                 tile.ContentView.Y = viewport.Y;
                 tile.ContentView.Height = viewport.Height;
                 tile.ContentView.Width = GetTileWidthOrHeight (i, Viewport.Width, visibleTiles, visibleSplitterLines);
             }
             else
             {
-                tile.ContentView.X = viewport.X;
+                tile.ContentView!.X = viewport.X;
                 tile.ContentView.Y = i == 0 ? viewport.Y : Pos.Bottom (visibleSplitterLines [i - 1]);
                 tile.ContentView.Width = viewport.Width;
                 tile.ContentView.Height = GetTileWidthOrHeight (i, Viewport.Height, visibleTiles, visibleSplitterLines);
@@ -821,7 +832,7 @@ public class TileView : View
 
     private class TileTitleToRender
     {
-        public TileTitleToRender (TileView parent, Tile tile, int depth)
+        public TileTitleToRender (TileView? parent, Tile tile, int depth)
         {
             Parent = parent;
             Tile = tile;
@@ -829,8 +840,8 @@ public class TileView : View
         }
 
         public int Depth { get; }
-        public TileView Parent { get; }
-        public Tile Tile { get; }
+        public TileView? Parent { get; }
+        public Tile? Tile { get; }
 
         /// <summary>
         ///     Translates the <see cref="Tile"/> title location from its local coordinate space
@@ -838,22 +849,22 @@ public class TileView : View
         /// </summary>
         public Point GetLocalCoordinateForTitle (TileView intoCoordinateSpace)
         {
-            Rectangle screen = Tile.ContentView.ViewportToScreen (Rectangle.Empty);
+            Rectangle screen = Tile!.ContentView!.ViewportToScreen (Rectangle.Empty);
 
             return intoCoordinateSpace.ScreenToFrame (new (screen.X, screen.Y - 1));
         }
 
         internal string GetTrimmedTitle ()
         {
-            Dim spaceDim = Tile.ContentView.Width;
+            Dim? spaceDim = Tile?.ContentView?.Width;
 
-            int spaceAbs = spaceDim.GetAnchor (Parent.Viewport.Width);
+            int spaceAbs = spaceDim!.GetAnchor (Parent!.Viewport.Width);
 
-            var title = $" {Tile.Title} ";
+            var title = $" {Tile!.Title} ";
 
             if (title.Length > spaceAbs)
             {
-                return title.Substring (0, spaceAbs);
+                return title!.Substring (0, spaceAbs);
             }
 
             return title;
@@ -864,7 +875,7 @@ public class TileView : View
     {
         public Point? moveRuneRenderLocation;
 
-        private Pos dragOrignalPos;
+        private Pos? dragOrignalPos;
         private Point? dragPosition;
 
         public TileViewLineView (TileView parent, int idx)
@@ -874,13 +885,13 @@ public class TileView : View
 
             Parent = parent;
             Idx = idx;
-            AddCommand (Command.Right, () => { return MoveSplitter (1, 0); });
+            AddCommand (Command.Right, () => MoveSplitter (1, 0));
 
-            AddCommand (Command.Left, () => { return MoveSplitter (-1, 0); });
+            AddCommand (Command.Left, () => MoveSplitter (-1, 0));
 
-            AddCommand (Command.Up, () => { return MoveSplitter (0, -1); });
+            AddCommand (Command.Up, () => MoveSplitter (0, -1));
 
-            AddCommand (Command.Down, () => { return MoveSplitter (0, 1); });
+            AddCommand (Command.Down, () => MoveSplitter (0, 1));
 
             KeyBindings.Add (Key.CursorRight, Command.Right);
             KeyBindings.Add (Key.CursorLeft, Command.Left);
@@ -960,7 +971,7 @@ public class TileView : View
 
                 //Driver.UncookMouse ();
                 FinalisePosition (
-                                  dragOrignalPos,
+                                  dragOrignalPos!,
                                   Orientation == Orientation.Horizontal ? Y : X
                                  );
                 dragPosition = null;
@@ -1087,4 +1098,4 @@ public class TileView : View
 }
 
 /// <summary>Represents a method that will handle splitter events.</summary>
-public delegate void SplitterEventHandler (object sender, SplitterEventArgs e);
+public delegate void SplitterEventHandler (object? sender, SplitterEventArgs e);

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

@@ -1177,7 +1177,7 @@ public class TreeView<T> : View, ITreeView where T : class
             {
                 // Else clear the line to prevent stale symbols due to scrolling etc
                 Move (0, line);
-                Driver?.SetAttribute (GetNormalColor ());
+                SetAttribute (GetNormalColor ());
                 Driver?.AddStr (new string (' ', Viewport.Width));
             }
         }

+ 9 - 9
UICatalog/Scenarios/CharacterMap.cs

@@ -693,7 +693,7 @@ internal class CharMap : View, IDesignable
         int cursorCol = Cursor.X + Viewport.X - RowLabelWidth - 1;
         int cursorRow = Cursor.Y + Viewport.Y - 1;
 
-        Driver.SetAttribute (GetHotNormalColor ());
+        SetAttribute (GetHotNormalColor ());
         Move (0, 0);
         Driver.AddStr (new (' ', RowLabelWidth + 1));
 
@@ -707,11 +707,11 @@ internal class CharMap : View, IDesignable
             if (x > RowLabelWidth - 2)
             {
                 Move (x, 0);
-                Driver.SetAttribute (GetHotNormalColor ());
+                SetAttribute (GetHotNormalColor ());
                 Driver.AddStr (" ");
-                Driver.SetAttribute (HasFocus && cursorCol + firstColumnX == x ? ColorScheme.HotFocus : GetHotNormalColor ());
+                SetAttribute (HasFocus && cursorCol + firstColumnX == x ? ColorScheme.HotFocus : GetHotNormalColor ());
                 Driver.AddStr ($"{hexDigit:x}");
-                Driver.SetAttribute (GetHotNormalColor ());
+                SetAttribute (GetHotNormalColor ());
                 Driver.AddStr (" ");
             }
         }
@@ -731,7 +731,7 @@ internal class CharMap : View, IDesignable
             }
 
             Move (firstColumnX + COLUMN_WIDTH, y);
-            Driver.SetAttribute (GetNormalColor ());
+            SetAttribute (GetNormalColor ());
 
             for (var col = 0; col < 16; col++)
             {
@@ -747,7 +747,7 @@ internal class CharMap : View, IDesignable
                 // If we're at the cursor position, and we don't have focus, invert the colors.
                 if (row == cursorRow && x == cursorCol && !HasFocus)
                 {
-                    Driver.SetAttribute (GetFocusColor ());
+                    SetAttribute (GetFocusColor ());
                 }
 
                 int scalar = val + col;
@@ -798,21 +798,21 @@ internal class CharMap : View, IDesignable
                 else
                 {
                     // Draw the width of the rune
-                    Driver.SetAttribute (ColorScheme.HotNormal);
+                    SetAttribute (ColorScheme.HotNormal);
                     Driver.AddStr ($"{width}");
                 }
 
                 // If we're at the cursor position, and we don't have focus, revert the colors to normal
                 if (row == cursorRow && x == cursorCol && !HasFocus)
                 {
-                    Driver.SetAttribute (GetNormalColor ());
+                    SetAttribute (GetNormalColor ());
                 }
             }
 
             // Draw row label (U+XXXX_)
             Move (0, y);
 
-            Driver.SetAttribute (HasFocus && y + Viewport.Y - 1 == cursorRow ? ColorScheme.HotFocus : ColorScheme.HotNormal);
+            SetAttribute (HasFocus && y + Viewport.Y - 1 == cursorRow ? ColorScheme.HotFocus : ColorScheme.HotNormal);
 
             if (!ShowGlyphWidths || (y + Viewport.Y) % _rowHeight > 0)
             {

+ 5 - 5
UICatalog/Scenarios/GraphViewExample.cs

@@ -1010,23 +1010,23 @@ public class GraphViewExample : Scenario
 
                 if (height >= 85)
                 {
-                    driver.SetAttribute (_red);
+                    graph.SetAttribute (_red);
                 }
                 else if (height >= 66)
                 {
-                    driver.SetAttribute (_brightred);
+                    graph.SetAttribute (_brightred);
                 }
                 else if (height >= 45)
                 {
-                    driver.SetAttribute (_brightyellow);
+                    graph.SetAttribute (_brightyellow);
                 }
                 else if (height >= 25)
                 {
-                    driver.SetAttribute (_brightgreen);
+                    graph.SetAttribute (_brightgreen);
                 }
                 else
                 {
-                    driver.SetAttribute (_green);
+                    graph.SetAttribute (_green);
                 }
 
                 graph.AddRune (x, y, beingDrawn.Fill.Rune);

+ 1 - 1
UICatalog/Scenarios/Images.cs

@@ -142,7 +142,7 @@ public class Images : Scenario
                                                                            )
                                                      );
 
-                    Driver.SetAttribute (attr);
+                    SetAttribute (attr);
                     AddRune (x, y, (Rune)' ');
                 }
             }

+ 3 - 3
UICatalog/Scenarios/LineDrawing.cs

@@ -276,7 +276,7 @@ public class DrawingArea : View
             {
                 if (c.Value is { })
                 {
-                    Driver?.SetAttribute (c.Value.Value.Attribute ?? ColorScheme.Normal);
+                    SetAttribute (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);
@@ -383,7 +383,7 @@ public class AttributeView : View
         bool isTransparentFg = fg == GetNormalColor ().Background;
         bool isTransparentBg = bg == GetNormalColor ().Background;
 
-        Driver?.SetAttribute (new (fg, isTransparentFg ? Color.Gray : fg));
+        SetAttribute (new (fg, isTransparentFg ? Color.Gray : fg));
 
         // Square of foreground color
         foreach ((int, int) point in ForegroundPoints)
@@ -405,7 +405,7 @@ public class AttributeView : View
             AddRune (point.Item1, point.Item2, rune);
         }
 
-        Driver?.SetAttribute (new (bg, isTransparentBg ? Color.Gray : bg));
+        SetAttribute (new (bg, isTransparentBg ? Color.Gray : bg));
 
         // Square of background color
         foreach ((int, int) point in BackgroundPoints)

+ 10 - 10
UICatalog/Scenarios/MultiColouredTable.cs

@@ -141,7 +141,7 @@ public class MultiColouredTable : Scenario
             {
                 if (unicorns != -1 && i >= unicorns && i <= unicorns + 8)
                 {
-                    Driver.SetAttribute (new (Color.White, cellColor.Background));
+                    SetAttribute (new (Color.White, cellColor.Background));
                 }
 
                 if (rainbows != -1 && i >= rainbows && i <= rainbows + 8)
@@ -151,11 +151,11 @@ public class MultiColouredTable : Scenario
                     switch (letterOfWord)
                     {
                         case 0:
-                            Driver.SetAttribute (new (Color.Red, cellColor.Background));
+                            SetAttribute (new (Color.Red, cellColor.Background));
 
                             break;
                         case 1:
-                            Driver.SetAttribute (
+                            SetAttribute (
                                                  new (
                                                       Color.BrightRed,
                                                       cellColor.Background
@@ -164,7 +164,7 @@ public class MultiColouredTable : Scenario
 
                             break;
                         case 2:
-                            Driver.SetAttribute (
+                            SetAttribute (
                                                  new (
                                                       Color.BrightYellow,
                                                       cellColor.Background
@@ -173,11 +173,11 @@ public class MultiColouredTable : Scenario
 
                             break;
                         case 3:
-                            Driver.SetAttribute (new (Color.Green, cellColor.Background));
+                            SetAttribute (new (Color.Green, cellColor.Background));
 
                             break;
                         case 4:
-                            Driver.SetAttribute (
+                            SetAttribute (
                                                  new (
                                                       Color.BrightGreen,
                                                       cellColor.Background
@@ -186,7 +186,7 @@ public class MultiColouredTable : Scenario
 
                             break;
                         case 5:
-                            Driver.SetAttribute (
+                            SetAttribute (
                                                  new (
                                                       Color.BrightBlue,
                                                       cellColor.Background
@@ -195,7 +195,7 @@ public class MultiColouredTable : Scenario
 
                             break;
                         case 6:
-                            Driver.SetAttribute (
+                            SetAttribute (
                                                  new (
                                                       Color.BrightCyan,
                                                       cellColor.Background
@@ -204,14 +204,14 @@ public class MultiColouredTable : Scenario
 
                             break;
                         case 7:
-                            Driver.SetAttribute (new (Color.Cyan, cellColor.Background));
+                            SetAttribute (new (Color.Cyan, cellColor.Background));
 
                             break;
                     }
                 }
 
                 Driver.AddRune ((Rune)render [i]);
-                Driver.SetAttribute (cellColor);
+                SetAttribute (cellColor);
             }
         }
     }

+ 3 - 3
UICatalog/Scenarios/Snake.cs

@@ -316,7 +316,7 @@ public class Snake : Scenario
 
         protected override bool OnDrawingContent (Rectangle viewport)
         {
-            Driver?.SetAttribute (white);
+            SetAttribute (white);
             ClearViewport ();
 
             var canvas = new LineCanvas ();
@@ -349,9 +349,9 @@ public class Snake : Scenario
                 AddRune (p.Key.X, p.Key.Y, p.Value);
             }
 
-            Driver?.SetAttribute (red);
+            SetAttribute (red);
             AddRune (State.Apple.X, State.Apple.Y, _appleRune);
-            Driver?.SetAttribute (white);
+            SetAttribute (white);
 
             return true;
         }

+ 2 - 2
UICatalog/Scenarios/TextEffectsScenario.cs

@@ -178,7 +178,7 @@ internal class GradientsView : View
 
         int width = text.Length;
         int x = xOffset + (GRADIENT_WIDTH - width) / 2; // Center the text within the gradient area width
-        Driver.SetAttribute (GetNormalColor ());
+        SetAttribute (GetNormalColor ());
         Move (x, yOffset + 1);
         Driver.AddStr (text);
     }
@@ -260,5 +260,5 @@ internal class GradientsView : View
         }
     }
 
-    private static void SetColor (Color color) { Application.Driver?.SetAttribute (new (color, color)); }
+    private void SetColor (Color color) { SetAttribute (new (color, color)); }
 }