glass

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 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.

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.

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
)

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