Class TextScreen
Socially Distant's console renderer. Used for the in-game Terminal.
Implements
Inherited Members
Namespace: SociallyDistant.Core.UI.Console
Assembly: SociallyDistant.Framework.dll
Syntax
public class TextScreen : Widget, IFontFamilyProvider, IInspectable, ITextScreen, IUpdateThemeProperties, IMouseDownHandler, IMouseScrollHandler, IKeyCharHandler, IKeyDownHandler, IDragStartHandler, IDragHandler, IDragEndHandler, IMouseHandler, IGainFocusHandler, ILoseFocusHandler, IAccessibleDescription
Properties
AccessibleContent
Gets a string of text representing the widget's content, in a screen-reader-friendly format.
Declaration
public string? AccessibleContent { get; }
Property Value
| Type | Description |
|---|---|
| string |
Columns
Gets the width of the screen, in characters.
Declaration
public int Columns { get; }
Property Value
| Type | Description |
|---|---|
| int |
CursorLeft
Gets the horizontal position of the cursor, in characters.
Declaration
public int CursorLeft { get; }
Property Value
| Type | Description |
|---|---|
| int |
CursorTop
Gets the vertical position of the cursor, in characters.
Declaration
public int CursorTop { get; }
Property Value
| Type | Description |
|---|---|
| int |
DesiredColumns
Gets or sets the amount of desired colums you would like the console to occupy.
Declaration
public int DesiredColumns { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
DesiredRows
Gets or sets the desired amount of rows you'd like the console to occupy.
Declaration
public int DesiredRows { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
FontOverride
Gets or sets a font family to use as the console font. If none is set, the monospace font for the current UI skin will be used.
Declaration
public IFontFamily? FontOverride { get; set; }
Property Value
| Type | Description |
|---|---|
| IFontFamily |
Remarks
<p>
You may be tempted to use a variable-width font to see what it looks like. The game won't stop you from
doing so, but you should have a first-aid kit ready for the inevitable and almost immediate typographical
hell you will unleash on yourself and the surrounding planet. Seriously, do not even try. Why did we even
bother exposing this fucking property?
</p>
HeightMode
Gets or sets a ConsoleSizeMode indicating how the widget should report its layout height to the UI system.
Declaration
public ConsoleSizeMode HeightMode { get; set; }
Property Value
| Type | Description |
|---|---|
| ConsoleSizeMode |
Rows
Gets the height of the screen, in characters.
Declaration
public int Rows { get; }
Property Value
| Type | Description |
|---|---|
| int |
Title
Gets or sets the title of this text screen. Implementations or users of ITextScreen can display this text in other UI elements, such as a tab.
Declaration
public string Title { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
WidthMode
Gets or sets a ConsoleSizeMode indicating how the widget should report its layout width to the UI system.
Declaration
public ConsoleSizeMode WidthMode { get; set; }
Property Value
| Type | Description |
|---|---|
| ConsoleSizeMode |
Methods
ArrangeChildren(IGuiContext, LayoutRect)
Declaration
protected override void ArrangeChildren(IGuiContext context, LayoutRect availableSpace)
Parameters
| Type | Name | Description |
|---|---|---|
| IGuiContext | context | |
| LayoutRect | availableSpace |
Overrides
ClearScreen()
Clear the screen.
Declaration
public void ClearScreen()
Fill(Rune, int, int, int, int)
Fill a rectangular region of the screen with a specified Rune value.
Declaration
public void Fill(Rune rune, int x, int y, int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| Rune | rune | The character to fill the rectangle with. |
| int | x | The left column of the rectangle. |
| int | y | The top row of the rectangle. |
| int | width | The width, in columns, of the rectangle. |
| int | height | The height, in rows, of the rectangle. |
GetContentSize(Point)
Declaration
protected override Point GetContentSize(Point availableSize)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | availableSize |
Returns
| Type | Description |
|---|---|
| Point |
Overrides
GetSelectedText()
Gets a string of text representing the current text selection.
Declaration
public string? GetSelectedText()
Returns
| Type | Description |
|---|---|
| string | The text highlighted on-screen. |
IsSelected(int, int)
Determines whether the character at the specified location is selected.
Declaration
public bool IsSelected(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| int | x | The column to check. |
| int | y | The row to check. |
Returns
| Type | Description |
|---|---|
| bool | True if selected, false otherwise. |
OnDrag(MouseButtonEvent)
Declaration
public void OnDrag(MouseButtonEvent e)
Parameters
| Type | Name | Description |
|---|---|---|
| MouseButtonEvent | e |
OnDragEnd(MouseButtonEvent)
Declaration
public void OnDragEnd(MouseButtonEvent e)
Parameters
| Type | Name | Description |
|---|---|---|
| MouseButtonEvent | e |
OnDragStart(MouseButtonEvent)
Declaration
public void OnDragStart(MouseButtonEvent e)
Parameters
| Type | Name | Description |
|---|---|---|
| MouseButtonEvent | e |
OnFocusGained(FocusEvent)
Declaration
public void OnFocusGained(FocusEvent e)
Parameters
| Type | Name | Description |
|---|---|---|
| FocusEvent | e |
OnFocusLost(FocusEvent)
Declaration
public void OnFocusLost(FocusEvent e)
Parameters
| Type | Name | Description |
|---|---|---|
| FocusEvent | e |
OnKeyChar(KeyCharEvent)
Declaration
public void OnKeyChar(KeyCharEvent e)
Parameters
| Type | Name | Description |
|---|---|---|
| KeyCharEvent | e |
OnKeyDown(KeyEvent)
Declaration
public void OnKeyDown(KeyEvent e)
Parameters
| Type | Name | Description |
|---|---|---|
| KeyEvent | e |
OnMouseDown(MouseButtonEvent)
Declaration
public void OnMouseDown(MouseButtonEvent e)
Parameters
| Type | Name | Description |
|---|---|---|
| MouseButtonEvent | e |
OnMouseScroll(MouseScrollEvent)
Declaration
public void OnMouseScroll(MouseScrollEvent e)
Parameters
| Type | Name | Description |
|---|---|---|
| MouseScrollEvent | e |
Print(in ReadOnlySpan<Rune>)
Print the specified set of Rune values to the screen.
Declaration
public void Print(in ReadOnlySpan<Rune> unicodeRunes)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<Rune> | unicodeRunes | A set of Unicode characters to write. |
Print(string)
Print the specified text to the screen.
Declaration
public void Print(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | A string of text to write. |
ReadLine(IHistoryCollection?, CancellationToken?)
Prompts the user to enter a line of text into the screen, creating a task that resolves with the entered text.
Declaration
public Task<string?> ReadLine(IHistoryCollection? historyCollection = null, CancellationToken? cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IHistoryCollection | historyCollection | An optional IHistoryCollection containing command-line history, if applicable. |
| CancellationToken? | cancellationToken | A cancellation token for interrupting the prompt. |
Returns
| Type | Description |
|---|---|
| Task<string> | A task that resolves with the entered text. If a null string is returned, the screen doesn't support keyboard input. |
RebuildGeometry(GeometryHelper)
Declaration
protected override void RebuildGeometry(GeometryHelper geometry)
Parameters
| Type | Name | Description |
|---|---|---|
| GeometryHelper | geometry |
Overrides
ResetBackgroundColor()
Reset the cursor's background color to its default.
Declaration
public void ResetBackgroundColor()
ResetCursorPosition()
Move the cursor to the top-left.
Declaration
public void ResetCursorPosition()
ResetFont()
Reset the cursor's font style to its default.
Declaration
public void ResetFont()
ResetForegroundColor()
Reset the cursor's foreground color to its default.
Declaration
public void ResetForegroundColor()
ResetTextEffects()
Reset the cursor's text effects to the default.
Declaration
public void ResetTextEffects()
ScrollDown(int)
Scroll down by the specified number of rows.
Declaration
public void ScrollDown(int numberOfRows = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| int | numberOfRows | A positive number of rows to scroll down. |
ScrollUp(int)
Scroll up by the specified number of rows.
Declaration
public void ScrollUp(int numberOfRows = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| int | numberOfRows | A positive number of rows to scroll. |
SetBackgroundColor(byte, byte, byte)
Set the background color of the cursor to the specified true color.
Declaration
public void SetBackgroundColor(byte red, byte green, byte blue)
Parameters
| Type | Name | Description |
|---|---|---|
| byte | red | Value for the red channel. |
| byte | green | Value for the green channel. |
| byte | blue | Value for the blue channel. |
SetBackgroundColor(ConsoleColor)
Set the background color of the cursor to the specified ConsoleColor value.
Declaration
public void SetBackgroundColor(ConsoleColor paletteColor)
Parameters
| Type | Name | Description |
|---|---|---|
| ConsoleColor | paletteColor | One of the 16 colors available in the ConsoleColor palette. |
SetCursorPosition(int, int)
Move the cursor to a new position.
Declaration
public void SetCursorPosition(int left, int top)
Parameters
| Type | Name | Description |
|---|---|---|
| int | left | The new column for the cursor. |
| int | top | The new row for the cursor. |
SetFont(bool, bool)
Change the cursor's font style.
Declaration
public void SetFont(bool bold, bool italic)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | bold | Value indicating whether text should be bold. |
| bool | italic | Value indicating whether text should be italic. |
SetForegroundColor(byte, byte, byte)
Set the foreground color of the cursor to the specified true color.
Declaration
public void SetForegroundColor(byte red, byte green, byte blue)
Parameters
| Type | Name | Description |
|---|---|---|
| byte | red | Value for the red channel. |
| byte | green | Value for the green channel. |
| byte | blue | Value for the blue channel. |
SetForegroundColor(ConsoleColor)
Set the foreground color of the cursor to the specified ConsoleColor value.
Declaration
public void SetForegroundColor(ConsoleColor paletteColor)
Parameters
| Type | Name | Description |
|---|---|---|
| ConsoleColor | paletteColor | One of the 16 colors available in the ConsoleColor palette. |
SetTextEffects(bool, bool)
Change the cursor's text effects.
Declaration
public void SetTextEffects(bool underline, bool strikeThrough)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | underline | Value indicating whether text should be underlined. |
| bool | strikeThrough | Value indicating whether text should be stricken out. |
UpdateThemeProperties()
Retrieves layout properties from the visual style. Called by the UI system on every frame before layout updates occur. If layout properties change during this method call, the widget will automatically invalidate its own layout.
Declaration
public void UpdateThemeProperties()
WaitForKey(CancellationToken?)
Creates an awaitable task that resolves when a key is pressed.
Declaration
public Task<ConsoleInputData?> WaitForKey(CancellationToken? cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken? | cancellationToken | A cancellation token for cancelling the task. |
Returns
| Type | Description |
|---|---|
| Task<ConsoleInputData?> | A Task<TResult> that resolves when a key is pressed inside this screen. A null value returned at task completion means that this screen doessn't support input. |
Write(Rune)
Write the specified Rune value to the screen, and advance the cursor by one cell.
Declaration
public void Write(Rune rune)
Parameters
| Type | Name | Description |
|---|---|---|
| Rune | rune | The Unicode character to write to the screen. |
Events
ConsoleKeyPressed
An event that fires every time a valid console key is pressed.
Declaration
public event Action<ConsoleInputData>? ConsoleKeyPressed
Event Type
| Type | Description |
|---|---|
| Action<ConsoleInputData> |
TitleChanged
Declaration
public event Action<string>? TitleChanged
Event Type
| Type | Description |
|---|---|
| Action<string> |