Skip to content
Merged
158 changes: 141 additions & 17 deletions GUIDE.md

Large diffs are not rendered by default.

163 changes: 145 additions & 18 deletions GUIDE_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4781,9 +4781,10 @@ _ = mgr.RestoreLayout(data)
**Floating panels.** By default `Float()` turns on a widget-drawn floating
panel right inside the canvas (drag/resize with the mouse, headless-testable).
The hook `DockPane.OnFloatNative func(p *DockPane)`, if set, hands the detach
off to a native OS window (`window/**`) instead of the widget floating — as
of this writing no platform backend assigns it (work in progress); with the
hook unset, the in-canvas fallback is what runs.
off to a native OS window (`window/**`) instead of the widget floating.
`window.Window.EnableDockFloating(dm)` (or `NativeFloating="True"` in XAML, see
below) assigns it on Win32 and X11; on Wayland, macOS and headless the hook
is not assigned and the in-canvas fallback is what runs.

XAML:

Expand Down Expand Up @@ -5507,6 +5508,36 @@ lets a consumer mutate the scene and produce the frame on one goroutine,
removing that race by construction. `Frames()` keeps working: the sink is an
alternative, not a replacement.

The UI also changes without the consumer: a clock, a hover, an animation step,
an open menu. Under external pacing such changes would stay undrawn until the
next request, and the consumer has no way to learn about them (v4.3):

```go
eng.SetOnFrameNeeded(func() { // there is something to draw and no frame is requested
if haveFreeBuffer() {
eng.RequestFrame()
}
})
```

The call comes on the engine's goroutine, at most once per frame interval, and
repeats while the damage is undrawn and no frame is requested: answer at once
or later, when a buffer frees up. Under ticker pacing there is no call.

#### A whole frame on request (v4.3)

```go
eng.RequestFullFrame() // the next frame carries every tile, with no comparison
```

For a consumer that lost part of the picture through no fault of the engine: a
remote client asked for a repaint, a suspended client came back. `RequestFrame`
draws only what changed, and a consumer with the frame in its own buffers
cannot get pixels the engine did not mark. The tree is not re-recorded for it —
the frame replays the retained command lists. Under external pacing the call
also requests the frame; under ticker pacing the frame comes on the next tick
even if the UI did not change.

#### When a channel consumer falls behind

The `Frames()` channel is shallow (8 frames) and drops a frame on overflow.
Expand Down Expand Up @@ -5588,7 +5619,7 @@ narrow interface — when the API changes, only that package needs editing.

---

### Engine counters and the draw-contract check (v4.0, in progress)
### Engine counters and the draw-contract check (v4.0)

Two tools for those who tune the frame and look for the reason it is slow or why the
window keeps holes in it.
Expand Down Expand Up @@ -5619,7 +5650,7 @@ eng.SetDrawContractCheck(true) // debugging: logs the widget that changes itself
`widget.DrawOverlayTraced` for overlays. Without it the path in the log stops at the
container.

### Failure policy (v4.0, in progress)
### Failure policy (v4.0)

A panic in a widget's or a consumer's code no longer kills the process. The engine
catches it at its own boundary, marks the culprit and carries on. The decision and its
Expand Down Expand Up @@ -5666,7 +5697,7 @@ place, and the program closes the window itself (`CloseModal`). It does not undo
a widget made before the panic. The operating-system window (the event pump in `window`)
is not protected yet: that is stage 9 of the plan.

### Scene and external surfaces (v4.0, in progress)
### Scene and external surfaces (v4.0)

