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
struct DesktopConforms 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:25viewport
var viewport: Rect { get }Available terminal-cell viewport.
Source · Desktop.swift:26icons
var icons: [DesktopIcon] { get }Current desktop icons in display order.
Source · Desktop.swift:27selectedIconID
var selectedIconID: String? { get }Identity of the selected icon, or nil.
Source · Desktop.swift:28hoveredIconID
var hoveredIconID: String? { get }Identity of the hovered icon, or nil.
Source · Desktop.swift:29style
var style: StyleVisual attributes used when painting this value.
Source · Desktop.swift:30selectionStyle
var selectionStyle: StyleStyle used for the selected choice/icon.
Source · Desktop.swift:31hoverStyle
var hoverStyle: StyleStyle used for an unselected hovered icon. Defaults to underline.
Source · Desktop.swift:32init(viewport:icons:)
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.
resizeViewport(to:)
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.
setIcons(_:)
mutating func setIcons(_ icons: [DesktopIcon])Replaces the icons, dropping selection and hover for removed IDs.
Parameters (1)
icons- Icons with unique IDs.
iconArea(for:)
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?.
icon(at:)
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?.
moveSelection(by:)
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.
activateSelected()
func activateSelected() -> String?Returns the launch target of the keyboard-selected icon.
Returns String?.
clearSelection()
mutating func clearSelection()Clears keyboard or mouse selection.
Source · Desktop.swift:89clearHover()
mutating func clearHover()Clears pointer hover, for example when the pointer leaves the desktop.
Source · Desktop.swift:94handleMouse(_:)
@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?.
render(in:buffer:)
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.