Table of Contents

Class Window

Namespace
ConsoleAppVisuals
Assembly
ConsoleAppVisuals.dll

The Window class is a collection of methods to manage visual elements stored in itself. You may add, remove, or render elements in the console after adding them to the Window class.

public static class Window
Inheritance
Window
Inherited Members

Remarks

For more information, consider visiting the documentation available here.

Fields

INTERVAL_BETWEEN_READS

Defines the interval of milliseconds between different read key of the console (used in the Freeze(ConsoleKey) method).

public const int INTERVAL_BETWEEN_READS = 10

Field Value

int

Properties

CountElements

Gets the number of elements currently stored in the window.

public static int CountElements { get; }

Property Value

int

Elements

Gets the list of elements stored in the window.

public static List<Element> Elements { get; }

Property Value

List<Element>

NextId

Gets the next id number each time a new element is added to the window.

public static int NextId { get; }

Property Value

int

Methods

ActivateAllElements()

Attempts to toggle the visibility of all Element in the window if the element fits the max number constraint.

public static void ActivateAllElements()

Remarks

For more information, consider visiting the documentation available here.

ActivateElement(Element, bool)

Attempts to toggle the visibility of the given Element if it fits the max number constraint. The element will be rendered if the render parameter is true.

[Visual]
public static void ActivateElement(Element element, bool render = true)

Parameters

element Element

The Element to be activated.

render bool

If true, the Element will be rendered.

Remarks

For more information, consider visiting the documentation available here.

Exceptions

ElementNotFoundException

Thrown when the element is invalid.

ActivateElement(int, bool)

Attempts to toggle the visibility of the Element with the given id if the element fits the max number constraint. The element will be rendered if the render parameter is true.

[Visual]
public static void ActivateElement(int id, bool render = true)

Parameters

id int

The id of the Element to activate.

render bool

If true, the Element will be rendered.

Remarks

For more information, consider visiting the documentation available here.

Exceptions

ArgumentOutOfRangeException

Thrown when the id is out of the range of the Window elements.

ActivateElement<T>(bool)

Attempts to toggle the visibility of the first Element with the given type if the element fits the max number constraint.

[Visual]
public static void ActivateElement<T>(bool render = true) where T : Element

Parameters

render bool

If true, the element will be rendered.

Type Parameters

T

The type of the element.

Remarks

For more information, consider visiting the documentation available here.

Exceptions

ElementNotFoundException

Thrown when the element is invalid.

AddElement(params Element[])

Adds one or more Element to the window. If the element is passive, it will try to toggle its visibility to true.

public static void AddElement(params Element[] elements)

Parameters

elements Element[]

The Element to be added.

Remarks

For more information, consider visiting the documentation available here.

Exceptions

ArgumentException

Thrown when no Element are provided.

DuplicateElementException

Thrown when the Element is already present in the Window.

CheckLine(int?)

Checks if the line is not out of the console range.

public static int? CheckLine(int? line)

Parameters

line int?

The line to be checked.

Returns

int?

The line if it is valid.

Remarks

For more information, consider visiting the documentation available here.

Exceptions

LineOutOfConsoleException

Thrown when the line is out of the console range.

Clear(bool, int?, int?, int)

Clears the console given a range of lines.

[Visual]
public static bool Clear(bool continuous = false, int? startLine = null, int? length = null, int step = 1)

Parameters

continuous bool

If true, the window will be cleared continuously.

startLine int?

The start line of the window to be cleared.

length int?

The number of lines to be cleared.

step int

The step of the window to be cleared.

Returns

bool

True if the window is successfully cleared, false otherwise.

Remarks

For more information, consider visiting the documentation available here.

Close()

Clears the console, show the cursor, and exit the program.

[Visual]
public static void Close()

Remarks

For more information, consider visiting the documentation available here.

DeactivateAllElements(bool)

This method deactivate the visibility of all Element.

public static void DeactivateAllElements(bool clear = true)

Parameters

clear bool

Remarks

For more information, consider visiting the documentation available here.

DeactivateElement(Element, bool)

Deactivates the visibility of the given Element. The console space taken by the element will be cleared if the clear parameter is true.

public static void DeactivateElement(Element element, bool clear = true)

Parameters

element Element

The Element to be deactivated.

clear bool

If true, the Element space will be cleared from the console.

Remarks

For more information, consider visiting the documentation available here.

Exceptions

ElementNotFoundException

Thrown when the element is invalid.

DeactivateElement(int, bool)

Deactivates the visibility of the Element with the given id. The console space taken by the element will be cleared if the clear parameter is true.

public static void DeactivateElement(int id, bool clear = true)

Parameters

id int

The id of the Element.

clear bool

If true, the Element space will be cleared from the console.

Remarks

For more information, consider visiting the documentation available here.

Exceptions

ArgumentOutOfRangeException

Thrown when the id is out of the range of the Window elements.

DeactivateElement<T>(bool)

Deactivates the visibility of the first Element with the given type. The console space taken by the element will be cleared if the clear parameter is true.

