Selaa lähdekoodia

Updated the `OnDrawingContent` method across multiple classes to accept a `DrawContext? context` parameter, replacing the parameterless version. This change standardizes the drawing API and enables context-aware drawing operations.

The refactor includes:
- Modifying method signatures in classes like `AnimationScenario`, `Images`, `DrawingArea`, `AttributeView`, `Snake`, and others.
- Removing the parameterless `OnDrawingContent` method from the `View` class.
- Updating calls to the base class implementation to pass the `context` parameter.
- Adjusting comments and documentation to reflect the new method signature.

This change ensures consistency and prepares the codebase for more advanced drawing capabilities.
Tig 1 viikko sitten
vanhempi
sitoutus
e192b5622d
30 muutettua tiedostoa jossa 33 lisäystä ja 47 poistoa
  1. 1 1
      Examples/UICatalog/Scenarios/AnimationScenario/AnimationScenario.cs
  2. 2 2
      Examples/UICatalog/Scenarios/Images.cs
  3. 2 2
      Examples/UICatalog/Scenarios/LineDrawing.cs
  4. 1 1
      Examples/UICatalog/Scenarios/RegionScenario.cs
  5. 1 1
      Examples/UICatalog/Scenarios/Snake.cs
  6. 1 1
      Examples/UICatalog/Scenarios/TextEffectsScenario.cs
  7. 1 3
      Terminal.Gui/ViewBase/Adornment/Border.cs
  8. 1 1
      Terminal.Gui/ViewBase/Adornment/ShadowView.cs
  9. 0 12
      Terminal.Gui/ViewBase/View.Drawing.cs
  10. 1 1
      Terminal.Gui/Views/Autocomplete/PopupAutocomplete.PopUp.cs
  11. 1 1
      Terminal.Gui/Views/CharMap/CharMap.cs
  12. 1 1
      Terminal.Gui/Views/Color/ColorBar.cs
  13. 1 1
      Terminal.Gui/Views/Color/ColorPicker.16.cs
  14. 1 1
      Terminal.Gui/Views/Color/ColorPicker.cs
  15. 2 2
      Terminal.Gui/Views/ComboBox.cs
  16. 1 1
      Terminal.Gui/Views/FileDialogs/FileDialog.cs
  17. 1 1
      Terminal.Gui/Views/GraphView/GraphView.cs
  18. 1 1
      Terminal.Gui/Views/HexView.cs
  19. 1 1
      Terminal.Gui/Views/Line.cs
  20. 2 2
      Terminal.Gui/Views/ListView.cs
  21. 1 1
      Terminal.Gui/Views/ProgressBar.cs
  22. 1 1
      Terminal.Gui/Views/Slider/Slider.cs
  23. 1 1
      Terminal.Gui/Views/SpinnerView/SpinnerView.cs
  24. 1 1
      Terminal.Gui/Views/TableView/TableView.cs
  25. 1 1
      Terminal.Gui/Views/TextInput/TextField.cs
  26. 1 1
      Terminal.Gui/Views/TextInput/TextValidateField.cs
  27. 1 1
      Terminal.Gui/Views/TextInput/TextView.cs
  28. 1 1
      Terminal.Gui/Views/TreeView/TreeView.cs
  29. 1 1
      Tests/UnitTests/View/Draw/DrawTests.cs
  30. 1 1
      Tests/UnitTestsParallelizable/ViewBase/Adornment/AdornmentTests.cs

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

@@ -173,7 +173,7 @@ public class AnimationScenario : Scenario
         private Rectangle _oldSize = Rectangle.Empty;
         public void NextFrame () { _currentFrame = (_currentFrame + 1) % _frameCount; }
 
