Table of Contents

Class Panel

Namespace
SharpConsoleUI.Panel
Assembly
SharpConsoleUI.dll

A single-row desktop bar with three zones (left, center, right). Manages element lifecycle, layout, rendering, and mouse routing.

public class Panel
Inheritance
Panel
Inherited Members
Extension Methods

Properties

BackgroundColor

Gets or sets the panel background color. Falls back to theme if null.

public Color? BackgroundColor { get; set; }

Property Value

Color?

ForegroundColor

Gets or sets the panel foreground color. Falls back to theme if null.

public Color? ForegroundColor { get; set; }

Property Value

Color?

Height

Gets the height of this panel (1 if visible, 0 if hidden).

public int Height { get; }

Property Value

int

IsDirty

Gets whether this panel needs to be redrawn.

public bool IsDirty { get; }

Property Value

bool

Visible

Gets or sets whether this panel is visible. Changing visibility triggers a full screen redraw to avoid ghost artifacts.

public bool Visible { get; set; }

Property Value

bool

Methods

AddCenter(params IPanelElement[])

Adds elements to the center zone.

public void AddCenter(params IPanelElement[] elements)

Parameters

elements IPanelElement[]

Elements to add.

AddLeft(params IPanelElement[])

Adds elements to the left zone.

public void AddLeft(params IPanelElement[] elements)

Parameters

elements IPanelElement[]

Elements to add.

AddRight(params IPanelElement[])

Adds elements to the right zone.

public void AddRight(params IPanelElement[] elements)

Parameters

elements IPanelElement[]

Elements to add.

Builder()

Creates a new PanelBuilder for fluent panel construction.

public static PanelBuilder Builder()

Returns

PanelBuilder

A new PanelBuilder instance.

ClearAll()

Clears all elements from all zones.

public void ClearAll()

ClearCenter()

Clears all elements from the center zone.

public void ClearCenter()

ClearLeft()

Clears all elements from the left zone.

public void ClearLeft()

ClearRight()

Clears all elements from the right zone.

public void ClearRight()

FindAllElements<T>()

Returns all elements of the specified type across all zones.

public IEnumerable<T> FindAllElements<T>() where T : class, IPanelElement

Returns

IEnumerable<T>

All matching elements.

Type Parameters

T

The element type to find.

FindElement<T>(string)

Finds an element by name and casts to the specified type.

public T? FindElement<T>(string name) where T : class, IPanelElement

Parameters

name string

The element name.

Returns

T

The element, or null if not found or wrong type.

Type Parameters

T

The expected element type.

GetElementBounds<T>()

Gets the rendered bounds (x, width) of the first element of the specified type. Returns null if no such element exists or has not been rendered yet.

public (int x, int width)? GetElementBounds<T>() where T : class, IPanelElement

Returns

(int x, int width)?

The x position and width of the element, or null.

Type Parameters

T

The element type to find.

HasElement<T>()

Returns true if any zone contains an element of the specified type.

public bool HasElement<T>() where T : class, IPanelElement

Returns

bool

True if at least one element of type T exists.

Type Parameters

T

The element type to check for.

MarkDirty()

Marks this panel as needing to be redrawn. Called by elements via Invalidate().

public void MarkDirty()

ProcessMouseEvent(MouseEventArgs)

Routes a mouse event to the element at the specified x position.

public bool ProcessMouseEvent(MouseEventArgs args)

Parameters

args MouseEventArgs

The mouse event arguments.

Returns

bool

True if an element handled the event.

Remove(IPanelElement)

Removes a specific element from any zone.

public bool Remove(IPanelElement element)

Parameters

element IPanelElement

The element to remove.

Returns

bool

True if the element was found and removed.

Remove(string)

Removes an element by name from any zone.

public bool Remove(string name)

Parameters

name string

The name of the element to remove.

Returns

bool

True if the element was found and removed.

Render(CharacterBuffer, int, int, Color, Color)

Renders this panel into the character buffer at the specified row.

public void Render(CharacterBuffer buffer, int y, int panelWidth, Color themeFg, Color themeBg)

Parameters

buffer CharacterBuffer

The character buffer to render into.

y int

The row to render at.

panelWidth int

The total width of the panel.

themeFg Color

The theme foreground color (used if panel has no color set).

themeBg Color

The theme background color (used if panel has no color set).