loom & weft
Made for Swift.

Published release 0.2.1. Unreleased PR #2 reference.

LOOM 0.2.1 / WIDGETS

PopupMenu

Render after the content it overlays: the assigned area is cleared before choices are drawn. Selection is clamped for presentation and determines scrolling. Hover is independent. title enables full borders and larger content insets; supporting introduction/footer rows are optional and depend on available space. The app handles keys, close actions, and placement.

Standard inherited Swift protocol operations such as synthesized equality and OptionSet set operations are not repeated. The public declarations below are extracted from the exact source revision listed in the coverage manifest.

Example

var popup = PopupMenu([PopupMenuItem("Open", detail: "Enter"), PopupMenuItem("Quit")])
popup.title = "Actions"
popup.showsCloseButton = true
let area = Rect(width: 40, height: popup.height())
_ = popup.visibleRange(in: area)
_ = popup.closeButtonArea(in: area)
Members on this page

Feature guides and release status

PopupMenu

Structure
struct PopupMenu

Conforms to: Widget.

An opaque, scrollable list with aligned labels, details, and horizontal separators.

Render after the content it overlays. The caller owns selection and placement; rendering and hit testing use the same visible range. Colors inherit the terminal.

Source · PopupMenu.swift:20

items

Instance Property
var items: [PopupMenuItem]

The menu’s choices in display order.

Source · PopupMenu.swift:21

hoveredIndex

Instance Property
var hoveredIndex: Int?

Pointer highlight, independent of keyboard selection and scrolling.

Source · PopupMenu.swift:23

hoverStyle

Instance Property
var hoverStyle: Style

Style used for an unselected hovered choice. Defaults to underline.

Source · PopupMenu.swift:24

selectedIndex

Instance Property
var selectedIndex: Int

Caller-selected zero-based item index.

Source · PopupMenu.swift:25

style

Instance Property
var style: Style

Visual attributes used when painting this value.

Source · PopupMenu.swift:26

detailStyle

Instance Property
var detailStyle: Style

Style of unselected supporting detail.

Source · PopupMenu.swift:27

selectionStyle

Instance Property
var selectionStyle: Style

Style used for the selected choice/icon.

Source · PopupMenu.swift:28

separatorStyle

Instance Property
var separatorStyle: Style

Style of popup separators and border rules.

Source · PopupMenu.swift:29

title

Instance Property
var title: String?

A title set into a full border.

Titled menus use two-column content insets.

Source · PopupMenu.swift:33

introduction

Instance Property
var introduction: String?

A single supporting row above the choices when the menu has enough room.

Source · PopupMenu.swift:35

showsCloseButton

Instance Property
var showsCloseButton: Bool

Whether a titled popup displays its close control.

Source · PopupMenu.swift:38

rightAlignsDetails

Instance Property
var rightAlignsDetails: Bool

Whether supporting popup details align to the right.

Source · PopupMenu.swift:39

fullBorder

Instance Property
var fullBorder: Bool

Adds square side borders to the existing top and bottom rules.

Source · PopupMenu.swift:41

showsSelectionMarker

Instance Property
var showsSelectionMarker: Bool

Displays the keyboard selection chevron and reserves its two columns.

Source · PopupMenu.swift:43

showsItemCount

Instance Property
var showsItemCount: Bool

Displays the number of items on the top border.

Source · PopupMenu.swift:45

emptyMessage

Instance Property
var emptyMessage: String

Text shown when the popup has no items.

Source · PopupMenu.swift:46

init(_:selectedIndex:)

Initializer
init(_ items: [PopupMenuItem], selectedIndex: Int = 0)

Creates a value with the supplied arguments. Default arguments are shown in the declaration.

Parameters (2)
items
Choices in display order.
selectedIndex
Zero-based keyboard-selected item index.
Source · PopupMenu.swift:48

height(maximumRows:)

Instance Method
func height(maximumRows: Int = 8) -> Int

Preferred height including the border, optional supporting rows, and at least one choice row.

Parameters (1)
maximumRows
Maximum number of visible choice rows.

Returns Int.

Source · PopupMenu.swift:54

visibleRange(in:)

Instance Method
func visibleRange(in area: Rect) -> Range<Int>

Item indices visible at this size, keeping the selected row near the middle.

Parameters (1)
in
Argument type and any default are shown in the declaration; see the behavior notes above.

Returns Range<Int>.

Source · PopupMenu.swift:61

item(at:in:)

Instance Method
func item(at point: Point, in area: Rect) -> Int?

Returns the item under a content cell, excluding separators and the scrollbar.

Parameters (2)
at
Argument type and any default are shown in the declaration; see the behavior notes above.
in
Argument type and any default are shown in the declaration; see the behavior notes above.

Returns Int?.

Source · PopupMenu.swift:70

closeButtonArea(in:)

Instance Method
func closeButtonArea(in area: Rect) -> Rect?

The title-bar close control, excluding its surrounding padding and border.

Parameters (1)
in
Argument type and any default are shown in the declaration; see the behavior notes above.

Returns Rect?.

Source · PopupMenu.swift:79

render(in:buffer:)

Instance Method
func render(in area: Rect, buffer: inout Buffer)

Paints this widget into the assigned terminal-cell rectangle. Application code owns state, input routing, and terminal lifetime.

Parameters (2)
in
Argument type and any default are shown in the declaration; see the behavior notes above.
buffer
Mutable destination cell grid.
Source · PopupMenu.swift:84