Class PopupMenu
- Namespace
- MiniTui
- Assembly
- MiniTui.dll
A menu overlay next to an anchor (1.x spec §7, §15). ↑ ↓ PgUp PgDn Home End and type-ahead move the selection; an item's mnemonic chooses it; Enter or a click chooses an item; → or Enter opens a submenu and ← closes it; Esc, Tab or a click outside dismisses the menu. Show it with ShowMenuAsync(IReadOnlyList<MenuItem>, Rect, int), or with Show(Overlay) and await Result or Chosen.
public sealed class PopupMenu : Overlay
- Inheritance
-
PopupMenu
- Inherited Members
Constructors
PopupMenu(IReadOnlyList<MenuItem>, Rect, int)
Create a menu. Show it with Show(Overlay) and await Result.
public PopupMenu(IReadOnlyList<MenuItem> items, Rect anchor, int selected = 0)
Parameters
itemsIReadOnlyList<MenuItem>The items, top to bottom.
anchorRectWhat the menu is for, in screen cells: a 1×1 rect for a point (a right-click), or the rect of a row or a field. The menu opens below it, or above when there's more room there.
selectedintThe item selected at first. A separator or disabled item moves the selection to the next enabled one.
Exceptions
- ArgumentException
itemscontains null.
Properties
Chosen
The chosen item, at any depth of submenus, or null when the menu was dismissed. Completes with Result.
public Task<MenuItem?> Chosen { get; }
Property Value
CloseOnClickOutside
Whether a press of any mouse button outside the overlay closes it (1.x spec §7.6). The press goes nowhere else. False by default.
public override bool CloseOnClickOutside { get; }
Property Value
Framed
Whether the app draws the themed block around the overlay. When false, the app only clears the Placement(Rect) rect, and Render(Buffer, Rect, RenderContext) gets all of it to draw, border included. True by default.
public override bool Framed { get; }
Property Value
KeysGroup
The heading for this component's bindings in the help overlay.
public override string KeysGroup { get; }
Property Value
MaxRows
At most this many item rows are shown; more scroll. Default 12.
public int MaxRows { get; init; }
Property Value
MinWidth
The menu is at least this wide, border included. A select passes its field's width. Default 0.
public int MinWidth { get; init; }
Property Value
Result
The chosen item's index, or null when the menu was dismissed or closed any other way. For an item chosen in a submenu, the index of the top-level item that holds it.
public Task<int?> Result { get; }
Property Value
Methods
HandleKey(ConsoleKeyInfo)
Handle a key before Keys. Return true if handled.
public override bool HandleKey(ConsoleKeyInfo key)
Parameters
keyConsoleKeyInfo
Returns
HandleMouse(MouseEvent)
Handle a mouse event inside this component's Area (1.x spec §4.7). Return true if handled; otherwise the event goes on to the component's parent, and is dropped if nothing handles it. A press has already focused the component when this runs.
public override bool HandleMouse(MouseEvent mouse)
Parameters
mouseMouseEvent
Returns
OnMount()
Called when the component is mounted, before its children.
protected override void OnMount()
OnUnmount()
Called when the component unmounts, after its children and after Lifetime is cancelled.
protected override void OnUnmount()
Placement(Rect)
Below the anchor, or above it, shifted left to stay on the screen (1.x spec §7.4). A submenu goes to the right of its parent, or to the left when it doesn't fit, with its first row beside the parent's row (§15.4).
public override Rect Placement(Rect screen)
Parameters
screenRect
Returns
Render(Buffer, Rect, RenderContext)
Draw the component. Called every frame its parent renders it.
public override void Render(Buffer buf, Rect area, RenderContext ctx)
Parameters
bufBufferareaRectctxRenderContext