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 ¶
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 ¶
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
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 ¶
PaintMaterial paints the blur over box, rounded by radii.
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 ¶
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 ¶
PaintMaterial paints the glass over box, rounded by radii.
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 ¶
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 )
Source Files
¶
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. |