Class Menu
- Namespace
- Myra.Graphics2D.UI
- Assembly
- Myra.dll
An abstract base class for menu widgets that display items in a horizontal or vertical arrangement.
public abstract class Menu : Widget, IItemWithId, INotifyAttachedPropertyChanged
- Inheritance
-
Menu
- Implements
- Derived
- Inherited Members
Constructors
Menu(Stylesheet, string)
Initializes a new instance of the Menu class with the specified stylesheet and style.
protected Menu(Stylesheet stylesheet, string styleName)
Parameters
stylesheetStylesheetThe stylesheet to use for applying the style.
styleNamestringThe name of the style to apply. Defaults to the default stylesheet style.
Menu(string)
Initializes a new instance of the Menu class with the specified style.
protected Menu(string styleName)
Parameters
styleNamestringThe name of the style to apply. Defaults to the default stylesheet style.
Properties
Desktop
Gets or sets the desktop that contains this menu.
public override Desktop Desktop { get; }
Property Value
HoverIndex
Gets or sets the index of the menu item that the cursor is currently hovering over.
[Browsable(false)]
public int? HoverIndex { get; set; }
Property Value
- int?
HoverIndexCanBeNull
Gets or sets a value indicating whether the hover index can be null when no item is hovered.
public bool HoverIndexCanBeNull { get; set; }
Property Value
InternalChild
Gets the internal grid widget that manages menu item layout and selection.
protected Grid InternalChild { get; }
Property Value
IsOpen
Gets a value indicating whether any submenu is currently open.
[Browsable(false)]
public bool IsOpen { get; }
Property Value
Items
Gets the collection of menu items displayed in the menu.
[Browsable(false)]
public ObservableCollection<IMenuItem> Items { get; }
Property Value
LabelColor
Gets or sets the color of menu item text.
[StylePropertyPath("LabelStyle/TextColor")]
public Color LabelColor { get; set; }
Property Value
- Color
LabelFont
Gets or sets the font used to render menu item text.
[StylePropertyPath("LabelStyle/Font")]
public SpriteFontBase LabelFont { get; set; }
Property Value
- SpriteFontBase
LabelHorizontalAlignment
Gets or sets the horizontal alignment of menu item text labels.
public HorizontalAlignment LabelHorizontalAlignment { get; set; }
Property Value
MenuStyle
Gets or sets the style applied to the menu.
[Browsable(false)]
public MenuStyle MenuStyle { get; }
Property Value
Orientation
Gets the orientation (horizontal or vertical) of the menu.
[Browsable(false)]
public abstract Orientation Orientation { get; }
Property Value
SelectedIndex
Gets or sets the index of the currently selected menu item.
[Browsable(false)]
public int? SelectedIndex { get; set; }
Property Value
- int?
SelectionBackground
Gets or sets the brush used to draw the background of a selected menu item.
public IBrush SelectionBackground { get; set; }
Property Value
SelectionHoverBackground
Gets or sets the brush used to draw the background when hovering over a menu item.
public IBrush SelectionHoverBackground { get; set; }
Property Value
Methods
ApplyStyle(WidgetStyle)
Applies the specified widget style to this menu.
protected override void ApplyStyle(WidgetStyle style)
Parameters
styleWidgetStyleThe widget style to apply.
Close()
Closes the menu and any open submenus, clearing selection and hover state.
public void Close()
FindMenuItemById(string)
Recursively search for the menu item by id
public MenuItem FindMenuItemById(string id)
Parameters
idstring
Returns
- MenuItem
null if not found
InternalMeasure(Point)
Measures the size required for the menu, updating the grid layout if needed.
protected override Point InternalMeasure(Point availableSize)
Parameters
availableSizePointThe available size for the menu.
Returns
- Point
The measured size needed for the menu.
MoveHover(int)
Moves the hover index by the specified delta amount, skipping separators.
public void MoveHover(int delta)
Parameters
deltaintThe amount to move the hover index (typically 1 or -1).
OnKeyDown(Keys)
Handles keyboard input for menu navigation and selection (Enter, Space, arrow keys, and mnemonic keys).
public override void OnKeyDown(Keys k)
Parameters
kKeysThe key being pressed.