diff --git a/docs/accessibility.md b/docs/accessibility.md index 46dc8094b..8ae83f600 100644 --- a/docs/accessibility.md +++ b/docs/accessibility.md @@ -12,9 +12,10 @@ paths a key or a click takes (`app/accessibility.go`). Role, bounds, name (`Label`), `Value`, `Hint`, `Description`, the states (`Focused`, `Disabled`, `Checked`, `Mixed`, `Selected`, `Expanded`, `ReadOnly`, `Secure`), `Focusable`, `Expandable`, a heading `Level`, `PosInSet` -and `SetSize`, a `Live` setting, a numeric `Range` for sliders, and, for the -focused text field, its `Selection` in code points. Components set the extras -through `gfx.HitOptions` (and `Canvas.ContainerWithOptions` for regions). +and `SetSize`, a `Live` setting, a numeric `Range` for sliders and labelled +progress bars, and, for the focused text field, its `Selection` in code points. +Components set the extras through `gfx.HitOptions` (and +`Canvas.ContainerWithOptions` for regions). What a node can do follows from its role and state (`AccessibilityNode.Patterns`), so every platform offers the same set. A node with no `ID` is a region @@ -22,6 +23,11 @@ so every platform offers the same set. A node with no `ID` is a region (`platform.AccessibilityContainer`): the list, grid, menu or menu bar whose bounds hold the node. +A progress bar declares only a read-only range: it is not focusable and offers no +press, increment or set-number request. `ui.Progress(c, fraction).Label("Uploading")` +exposes one; a `Progress` with no `Label` declares no node at all, so it keeps +taking no pointer or focus from the row that holds it. + ## Requests | Request | Press | Focus | Increment / Decrement | SetNumber | SetText | SetSelection | @@ -39,6 +45,11 @@ control refuse. Each repaint a request causes is presented in order. | Actions | press, increment, decrement, focus, set value, set selected text range | Invoke, Toggle, Value, RangeValue, SelectionItem, Selection, ExpandCollapse, Text | Action, Value, Text, EditableText, Component.GrabFocus | the browser's own | | Events | focus change, live-region announcement | focus, property changes, text changed / selection changed, live region changed, structure | state-changed, property-change, children-changed, text-changed, caret-moved, announcement | the browser's own | +A progress bar maps to `NSAccessibilityProgressIndicatorRole` on macOS, UIA's +`ProgressBar` control type (50012) on Windows, `ROLE_PROGRESS_BAR` on AT-SPI and +`role="progressbar"` on Web; its 0–100 range is exposed as a read-only +`RangeValue`. + Cost when nobody is listening: - Windows builds no element until a client first asks (`WM_GETOBJECT`), keeping diff --git a/docs/maintaining-controls.md b/docs/maintaining-controls.md index 555e3c44e..fce0089ca 100644 --- a/docs/maintaining-controls.md +++ b/docs/maintaining-controls.md @@ -30,8 +30,9 @@ an explicit edit there. There are two authoring paths, and they are not duplicates: - **Page controls** are `ui.*` or `ui.*Base` + Draw. They own page identity, - focus, input and state; the styled painter reuses the components' canvas - recipes. `ui` exports no `Begin*`. + focus, input and state; the recipe gives their node its default look and + measurement, and the styled painter draws only the parts the control owns. + `ui` exports no `Begin*`. - **Canvas recipes** are the `Begin*` constructors in package `components` and their `Paint`/`Layout` methods. They construct a value, paint through `gfx.Canvas` and declare hits; they are used inside a `ui.Control`/`Draw`, for pure measurement, or in source copied by @@ -120,14 +121,29 @@ The two forms are the same control. What differs is the look and nothing else. ### Where the behavior lives -Select, Slider, Input, Textarea and Field are built as `X = XBase` plus the theme's look -(`flagThemed`), so their behavior is written once. Button, Checkbox, Switch and Tabs are -separate code paths from their Bases: the styled form is painted by the styled layer's -painter (`ui/controls_paint.go`), which draws the recipe and declares the hit, and the Base -declares it again in `base/bases.go`. The parity test is what keeps those two declarations -equal until they share one. +A themed control is a node. Its box, padding, content, state look and children are the +engine's node attributes; the recipe in `components` supplies only the defaults that an +explicit `Box` call overrides. Behaviour — pointer, keyboard, focus, disabled, role, value — +is declared once on the control's root node in `base`, not by its painter. The painter in +`ui` (`ui/controls_paint.go`, `ui/tabs_paint.go`, `ui/select_paint.go`, …) draws only the +parts the control owns — check mark, switch thumb, track, chevron, indicator — and declares +no hit. -The behavior lives in package `base`, the appearance in package `components`: `base` never +Select, Slider, Input, Textarea and Field are built as `X = XBase` plus the theme's look +(`flagThemed`), so their behavior is written once. Button, Checkbox, Switch, Tabs and the +other migrated controls have their own declarations, but share the same node contract; the +parity tests keep both forms reporting the same role, state and actions, and +`ui/slot_parity_test.go` keeps a control in a slot painting and hitting like its `Begin*` +recipe. + +Every universal `Box` attribute a control accepts must either do its job or be rejected in +a dev build; neither outcome may be silent. The rejection rules live in +`base/attrcheck_dev.go` (empty in release builds) and their messages name the element, the +attribute and the reason; `VIVA_ATTR_CHECK=warn` prints them instead of panicking. +`base/attrs.go` only records the few defaults a node's value cannot express, and +`base/attrcheck_dev_test.go` / `attrcheck_release_test.go` cover both builds. + +The behaviour lives in package `base`, the appearance in package `components`: `base` never imports `components`, and the painters (in `ui`) read the engine's state through its exported accessors and call the recipes. `internal/layering` enforces the direction. @@ -135,8 +151,9 @@ exported accessors and call the recipes. `internal/layering` enforces the direct The look of a control is a recipe in `components` (`components/button.go`, …). Variants and sizes of a styled control are declared through `base.Box` (`Box.Outline`, `Box.Small`, …) -and drawn by the recipe in `ui`'s painter (for a button, `ui/controls_paint.go`). A change -to how a control looks belongs in the recipe; a change to what it does belongs in `base`. +and resolved onto the node's `Look`; an explicit element attribute (`.Pad`, `.FontSize`, +`.Color`, `.Radius`, …) overrides the recipe's default. A change to how a control looks +belongs in the recipe; a change to what it does belongs in `base`. ## Adding a control @@ -156,12 +173,16 @@ missed. 3. **Base** — add the Base in `base/bases.go` and `base/page_bases.go`, and a row for it in `TestStyledControlsDeclareWhatTheirBasesDeclare` and `comparedWithTheirStyledForm`. `TestEveryPageBaseIsComparedOrExplained` fails until you do. -4. **Guide and docs** — every exported `Box` method must appear in +4. **Attribute rule** — decide which universal attributes the new element takes. Each + attribute either works on it or is rejected by `base/attrcheck_dev.go` with a message + saying why; add the positive and negative cases to `base/attrcheck_dev_test.go`. A + control with a content slot takes `Children`; its own parts stay its own. +5. **Guide and docs** — every exported `Box` method must appear in `cmd/viva/initfiles/AGENTS.md.txt` (`base/guide_test.go`), and a program shown in a guide is the one in `examples/guides` (`website`: `npm run sync:examples`). -5. **Catalog** — a demo in `internal/componentdemo`, registered in `state.go` and the +6. **Catalog** — a demo in `internal/componentdemo`, registered in `state.go` and the catalog, so the component browser shows it. -6. **Cost** — a benchmark for the declaration, and a zero-allocation check for a warm +7. **Cost** — a benchmark for the declaration, and a zero-allocation check for a warm repaint (see `TestSelectDisabledOptionsDeclareWithoutAllocating` for the form). ## Where the packages stop diff --git a/docs/skills/building-with-viva/SKILL.md b/docs/skills/building-with-viva/SKILL.md index 9255d0108..b668265ae 100644 --- a/docs/skills/building-with-viva/SKILL.md +++ b/docs/skills/building-with-viva/SKILL.md @@ -61,6 +61,9 @@ func (m *model) page(c ui.C) { - The core page imports `github.com/vivaui/viva/ui`: colors, geometry and the theme are re-exported there (`ui.RGB`, `ui.Rect`, `ui.Theme`, `ui.LightTheme()`). Optional page packages (`ui/calendar`, `ui/message`, `ui/chart`, …) are imported only when used. `gfx` is the layer below (canvas, paths, input events, keys, identities); reach for it only to draw or handle input yourself. - Everything is a function of `ui` taking `c` first, and the chain is the same everywhere: `.Pad`, `.Gap`, `.Grow`, `.Width`, `.Background`, `.Children(func() { ... })`. Containers: `Row`, `Column`, `Stack`, `Grid`, `Flow`, `Scroll`. Leaves: `Text`, `Paragraph`, `Wrap`, `Spacer`, `Divider`, `Icon`, `Image`, `Button`, `Checkbox`, `Switch`, `Select`, `Choice`, `Tabs`, `Slider`, `Progress`, `Spinner`, `Splitter`, `Slot`. - Lengths are `float32`; sizes are border boxes. A child is as big as its content unless told `Width`/`Height`/`Size`, `Fill`, or `Grow(n)`. In a `Row`, a text field needs `Grow(1)` or `Width`, or it is invisible. +- A themed control is a node, not a fixed picture: its defaults come from the recipe, and the element attributes it accepts (`.FontSize`, `.Color`, `.Radius`, `Hover`/`Pressed`/`Focus`, and `.Pad`/`.Gap`/`.Children` where the control lays content out) override them. Not every control takes every attribute; a dev build panics when one would do nothing, and `VIVA_ATTR_CHECK=warn` reports instead of stopping, for cleaning up a page. +- `Children` is the content slot of a control that has one: `ui.Button(c, "Save").Children(func() { ... })` replaces the default label with your content, laid out in the content rectangle. The `Label` argument remains the control's assistive name, and hits, focus and disabled stay on the control. Without `Children` the default label is drawn as before; the control's own parts (check mark, switch thumb, tab indicator) are not content. +- Element attributes reach the parts of composite controls: `ui.Table(...).FontSize(...).Color(...)` styles header and cells, `ui.Image(...).Radius(...).Opacity(...)` cuts and fades the picture itself, `ui.Checkbox(...).Size(...)` sizes the box and scales the mark, `ui.Switch(...).FillWidth()` / `.WidthPercent(...)` stretches the track, `ui.Tabs(...).PadSides(...)` pads all four sides, and `ui.Progress(...).Label(...)` exposes the bar as a read-only progress bar (unlabelled bars stay decorative and take no pointer). ### Lists, tables and trees