-        protected override bool OnDrawingContent ()
+        protected override bool OnDrawingContent (DrawContext? context)
         {
             if (_frameCount == 0)
             {

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

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

@@ -273,7 +273,7 @@ public class DrawingArea : View
     public ITool CurrentTool { get; set; } = new DrawLineTool ();
     public DrawingArea () { AddLayer (); }
 
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         foreach (LineCanvas canvas in Layers)
         {
@@ -380,7 +380,7 @@ public class AttributeView : View
     }
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         Color fg = Value.Foreground;
         Color bg = Value.Background;

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

@@ -268,7 +268,7 @@ public class AttributeView : View
     }
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         Color fg = Value?.Foreground ?? Color.Black;
         Color bg = Value?.Background ?? Color.Black;

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

@@ -322,7 +322,7 @@ public class Snake : Scenario
 
         private SnakeState State { get; }
 
-        protected override bool OnDrawingContent ()
+        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 ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         DrawTopLineGradient (Viewport);
 

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

@@ -241,7 +241,7 @@ public partial class Border : Adornment
 
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         if (Thickness == Thickness.Empty)
         {
@@ -539,8 +539,6 @@ public partial class Border : Adornment
         }
 
         return true;
-
-        ;
     }
 
     /// <summary>

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

@@ -20,7 +20,7 @@ internal class ShadowView : View
     }
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         switch (ShadowStyle)
         {

+ 0 - 12
Terminal.Gui/ViewBase/View.Drawing.cs

@@ -504,12 +504,6 @@ public partial class View // Drawing APIs
             return;
         }
 
-        // TODO: Upgrade all overrides of OnDrawingContent to use DrawContext and remove this override
-        if (OnDrawingContent ())
-        {
-            return;
-        }
-
         var dev = new DrawEventArgs (Viewport, Rectangle.Empty, context);
         DrawingContent?.Invoke (this, dev);
 
@@ -528,12 +522,6 @@ public partial class View // Drawing APIs
     /// <returns><see langword="true"/> to stop further drawing content.</returns>
     protected virtual bool OnDrawingContent (DrawContext? context) { return false; }
 
-    /// <summary>
-    ///     Called when the View's content is to be drawn. The default implementation does nothing.
-    /// </summary>
-    /// <returns><see langword="true"/> to stop further drawing content.</returns>
-    protected virtual bool OnDrawingContent () { return false; }
-
     /// <summary>Raised when the View's content is to be drawn.</summary>
     /// <remarks>
     ///     <para>Will be invoked before any subviews added with <see cref="Add(View)"/> have been drawn.</para>

+ 1 - 1
Terminal.Gui/Views/Autocomplete/PopupAutocomplete.PopUp.cs

@@ -15,7 +15,7 @@ public abstract partial class PopupAutocomplete
 
         private readonly PopupAutocomplete _autoComplete;
 
