Table of Contents

Class StartMenuElement

Namespace
SharpConsoleUI.Panel
Assembly
SharpConsoleUI.dll

A panel element that renders a start menu button and opens the StartMenuDialog on click. Owns its own configuration, keyboard shortcut, and registered actions.

public class StartMenuElement : PanelElement, IPanelElement
Inheritance
StartMenuElement
Implements
Inherited Members
Extension Methods

Constructors

StartMenuElement(string?)

Initializes a new StartMenuElement.

public StartMenuElement(string? name = null)

Parameters

name string

Optional element name. Defaults to "startmenu".

Properties

ButtonBackground

Gets or sets the button background color.

public Color? ButtonBackground { get; set; }

Property Value

Color?

ButtonForeground

Gets or sets the button foreground color.

public Color? ButtonForeground { get; set; }

Property Value

Color?

FixedWidth

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

public override int? FixedWidth { get; }

Property Value

int?

IsInBottomPanel

Gets whether this element is in the bottom panel.

public bool IsInBottomPanel { get; }

Property Value

bool

Options

Gets or sets the start menu options (layout, colors, categories, etc.).

public StartMenuOptions Options { get; set; }

Property Value

StartMenuOptions

ShortcutKey

Gets or sets the keyboard shortcut key for toggling this start menu.

public ConsoleKey ShortcutKey { get; set; }

Property Value

ConsoleKey

ShortcutModifiers

Gets or sets the keyboard shortcut modifier keys for toggling this start menu.

public ConsoleModifiers ShortcutModifiers { get; set; }

Property Value

ConsoleModifiers

Text

Gets or sets the button text (supports markup).

public string Text { get; set; }

Property Value

string

Methods

GetActions()

Gets all registered actions for this start menu.

public IReadOnlyList<StartMenuAction> GetActions()

Returns

IReadOnlyList<StartMenuAction>

GetBounds()

Gets the rendered bounds (x, width) of this element on screen. Returns null if not yet rendered.

public (int x, int width)? GetBounds()

Returns

(int x, int width)?

MeasureWidth()

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

public override int MeasureWidth()

Returns

int

The measured width in columns.

ProcessMouseEvent(MouseEventArgs, int, int)

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

public override 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.

RegisterAction(string, Action, string?, int)

Registers a new action in this start menu.

public void RegisterAction(string name, Action callback, string? category = null, int order = 0)

Parameters

name string

Display name of the action.

callback Action

Callback to execute when action is selected.

category string

Optional category for grouping actions.

order int

Display order (lower values appear first).

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

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

public override 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.

Show()

Shows or toggles the start menu dialog for this element.

public void Show()

UnregisterAction(string)

Removes an action from this start menu by name.

public void UnregisterAction(string name)

Parameters

name string

Name of the action to remove.