From ce15aa2d0f62863d89cadde7622c6296e136c39d Mon Sep 17 00:00:00 2001 From: Tig Date: Thu, 4 Dec 2025 16:53:03 -0700 Subject: [PATCH] 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. --- Examples/UICatalog/Scenarios/Images.cs | 4 ++-- Examples/UICatalog/Scenarios/LineDrawing.cs | 9 +++----- Examples/UICatalog/Scenarios/Snake.cs | 2 +- .../Scenarios/TextEffectsScenario.cs | 2 +- Terminal.Gui/App/ApplicationImpl.Screen.cs | 2 +- Terminal.Gui/Drivers/IDriver.cs | 21 ++++++++----------- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/Examples/UICatalog/Scenarios/Images.cs b/Examples/UICatalog/Scenarios/Images.cs index 91803b817..5a5d2a7d7 100644 --- a/Examples/UICatalog/Scenarios/Images.cs +++ b/Examples/UICatalog/Scenarios/Images.cs @@ -631,7 +631,7 @@ public class Images : Scenario public Image FullResImage; private Image _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) { diff --git a/Examples/UICatalog/Scenarios/LineDrawing.cs b/Examples/UICatalog/Scenarios/LineDrawing.cs index 7e0335994..e8608c051 100644 --- a/Examples/UICatalog/Scenarios/LineDrawing.cs +++ b/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 } /// - protected override bool OnDrawingContent (DrawContext? context) + protected override bool OnDrawingContent (DrawContext context) { Color fg = Value.Foreground; Color bg = Value.Background; diff --git a/Examples/UICatalog/Scenarios/Snake.cs b/Examples/UICatalog/Scenarios/Snake.cs index 8632facda..c021cb795 100644 --- a/Examples/UICatalog/Scenarios/Snake.cs +++ b/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 (); diff --git a/Examples/UICatalog/Scenarios/TextEffectsScenario.cs b/Examples/UICatalog/Scenarios/TextEffectsScenario.cs index cf0745b86..c446bc035 100644 --- a/Examples/UICatalog/Scenarios/TextEffectsScenario.cs +++ b/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); diff --git a/Terminal.Gui/App/ApplicationImpl.Screen.cs b/Terminal.Gui/App/ApplicationImpl.Screen.cs index bbd43cf70..851c031dc 100644 --- a/Terminal.Gui/App/ApplicationImpl.Screen.cs +++ b/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); } } diff --git a/Terminal.Gui/Drivers/IDriver.cs b/Terminal.Gui/Drivers/IDriver.cs index 8616d8edf..5e677140d 100644 --- a/Terminal.Gui/Drivers/IDriver.cs +++ b/Terminal.Gui/Drivers/IDriver.cs @@ -1,4 +1,3 @@ - namespace Terminal.Gui.Drivers; /// Base interface for Terminal.Gui Driver implementations. @@ -31,19 +30,16 @@ public interface IDriver ISizeMonitor SizeMonitor { get; } /// Get the operating system clipboard. - /// IClipboard? Clipboard { get; } /// Gets the location and size of the terminal screen. Rectangle Screen { get; } /// - /// Sets the screen size for testing purposes. Only supported by FakeDriver. - /// is the source of truth for screen dimensions. + /// Sets the screen size. is the source of truth for screen dimensions. /// /// The new width in columns. /// The new height in rows. - /// Thrown when called on non-FakeDriver instances. void SetScreenSize (int width, int height); /// @@ -53,7 +49,6 @@ public interface IDriver /// The rectangle describing the of region. Region? Clip { get; set; } - /// /// Gets the column last set by . and are used by /// and to determine where to add content. @@ -101,7 +96,8 @@ public interface IDriver bool Force16Colors { get; set; } /// - /// The that will be used for the next or + /// The that will be used for the next or + /// /// call. /// Attribute CurrentAttribute { get; set; } @@ -218,13 +214,15 @@ public interface IDriver /// void FillRect (Rectangle rect, char c); - /// Gets the terminal cursor visibility. /// The current /// upon success bool GetCursorVisibility (out CursorVisibility visibility); - /// Updates the screen to reflect all the changes that have been done to the display buffer + /// + /// INTERNAL: Updates the terminal with the current output buffer. Should not be used by applications. Drawing occurs + /// once each Application main loop iteration. + /// void Refresh (); /// Sets the terminal cursor visibility. @@ -233,8 +231,8 @@ public interface IDriver bool SetCursorVisibility (CursorVisibility visibility); /// - /// The event fired when the screen changes (size, position, etc.). - /// is the source of truth for screen dimensions. + /// The event fired when the screen changes (size, position, etc.). + /// is the source of truth for screen dimensions. /// event EventHandler? SizeChanged; @@ -295,7 +293,6 @@ public interface IDriver /// public AnsiRequestScheduler GetRequestScheduler (); - /// /// Gets a string representation of . ///