Class MenuBuilder
- Namespace
- SharpConsoleUI.Builders
- Assembly
- SharpConsoleUI.dll
Fluent builder for creating MenuControl instances with a clean, chainable API.
public class MenuBuilder
- Inheritance
-
MenuBuilder
- Inherited Members
Methods
AddItem(string, Action)
Adds a simple menu item with text and action (no shortcut).
public MenuBuilder AddItem(string text, Action action)
Parameters
textstringThe text to display for this menu item.
actionActionThe action to execute when selected.
Returns
AddItem(string, Action, Color)
Adds a simple menu item with text, action, and custom foreground color.
public MenuBuilder AddItem(string text, Action action, Color foregroundColor)
Parameters
textstringThe text to display for this menu item.
actionActionThe action to execute when selected.
foregroundColorColorThe custom foreground color for this item.
Returns
AddItem(string, Action<MenuItemBuilder>)
Adds a menu item with subitems using a configuration action.
public MenuBuilder AddItem(string text, Action<MenuItemBuilder> configure)
Parameters
textstringThe text to display for this menu item.
configureAction<MenuItemBuilder>Action to configure the menu item's children.
Returns
AddItem(string, string, Action)
Adds a simple menu item with text, shortcut, and action.
public MenuBuilder AddItem(string text, string shortcut, Action action)
Parameters
textstringThe text to display for this menu item.
shortcutstringThe keyboard shortcut text (display only).
actionActionThe action to execute when selected.
Returns
AddItem(string, string, Action, Color)
Adds a simple menu item with text, shortcut, action, and custom foreground color.
public MenuBuilder AddItem(string text, string shortcut, Action action, Color foregroundColor)
Parameters
textstringThe text to display for this menu item.
shortcutstringThe keyboard shortcut text (display only).
actionActionThe action to execute when selected.
foregroundColorColorThe custom foreground color for this item.
Returns
AddSeparator()
Adds a separator line to the menu.
public MenuBuilder AddSeparator()
Returns
Build()
Builds and returns the configured MenuControl instance.
public MenuControl Build()
Returns
Horizontal()
Sets the menu orientation to horizontal (menu bar style).
public MenuBuilder Horizontal()
Returns
OnItemHovered(EventHandler<MenuItem>)
Registers an event handler for when a menu item is hovered.
public MenuBuilder OnItemHovered(EventHandler<MenuItem> handler)
Parameters
handlerEventHandler<MenuItem>
Returns
OnItemSelected(WindowEventHandler<MenuItem>)
Registers an event handler for when a menu item is selected, with access to the parent window.
public MenuBuilder OnItemSelected(WindowEventHandler<MenuItem> handler)
Parameters
handlerWindowEventHandler<MenuItem>
Returns
OnItemSelected(EventHandler<MenuItem>)
Registers an event handler for when a menu item is selected.
public MenuBuilder OnItemSelected(EventHandler<MenuItem> handler)
Parameters
handlerEventHandler<MenuItem>
Returns
Sticky()
Enables sticky mode, where the menu keeps focus when dropdowns are open.
public MenuBuilder Sticky()
Returns
Vertical()
Sets the menu orientation to vertical (sidebar style).
public MenuBuilder Vertical()
Returns
WithDropdownBackgroundColor(Color)
Sets the background color for dropdown menus.
public MenuBuilder WithDropdownBackgroundColor(Color color)
Parameters
colorColor
Returns
WithDropdownColors(Color, Color, Color, Color)
Sets all dropdown colors at once.
public MenuBuilder WithDropdownColors(Color background, Color foreground, Color highlightBackground, Color highlightForeground)
Parameters
backgroundColorforegroundColorhighlightBackgroundColorhighlightForegroundColor
Returns
WithDropdownForegroundColor(Color)
Sets the foreground color for dropdown menu items.
public MenuBuilder WithDropdownForegroundColor(Color color)
Parameters
colorColor
Returns
WithDropdownHighlightBackgroundColor(Color)
Sets the background color for highlighted dropdown items.
public MenuBuilder WithDropdownHighlightBackgroundColor(Color color)
Parameters
colorColor
Returns
WithDropdownHighlightForegroundColor(Color)
Sets the foreground color for highlighted dropdown items.
public MenuBuilder WithDropdownHighlightForegroundColor(Color color)
Parameters
colorColor
Returns
WithMenuBarBackgroundColor(Color)
Sets the background color for the menu bar (top-level items).
public MenuBuilder WithMenuBarBackgroundColor(Color color)
Parameters
colorColor
Returns
WithMenuBarColors(Color, Color, Color, Color)
Sets all menu bar colors at once.
public MenuBuilder WithMenuBarColors(Color background, Color foreground, Color highlightBackground, Color highlightForeground)
Parameters
backgroundColorforegroundColorhighlightBackgroundColorhighlightForegroundColor
Returns
WithMenuBarForegroundColor(Color)
Sets the foreground color for the menu bar (top-level items).
public MenuBuilder WithMenuBarForegroundColor(Color color)
Parameters
colorColor
Returns
WithMenuBarHighlightBackgroundColor(Color)
Sets the background color for highlighted menu bar items.
public MenuBuilder WithMenuBarHighlightBackgroundColor(Color color)
Parameters
colorColor
Returns
WithMenuBarHighlightForegroundColor(Color)
Sets the foreground color for highlighted menu bar items.
public MenuBuilder WithMenuBarHighlightForegroundColor(Color color)
Parameters
colorColor
Returns
WithName(string)
Sets the name of the menu control for identification.
public MenuBuilder WithName(string name)
Parameters
namestring
Returns
Operators
implicit operator MenuControl(MenuBuilder)
Allows implicit conversion from MenuBuilder to MenuControl.
public static implicit operator MenuControl(MenuBuilder builder)
Parameters
builderMenuBuilder