Table of Contents

Class PanelElement

Namespace
SharpConsoleUI.Panel
Assembly
SharpConsoleUI.dll

Abstract base class implementing IPanelElement with sensible defaults. Elements that don't need to inherit from something else should extend this.

public abstract class PanelElement : IPanelElement
Inheritance
PanelElement
Implements
Derived
Inherited Members
Extension Methods

Constructors

PanelElement(string)

Initializes a new PanelElement with the given name.

protected PanelElement(string name)

Parameters

name string

The unique name of this element.

Properties

FixedWidth

Gets the fixed width of this element, or null if it uses MeasureWidth() or flex sizing.

public virtual int? FixedWidth { get; }

Property Value

int?

FlexGrow

Gets the flex grow factor. 0 = fixed sizing, >0 = flex proportional to other flex elements.

public virtual int FlexGrow { get; }

Property Value

int

MaxWidth

Gets the maximum width constraint for flex elements.

public virtual int? MaxWidth { get; }

Property Value

int?

MinWidth

Gets the minimum width constraint for flex elements.

public virtual int? MinWidth { get; }

Property Value

int?

Name

Gets the unique name of this element.

public string Name { get; }

Property Value

string

Owner

Gets the parent panel this element is attached to, or null if detached.

protected Panel? Owner { get; }

Property Value

Panel

Visible

Gets or sets whether this element is visible.

public bool Visible { get; set; }

Property Value

bool

WindowSystem

Gets the console window system via the parent panel, or null if not attached.

protected ConsoleWindowSystem? WindowSystem { get; }

Property Value

ConsoleWindowSystem

Methods

Invalidate()

Notifies the parent panel that this element needs to be redrawn.

protected void Invalidate()

MeasureWidth()

Measures the natural content width of this element. Used when FixedWidth is null and FlexGrow is 0.

public virtual int MeasureWidth()

Returns

int

The measured width in columns.

OnAttached(Panel)

Called when this element is added to a panel.

public void OnAttached(Panel panel)

Parameters

panel Panel

The parent panel.

OnDetached()

Called when this element is removed from a panel.

public void OnDetached()

ProcessMouseEvent(MouseEventArgs, int, int)

Processes a mouse event that occurred within this element's bounds.

public virtual bool ProcessMouseEvent(MouseEventArgs args, int elementX, int elementWidth)

Parameters

args MouseEventArgs

The mouse event arguments.

elementX int

The x position of this element on screen.

elementWidth int

The allocated width of this element.

Returns

bool

True if the event was handled.

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

Renders the element into the character buffer at the specified position.

public abstract void Render(CharacterBuffer buffer, int x, int y, int width, Color fg, Color bg)

Parameters

buffer CharacterBuffer

The character buffer to render into.

x int

The x position to render at.

y int

The y position to render at.

width int

The allocated width for this element.

fg Color

The default foreground color.

bg Color

The default background color.