Skip to content

Commit 947914b

Browse files
committed
Made more Driver APIs internal
1 parent 55387d3 commit 947914b

File tree

9 files changed

+46
-32
lines changed

9 files changed

+46
-32
lines changed

Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public abstract class ConsoleDriver
3030
/// to.
3131
/// </summary>
3232
/// <value>The rectangle describing the of <see cref="Clip"/> region.</value>
33-
public Region? Clip
33+
internal Region? Clip
3434
{
3535
get => _clip;
3636
set
@@ -312,7 +312,7 @@ internal void AddRune (Rune rune)
312312
/// <para>If <paramref name="str"/> requires more columns than are available, the output will be clipped.</para>
313313
/// </remarks>
314314
/// <param name="str">String.</param>
315-
public void AddStr (string str)
315+
internal void AddStr (string str)
316316
{
317317
List<Rune> runes = str.EnumerateRunes ().ToList ();
318318

@@ -323,7 +323,7 @@ public void AddStr (string str)
323323
}
324324

325325
/// <summary>Clears the <see cref="Contents"/> of the driver.</summary>
326-
public void ClearContents ()
326+
internal void ClearContents ()
327327
{
328328
Contents = new Cell [Rows, Cols];
329329

@@ -362,7 +362,7 @@ public void ClearContents ()
362362
/// Sets <see cref="Contents"/> as dirty for situations where views
363363
/// don't need layout and redrawing, but just refresh the screen.
364364
/// </summary>
365-
public void SetContentsAsDirty ()
365+
internal void SetContentsAsDirty ()
366366
{
367367
lock (Contents!)
368368
{
@@ -387,7 +387,7 @@ public void SetContentsAsDirty ()
387387
/// </remarks>
388388
/// <param name="rect">The Screen-relative rectangle.</param>
389389
/// <param name="rune">The Rune used to fill the rectangle</param>
390-
public void FillRect (Rectangle rect, Rune rune = default)
390+
internal void FillRect (Rectangle rect, Rune rune = default)
391391
{
392392
// BUGBUG: This should be a method on Region
393393
rect = Rectangle.Intersect (rect, Clip?.GetBounds () ?? Screen);
@@ -418,7 +418,7 @@ public void FillRect (Rectangle rect, Rune rune = default)
418418
/// </summary>
419419
/// <param name="rect"></param>
420420
/// <param name="c"></param>
421-
public void FillRect (Rectangle rect, char c) { FillRect (rect, new Rune (c)); }
421+
internal void FillRect (Rectangle rect, char c) { FillRect (rect, new Rune (c)); }
422422

423423
/// <summary>Gets the terminal cursor visibility.</summary>
424424
/// <param name="visibility">The current <see cref="CursorVisibility"/></param>
@@ -445,7 +445,7 @@ public void FillRect (Rectangle rect, Rune rune = default)
445445
/// <see langword="false"/> if the coordinate is outside the screen bounds or outside of <see cref="Clip"/>.
446446
/// <see langword="true"/> otherwise.
447447
/// </returns>
448-
public bool IsValidLocation (Rune rune, int col, int row)
448+
internal bool IsValidLocation (Rune rune, int col, int row)
449449
{
450450
if (rune.GetColumns () < 2)
451451
{
@@ -458,6 +458,7 @@ public bool IsValidLocation (Rune rune, int col, int row)
458458
}
459459
}
460460

461+
// TODO: Make internal once Menu is upgraded
461462
/// <summary>
462463
/// Updates <see cref="Col"/> and <see cref="Row"/> to the specified column and row in <see cref="Contents"/>.
463464
/// Used by <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content.
@@ -480,10 +481,10 @@ public virtual void Move (int col, int row)
480481

481482
/// <summary>Called when the terminal size changes. Fires the <see cref="SizeChanged"/> event.</summary>
482483
/// <param name="args"></param>
483-
public void OnSizeChanged (SizeChangedEventArgs args) { SizeChanged?.Invoke (this, args); }
484+
internal void OnSizeChanged (SizeChangedEventArgs args) { SizeChanged?.Invoke (this, args); }
484485

485486
/// <summary>Updates the screen to reflect all the changes that have been done to the display buffer</summary>
486-
public void Refresh ()
487+
internal void Refresh ()
487488
{
488489
bool updated = UpdateScreen ();
489490
UpdateCursor ();

Terminal.Gui/View/View.Drawing.Primitives.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,20 @@ public void FillRect (Rectangle rect, Color? color = null)
154154
SetClip (prevClip);
155155
}
156156

157+
/// <summary>Fills the specified <see cref="Viewport"/>-relative rectangle.</summary>
158+
/// <param name="rect">The Viewport-relative rectangle to clear.</param>
159+
/// <param name="rune">The Rune to fill with.</param>
160+
public void FillRect (Rectangle rect, Rune rune)
161+
{
162+
if (Driver is null)
163+
{
164+
return;
165+
}
166+
167+
Region prevClip = ClipViewport ();
168+
Rectangle toClear = ViewportToScreen (rect);
169+
Driver.FillRect (toClear, rune);
170+
SetClip (prevClip);
171+
}
172+
157173
}

Terminal.Gui/Views/ListView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public interface IListDataSource : IDisposable
3232

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

Terminal.Gui/Views/Menu/Menu.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,7 @@ private void Top_DrawComplete (object? sender, DrawEventArgs e)
436436

437437
if (item is null && BorderStyle != LineStyle.None)
438438
{
439-
Point s = ViewportToScreen (new Point (-1, i));
440-
Driver.Move (s.X, s.Y);
441-
Driver.AddRune (Glyphs.LeftTee);
439+
AddRune (-1, i, Glyphs.LeftTee);
442440
}
443441
else if (Frame.X < Driver.Cols)
444442
{
@@ -462,31 +460,29 @@ private void Top_DrawComplete (object? sender, DrawEventArgs e)
462460

463461
if (item is null)
464462
{
465-
Driver.AddRune (Glyphs.HLine);
463+
AddRune (Glyphs.HLine);
466464
}
467465
else if (i == 0 && p == 0 && _host.UseSubMenusSingleFrame && item.Parent!.Parent is { })
468466
{
469-
Driver.AddRune (Glyphs.LeftArrow);
467+
AddRune (Glyphs.LeftArrow);
470468
}
471469

472470
// This `- 3` is left border + right border + one row in from right
473471
else if (p == Frame.Width - 3 && _barItems?.SubMenu (_barItems.Children [i]!) is { })
474472
{
475-
Driver.AddRune (Glyphs.RightArrow);
473+
AddRune (Glyphs.RightArrow);
476474
}
477475
else
478476
{
479-
Driver.AddRune ((Rune)' ');
477+
AddRune ((Rune)' ');
480478
}
481479
}
482480

483481
if (item is null)
484482
{
485483
if (BorderStyle != LineStyle.None && SuperView?.Frame.Right - Frame.X > Frame.Width)
486484
{
487-
Point s = ViewportToScreen (new Point (Frame.Width - 2, i));
488-
Driver.Move (s.X, s.Y);
489-
Driver.AddRune (Glyphs.RightTee);
485+
AddRune (Frame.Width - 2, i, Glyphs.RightTee);
490486
}
491487

492488
continue;
@@ -572,6 +568,7 @@ private void Top_DrawComplete (object? sender, DrawEventArgs e)
572568
// The shortcut tag string
573569
if (!string.IsNullOrEmpty (item.ShortcutTag))
574570
{
571+
575572
Driver.Move (screen.X + l - item.ShortcutTag.GetColumns (), screen.Y);
576573
Driver.AddStr (item.ShortcutTag);
577574
}

UICatalog/Scenarios/AdvancedClipping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public override void Main ()
2222

2323
app.DrawingContent += (s, e) =>
2424
{
25-
Application.Driver?.FillRect (app.ViewportToScreen (app.Viewport), CM.Glyphs.Dot);
25+
app!.FillRect (app!.Viewport, CM.Glyphs.Dot);
2626
e.Cancel = true;
2727
};
2828

UICatalog/Scenarios/CharacterMap.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ protected override bool OnDrawingContent ()
695695

696696
SetAttribute (GetHotNormalColor ());
697697
Move (0, 0);
698-
Driver.AddStr (new (' ', RowLabelWidth + 1));
698+
AddStr (new (' ', RowLabelWidth + 1));
699699

700700
int firstColumnX = RowLabelWidth - Viewport.X;
701701

@@ -708,11 +708,11 @@ protected override bool OnDrawingContent ()
708708
{
709709
Move (x, 0);
710710
SetAttribute (GetHotNormalColor ());
711-
Driver.AddStr (" ");
711+
AddStr (" ");
712712
SetAttribute (HasFocus && cursorCol + firstColumnX == x ? ColorScheme.HotFocus : GetHotNormalColor ());
713-
Driver.AddStr ($"{hexDigit:x}");
713+
AddStr ($"{hexDigit:x}");
714714
SetAttribute (GetHotNormalColor ());
715-
Driver.AddStr (" ");
715+
AddStr (" ");
716716
}
717717
}
718718

@@ -799,7 +799,7 @@ protected override bool OnDrawingContent ()
799799
{
800800
// Draw the width of the rune
801801
SetAttribute (ColorScheme.HotNormal);
802-
Driver.AddStr ($"{width}");
802+
AddStr ($"{width}");
803803
}
804804

805805
// If we're at the cursor position, and we don't have focus, revert the colors to normal
@@ -816,11 +816,11 @@ protected override bool OnDrawingContent ()
816816

817817
if (!ShowGlyphWidths || (y + Viewport.Y) % _rowHeight > 0)
818818
{
819-
Driver.AddStr ($"U+{val / 16:x5}_ ");
819+
AddStr ($"U+{val / 16:x5}_ ");
820820
}
821821
else
822822
{
823-
Driver.AddStr (new (' ', RowLabelWidth));
823+
AddStr (new (' ', RowLabelWidth));
824824
}
825825
}
826826

UICatalog/Scenarios/ShadowStyles.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override void Main ()
4545

4646
app.DrawingContent += (s, e) =>
4747
{
48-
Application.Driver?.FillRect (app.ViewportToScreen (app.Viewport), CM.Glyphs.Dot);
48+
app!.FillRect (app!.Viewport, CM.Glyphs.Dot);
4949
e.Cancel = true;
5050
};
5151

UICatalog/Scenarios/SimpleDialog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override void Main ()
2121

2222
appWindow.DrawingText += (s, e) =>
2323
{
24-
Application.Driver?.FillRect (appWindow.ViewportToScreen (appWindow.Viewport), '*');
24+
appWindow!.FillRect (appWindow!.Viewport, CM.Glyphs.Dot);
2525
e.Cancel = true;
2626
};
2727

UICatalog/Scenarios/TextEffectsScenario.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private void CenterText (string text, int xOffset, int yOffset)
180180
int x = xOffset + (GRADIENT_WIDTH - width) / 2; // Center the text within the gradient area width
181181
SetAttribute (GetNormalColor ());
182182
Move (x, yOffset + 1);
183-
Driver.AddStr (text);
183+
AddStr (text);
184184
}
185185

186186
private void DrawGradientArea (GradientDirection direction, int xOffset, int yOffset)

0 commit comments

Comments
 (0)