using static Terminal.Gui.SpinnerStyle;
namespace Terminal.Gui;
public partial class View
{
/// Moves the drawing cursor to the specified -relative location in the view.
///
///
/// The top-left corner of the visible content area is ViewPort.Location.
///
///
/// Column (viewport-relative).
/// Row (viewport-relative).
public bool Move (int col, int row)
{
if (Driver is null || Driver?.Rows == 0)
{
return false;
}
Point screen = ViewportToScreen (new Point (col, row));
Driver?.Move (screen.X, screen.Y);
return true;
}
/// Draws the specified character at the current draw position.
/// The Rune.
public void AddRune (Rune rune)
{
Driver?.AddRune (rune);
}
///
/// Adds the specified to the display at the current cursor position. This method is a
/// convenience method that calls with the constructor.
///
/// Character to add.
public void AddRune (char c) { AddRune (new Rune (c)); }
/// Draws the specified character in the specified viewport-relative column and row of the View.
///
/// If the provided coordinates are outside the visible content area, this method does nothing.
///
///
/// The top-left corner of the visible content area is ViewPort.Location.
///
/// Column (viewport-relative).
/// Row (viewport-relative).
/// The Rune.
public void AddRune (int col, int row, Rune rune)
{
if (Move (col, row))
{
Driver?.AddRune (rune);
}
}
/// Adds the to the display at the current draw position.
///
///
/// When the method returns, the draw position will be incremented by the number of columns
/// required, unless the new column value is outside the or .
///
/// If requires more columns than are available, the output will be clipped.
///
/// String.
public void AddStr (string str)
{
Driver?.AddStr (str);
}
/// Utility function to draw strings that contain a hotkey.
/// String to display, the hotkey specifier before a letter flags the next letter as the hotkey.
/// Hot color.
/// Normal color.
///
///
/// The hotkey is any character following the hotkey specifier, which is the underscore ('_') character by
/// default.
///
/// The hotkey specifier can be changed via
///
public void DrawHotString (string text, Attribute hotColor, Attribute normalColor)
{
Rune hotkeySpec = HotKeySpecifier == (Rune)0xffff ? (Rune)'_' : HotKeySpecifier;
SetAttribute (normalColor);
foreach (Rune rune in text.EnumerateRunes ())
{
if (rune == new Rune (hotkeySpec.Value))
{
SetAttribute (hotColor);
continue;
}
AddRune (rune);
SetAttribute (normalColor);
}
}
///
/// Utility function to draw strings that contains a hotkey using a and the "focused"
/// state.
///
/// String to display, the underscore before a letter flags the next letter as the hotkey.
///
/// If set to this uses the focused colors from the color scheme, otherwise
/// the regular ones.
///
public void DrawHotString (string text, bool focused)
{
if (focused)
{
DrawHotString (text, GetHotFocusColor (), GetFocusColor ());
}
else
{
DrawHotString (
text,
Enabled ? GetHotNormalColor () : ColorScheme!.Disabled,
Enabled ? GetNormalColor () : ColorScheme!.Disabled
);
}
}
/// Fills the specified -relative rectangle with the specified color.
/// The Viewport-relative rectangle to clear.
/// The color to use to fill the rectangle. If not provided, the Normal background color will be used.
public void FillRect (Rectangle rect, Color? color = null)
{
if (Driver is null)
{
return;
}
Region prevClip = AddViewportToClip ();
Rectangle toClear = ViewportToScreen (rect);
Attribute prev = SetAttribute (new (color ?? GetNormalColor ().Background));
Driver.FillRect (toClear);
SetAttribute (prev);
SetClip (prevClip);
}
/// Fills the specified -relative rectangle.
/// The Viewport-relative rectangle to clear.
/// The Rune to fill with.
public void FillRect (Rectangle rect, Rune rune)
{
if (Driver is null)
{
return;
}
Region prevClip = AddViewportToClip ();
Rectangle toClear = ViewportToScreen (rect);
Driver.FillRect (toClear, rune);
SetClip (prevClip);
}
}