glass

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 7 Imported by: 1 module, 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

glass

Liquid Glass for MyGo apps of native UI, as macOS 26 and later draw it, on every platform: a material that what is under an element shows through, frosted and bent along its edges.

import "github.com/caelyreth/evil-mygo/plugins/glass"

ui.Row(c).Padding(8, 16).Radius(22).Material(glass.Glass{}).Children(func() {
	ui.Text(c, "On glass")
})

glass.Group merges panes of glass that nearly touch into one surface, as AppKit's NSGlassEffectContainerView does:

g := glass.NewGroup(c)
g.Radius = 22
g.Gap(6).Children(func() {
	g.Pane(ui.Box(c).Padding(8, 16).Center().Children(func() { ui.Text(c, "Cut") }))
	g.Pane(ui.Box(c).Padding(8, 16).Center().Children(func() { ui.Text(c, "Copy") }))
})

On macOS 26 and later, glass.Glass{Native: true} draws a toolbar over a ui.WebView with the system's NSGlassEffectView, which samples the page; elsewhere it falls back to the shader. With Reduce Transparency, the materials draw opaque surfaces.

glass.ScrollEdge is macOS's scroll edge effect, which content scrolling under a bar fades (soft) or frosts (hard) under, and glass.Blur blurs what is under an element without the glass, evenly or, with a mask, progressively:

ui.Box(c).Absolute().Top(0).Left(0).Right(0).Height(74).PassThrough().Material(glass.ScrollEdge{})
ui.Box(c).Absolute().Top(0).Left(0).Right(0).Height(88).PassThrough().
	Material(glass.Blur{Radius: 6, Mask: &ui.LinearGradient{From: ui.RGB(0, 0, 0), To: ui.Transparent, Angle: 180}})

See the documentation, and the Glass page of examples/gallery.

The glass and the blur, which a hard scroll edge draws with, are effects of MyGo's renderers (scene.Effect): their shaders in WGSL, HLSL and GLSL (glass.wgsl, glass.hlsl, glass.glsl, and blur.*), and their twins for the CPU renderer (pixels.go, blur.go), which must draw the same pixels; the tests compare each GPU's drawing with the CPU's. go generate compiles the Direct3D bytecode ahead of time where it can (shaders_windows.go). WebGPU compiles the WGSL when the renderer first needs it. Renderers compile the source when the code compiled ahead of time is older than it or than their own part of the shader.

Documentation

Overview

