loom & weft
Made for Swift.

Published release 0.2.1. Unreleased PR #2 reference.

LOOM 0.2.1 / WIDGETS

Desktop

A grid with owned selection/hover state and caller-owned background/actions. Use the same viewport for rendering and hit testing. moveSelection wraps in reading order. Mouse-down selects and returns a launch target; motion updates hover; wheel input scrolls. Replace icons with setIcons to drop state for removed IDs.

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 desktop = Desktop(viewport: Rect(width: 80, height: 24), icons: [
    DesktopIcon(id: "help", label: "Help", symbol: "?", launchTarget: "help")
])
desktop.moveSelection(by: 1)
_ = desktop.activateSelected()
Members on this page

Feature guides and release status

Desktop

Structure
struct Desktop

Conforms to: Widget.

A responsive grid of terminal-cell icons for a separate desktop screen.

The desktop owns icon selection and hover state. Its caller owns the screen background, launch actions, and any windows opened from the icons.

Source · Desktop.swift:25

viewport

Instance Property
var viewport: Rect { get }

Available terminal-cell viewport.

Source · Desktop.swift:26

icons

Instance Property
var icons: [DesktopIcon] { get }

Current desktop icons in display order.

Source · Desktop.swift:27

selectedIconID

Instance Property
var selectedIconID: String? { get }

Identity of the selected icon, or nil.

Source · Desktop.swift:28

hoveredIconID

Instance Property
var hoveredIconID: String? { get }

Identity of the hovered icon, or nil.

Source · Desktop.swift:29

style

Instance Property
var style: Style

Visual attributes used when painting this value.

Source · Desktop.swift:30

selectionStyle

Instance Property
var selectionStyle: Style

Style used for the selected choice/icon.

Source · Desktop.swift:31

hoverStyle

Instance Property
var hoverStyle: Style

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

Source · Desktop.swift:32

init(viewport:icons:)

Initializer
init(viewport: Rect, icons: [DesktopIcon])

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

Parameters (2)
viewport
Available terminal-cell viewport.
icons
Icons with unique IDs.
Source · Desktop.swift:36

resizeViewport(to:)

Instance Method
mutating func resizeViewport(to viewport: Rect)

Updates the terminal-cell viewport and keeps a selected icon visible.

Parameters (1)
to
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · Desktop.swift:42

setIcons(_:)

Instance Method
mutating func setIcons(_ icons: [DesktopIcon])

Replaces the icons, dropping selection and hover for removed IDs.

Parameters (1)
icons
Icons with unique IDs.
Source · Desktop.swift:49

iconArea(for:)

Instance Method
func iconArea(for id: String) -> Rect?

Returns the visible terminal-cell rectangle of an icon.

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

Returns Rect?.

Source · Desktop.swift:61

icon(at:)

Instance Method
func icon(at point: Point) -> DesktopIcon?

Returns the icon under a terminal-cell point, if any.

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

Returns DesktopIcon?.

Source · Desktop.swift:67

moveSelection(by:)

Instance Method
mutating func moveSelection(by steps: Int)

Moves keyboard selection through icons in reading order, wrapping at the ends.

Parameters (1)
by
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · Desktop.swift:72

activateSelected()

Instance Method
func activateSelected() -> String?

Returns the launch target of the keyboard-selected icon.

Returns String?.

Source · Desktop.swift:84

clearSelection()

Instance Method
mutating func clearSelection()

Clears keyboard or mouse selection.

Source · Desktop.swift:89

clearHover()

Instance Method
mutating func clearHover()

Clears pointer hover, for example when the pointer leaves the desktop.

Source · Desktop.swift:94

handleMouse(_:)

Instance Method
@discardableResult mutating func handleMouse(_ mouse: MouseEvent) -> String?

Selects and launches an icon on mouse-down; pointer motion updates hover.

A mouse-down on empty desktop space clears selection. Other events do not launch an icon. The returned target is interpreted by the application.

Parameters (1)
mouse
Mouse action and terminal-cell position.

Returns String?.

Source · Desktop.swift:103

render(in:buffer:)

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

Renders icons using the same geometry as hit testing.

Pass viewport as area so rendering and input refer to the same cells.

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