Skip to main content

egui_glass/
lib.rs

1//! Apple Liquid Glass style widgets for egui, rendered on the GPU through
2//! egui-wgpu paint callbacks.
3//!
4//! Requires egui / egui-wgpu 0.35 and wgpu 29. With eframe, enable its `wgpu`
5//! feature and select `eframe::Renderer::Wgpu`; the glow renderer is unsupported.
6//!
7//! ```no_run
8//! # fn setup(ctx: &egui::Context, rs: &egui_wgpu::RenderState, wallpaper: egui::ColorImage) {
9//! egui_glass::init(rs, 1);
10//! egui_glass::set_backdrop(ctx, rs, &wallpaper);
11//! # }
12//! # fn ui(ui: &mut egui::Ui) {
13//! egui_glass::show_backdrop(ui, ui.max_rect());
14//! egui_glass::Glass::new(egui_glass::GlassStyle::regular()).show(ui, |ui| {
15//!     ui.label("Hello");
16//! });
17//! # }
18//! ```
19//!
20//! Glass refracts a *backdrop image* you register once (or whenever it changes),
21//! not the live framebuffer: egui paints in a single pass, so the pixels behind a
22//! widget are not available to a shader in the same frame. [`LiveBackdrop`]
23//! lifts that limit by rendering your content a second time off screen.
24//!
25//! # Integration order
26//!
27//! Call [`init`] once per renderer, then create a [`LiveBackdrop`] if needed,
28//! then upload the backdrop and register native textures. Draw the backdrop
29//! before glass each frame. The MSAA count passed to [`init`] must match the
30//! host renderer (0 is treated as 1).
31//!
32//! # Features
33//!
34//! No default features. The optional `serde` feature enables serialization and
35//! deserialization of [`GlassStyle`], with defaults for missing fields.
36//!
37//! See the [guide](https://github.com/heonny/egui-glass/blob/main/docs/guide.md)
38//! and [reference](https://github.com/heonny/egui-glass/blob/main/docs/reference.md)
39//! for integration details, performance costs, and limitations.
40
41mod backdrop;
42mod live;
43mod mipgen;
44mod renderer;
45mod slider;
46mod style;
47mod widgets;
48
49pub use backdrop::{
50    backdrop_rect, backdrop_size, free_native_texture_id, register_native_texture, set_backdrop, show_backdrop, show_backdrop_mapped,
51};
52pub use live::LiveBackdrop;
53pub use renderer::init;
54pub use slider::GlassSlider;
55pub use style::GlassStyle;
56pub use widgets::{paint_glass, Glass, GlassButton, GlassToolbar};