public static void DeactivateElement<T>(bool clear = true) where T : Element

Parameters

clear bool

If true, the element will be cleared.

Type Parameters

T

The type of the element.

Remarks

For more information, consider visiting the documentation available here.

Exceptions

ElementNotFoundException

Thrown when the element is invalid.

Freeze(ConsoleKey)

Freezes the execution of the program until the given key is pressed.

[Visual]
public static void Freeze(ConsoleKey key = ConsoleKey.Enter)

Parameters

key ConsoleKey

The key to be pressed to continue the execution.

Remarks

For more information, consider visiting the documentation available here.

GetElement<T>()

Gets the first Element of the given type present in the Window.

public static T? GetElement<T>() where T : Element

Returns

T

The element with the given type if it exists, null otherwise.

Type Parameters

T

The type of the element.

Remarks

For more information, consider visiting the documentation available here.

GetElement<T>(int)

Gets the Element with the given id in the Window.

public static T? GetElement<T>(int id) where T : Element

Parameters

id int

The id of the element.

Returns

T

The Element with the given id if it exists, null otherwise.

Type Parameters

T

Remarks

For more information, consider visiting the documentation available here.

Exceptions

ArgumentOutOfRangeException

Thrown when the id is out of the range of the Window elements.

GetLineAvailable(Placement)

Gets the last line available to render an Element on the console given a placement.

public static int GetLineAvailable(Placement placement)

Parameters

placement Placement

The placement to get the line.

Returns

int

The last line available to render an Element on the console.

Remarks

For more information, consider visiting the documentation available here.

Exceptions

ArgumentOutOfRangeException

Thrown when the placement is invalid.

GetVisibleElement<T>()

Gets the visible Element with the given type in the Window.

public static T? GetVisibleElement<T>() where T : Element

Returns

T

The visible Element with the given type if it exists, null otherwise.

Type Parameters

T

The type of the element.

Remarks

For more information, consider visiting the documentation available here.

InsertElement(Element, int)

Inserts an Element at the given id in the Window.

public static void InsertElement(Element element, int id)

Parameters

element Element

The Element to be inserted.

id int

The target id to insert the element.

Remarks

For more information, consider visiting the documentation available here.

Exceptions

ArgumentOutOfRangeException

Thrown when the id is out of the range of the Window elements.

IsElementActivatable(int)

Tests if an Element given by an id can be activated

public static bool IsElementActivatable(int id)

Parameters

id int

The id of the Element to test.

Returns

bool

True if the Element can be activated, false otherwise.

Remarks

For more information, consider visiting the documentation available here.

Open()

Clears the console and hide the cursor.

[Visual]
public static void Open()

Remarks

For more information, consider visiting the documentation available here.

Range(int, int)

Collects a range of Element given a start id and a count.

public static List<Element> Range(int index, int count)

Parameters

index int

The start id of the range.

count int

The number of elements to be collected.

Returns

List<Element>

The list of Element given a range of ids.

Remarks

For more information, consider visiting the documentation available here.

RemoveAllElements()

Removes all Element from the window.

public static void RemoveAllElements()

Remarks

For more information, consider visiting the documentation available here.

RemoveElement(params Element[])

Removes one or more Element from the Window.

public static bool RemoveElement(params Element[] elements)

Parameters

elements Element[]

The Element to be removed.

Returns

bool

True if the element is successfully removed, false otherwise.

Remarks

For more information, consider visiting the documentation available here.

Exceptions

ElementNotFoundException

Thrown when the Element is not found in the Window.

RemoveElement(int)

Removes the Element with the given id from the Window.

public static void RemoveElement(int id)

Parameters

id int

The id of the element to be removed.

Remarks

For more information, consider visiting the documentation available here.

Exceptions

ArgumentOutOfRangeException

Thrown when the id is out of the range of the Window elements.

RemoveElement<T>()

Removes the first Element of the given type from the Window.

public static bool RemoveElement<T>() where T : Element

Returns

bool

True if the element is successfully removed, false otherwise.

Type Parameters

T

The type of the element.

Remarks

For more information, consider visiting the documentation available here.

Exceptions

ElementNotFoundException

Thrown when the Element is not found in the Window.

Render()

Displays all the visible Element in the window.

[Visual]
public static void Render()

Remarks

For more information, consider visiting the documentation available here.

Render(params Element[])

Displays the given Element in the window.

[Visual]
public static void Render(params Element[] elements)

Parameters

elements Element[]

The Element to be displayed.

Remarks

For more information, consider visiting the documentation available here.

Exceptions

ElementNotFoundException

Thrown when the element is not found in the Window.

RenderElementsSpace(bool)

Renders the space of all visible Element in the window. May ignore the visibility to display the hidden Element spaces.

[Visual]
public static bool RenderElementsSpace(bool ignoreVisibility = false)

Parameters

ignoreVisibility bool

If true, the space of the hidden Element will be drawn.

Returns

bool

True if the space of the Element is successfully drawn, false otherwise.

Remarks

For more information, consider visiting the documentation available here.