Skip to main content

Crate egui_glass

Crate egui_glass 

Source
Expand description

Apple Liquid Glass style widgets for egui, rendered on the GPU through egui-wgpu paint callbacks.

Requires egui / egui-wgpu 0.35 and wgpu 29. With eframe, enable its wgpu feature and select eframe::Renderer::Wgpu; the glow renderer is unsupported.

egui_glass::init(rs, 1);
egui_glass::set_backdrop(ctx, rs, &wallpaper);
egui_glass::show_backdrop(ui, ui.max_rect());
egui_glass::Glass::new(egui_glass::GlassStyle::regular()).show(ui, |ui| {
    ui.label("Hello");
});

Glass refracts a backdrop image you register once (or whenever it changes), not the live framebuffer: egui paints in a single pass, so the pixels behind a widget are not available to a shader in the same frame. LiveBackdrop lifts that limit by rendering your content a second time off screen.

§Integration order

Call init once per renderer, then create a LiveBackdrop if needed, then upload the backdrop and register native textures. Draw the backdrop before glass each frame. The MSAA count passed to init must match the host renderer (0 is treated as 1).

§Features

No default features. The optional serde feature enables serialization and deserialization of GlassStyle, with defaults for missing fields.

See the guide and reference for integration details, performance costs, and limitations.

Structs§

Glass
A glass container: card, section, sidebar, sheet.
GlassButton
A capsule glass button with a text (or icon glyph) label.
GlassSlider
A horizontal slider with a refractive glass thumb and an editable value.
GlassStyle
Visual parameters of a glass surface. All lengths are in logical points.
GlassToolbar
A capsule glass bar holding flat buttons (ui.button, ui.selectable_label, …). Children get a transparent idle background and a soft highlight on hover, following Apple’s rule of never stacking glass on glass.
LiveBackdrop
Renders content off screen so glass can refract it. Cheap to clone.

Functions§

backdrop_rect
Screen rect (points) the whole backdrop image is currently mapped to, as recorded by the last show_backdrop. Useful to align content with it.
backdrop_size
Pixel size of the registered backdrop image.
free_native_texture_id
Frees a texture registered with register_native_texture. Stop drawing with the id before freeing it. Do not free the active backdrop returned by set_backdrop; replacing the backdrop frees that id automatically.
init
Registers the glass pipeline with egui-wgpu. Call once, e.g. from App::new. msaa_samples must match NativeOptions::multisampling (0 or 1 when unset).
paint_glass
Paints a glass surface filling rect. Building block for custom widgets.
register_native_texture
Registers a wgpu texture for drawing with egui, in the app’s renderer and (if a crate::LiveBackdrop exists) in its off-screen renderer too, so images drawn with it also show through live glass. Create the live backdrop first; textures registered earlier are not mirrored retroactively. Release the returned id with free_native_texture_id.
set_backdrop
Uploads image as the backdrop every glass surface refracts, replacing any previous one. Returns the egui texture id so the app can draw it. The previous backdrop’s texture id is freed and must no longer be used. Image dimensions and pixel storage must be consistent and fit the device’s texture limits. Create crate::LiveBackdrop before uploading if needed.
show_backdrop
Draws the backdrop image covering rect (aspect-fill, centered) and records the mapping so glass widgets sample the same pixels.
show_backdrop_mapped
Draws the whole backdrop image into image_rect (clipped to clip) and records that mapping. Use this when you place the image yourself. Glass that samples outside image_rect shows outside (typically your page colour).