A window of another program can be shown on the engine's screen next to the engine's own
windows: in the same widget tree, in one Z order, with the same input. The decision is in
Expand Down Expand Up @@ -5713,6 +5744,32 @@ panel.RaiseChild(surf) // raise above the siblings; LowerC
returns to the direct blur, for comparison.
- **Window move.** A move is announced together with the shadow margin, so the shadow of a
dragged window moves as a copy, not as tiles.
- **Shadow without its middle (v4.3).** A window with an opaque background covers its own
middle, so the shadow under it is not drawn at all — only the ring around it, and the
ring is blended straight from the shadow template, the middles of its sides two pixels at
a time (0.15 ms instead of 2 ms a frame under a 1200×720 window; a whole shadow, with no
hole, takes 0.8 ms). Your own layer gets the same with
`widget.DrawShadowSpecAround(ctx, r, corner, sp, widget.ShadowCovered(r, corner))`: the
last argument is what the layer paints opaquely right after. A layer with a translucent
background, or glass that reads what is under it, has nothing to promise — it uses
`DrawShadowSpec`.
- **The opaque region reaches the blit (v4.3).** For a buffer with alpha, the parts named by
`SetOpaqueRegion` are copied row by row like an opaque buffer; only the rest is blended.
A window with round corners or its own shadow no longer has to be blended whole or to
pass for opaque. It is a promise, like a buffer's `opaque`. A region of more than 16
rectangles does not affect the blit.
- **A move does not redraw a program's window (v4.3).** After a declared move
(`widget.NotifyWidgetMove`) the frame does not draw the tiles of an external surface that
the move already put in place: it draws the rim, what the window uncovered and what lies
over it. The engine does not trust the declaration and keeps a tile only when it is
proven: the surface is opaque there (an `opaque` buffer or a `SetOpaqueRegion` part),
nothing lies over it, its content has not changed since the last frame, and it moved by
exactly the move's offset. For this to work, declare the window's place as owned damage
(`SetBounds`, `InvalidateArea`), not as orphan `widget.InvalidateRect`, which redraws
everything under it. A round clip may move with the window (a program window's frame) or
stay put (content scrolled inside a frame): tiles under the cut corners are drawn, the
rest are kept. `Stats().TilesMoved` counts the kept tiles; `Engine.SetMoveReuse(false)` restores the old
behaviour, and the picture is the same on both paths.

- **Your own output buffers.** `Engine.SetSurfaces(bufs, stride, format)` takes two to
four consumer buffers of one size: the engine draws the frame straight into a free one
Expand All @@ -5731,7 +5788,7 @@ panel.RaiseChild(surf) // raise above the siblings; LowerC
the `core/scene` package (stage 7). The WinLine session runs on the scene behind a switch;
the old path is not removed yet. RemoteApp windows (RAIL) are not part of the scene.

### UI scale at a fixed frame size (v4.0, in progress)
### UI scale at a fixed frame size (v4.0)

`SetScale(k)` keeps the logical canvas size and grows the physical one: a 1280×800
window at 1.5 is drawn at 1920×1200 — that is how HiDPI works for an OS window. A
Expand All @@ -5755,7 +5812,7 @@ eng.ScaleWithin() // true: "scale within the frame" mode
1:1. `SetSurfaces` buffers are sized to the physical size and must be set again after a
scale change.

### Engine motion profile (v4.0, in progress)
### Engine motion profile (v4.0)

"Reduced motion" (`theme.FlagMotionReduce`) is a theme setting, which means it applies to
the whole process. The motion profile belongs to one engine: a remote session and the
Expand Down Expand Up @@ -5790,7 +5847,7 @@ eng.MotionProfile()
For WinLine: the remote session is `MotionRemote`, a client without menu animations is
`MotionOff`, the local screen is `MotionFull`.

### Menu and popup transitions (v4.0, in progress)
### Menu and popup transitions (v4.0)

Menus, dropdown lists, colour pickers and date-picker calendars appear and disappear with a
fade and a slide from their anchor. One call turns it on; duration and curve come from the
Expand Down Expand Up @@ -5819,9 +5876,9 @@ eng.SetOverlayTransitions(true) // off by default
`PopupFrame.Transition` carries `Opacity`, `Offset` and `Closing`, and a host that
declares `Engine.SetPopupFade(true)` keeps the window of a disappearing menu until the
transition ends. `window.Window` and the dialog and panel hosts declare it themselves.
Win32 — whole-window opacity (a layered window); X11 with a compositor — a copy of the
frame with a multiplier; X11 without a compositor and Wayland — no transition: the window
appears and disappears at once.
Win32 — whole-window opacity (`UpdateLayeredWindow` or, for menus by DWM,
`SetLayeredWindowAttributes`); X11 with a compositor — a copy of the frame with a multiplier; X11 without a
compositor and Wayland — no transition: the window appears and disappears at once.
- **Your own overlay** only needs `OverlayBounds` (`widget.OverlayBoundsProvider`): without
it the overlay is drawn at once, with no transition. One that animates itself
(`desktop.Flyout`) opts out with `widget.SelfAnimatedOverlay`; a shadow reaching further
Expand Down Expand Up @@ -5852,7 +5909,77 @@ dropped frame would leave it half-transparent) and an X11 check on a test machin
separate engine-level transition for submenus; tooltip and modal transitions by the same
mechanism.

### Shared glyph cache of the process (v4.0, in progress)
### Shadows of windows, menus and popups: DWM or the engine (v4.2)

DWM gives the shadow and rounded corners to a window, a dialog, a menu and a dropdown list
when it gives them; when it doesn't and a shadow is needed, the engine draws it itself.
The application does nothing — this is the default (`window.ShadowAuto`). To choose the
source explicitly:

```go
win.SetShadowSource(window.ShadowAuto) // default: DWM where it gives a shadow, else the engine
win.SetShadowSource(window.ShadowSystem) // DWM only: where it gives none — no shadow
win.SetShadowSource(window.ShadowEngine) // always the engine: the DWM shadow is removed, square corners
```

The choice applies to the window, its menus and popups, and to the dialogs and floating
panels the window opens in their own OS windows. The window changes its shadow at once,
popups from their next show.

**Where DWM gives a shadow and where it doesn't.**

| | DWM gives | the engine draws (`ShadowAuto`) |
|---|---|---|
| window, dialog (Windows 11) | rounding and shadow | — |
| window, dialog (Windows 10) | shadow from the DWM frame, square corners | — |
| window with window shadows turned off (performance options, RDP) | nothing | its own shadow window |
| rounded menu, popup (Windows 11) | rounding and shadow, per cascade level | — |
| square popup, Windows 10, X11, Wayland | nothing | shadow and antialiased corners in the frame |

