glass

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 6 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 Golet 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/HyperparameterSI/golet/backend/plugins/glass"

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

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 Golet's renderers (scene.Effect): their shaders in Metal Shading Language, HLSL and GLSL (glass.metal, 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 shaders ahead of time where it can: the Metal library on macOS, with Xcode (shaders_darwin.go), and the Direct3D bytecode on Windows (shaders_windows.go). Renderers compile the source when the code compiled ahead of time is older than it or than their own part of the shader.

Native control theme

glass.Theme(dark) opts styled native controls into Liquid Glass. Cache a light and dark theme, then call c.SetTheme(theme) before building your view:

// Author: HyperparameterSI
var lightGlass = glass.Theme(false)
var darkGlass = glass.Theme(true)

func view(c *ui.Context) {
    theme := lightGlass
    if c.Theme().Dark {
        theme = darkGlass
    }
    c.SetTheme(theme)
    ui.Column(c).Padding(24).Gap(12).Children(func() {
        ui.Text(c, "Workspace")
        ui.Button(c, "Open")
        ui.PrimaryButton(c, "Continue")
    })
}

Buttons, text fields, selects, autocomplete, time inputs, sidebar backgrounds, tab/segmented tracks, popovers and dialogs adopt the material. Toggle selections, checkboxes, radio buttons, switch tracks, steppers and color-well frames also use the theme materials. Check marks, selection dots and color swatches retain their semantic colors so their state stays clear. Cards and document content stay solid unless explicitly given a material. For a custom floating panel, use .Material(theme.PanelMaterial).

The theme exposes ControlMaterial, AccentMaterial and PanelMaterial. Set any slot to nil to retain solid styling for that group. High contrast automatically skips theme materials; reduced motion uses the UI animation system. Explicitly applied materials remain under the application's control. To offer a “Reduce transparency” option, switch to ui.FormaTheme(dark).

This uses Golet's existing Metal, Direct3D, OpenGL and CPU effects, not Apple's AppKit controls or a webview. Refraction samples previously drawn content inside the window, not the desktop behind the window. Place floating controls over an image, gradient or scrolling content to see the glass; on a uniform background the effect is intentionally subtle. Avoid covering the whole view with nested glass panels: each material needs backdrop processing.

The Gallery → Glass page (also opened from Studio) includes a “Liquid Glass control theme” switch. Studio's native demos share this selection and the light/dark appearance setting: open windows update immediately, and new windows inherit it for the current session. Gallery cards also adopt the panel material. WebView page content and the separate Chromium browser keep their own styling.

Emphasized glass

The control theme now uses glass.Vivid: more visible backdrop detail, stronger edge refraction and a brighter hairline rim, with separate light/dark tone curves. It reuses the existing GPU/CPU pipeline without extra blur passes or idle animation. This is a Golet preset inspired by macOS, not an AppKit API name. Glass{} remains Regular for existing applications.

For a quieter control theme, replace its material slots after creating it:

theme.ControlMaterial = glass.Glass{Interactive: true}
theme.AccentMaterial = glass.Glass{Tint: theme.Accent, Interactive: true}
theme.PanelMaterial = glass.Glass{}

Studio's theme lab places glass above a static wallpaper so its edge refraction can be seen. Select the plain background option to compare it against a flat surface. High contrast continues to use solid control and panel fills.

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. Golet'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,
	Metal:    scene.EffectCode{Source: metalSource, Compiled: metalLibrary, Sum: metalSum},
	HLSL:     scene.EffectCode{Source: hlslSource, Compiled: hlslBytecode, Sum: hlslSum},
	GLSL:     glslSource,
	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.

func Theme added in v0.1.6

func Theme(dark bool) *ui.Theme

Theme returns an opt-in Liquid Glass theme for native controls. Cache one for each appearance and set it on the UI context before building controls. Only apps importing glass carry its shaders. Content keeps a solid surface; buttons, editable fields, navigation tracks and popovers use vivid glass. High-contrast preferences automatically keep the controls' solid fills.

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
}

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 of an interactive glass's element: the glass grows as it is pressed and shrinks back as it is let go, within 150 ms, as AppKit's does.

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 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
	// Vivid keeps more backdrop detail with a stronger lens and illuminated
	// rim. It is Golet's emphasized preset, not a separate AppKit material.
	Vivid
)

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 Metal libraries on macOS, with Xcode's metal tools, into shaders_darwin.go, and 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 Metal libraries on macOS, with Xcode's metal tools, into shaders_darwin.go, and 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