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
ForegroundColor
Gets or sets the panel foreground color. Falls back to theme if null.
public Color? ForegroundColor { get; set; }
Property Value
Height
Gets the height of this panel (1 if visible, 0 if hidden).
public int Height { get; }
Property Value
IsDirty
Gets whether this panel needs to be redrawn.
public bool IsDirty { get; }
Property Value
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
Methods
AddCenter(params IPanelElement[])
Adds elements to the center zone.
public void AddCenter(params IPanelElement[] elements)
Parameters
elementsIPanelElement[]Elements to add.
AddLeft(params IPanelElement[])
Adds elements to the left zone.
public void AddLeft(params IPanelElement[] elements)
Parameters
elementsIPanelElement[]Elements to add.
AddRight(params IPanelElement[])
Adds elements to the right zone.
public void AddRight(params IPanelElement[] elements)
Parameters
elementsIPanelElement[]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
TThe 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
namestringThe element name.
Returns
- T
The element, or null if not found or wrong type.
Type Parameters
TThe 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
Type Parameters
TThe 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
TThe 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
argsMouseEventArgsThe 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
elementIPanelElementThe 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
namestringThe 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
bufferCharacterBufferThe character buffer to render into.
yintThe row to render at.
panelWidthintThe total width of the panel.
themeFgColorThe theme foreground color (used if panel has no color set).
themeBgColorThe theme background color (used if panel has no color set).