Package glass draws Liquid Glass in native UI, as macOS 26 and later draw it (AppKit's NSGlassEffectView), on every platform: what the elements under it painted shows through, blurred, bent near its edges as through the rim of a lens, and lit along its hairline rim. MyGo's renderers draw it with shaders of this package, on the GPU or the CPU, so it looks the same everywhere.

ui.Row(c).Padding(8, 16).Radius(22).Material(glass.Glass{})

ScrollEdge is macOS's scroll edge effect, which content scrolling under a bar fades or frosts under, and Blur blurs what is under an element without the glass, evenly or fading along a gradient.

Index

Constants

This section is empty.

Variables

View Source
var Effect = &scene.Effect{
	Name:     "glass",
	Backdrop: true,
	HLSL:     scene.EffectCode{Source: hlslSource, Compiled: hlslBytecode, Sum: hlslSum},
	GLSL:     glslSource,
	WGSL:     wgslSource,
	Pixels:   func() scene.EffectPixels { return &pixels{} },
}

Effect is the glass's effect, which the renderers draw (see scene.Effect): what is behind the pane, blurred, sampled within the bezel where the curved surface refracts it (lens), mapped from its lightness (tone), tinted, and lit along the rim.

Functions

func Paint

func Paint(p *ui.Painter, r ui.Rect, radius float32, g Glass)

Paint paints a pane of glass shaped as r rounded by radius, in a drawing (Element.Draw), over what the painter painted before it.

Types

type Blur

type Blur struct {
	// Radius is how much what shows through blurs, in DIPs: the standard
	// deviation of a Gaussian, as CSS's blur() takes.
	Radius float32
	// Mask, if set, varies the blur along a gradient, by the alpha of its
	// colors, as CSS's mask-image does: what shows through blurs by Radius
	// where the gradient is opaque, by less where it is translucent, and
	// not at all where it is transparent. Its colors do not show.
	Mask *ui.LinearGradient
}

Blur is a backdrop blur, a ui.Material: what was painted under the element shows through it blurred, with no tint, rim or shadow. With a Mask, the blur fades along a gradient, a progressive blur, as under a bar that content scrolls under (ScrollEdge is macOS's own effect there):

ui.Row(c).Absolute().Top(0).Left(0).Right(0).Height(56).Material(glass.Blur{
	Radius: 12,
	Mask:   &ui.LinearGradient{From: ui.RGB(0, 0, 0), To: ui.Transparent, Angle: 180},
})

func (Blur) PaintMaterial

func (b Blur) PaintMaterial(p *ui.Painter, box ui.Rect, radii [4]float32)

PaintMaterial paints the blur over box, rounded by radii.

func (Blur) String

func (b Blur) String() string

String describes the blur, as the inspector shows it.

type Glass

type Glass struct {
	// Style is the glass's material.
	Style Style
	// Tint colors the glass, by its alpha, as for a prominent button: an
	// opaque tint lets a little of the glass show, as AppKit's does.
	Tint ui.Color
	// Interactive makes the glass grow a little while the element is
	// pressed, as AppKit's interactive glass does.
	Interactive bool
	// Native asks for the system's glass where the window has it (macOS
	// 26 and later), drawn under the content: it samples what is under the
	// window's surface, as a ui.WebView's page, not the elements the frame
	// painted. Elsewhere, and with Reduce Transparency, the shader draws
	// it.
	Native bool
	// Clarity, from 0 to 1, makes panes as large as sidebars clearer,
	// the content under them reading through: 0, the default, is
	// macOS's material, as frosty as a control's; 0.5 blurs half as much
	// and lightens (or darkens) less; 1 is nearly clear. Panes up to 100
	// DIPs keep their material whatever it is; it takes full effect from
	// 200. On Clear glass, which barely tones already, it only lights the
	// rim and curves the bezel.
	Clarity float32
	// contains filtered or unexported fields
}

Glass is Liquid Glass, a ui.Material: Element.Material fills an element with it, in place of a background, shaped by its Radius. What was painted under the element shows through it, as content that scrolls under a bar placed over it with Absolute, and other glass.

func (Glass) BuildMaterial

func (g Glass) BuildMaterial(e ui.Element) ui.Material

BuildMaterial follows the press and hover of an interactive glass's element: the glass grows as it is pressed, and lights its rim as the pointer enters it, within 150 ms, as AppKit's does.

func (Glass) NativeGlass

func (g Glass) NativeGlass() (ui.NativeGlassSpec, bool)

NativeGlass asks for the system's glass, which ui places under the surface, where it has Liquid Glass.

func (Glass) PaintMaterial

func (g Glass) PaintMaterial(p *ui.Painter, box ui.Rect, radii [4]float32)

PaintMaterial paints the glass over box, rounded by radii.

func (Glass) String

func (g Glass) String() string

String describes the glass, as the inspector shows it.

type Group

type Group struct {
	ui.Element
	// Style is the group's material, as Glass's.
	Style Style
	// Tint colors the glass, as Glass's.
	Tint ui.Color
	// Clarity makes large groups clearer, as Glass's.
	Clarity float32
	// Radius is the corners of each element's pane, in DIPs.
	Radius float32
	// Merge is how smoothly panes blend into one surface, in DIPs: 24 by
	// default, which bridges panes up to about 12 DIPs apart; 0 keeps
	// them apart.
	Merge float32
	// contains filtered or unexported fields
}

Group is a row of elements on one pane of glass, whose corners merge while they are close, as macOS's NSGlassEffectContainerView draws them:

g := glass.NewGroup(c)
g.Radius = 22
g.Gap(6).Children(func() {
	g.Pane(ui.Box(c).Padding(8, 16).Center().Children(func() { ui.Text(c, "Cut") }))
	g.Pane(ui.Box(c).Padding(8, 16).Center().Children(func() { ui.Text(c, "Copy") }))
})

The elements are an ordinary row's; the glass is painted behind them, one surface over all of them, so that it merges where they nearly touch instead of showing two panes. The elements keep their own backgrounds, borders and hit areas.

func NewGroup

func NewGroup(c *ui.Context) *Group

NewGroup returns an empty Group, a row, whose Material paints the glass behind the elements its Pane adds.

func (*Group) PaintMaterial

func (g *Group) PaintMaterial(p *ui.Painter, box ui.Rect, _ [4]float32)

PaintMaterial paints the group's glass over the union of its panes.

func (*Group) Pane

func (g *Group) Pane(e ui.Element) ui.Element

Pane adds e to the group's glass, and returns it.

func (*Group) String

func (g *Group) String() string

String describes the group, as the inspector shows it.

type ScrollEdge

type ScrollEdge struct {
	// Hard makes the edge hard: what is under it blurred by about 6 DIPs, its
	// colors saturated, under 82% of the background, evenly, with a
	// hairline along its other edge. Soft, it fades the background over
	// the content, from 85% at the bar's edge to nothing at the other.
	Hard bool
	// Bottom puts the bar at the element's bottom, the effect rising from
	// it, rather than at its top.
	Bottom bool
	// Background is what the content scrolls over, which the effect lays
	// over it; unset, the theme's Background.
	Background ui.Color
}

ScrollEdge is the scroll edge effect of macOS 26 and later, a ui.Material: what macOS draws over content scrolling under a bar of controls, so that they stand out from it, as SwiftUI's safeAreaBar with scrollEdgeEffectStyle does. Fill an element over the content's edge with it, under the bar, as long as the bar and 10 DIPs more when soft, as long as the bar when hard:

ui.Box(c).Absolute().Top(0).Left(0).Right(0).Height(74).PassThrough().Material(glass.ScrollEdge{})

Its looks are macOS 27's, measured from SwiftUI's: the soft edge fades the content into its background, with no blur; the hard edge frosts it.

func (ScrollEdge) PaintMaterial

func (e ScrollEdge) PaintMaterial(p *ui.Painter, box ui.Rect, radii [4]float32)

PaintMaterial paints the scroll edge over box, rounded by radii.

func (ScrollEdge) String

func (e ScrollEdge) String() string

String describes the scroll edge, as the inspector shows it.

type Style

type Style uint8

Style is the material of Glass.

const (
	// Regular frosts what shows through and lightens it, or darkens it in
	// dark mode, so that what is on the glass reads over anything: for
	// bars, buttons and panels. Larger panes are frostier.
	Regular Style = iota
	// Clear barely blurs nor tones what shows through, for glass over
	// photos and video, where what is on it brings its own contrast.
	Clear
)

Directories

Path Synopsis
internal
gen command
Command gen compiles the glass's and the blur's shaders ahead of time, so that renderers start without compiling them: the Direct3D bytecode on Windows, with the system's d3dcompiler_47.dll, into shaders_windows.go.
Command gen compiles the glass's and the blur's shaders ahead of time, so that renderers start without compiling them: the Direct3D bytecode on Windows, with the system's d3dcompiler_47.dll, into shaders_windows.go.

Jump to

Keyboard shortcuts

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