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
// 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 ¶
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 ¶ added in v0.1.17
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 ¶
PaintMaterial paints the glass over box, rounded by radii.
type Group ¶ added in v0.1.17
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 ¶ added in v0.1.17
NewGroup returns an empty Group, a row, whose Material paints the glass behind the elements its Pane adds.
func (*Group) PaintMaterial ¶ added in v0.1.17
PaintMaterial paints the group's glass over the union of its panes.
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 is Golet's enhanced shader material with a stronger lens and rim. 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. |