Table of Contents

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

items IReadOnlyList<MenuItem>

The items, top to bottom.

anchor Rect

What 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.

selected int

The item selected at first. A separator or disabled item moves the selection to the next enabled one.

Exceptions

ArgumentException

items contains 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

Task<MenuItem>

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

bool

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

bool

KeysGroup

The heading for this component's bindings in the help overlay.

public override string KeysGroup { get; }

Property Value

string

MaxRows

At most this many item rows are shown; more scroll. Default 12.

public int MaxRows { get; init; }

Property Value

int

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

int

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

Task<int?>

Methods

HandleKey(ConsoleKeyInfo)

Handle a key before Keys. Return true if handled.

public override bool HandleKey(ConsoleKeyInfo key)

Parameters

key ConsoleKeyInfo

Returns

bool

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

mouse MouseEvent

Returns

bool

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

screen Rect

Returns

Rect

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

buf Buffer
area Rect
ctx RenderContext