Browse Source

Updated `OnDrawingContent` methods across multiple classes to use non-nullable `DrawContext` parameters, improving type safety.

Refactored `IDriver` interface:
- Updated `SetScreenSize` to remove `NotSupportedException`.
- Clarified `Refresh` method as internal and updated documentation for `SizeChanged` event.
Tig 1 week ago
parent
commit
ce15aa2d0f

+ 2 - 2
Examples/UICatalog/Scenarios/Images.cs

@@ -631,7 +631,7 @@ public class Images : Scenario
         public Image<Rgba32> FullResImage;
         private Image<Rgba32> _matchSize;
 
-        protected override bool OnDrawingContent (DrawContext? context)
+        protected override bool OnDrawingContent (DrawContext context)
         {
             if (FullResImage == null)
             {
@@ -708,7 +708,7 @@ public class Images : Scenario
             return (columns, rows);
         }
 
-        protected override bool OnDrawingContent (DrawContext? context)
+        protected override bool OnDrawingContent (DrawContext context)
         {
             if (_palette == null || _palette.Count == 0)
             {

+ 3 - 6
Examples/UICatalog/Scenarios/LineDrawing.cs

@@ -1,7 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using System.Text;
 
 namespace UICatalog.Scenarios;
 
@@ -273,7 +270,7 @@ public class DrawingArea : View
     public ITool CurrentTool { get; set; } = new DrawLineTool ();
     public DrawingArea () { AddLayer (); }
 
-    protected override bool OnDrawingContent (DrawContext? context)
+    protected override bool OnDrawingContent (DrawContext context)
     {
         foreach (LineCanvas canvas in Layers)
         {
@@ -380,7 +377,7 @@ public class AttributeView : View
     }
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent (DrawContext? context)
+    protected override bool OnDrawingContent (DrawContext context)
     {
         Color fg = Value.Foreground;
         Color bg = Value.Background;

+ 1 - 1
Examples/UICatalog/Scenarios/Snake.cs

@@ -322,7 +322,7 @@ public class Snake : Scenario
 
         private SnakeState State { get; }
 
-        protected override bool OnDrawingContent (DrawContext? context)
+        protected override bool OnDrawingContent (DrawContext context)
         {
             SetAttribute (white);
             ClearViewport ();

+ 1 - 1
Examples/UICatalog/Scenarios/TextEffectsScenario.cs

@@ -109,7 +109,7 @@ internal class GradientsView : View
     private const int LABEL_HEIGHT = 1;
     private const int GRADIENT_WITH_LABEL_HEIGHT = GRADIENT_HEIGHT + LABEL_HEIGHT + 1; // +1 for spacing
 
-    protected override bool OnDrawingContent (DrawContext? context)
+    protected override bool OnDrawingContent (DrawContext context)
     {
         DrawTopLineGradient (Viewport);
 

+ 1 - 1
Terminal.Gui/App/ApplicationImpl.Screen.cs

@@ -16,7 +16,7 @@ internal partial class ApplicationImpl
                 throw new NotImplementedException ("Screen locations other than 0, 0 are not yet supported");
             }
 
-            Driver?.SetScreenSize (value.Size.Width, value.Size.Height);
+            Driver?.SetScreenSize (value.Width, value.Height);
         }
     }
 

+ 9 - 12
Terminal.Gui/Drivers/IDriver.cs

@@ -1,4 +1,3 @@
-
 namespace Terminal.Gui.Drivers;
 
 /// <summary>Base interface for Terminal.Gui Driver implementations.</summary>
@@ -31,19 +30,16 @@ public interface IDriver
     ISizeMonitor SizeMonitor { get; }
 
     /// <summary>Get the operating system clipboard.</summary>
-    /// 
     IClipboard? Clipboard { get; }
 
     /// <summary>Gets the location and size of the terminal screen.</summary>
     Rectangle Screen { get; }
 
     /// <summary>
-    /// Sets the screen size for testing purposes. Only supported by FakeDriver.
-    /// <see cref="Screen"/> is the source of truth for screen dimensions.
+    ///     Sets the screen size. <see cref="Screen"/> is the source of truth for screen dimensions.
     /// </summary>
     /// <param name="width">The new width in columns.</param>
     /// <param name="height">The new height in rows.</param>
-    /// <exception cref="NotSupportedException">Thrown when called on non-FakeDriver instances.</exception>
     void SetScreenSize (int width, int height);
 
     /// <summary>
@@ -53,7 +49,6 @@ public interface IDriver
     /// <value>The rectangle describing the of <see cref="Clip"/> region.</value>
     Region? Clip { get; set; }
 
-
     /// <summary>
     ///     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.
@@ -101,7 +96,8 @@ public interface IDriver
     bool Force16Colors { get; set; }
 
     /// <summary>
-    ///     The <see cref="System.Attribute"/> that will be used for the next <see cref="AddRune(Rune)"/> or <see cref="AddStr"/>
+    ///     The <see cref="System.Attribute"/> that will be used for the next <see cref="AddRune(Rune)"/> or
+    ///     <see cref="AddStr"/>
     ///     call.
     /// </summary>
     Attribute CurrentAttribute { get; set; }
@@ -218,13 +214,15 @@ public interface IDriver
     /// <param name="c"></param>
     void FillRect (Rectangle rect, char c);
 
-
     /// <summary>Gets the terminal cursor visibility.</summary>
     /// <param name="visibility">The current <see cref="CursorVisibility"/></param>
     /// <returns><see langword="true"/> upon success</returns>
     bool GetCursorVisibility (out CursorVisibility visibility);
 
-    /// <summary>Updates the screen to reflect all the changes that have been done to the display buffer</summary>
+    /// <summary>
+    ///     INTERNAL: Updates the terminal with the current output buffer. Should not be used by applications. Drawing occurs
+    ///     once each Application main loop iteration.
+    /// </summary>
     void Refresh ();
 
     /// <summary>Sets the terminal cursor visibility.</summary>
@@ -233,8 +231,8 @@ public interface IDriver
     bool SetCursorVisibility (CursorVisibility visibility);
 
     /// <summary>
-    /// The event fired when the screen changes (size, position, etc.).
-    /// <see cref="Screen"/> is the source of truth for screen dimensions.
+    ///     The event fired when the screen changes (size, position, etc.).
+    ///     <see cref="Screen"/> is the source of truth for screen dimensions.
     /// </summary>
     event EventHandler<SizeChangedEventArgs>? SizeChanged;
 
@@ -295,7 +293,6 @@ public interface IDriver
     /// <returns></returns>
     public AnsiRequestScheduler GetRequestScheduler ();
 
-
     /// <summary>
     ///     Gets a string representation of <see cref="Contents"/>.
     /// </summary>