Bladeren bron

Made more Driver APIs internal

Tig 9 maanden geleden
bovenliggende
commit
947914b53d

+ 10 - 9
Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs

@@ -30,7 +30,7 @@ public abstract class ConsoleDriver
     ///     to.
     ///     to.
     /// </summary>
     /// </summary>
     /// <value>The rectangle describing the of <see cref="Clip"/> region.</value>
     /// <value>The rectangle describing the of <see cref="Clip"/> region.</value>
-    public Region? Clip
+    internal Region? Clip
     {
     {
         get => _clip;
         get => _clip;
         set
         set
@@ -312,7 +312,7 @@ public abstract class ConsoleDriver
     ///     <para>If <paramref name="str"/> requires more columns than are available, the output will be clipped.</para>
     ///     <para>If <paramref name="str"/> requires more columns than are available, the output will be clipped.</para>
     /// </remarks>
     /// </remarks>
     /// <param name="str">String.</param>
     /// <param name="str">String.</param>
-    public void AddStr (string str)
+    internal void AddStr (string str)
     {
     {
         List<Rune> runes = str.EnumerateRunes ().ToList ();
         List<Rune> runes = str.EnumerateRunes ().ToList ();
 
 
@@ -323,7 +323,7 @@ public abstract class ConsoleDriver
     }
     }
 
 
     /// <summary>Clears the <see cref="Contents"/> of the driver.</summary>
     /// <summary>Clears the <see cref="Contents"/> of the driver.</summary>
-    public void ClearContents ()
+    internal void ClearContents ()
     {
     {
         Contents = new Cell [Rows, Cols];
         Contents = new Cell [Rows, Cols];
 
 
@@ -362,7 +362,7 @@ public abstract class ConsoleDriver
     /// Sets <see cref="Contents"/> as dirty for situations where views
     /// Sets <see cref="Contents"/> as dirty for situations where views
     /// don't need layout and redrawing, but just refresh the screen.
     /// don't need layout and redrawing, but just refresh the screen.
     /// </summary>
     /// </summary>
-    public void SetContentsAsDirty ()
+    internal void SetContentsAsDirty ()
     {
     {
         lock (Contents!)
         lock (Contents!)
         {
         {
@@ -387,7 +387,7 @@ public abstract class ConsoleDriver
     /// </remarks>
     /// </remarks>
     /// <param name="rect">The Screen-relative rectangle.</param>
     /// <param name="rect">The Screen-relative rectangle.</param>
     /// <param name="rune">The Rune used to fill the rectangle</param>
     /// <param name="rune">The Rune used to fill the rectangle</param>
-    public void FillRect (Rectangle rect, Rune rune = default)
+    internal void FillRect (Rectangle rect, Rune rune = default)
     {
     {
         // BUGBUG: This should be a method on Region
         // BUGBUG: This should be a method on Region
         rect = Rectangle.Intersect (rect, Clip?.GetBounds () ?? Screen);
         rect = Rectangle.Intersect (rect, Clip?.GetBounds () ?? Screen);
@@ -418,7 +418,7 @@ public abstract class ConsoleDriver
     /// </summary>
     /// </summary>
     /// <param name="rect"></param>
     /// <param name="rect"></param>
     /// <param name="c"></param>
     /// <param name="c"></param>
-    public void FillRect (Rectangle rect, char c) { FillRect (rect, new Rune (c)); }
+    internal void FillRect (Rectangle rect, char c) { FillRect (rect, new Rune (c)); }
 
 
     /// <summary>Gets the terminal cursor visibility.</summary>
     /// <summary>Gets the terminal cursor visibility.</summary>
     /// <param name="visibility">The current <see cref="CursorVisibility"/></param>
     /// <param name="visibility">The current <see cref="CursorVisibility"/></param>
@@ -445,7 +445,7 @@ public abstract class ConsoleDriver
     ///     <see langword="false"/> if the coordinate is outside the screen bounds or outside of <see cref="Clip"/>.
     ///     <see langword="false"/> if the coordinate is outside the screen bounds or outside of <see cref="Clip"/>.
     ///     <see langword="true"/> otherwise.
     ///     <see langword="true"/> otherwise.
     /// </returns>
     /// </returns>
-    public bool IsValidLocation (Rune rune, int col, int row)
+    internal bool IsValidLocation (Rune rune, int col, int row)
     {
     {
         if (rune.GetColumns () < 2)
         if (rune.GetColumns () < 2)
         {
         {
@@ -458,6 +458,7 @@ public abstract class ConsoleDriver
         }
         }
     }
     }
 
 
+    // TODO: Make internal once Menu is upgraded
     /// <summary>
     /// <summary>
     ///     Updates <see cref="Col"/> and <see cref="Row"/> to the specified column and row in <see cref="Contents"/>.
     ///     Updates <see cref="Col"/> and <see cref="Row"/> to the specified column and row in <see cref="Contents"/>.
     ///     Used by <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content.
     ///     Used by <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content.
@@ -480,10 +481,10 @@ public abstract class ConsoleDriver
 
 
     /// <summary>Called when the terminal size changes. Fires the <see cref="SizeChanged"/> event.</summary>
     /// <summary>Called when the terminal size changes. Fires the <see cref="SizeChanged"/> event.</summary>
     /// <param name="args"></param>
     /// <param name="args"></param>
-    public void OnSizeChanged (SizeChangedEventArgs args) { SizeChanged?.Invoke (this, args); }
+    internal void OnSizeChanged (SizeChangedEventArgs args) { SizeChanged?.Invoke (this, args); }
 
 
     /// <summary>Updates the screen to reflect all the changes that have been done to the display buffer</summary>
     /// <summary>Updates the screen to reflect all the changes that have been done to the display buffer</summary>
-    public void Refresh ()
+    internal void Refresh ()
     {
     {
         bool updated = UpdateScreen ();
         bool updated = UpdateScreen ();
         UpdateCursor ();
         UpdateCursor ();

+ 16 - 0
Terminal.Gui/View/View.Drawing.Primitives.cs

@@ -154,4 +154,20 @@ public partial class View
         SetClip (prevClip);
         SetClip (prevClip);
     }
     }
 
 
+    /// <summary>Fills the specified <see cref="Viewport"/>-relative rectangle.</summary>
+    /// <param name="rect">The Viewport-relative rectangle to clear.</param>
+    /// <param name="rune">The Rune to fill with.</param>
+    public void FillRect (Rectangle rect, Rune rune)
+    {
+        if (Driver is null)
+        {
+            return;
+        }
+
+        Region prevClip = ClipViewport ();
+        Rectangle toClear = ViewportToScreen (rect);
+        Driver.FillRect (toClear, rune);
+        SetClip (prevClip);
+    }
+
 }
 }

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

@@ -32,7 +32,7 @@ public interface IListDataSource : IDisposable
 
 
     /// <summary>This method is invoked to render a specified item, the method should cover the entire provided width.</summary>
     /// <summary>This method is invoked to render a specified item, the method should cover the entire provided width.</summary>
     /// <returns>The render.</returns>
     /// <returns>The render.</returns>
-    /// <param name="container">The list view to render.</param>
+    /// <param name="listView">The list view to render.</param>
     /// <param name="selected">Describes whether the item being rendered is currently selected by the user.</param>
     /// <param name="selected">Describes whether the item being rendered is currently selected by the user.</param>
     /// <param name="item">The index of the item to render, zero for the first item and so on.</param>
     /// <param name="item">The index of the item to render, zero for the first item and so on.</param>
     /// <param name="col">The column where the rendering will start</param>
     /// <param name="col">The column where the rendering will start</param>
@@ -44,7 +44,7 @@ public interface IListDataSource : IDisposable
     ///     or not.
     ///     or not.
     /// </remarks>
     /// </remarks>
     void Render (
     void Render (
-        ListView container,
+        ListView listView,
         bool selected,
         bool selected,
         int item,
         int item,
         int col,
         int col,

+ 7 - 10
Terminal.Gui/Views/Menu/Menu.cs

@@ -436,9 +436,7 @@ internal sealed class Menu : View
 
 
             if (item is null && BorderStyle != LineStyle.None)
             if (item is null && BorderStyle != LineStyle.None)
             {
             {
-                Point s = ViewportToScreen (new Point (-1, i));
-                Driver.Move (s.X, s.Y);
-                Driver.AddRune (Glyphs.LeftTee);
+                AddRune (-1, i, Glyphs.LeftTee);
             }
             }
             else if (Frame.X < Driver.Cols)
             else if (Frame.X < Driver.Cols)
             {
             {
@@ -462,21 +460,21 @@ internal sealed class Menu : View
 
 
                 if (item is null)
                 if (item is null)
                 {
                 {
-                    Driver.AddRune (Glyphs.HLine);
+                    AddRune (Glyphs.HLine);
                 }
                 }
                 else if (i == 0 && p == 0 && _host.UseSubMenusSingleFrame && item.Parent!.Parent is { })
                 else if (i == 0 && p == 0 && _host.UseSubMenusSingleFrame && item.Parent!.Parent is { })
                 {
                 {
-                    Driver.AddRune (Glyphs.LeftArrow);
+                    AddRune (Glyphs.LeftArrow);
                 }
                 }
 
 
                 // This `- 3` is left border + right border + one row in from right
                 // This `- 3` is left border + right border + one row in from right
                 else if (p == Frame.Width - 3 && _barItems?.SubMenu (_barItems.Children [i]!) is { })
                 else if (p == Frame.Width - 3 && _barItems?.SubMenu (_barItems.Children [i]!) is { })
                 {
                 {
-                    Driver.AddRune (Glyphs.RightArrow);
+                    AddRune (Glyphs.RightArrow);
                 }
                 }
                 else
                 else
                 {
                 {
-                    Driver.AddRune ((Rune)' ');
+                    AddRune ((Rune)' ');
                 }
                 }
             }
             }
 
 
@@ -484,9 +482,7 @@ internal sealed class Menu : View
             {
             {
                 if (BorderStyle != LineStyle.None && SuperView?.Frame.Right - Frame.X > Frame.Width)
                 if (BorderStyle != LineStyle.None && SuperView?.Frame.Right - Frame.X > Frame.Width)
                 {
                 {
-                    Point s = ViewportToScreen (new Point (Frame.Width - 2, i));
-                    Driver.Move (s.X, s.Y);
-                    Driver.AddRune (Glyphs.RightTee);
+                    AddRune (Frame.Width - 2, i, Glyphs.RightTee);
                 }
                 }
 
 
                 continue;
                 continue;
@@ -572,6 +568,7 @@ internal sealed class Menu : View
                     // The shortcut tag string
                     // The shortcut tag string
                     if (!string.IsNullOrEmpty (item.ShortcutTag))
                     if (!string.IsNullOrEmpty (item.ShortcutTag))
                     {
                     {
+
                         Driver.Move (screen.X + l - item.ShortcutTag.GetColumns (), screen.Y);
                         Driver.Move (screen.X + l - item.ShortcutTag.GetColumns (), screen.Y);
                         Driver.AddStr (item.ShortcutTag);
                         Driver.AddStr (item.ShortcutTag);
                     }
                     }

+ 1 - 1
UICatalog/Scenarios/AdvancedClipping.cs

@@ -22,7 +22,7 @@ public class AdvancedClipping : Scenario
 
 
         app.DrawingContent += (s, e) =>
         app.DrawingContent += (s, e) =>
                            {
                            {
-                               Application.Driver?.FillRect (app.ViewportToScreen (app.Viewport), CM.Glyphs.Dot);
+                               app!.FillRect (app!.Viewport, CM.Glyphs.Dot);
                                e.Cancel = true;
                                e.Cancel = true;
                            };
                            };
 
 

+ 7 - 7
UICatalog/Scenarios/CharacterMap.cs

@@ -695,7 +695,7 @@ internal class CharMap : View, IDesignable
 
 
         SetAttribute (GetHotNormalColor ());
         SetAttribute (GetHotNormalColor ());
         Move (0, 0);
         Move (0, 0);
-        Driver.AddStr (new (' ', RowLabelWidth + 1));
+        AddStr (new (' ', RowLabelWidth + 1));
 
 
         int firstColumnX = RowLabelWidth - Viewport.X;
         int firstColumnX = RowLabelWidth - Viewport.X;
 
 
@@ -708,11 +708,11 @@ internal class CharMap : View, IDesignable
             {
             {
                 Move (x, 0);
                 Move (x, 0);
                 SetAttribute (GetHotNormalColor ());
                 SetAttribute (GetHotNormalColor ());
-                Driver.AddStr (" ");
+                AddStr (" ");
                 SetAttribute (HasFocus && cursorCol + firstColumnX == x ? ColorScheme.HotFocus : GetHotNormalColor ());
                 SetAttribute (HasFocus && cursorCol + firstColumnX == x ? ColorScheme.HotFocus : GetHotNormalColor ());
-                Driver.AddStr ($"{hexDigit:x}");
+                AddStr ($"{hexDigit:x}");
                 SetAttribute (GetHotNormalColor ());
                 SetAttribute (GetHotNormalColor ());
-                Driver.AddStr (" ");
+                AddStr (" ");
             }
             }
         }
         }
 
 
@@ -799,7 +799,7 @@ internal class CharMap : View, IDesignable
                 {
                 {
                     // Draw the width of the rune
                     // Draw the width of the rune
                     SetAttribute (ColorScheme.HotNormal);
                     SetAttribute (ColorScheme.HotNormal);
-                    Driver.AddStr ($"{width}");
+                    AddStr ($"{width}");
                 }
                 }
 
 
                 // If we're at the cursor position, and we don't have focus, revert the colors to normal
                 // If we're at the cursor position, and we don't have focus, revert the colors to normal
@@ -816,11 +816,11 @@ internal class CharMap : View, IDesignable
 
 
             if (!ShowGlyphWidths || (y + Viewport.Y) % _rowHeight > 0)
             if (!ShowGlyphWidths || (y + Viewport.Y) % _rowHeight > 0)
             {
             {
-                Driver.AddStr ($"U+{val / 16:x5}_ ");
+                AddStr ($"U+{val / 16:x5}_ ");
             }
             }
             else
             else
             {
             {
-                Driver.AddStr (new (' ', RowLabelWidth));
+                AddStr (new (' ', RowLabelWidth));
             }
             }
         }
         }
 
 

+ 1 - 1
UICatalog/Scenarios/ShadowStyles.cs

@@ -45,7 +45,7 @@ public class ShadowStyles : Scenario
 
 
         app.DrawingContent += (s, e) =>
         app.DrawingContent += (s, e) =>
                            {
                            {
-                               Application.Driver?.FillRect (app.ViewportToScreen (app.Viewport), CM.Glyphs.Dot);
+                               app!.FillRect (app!.Viewport, CM.Glyphs.Dot);
                                e.Cancel = true;
                                e.Cancel = true;
                            };
                            };
 
 

+ 1 - 1
UICatalog/Scenarios/SimpleDialog.cs

@@ -21,7 +21,7 @@ public sealed class SimpleDialog : Scenario
 
 
         appWindow.DrawingText += (s, e) =>
         appWindow.DrawingText += (s, e) =>
                                  {
                                  {
-                                     Application.Driver?.FillRect (appWindow.ViewportToScreen (appWindow.Viewport), '*');
+                                     appWindow!.FillRect (appWindow!.Viewport, CM.Glyphs.Dot);
                                      e.Cancel = true;
                                      e.Cancel = true;
                                  };
                                  };
 
 

+ 1 - 1
UICatalog/Scenarios/TextEffectsScenario.cs

@@ -180,7 +180,7 @@ internal class GradientsView : View
         int x = xOffset + (GRADIENT_WIDTH - width) / 2; // Center the text within the gradient area width
         int x = xOffset + (GRADIENT_WIDTH - width) / 2; // Center the text within the gradient area width
         SetAttribute (GetNormalColor ());
         SetAttribute (GetNormalColor ());
         Move (x, yOffset + 1);
         Move (x, yOffset + 1);
-        Driver.AddStr (text);
+        AddStr (text);
     }
     }
 
 
     private void DrawGradientArea (GradientDirection direction, int xOffset, int yOffset)
     private void DrawGradientArea (GradientDirection direction, int xOffset, int yOffset)