Skip to content
  1. Docs
  2. enzUI framework
  3. Developers

Materials

Liquid glass in the app and over the desktop, adaptive ink, and paper-like grain.

enzUI has two surface effects beyond plain fills: glass, a sampled-backdrop material with refraction and tint, and grain, a paper-like speckle that lies on any surface. Both fall back cleanly: reduced transparency, increased contrast and the software renderer paint an opaque panel instead of glass, and high-contrast palettes draw no grain.

The gallery's Materials and depth page

Glass on a widget

Most widgets with a panel take .material(style), which puts them on glass of their own shape:

rust
enz_banner("Update installed")
    .material(MaterialStyle::Regular)
MaterialStyleUse
RegularThe default: clear glass with a bending rim, for controls and chrome
SubtleA light frost, slightly darker, for controls over busy content
FrostedFrosted and darker, with maximum luminance roll-off, for panels that carry text
LensStrong refraction and colour fringe on a deep rim, for hero elements
ClearMedia glass: light ink over glass that dims bright content
OpticalDiagnostic optical geometry with zero tint and configurable lighting
FlatFrostedFlat theme-tinted blur, without lens distortion or rim lighting
SolidThe opaque panel, with no glass

enz_glass(widget) wraps anything else. Give it the content's radius with .radius(px), or .radius_resolved(|theme| ..) when the corners follow the theme's radius scale. Menu buttons, context menus and action bars take .menu_material(style) for their popups, and app-shell panes take PaneStyle::material(style).

Controls inside glass default to glass: their fills and borders turn translucent, secondary text becomes the ink at reduced opacity, and ghost glyphs take the ink instead of the accent. Tokens a caller pinned are kept.

Ink

MaterialStyle::ink selects the foreground policy:

  • Every style except Clear keeps the app's theme ink, whatever passes beneath.
  • Clear always uses light ink over glass that dims bright content just enough. Use it for controls over video and photos.
  • Adaptive ink is opt-in: enz_glass(..).ink(GlassInk::Adaptive) or EnzSurface::glass_ink. The renderer measures the average brightness behind the surface and picks dark ink over light content and light ink over dark. It does not chase frames: a change must last about a second before the ink switches, and the switch is a 0.3 s crossfade, so a playing video does not make it flicker.

Contrast protection adjusts backdrop luminance; it does not guarantee a contrast ratio on arbitrary content. Check text against the rendered backdrop. enz_adaptive_glass fills any shape, such as clock numerals or a pill, with glass whose tone adapts to the backdrop.

Glass over the desktop

A pane can show the wallpaper and the windows behind the app instead of the app's own drawing. The compositor paints it from the same tokens over the enzui-material-v1 protocol, so Regular looks the same in both places.

rust
// Once the window is open:
desktop_glass::bind(id).map(Message::Glass)

// In the view:
let sidebar = enz_surface(places)
    .material(MaterialStyle::Regular)
    .backdrop(Backdrop::Window);
enz_desktop_glass(&state.glass, row![sidebar, content])

App-shell panes take PaneStyle::material(style).behind_window(). The window must be transparent, with nothing painted under the pane (shell_tone: SurfaceTone::Transparent in a shell). Some limits:

  • The pane draws nothing until bind resolves.
  • A compositor without the protocol gets in-app glass instead, and reduced transparency makes the pane solid.
  • Keep window-backdrop panes outside scrollables: their regions use window coordinates without scroll clipping.
  • The compositor receives at most 32 panes.
  • Subscribe to desktop_glass::luminance_changes so adaptive ink follows the desktop while the window is idle.

The theme file's [window] frame key lets a user put every app's window frame on glass; see Theme file.

Grain

Grain is a paper-like speckle. It is not a material: it lies on any surface's fill (or on glass) and works in every renderer.

rust
enz_surface(content).grain(Grain::default())        // under the content
enz_surface(content).grain(GrainSpec::Theme)        // the theme's [grain]
PaneStyle::default().grain(Grain::subtle())         // a grainy shell pane
enz_grain(picture).grain(Grain::paper())            // over any element
PresetLook
Grain::default()Fine light and dark specks, quiet enough for UI panels
Grain::subtle()The same, barely there, for large surfaces
Grain::paper()Strong, laid over the content too: a printed page
Grain::film()Coarser specks that shimmer at 24 fps

Every knob is a builder: intensity, density, scale, tone, inks / tint, opacity, the built-in noise's frequency, octaves and seed, tile, tiling, placement and motion. Grain::svg(document) takes any SVG: its brightness becomes specks, or .mapping(GrainMapping::Artwork) draws it in its own colours. An feTurbulence SVG gets GrainTiling::Blend, which cross-fades its tile edges; art that does not repeat by itself can use GrainTiling::Mirror.

Tiles are made once per screen scale and cached, so a grainy surface costs one image draw per visible tile. Still grain asks for no frames; film grain redraws at its frame rate, and reduced motion stills it. The theme file's [grain] table shapes GrainSpec::Theme for every app.

Depth

enz_elevation wraps content in a semantic shadow level from 0 to 5, resolved from the theme. enz_glow adds a coloured halo and enz_gradient_background a linear-gradient surface.