Shader backgrounds
Quiet animated GPU fields for welcome and empty pages, following the pointer.
Loading the live example…
import (
"github.com/egoist/mygo/ui"
"github.com/oneo-me/onevra/source/components"
"github.com/oneo-me/onevra/source/components/shaders"
)
type welcomePage struct {
intensity float64
still bool
}
func (w *welcomePage) View(c *ui.Context) {
t := c.Theme()
// Move the pointer over the field, and click to send a ripple.
shaders.SignalField(c, shaders.Options{
Intensity: float32(w.intensity),
Still: w.still,
}).Column().Children(func() {
ui.Column(c).Fill().Center().Gap(t.Space(3)).Children(func() {
components.Text(c, "Welcome back").FontSize(t.Rem(1.6)).Bold()
components.Text(c, "Nothing open yet. Start a project or open one.").TextColor(t.TextMuted)
ui.Row(c).Width(260).Gap(t.Space(3)).AlignItems(ui.Center).Padding(t.Space(2), 0).Children(func() {
components.Text(c, "Intensity").TextColor(t.TextMuted)
components.Slider(c, &w.intensity, 0.2, 2).Label("Intensity").Grow(1)
})
components.Switch(c, &w.still, "Still")
})
})
}A background fills its parent, and the page builds inside it with Children. shaders.SignalField breathes with slow noise, gathers light around the pointer and ripples where it is clicked; its middle stays calmer than its edges, where content sits.
Backgrounds draw only on a GPU renderer and leave the theme background on the CPU renderer, including headless tests. Reduced Motion freezes the drift. Content that takes the pointer itself, such as a honeycomb, calls shaders.Ripple for its presses.
API
SignalField
func SignalField(c *ui.Context, o Options) ui.ElementSignalField fills its parent with a sparse grid of dots that breathe with slow noise, gather light around the pointer and pulse outward where it clicks. Its middle stays calmer than its edges, where content usually sits.
pkg.go.devOptions
Ripple
func Ripple(c *ui.Context, background ui.Element)Ripple ripples background, an element a background function returned, where the pointer last was over it, as a click there does. Content that takes the pointer's input itself, such as components.Honeycomb with its OnPress, hides its presses from the background, and calls Ripple for them. It does nothing where the background skips ripples.
pkg.go.dev