Skip to content

Window Class

Represents a windowed controls console.

C#
[DataContract]
[JsonObject(MemberSerialization.OptIn)]
public class Window : Console, IDisposable, IScreenSurfaceEditable, IScreenSurface, IScreenObject, IPositionable, IComponentHost, ISurface, ISurfaceSettable, ICellSurfaceResize, IWindowData

Inheritance objectScreenObjectScreenSurfaceConsole

Implements IDisposable, IScreenSurfaceEditable, IScreenSurface, IScreenObject, SadRogue.Primitives.IPositionable, IComponentHost, ISurface, ISurfaceSettable, ICellSurfaceResize, IWindowData

Creates a new window.

C#
public Window(int width, int height)

width int
The width in cells of the surface.

height int
The height in cells of the surface.

Creates a new screen object that can render a surface. Uses the specified cells to generate the surface.

C#
public Window(int width, int height, ColoredGlyphBase[]? initialCells)

width int
The width in cells of the surface.

height int
The height in cells of the surface.

initialCells ColoredGlyphBase[]
The initial cells to seed the surface.

Creates a new window with the specified width and height, with SadRogue.Primitives.Color.Transparent for the background and SadRogue.Primitives.Color.White for the foreground.

C#
public Window(int width, int height, int bufferWidth, int bufferHeight)

width int
The visible width of the window in cells.

height int
The visible height of the window in cells.

bufferWidth int
The total width of the window in cells.

bufferHeight int
The total height of the window in cells.

Window(int, int, int, int, ColoredGlyphBase[]?)

Section titled “Window(int, int, int, int, ColoredGlyphBase[]?)”

Creates a window with the specified width and height, with SadRogue.Primitives.Color.Transparent for the background and SadRogue.Primitives.Color.White for the foreground.

C#
public Window(int width, int height, int bufferWidth, int bufferHeight, ColoredGlyphBase[]? initialCells)

width int
The width of the window in cells.

height int
The height of the window in cells.

bufferWidth int
The total width of the window in cells.

bufferHeight int
The total height of the window in cells.

initialCells ColoredGlyphBase[]
The cells to seed the window with. If null, creates the cells for you.

Creates a new window using the existing surface.

C#
public Window(ICellSurface surface, IFont? font = null, Point? fontSize = null)

surface ICellSurface
The surface.

font IFont
The font to use with the surface.

fontSize System.NullableSadRogue.Primitives.Point
The font size.

The mouse state of the previous update frame.

C#
protected bool PreviousMouseLeftButtonDown

The controls host holding all the controls.

C#
public ControlHost Controls { get; }

The Y coordinate of the title drawing area. This can be set to any value > 0 and < the height.

C#
[DataMember]
public int TitleAreaY { get; set; }

The X coordinate of the title drawing area. This is automatically set by the theme.

C#
[DataMember]
public int TitleAreaX { get; set; }

The width of the title drawing area. This is automatically set by the theme.

C#
[DataMember]
public int TitleAreaLength { get; set; }

The line style for the border.

C#
[DataMember]
public int[] BorderLineStyle { get; set; }

The position of the cell that the window drag started at.

C#
[IgnoreDataMember]
protected Point CellAtDragPosition { get; set; }

Temporary value to hold the state of IsExclusiveMouse prior to dragging.

C#
[IgnoreDataMember]
protected bool PreviousMouseExclusiveDrag { get; set; }

When true, indicates that the window has been added to a parent; otherwise false.

C#
[IgnoreDataMember]
protected bool AddedToParent { get; set; }

When true, indicates that the window is being dragged; otherwise false.

C#
[IgnoreDataMember]
protected bool IsDragging { get; set; }

Gets or sets the alignment of the window title.

C#
[DataMember]
public HorizontalAlignment TitleAlignment { get; set; }

Gets the whether or not the window is being shown as modal.

C#
[IgnoreDataMember]
public bool IsModal { get; }

Gets or sets whether or not this window can be moved with the mouse.

C#
[DataMember]
public bool CanDrag { get; set; }

Gets or sets whether or not this window can be closed when the escape key is pressed.

C#
[DataMember]
public bool CloseOnEscKey { get; set; }

Gets or set the dialog result status of the window.

C#
[DataMember]
public bool DialogResult { get; set; }

Indicates that when this window is shown by the Show() method or by setting the IsVisible property to true, the window will be shown as modal.

C#
[DataMember]
public bool IsModalDefault { get; set; }

Gets or sets the title displayed on the window.

C#
public string Title { get; set; }

Processes the mouse.

C#
public override bool ProcessMouse(MouseScreenObjectState state)

state MouseScreenObjectState
The mouse state related to this object.

bool
True when this object should halt further mouse processing..

C#
protected virtual void DrawBorder()

