layer-lab

command
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Optics Lab

A native-only playground for ui.Effect and ui/shader's layerSample. The specimen is a real MyGo component: editable track title, seek slider, play button and save button, alongside vector artwork and native text.

go run ./examples/layer-lab
# Or, with Nix:
nix-shell -p go --run 'go run ./examples/layer-lab'

Choose crystal refraction, fluted/frosted glass, liquid ripples, chromatic prisms or mosaic focus. Move over the specimen to position the lens; turn off Follow pointer to pin it. Adjust strength, lens size and dispersion. Show original bypasses the shader, and zero strength is also an identity operation. Animate light pauses/resumes the clock without a time jump. The player is a UI specimen, not an audio player.

What this demonstrates

  • stage.Cache().Effect(...) captures the native subtree into a reusable GPU layer. optics.kage only reads that layer with layerSample; it does not read the window backdrop, decode an image or use the glass plugin.
  • effects.go sets pre-looked-up uniforms at paint time and requests paint-only animation at up to 60 FPS. The source cache avoids GPU rerasterization when the component's pixels have not changed; normal painting still records/compares its scene to discover changes.
  • The glass uses edge refraction, magnification, separate RGB samples, directional highlights and a small frost kernel. Other modes change sampling coordinates or combine offset samples of the same tree.
  • Effect coordinates are DIPs; capture resolution follows the display scale. Sampling is clamped to the source, so no extra capture margin is needed.

Deliberate limitations

Shader effects do not change hit testing, focus, IME or accessibility geometry. Controls still work at their original positions, not at a displaced image of them. This makes the boundary of the existing effect API visible rather than pretending to solve interactive GPU embedding.

The full-size shader is bypassed on software renderers and with Reduce Transparency; the live native component still works. Reduce Motion freezes animation. Pausing or bypassing the effect requests no continuous frames (a focused text field may still blink its caret).

go test ./examples/layer-lab
# Optional automation for inspecting the real GPU window:
go build -tags e2e -o /tmp/mygo-layer-lab ./examples/layer-lab
MYGO_AUTOMATION=/path/to/private-dir/lab.sock /tmp/mygo-layer-lab
go run ./plugins/automation/cmd/mygo-automation open --socket /path/to/private-dir/lab.sock

Documentation

Overview

Layer-lab bends a live native component with layerSample: refractive glass, fluted glass, ripples, chromatic prisms and a mosaic lens.

go run ./examples/layer-lab

No webview, glass plugin or external images are involved. The component remains interactive, but shader distortion does not remap hit testing.

Jump to

Keyboard shortcuts

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