-        protected override bool OnDrawingContent ()
+        protected override bool OnDrawingContent (DrawContext? context)
         {
             if (!_autoComplete.LastPopupPos.HasValue)
             {

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

@@ -580,7 +580,7 @@ public class CharMap : View, IDesignable
     private static int RowLabelWidth => $"U+{MAX_CODE_POINT:x5}".Length + 1;
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         if (Viewport.Height == 0 || Viewport.Width == 0)
         {

+ 1 - 1
Terminal.Gui/Views/Color/ColorBar.cs

@@ -101,7 +101,7 @@ internal abstract class ColorBar : View, IColorBar
     }
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         if (!string.IsNullOrWhiteSpace (Text))
         {

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

@@ -132,7 +132,7 @@ public class ColorPicker16 : View
     }
 
     ///<inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         SetAttribute (HasFocus ? GetAttributeForRole (VisualRole.Focus) : GetAttributeForRole (VisualRole.Normal));
         var colorIndex = 0;

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

@@ -99,7 +99,7 @@ public partial class ColorPicker : View, IDesignable
     public event EventHandler<ResultEventArgs<Color>>? ColorChanged;
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         Attribute normal = GetAttributeForRole (VisualRole.Normal);
         SetAttribute (new (SelectedColor, normal.Background, Enabled ? TextStyle.None : TextStyle.Faint));

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

@@ -287,7 +287,7 @@ public class ComboBox : View, IDesignable
     public virtual void OnCollapsed () { Collapsed?.Invoke (this, EventArgs.Empty); }
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
 
         if (!_autoHide)
@@ -881,7 +881,7 @@ public class ComboBox : View, IDesignable
             return res;
         }
 
-        protected override bool OnDrawingContent ()
+        protected override bool OnDrawingContent (DrawContext? context)
         {
             Attribute current = GetAttributeForRole (VisualRole.Focus);
             SetAttribute (current);

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

@@ -409,7 +409,7 @@ public class FileDialog : Dialog, IDesignable
     }
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         if (!string.IsNullOrWhiteSpace (_feedback))
         {

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

@@ -198,7 +198,7 @@ public class GraphView : View, IDesignable
     }
 
     ///<inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         if (CellSize.X == 0 || CellSize.Y == 0)
         {

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

@@ -431,7 +431,7 @@ public class HexView : View, IDesignable
     }
 
     ///<inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         if (Source is null)
         {

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

@@ -217,7 +217,7 @@ public class Line : View, IOrientation
     ///     This method adds the line to the LineCanvas for rendering.
     ///     The actual rendering is performed by the parent view through <see cref="View.RenderLineCanvas"/>.
     /// </remarks>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         Point pos = ViewportToScreen (Viewport).Location;
         int length = Orientation == Orientation.Horizontal ? Frame.Width : Frame.Height;

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

@@ -721,11 +721,11 @@ public class ListView : View, IDesignable
     protected virtual void OnCollectionChanged (NotifyCollectionChangedEventArgs e) { CollectionChanged?.Invoke (this, e); }
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         if (Source is null)
         {
-            return base.OnDrawingContent ();
+            return base.OnDrawingContent (context);
         }
 
         var current = Attribute.Default;

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

@@ -132,7 +132,7 @@ public class ProgressBar : View, IDesignable
     }
 
     ///<inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         SetAttribute (GetAttributeForRole (VisualRole.Active));
 

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

@@ -779,7 +779,7 @@ public class Slider<T> : View, IOrientation
     #region Drawing
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         // TODO: make this more surgical to reduce repaint
 

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

@@ -172,7 +172,7 @@ public class SpinnerView : View, IDesignable
     protected override bool OnClearingViewport () { return true; }
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         Render ();
 

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

@@ -931,7 +931,7 @@ public class TableView : View, IDesignable
     }
 
     ///<inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         Move (0, 0);
 

+ 1 - 1
Terminal.Gui/Views/TextInput/TextField.cs

@@ -922,7 +922,7 @@ public class TextField : View, IDesignable
     }
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         _isDrawing = true;
 

+ 1 - 1
Terminal.Gui/Views/TextInput/TextValidateField.cs

@@ -172,7 +172,7 @@ public class TextValidateField : View, IDesignable
     }
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         if (_provider is null)
         {

+ 1 - 1
Terminal.Gui/Views/TextInput/TextView.cs

@@ -1781,7 +1781,7 @@ public class TextView : View, IDesignable
     }
 
     /// <inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         _isDrawing = true;
 

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

@@ -1148,7 +1148,7 @@ public class TreeView<T> : View, ITreeView where T : class
     public event EventHandler<ObjectActivatedEventArgs<T>> ObjectActivated;
 
     ///<inheritdoc/>
-    protected override bool OnDrawingContent ()
+    protected override bool OnDrawingContent (DrawContext? context)
     {
         if (roots is null)
         {

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

@@ -906,7 +906,7 @@ At 0,0
         public bool IsKeyUp { get; set; }
         public override string Text { get; set; } = null!;
 
-        protected override bool OnDrawingContent ()
+        protected override bool OnDrawingContent (DrawContext? context)
         {
             var idx = 0;
 

+ 1 - 1
Tests/UnitTestsParallelizable/ViewBase/Adornment/AdornmentTests.cs

@@ -10,7 +10,7 @@ public class AdornmentTests
     //    public bool PaddingDrawn { get; set; }
 
     //    /// <inheritdoc />
-    //    protected override bool OnDrawingContent () 
+    //    protected override bool OnDrawingContent (DrawContext? context) 
     //    {
     //        if (Border is { } && Border.Thickness != Thickness.Empty)
     //        {