Processes the keyboard looking for the ESC key press to close the window, if required. Otherwise the base ControlsConsole will process the keyboard.

C#
public override bool ProcessKeyboard(Keyboard info)

info Keyboard
Keyboard state.

bool

Depending on if the window is visible, calls Show(bool) or Hide().

C#
protected override void OnVisibleChanged()

User-definable code called when the window is shown.

C#
protected virtual void OnShown()

User-definable code called when the window is hidden.

C#
protected virtual void OnHidden()

Displays this window using the modal value of the IsModalDefault property.

C#
public void Show()

Displays this window.

C#
public virtual void Show(bool modal)

modal bool
When true, the window will be displayed as modal; otherwise false.

Hides the window.

C#
public virtual void Hide()

Centers the window within the bounds of RenderWidth and RenderHeight

C#
public void Center()

Returns the value “Window”.

C#
public override string ToString()

string
The string “Window”.

Ask(string, string, string, Action<bool, string>?, Validator?, string?, Colors?)

Section titled “Ask(string, string, string, Action<bool, string>?, Validator?, string?, Colors?)”

Displays a window with an input box and an optional validator with a text prompt.

C#
public static void Ask(string message, string acceptPrompt, string cancelPrompt, Action<bool, string>? closedCallback, StringValidation.Validator? validator = null, string? defaultValue = null, Colors? colors = null)

message string
The message to print in the window.

acceptPrompt string
The text of the accept button.

cancelPrompt string
The text of the cancel button.

closedCallback Action<bool, string>
A delegate called when the window is closed.

validator StringValidation.Validator
An optional validator to validate the input text.

defaultValue string
An optional default value of the input text box.

colors Colors
An optional set of colors to apply to the window.

Ask(ColoredString, string, string, Action<bool, string>?, Validator?, string?, Colors?)

Section titled “Ask(ColoredString, string, string, Action<bool, string>?, Validator?, string?, Colors?)”

Displays a window with an input box and an optional validator, using a ColoredString as the prompt text.

C#
public static void Ask(ColoredString message, string acceptPrompt, string cancelPrompt, Action<bool, string>? closedCallback, StringValidation.Validator? validator = null, string? defaultValue = null, Colors? colors = null)

message ColoredString
The message to print in the window.

acceptPrompt string
The text of the accept button.

cancelPrompt string
The text of the cancel button.

closedCallback Action<bool, string>
A delegate called when the window is closed.

validator StringValidation.Validator
An optional validator to validate the input text.

defaultValue string
An optional default value of the input text box.

colors Colors
An optional set of colors to apply to the window.

Prompt(string, string, string, Action<bool>?, Colors?)

Section titled “Prompt(string, string, string, Action<bool>?, Colors?)”

Shows a window prompt with two buttons for the user to click.

C#
public static void Prompt(string message, string yesPrompt, string noPrompt, Action<bool>? closedCallback, Colors? colors = null)

message string
The text to display.

yesPrompt string
The yes button’s text.

noPrompt string
The no button’s text.

closedCallback Action<bool>
Callback with the yes (true) or no (false) result.

colors Colors
The colors to apply for the message box and buttons. If null.

Prompt(ColoredString, string, string, Action<bool>?, Colors?)

Section titled “Prompt(ColoredString, string, string, Action<bool>?, Colors?)”

Shows a window prompt with two buttons for the user to click.

C#
public static void Prompt(ColoredString message, string yesPrompt, string noPrompt, Action<bool>? closedCallback, Colors? colors = null)

message ColoredString
The text to display. (background color is ignored)

yesPrompt string
The yes button’s text.

noPrompt string
The no button’s text.

closedCallback Action<bool>
Callback with the yes (true) or no (false) result.

colors Colors
The colors to apply for the message box and buttons. If null.

Displays a dialog to the user with a specific message.

C#
public static void Message(string message, string closeButtonText, Action? closedCallback = null, Colors? colors = null)

message string
The message.

closeButtonText string
The text of the dialog’s close button.

closedCallback Action
A callback indicating the message was dismissed.

colors Colors
The colors to apply for the message box and buttons. If null.

Message(ColoredString, string, Action?, Colors?)

Section titled “Message(ColoredString, string, Action?, Colors?)”

Displays a dialog to the user with a specific message.

C#
public static void Message(ColoredString message, string closeButtonText, Action? closedCallback = null, Colors? colors = null)

message ColoredString
The message. (background color is ignored)

closeButtonText string
The text of the dialog’s close button.

closedCallback Action
A callback indicating the message was dismissed.

colors Colors
The colors to apply for the message box and buttons. If null.

Raised when the window is closed.

C#
public event EventHandler? Closed

EventHandler

Raised when the window is shown.

C#
public event EventHandler? Shown

EventHandler