class

Phosphor::PopupMenuMock

Inherits Phosphor::MockWidget < Reference < Object

A floating context menu that appears at a specific absolute position, rendered as an overlay last in Screen#render, sized to its content.

Generic and app-agnostic: no knowledge of AppState, Msg, or the application theme. The Widget wrapper resolves theme → Style values and sets them in Props before each render.

Distinct from ConfirmMock (list of actions, not a yes/no question) and ListMock (positional, floating, transient rather than filling a layout slot). Unlike every other MockWidget, PopupMenuMock ignores the frame it's given for positioning — it places itself at props.origin_x/props.origin_y instead, using the frame only to size and clip itself so it never writes off-screen.

Constructors

new(props : Props, state : WidgetState = WidgetState.new)

Initialises the popup with props and an optional state.

Source

Instance methods

handle_cmd(cmd : Cmd) : CmdResult

Responds to navigation, confirm, and cancel commands.

  • Cmd::MoveDown — advances state.focused_index by one item, wrapping to the start, skipping over disabled items.
  • Cmd::MoveUp — retreats state.focused_index by one item, wrapping to the end, skipping over disabled items.
  • Cmd::ConfirmCmdResult::Bubble if the focused item isn't disabled, so the owning Widget can emit a domain Msg; CmdResult::None if it's disabled or there are no items.
  • Cmd::Cancel — always CmdResult::Bubble, regardless of the focused item, so the owning Widget can dismiss the popup.
  • Any other command — returns CmdResult::None.
Source
props
Source
props=(props : Props)
Source
render_content(frame : Frame, buf : Buffer) : Void

Draws a bordered box of items at props.origin_x/props.origin_y, sized to content and clipped to frame.

Width is the longest item label plus 2 cells (the border's left and right edges), capped at frame.width; height is props.items.size plus 2 (top and bottom border rows), capped at frame.height. The popup's actual top-left corner is props.origin_x/props.origin_y shifted inward just enough to keep the whole box within frame — never partially off-screen when there's room to avoid it. Drawing itself (border + items) delegates to BorderMock wrapping an internal item-list widget, the same composition ConfirmMock uses.

Source
state

Narrows the inherited state getter to PopupMenuMock::WidgetState. Safe: initialize only ever stores a WidgetState into the base @state ivar.

Source

Nested types