"DWM gives a shadow" means composition is on and window shadows aren't turned off in the
system (`SPI_GETDROPSHADOW`): remote desktop sessions with a light experience and a
cleared "Show shadows under windows" have none. A change of the setting is picked up live.

- **Menus by DWM** (Windows 11). A cascading menu is shown as one window per level, each
with its own DWM shadow: one window's shadow would follow the bounding rectangle, under
the empty space between the menu and the submenu too. A level's frame has no shadow of
its own and square corners; DWM rounds the window (`DWMWCP_ROUND` for a radius of 6 or
more, else `DWMWCP_ROUNDSMALL`). DWM gives no shadow to a square popup — the engine draws
its shadow.
- **Menus by the engine.** The popup frame takes a shadow margin (`PopupFrame.Pad`), the
shadow and antialiased corners are drawn into it as in the canvas; the OS window blends
per-pixel alpha: Win32 — `UpdateLayeredWindow` (pixels with alpha 0 let the mouse
through), X11 with a compositor — ARGB and an input shape of the painted pixels, X11
without a compositor — a shape of the solid pixels (no shadow, no black), Wayland — an
ARGB `xdg_popup` buffer. At the screen edge the menu body, not the shadow margin, is
fitted into the work area.
- **The window's own shadow** (Win32) is a separate OS window right below the window:
layered, transparent to the mouse, never activated, not on the taskbar or in Alt+Tab; it
follows the window and is absent for a maximized, minimized, fullscreen and
`Style.Borderless` window. Its look comes from the theme tokens (`widget.WindowShadow`,
`widget.DialogShadow` for dialogs), without them a soft shadow (blur 16, offset 6). The
picture is assembled from a small sample, so resizing a large window doesn't blur the
whole outline again. On X11 and Wayland the window manager gives windows their shadow.

**Your own popup host** declares what its windows can do with flags:

```go
eng.SetPopupSink(func(frames []engine.PopupFrame) {
for _, f := range frames {
switch {
case f.System: // shadow and rounding with radius f.Corner are up to the OS window
default: // the body is f.Rect.Inset(f.Pad), the shadow is around it in the frame's alpha
}
}
})
eng.SetPopupShadowMode(engine.PopupShadowSystem | engine.PopupShadowEngine)
```

`PopupShadowNone` (the default) — the frame is exactly `OverlayBounds`, as before. The
engine learns an overlay's parts from `widget.OverlayPartsProvider` (`PopupMenu` and the
widgets with a menu inside report the cascade levels and the radius).

### Shared glyph cache of the process (v4.0)

When several engines run in one process — one per monitor, hosted dialogs, a second
desktop — each glyph is rasterised once per process, not once per engine. Nothing has to be
Expand Down Expand Up @@ -5882,7 +6009,7 @@ engine.SetGlyphCacheBudget(128 << 20) // bytes; 0 or less means the default, 64
the accounting keep working, but the memory limit no longer applies to them.


### Command path, tiled raster and one frame buffer (v4.0, in progress)
### Command path, tiled raster and one frame buffer (v4.0)

A frame is built in three steps: the tree records drawing commands, the commands
are rasterised by 64×64 tiles in a worker pool, and only the changed tiles go to
Expand Down Expand Up @@ -5923,7 +6050,7 @@ eng.SetSingleBuffer(false) // two copies of the frame instead of one
bytes of the frame buffers (about W·H·4 with one buffer).


### Tree owner, measuring services and the popup arena (v4.0, in progress)
### Tree owner, measuring services and the popup arena (v4.0)

A widget tree belongs to the engine it was handed to: `SetRoot`, and
`ShowModal` (a modal dialog inside the canvas). A widget change wakes only that
Expand Down Expand Up @@ -5971,7 +6098,7 @@ popup memory is the largest open popup plus the images of all open ones.
`Stats().PopupBytes` reports it; with no popups open it is zero.


## Live tiles of the Start menu (v4.0, in progress)
## Live tiles of the Start menu (v4.0)

A Windows 10 tile can show live content: a clock, mail, weather. A source
implements `desktop.TileSource`, and the tile receives it in the `Live` field:
Expand Down Expand Up @@ -6031,7 +6158,7 @@ For local development use `replace`:
replace github.com/oops1/headless-gui/v4 => ../headless-gui
```

### Engine packages `core/` (v4.0, in progress)
### Engine packages `core/` (v4.0)

Raster, text, the drawing context, input, the frame loop and overlays moved out of `engine`
into separate packages. An application does not need to import them: the old names are kept.
Expand Down Expand Up @@ -6071,7 +6198,7 @@ takes a lock or passes the call on. Calls through interfaces and function litera
by the check; for them the rule rests on review. New code in these packages must keep the rule:
a short leaf section with no calls out.

### Widget packages `widget/*` (v4.0, in progress)
### Widget packages `widget/*` (v4.0)

`widget` is split into packages (ADR-0012). Programs need no changes: `widget` keeps the
same API, but it is now a facade: for every name of the packages below it holds a type
Expand Down
Loading
Loading