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
namestringOptional element name. Defaults to "startmenu".
Properties
ButtonBackground
Gets or sets the button background color.
public Color? ButtonBackground { get; set; }
Property Value
ButtonForeground
Gets or sets the button foreground color.
public Color? ButtonForeground { get; set; }
Property Value
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
Options
Gets or sets the start menu options (layout, colors, categories, etc.).
public StartMenuOptions Options { get; set; }
Property Value
ShortcutKey
Gets or sets the keyboard shortcut key for toggling this start menu.
public ConsoleKey ShortcutKey { get; set; }
Property Value
ShortcutModifiers
Gets or sets the keyboard shortcut modifier keys for toggling this start menu.
public ConsoleModifiers ShortcutModifiers { get; set; }
Property Value
Text
Gets or sets the button text (supports markup).
public string Text { get; set; }
Property Value
Methods
GetActions()
Gets all registered actions for this start menu.
public IReadOnlyList<StartMenuAction> GetActions()
Returns
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
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
argsMouseEventArgsThe mouse event arguments.
elementXintThe x position of this element on screen.
elementWidthintThe 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
namestringDisplay name of the action.
callbackActionCallback to execute when action is selected.
categorystringOptional category for grouping actions.
orderintDisplay 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
bufferCharacterBufferThe character buffer to render into.
xintThe x position to render at.
yintThe y position to render at.
widthintThe allocated width for this element.
fgColorThe default foreground color.
bgColorThe 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
namestringName of the action to remove.