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.
- Glass
Button - A capsule glass button with a text (or icon glyph) label.
- Glass
Slider - A horizontal slider with a refractive glass thumb and an editable value.
- Glass
Style - Visual parameters of a glass surface. All lengths are in logical points.
- Glass
Toolbar - 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. - Live
Backdrop - 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 byset_backdrop; replacing the backdrop frees that id automatically. - init
- Registers the glass pipeline with egui-wgpu. Call once, e.g. from
App::new.msaa_samplesmust matchNativeOptions::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::LiveBackdropexists) 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 withfree_native_texture_id. - set_
backdrop - Uploads
imageas 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. Createcrate::LiveBackdropbefore 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 toclip) and records that mapping. Use this when you place the image yourself. Glass that samples outsideimage_rectshowsoutside(typically your page colour).