a11y

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package a11y is Silk's accessibility surface — the equivalent of Qt's QAccessible. Widgets advertise their semantic role, name, value and state so screen-readers, automated test harnesses, and other tooling can enumerate the UI without poking at private fields.

Two participation modes:

  1. Explicit: widgets implement the Accessible interface (and optionally AccessibleDescription / AccessibleValue / AccessibleState) for full control over the reported metadata.

  2. Duck-typed: widgets that don't implement Accessible still produce a useful Node via DescribeViaInterfaces, which inspects well-known method names (Text / Title / IsChecked / Value / IsEnabled / IsVisible / HasFocus / Bounds) on the widget. This keeps the 62-widget catalog covered without modifying every widget file at once.

Walk(root) delivers a flat *Node tree rooted at the given widget. Hosts marshal the tree to whatever sink they want — a screen-reader bridge, an integration-test snapshot, or a debug overlay. The package itself talks to no OS API; platform-specific bridges (VoiceOver / NVDA / AT-SPI) belong in separate packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Accessible

type Accessible interface {
	AccessibleRole() Role
	AccessibleName() string
}

Accessible is the explicit opt-in interface. Widgets that implement it advertise role + name directly; anything missing falls back to DescribeViaInterfaces.

type AccessibleDescription

type AccessibleDescription interface {
	AccessibleDescription() string
}

AccessibleDescription is an optional refinement returning a longer help text. Most widgets leave this empty; tooltips and form fields with explanatory copy implement it.

type AccessibleState

type AccessibleState interface {
	AccessibleState() State
}

AccessibleState is implemented by widgets that want to report a State bitmask explicitly. Widgets that don't implement this still get state inferred from their bool methods (IsEnabled / IsVisible / HasFocus / IsChecked).

type AccessibleValue

type AccessibleValue interface {
	AccessibleValue() string
}

AccessibleValue is implemented by widgets whose state has a human-readable value distinct from its name — slider position number, edit content, progress percent, etc.

type Node

type Node struct {
	Role        Role
	Name        string
	Description string
	Value       string
	State       State
	X, Y, W, H  float64
	Children    []*Node
}

Node is a flat record describing one accessible element. Trees of Nodes mirror the widget hierarchy. All fields are public so tests and bridges can read directly; mutation is allowed but only on freshly-Walked trees (the package never holds onto Nodes after they leave Walk).

func Walk

func Walk(root interface{}) *Node

Walk produces a *Node tree rooted at root. Hidden widgets are skipped — bridges only care about visible UI. Use WalkAll to include hidden subtrees (useful for designers and integration tests that want a full inventory).

The walk is depth-first so child order in the returned tree matches the widget paint order. Recursive — applications with very deep trees should chunk via WalkSubtree if stack exhaustion is a concern.

func WalkAll

func WalkAll(root interface{}) *Node

WalkAll behaves like Walk but does not skip hidden widgets. Use when you want a complete inventory regardless of current visibility.

type Role

type Role int

Role identifies the semantic kind of a UI element. Values map roughly to ARIA roles and QAccessible::Role so OS-specific bridges have a clean translation table.

const (
	// RoleUnknown is the default for widgets that haven't declared a role
	// and don't match any inference heuristic.
	RoleUnknown Role = iota

	RoleApplication
	RoleWindow
	RoleDialog
	RoleGroup
	RoleSeparator
	RoleStatusBar
	RoleToolBar
	RoleMenuBar
	RoleMenu
	RoleMenuItem

	RoleButton
	RoleCheckBox
	RoleRadioButton
	RoleSwitch
	RoleEdit
	RoleSearchBox
	RoleSpinBox
	RoleSlider
	RoleProgressBar
	RoleComboBox
	RoleLabel
	RoleLink
	RoleImage

	RoleList
	RoleListItem
	RoleTree
	RoleTreeItem
	RoleTable
	RoleCell
	RoleTab
	RoleTabPanel

	RoleScrollBar
	RoleSplitter
	RoleCard
	RoleAccordion
	RoleNotification
	RoleTooltip
	RoleBadge
)

func (Role) String

func (r Role) String() string

String returns a stable human-readable name. Used by tests and debug dumps; bridges should switch on Role rather than parse the string.

type State

type State uint32

State is a bitmask of UI state flags. Multiple flags can be set simultaneously (e.g. a focused-but-disabled control).

const (
	StateFocused State = 1 << iota
	StateChecked
	StateDisabled
	StateHidden
	StateReadOnly
	StatePressed
	StateExpanded
	StateSelected
	StateRequired
	StateInvalid
)

func (State) Has

func (s State) Has(mask State) bool

Has reports whether all of mask is set in s. Bitwise convenience — reads better than s & mask == mask at every call site.

func (State) With

func (s State) With(mask State) State

With returns s with mask added. Useful in builder-style state composition.

func (State) Without

func (s State) Without(mask State) State

Without returns s with mask cleared.

type Walker

type Walker interface {
	Children() []Walker
}

Walker is the minimum surface a tree-walkable widget needs to expose. gui.IWidget already implements every method here, so no widget-side glue is required to wire glui apps through Walk. Custom UI containers (graph items, designer fakes) implement the same shape and slot in.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL