Skip to main content

Crate rust_glass

Crate rust_glass 

Source
Expand description

A GPU rendered UI framework in the style of Apple’s Liquid Glass, with an immediate mode API.

You describe the whole interface every frame in App::update. Widgets return a Response that tells you whether they were clicked or changed. Glass controls bend, blur and tint whatever is drawn behind them, including other glass.

use rust_glass::prelude::*;

struct Hello {
    volume: f32,
}

impl App for Hello {
    fn update(&mut self, ctx: &mut Context, _: &FrameInfo) {
        let area = ctx.screen.shrink(24.0);
        region(ctx, "main", area, |ui| {
            ui.heading("Hello");
            ui.slider(&mut self.volume, 0.0..=1.0);
            if ui.prominent_button("Reset").clicked() {
                self.volume = 0.5;
            }
        });
    }
}

fn main() -> Result<(), String> {
    run(Options::default(), Hello { volume: 0.3 })
}

The guide explains layout, widgets, theming, materials and testing.

Re-exports§

pub use app::App;
pub use app::FrameInfo;
pub use app::FrameStats;
pub use app::Options;
pub use app::run;
pub use color::Color;
pub use context::Context;
pub use context::Id;
pub use context::Order;
pub use context::Response;
pub use context::Sense;
pub use geometry::Rect;
pub use geometry::Vec2;
pub use geometry::rect;
pub use geometry::vec2;
pub use icon::Icon;
pub use material::Corner;
pub use material::Glass;
pub use material::GlassShape;
pub use material::Material;
pub use paint::ImageId;
pub use paint::Painter;
pub use theme::Surface;
pub use theme::Theme;
pub use ui::Ui;
pub use ui::Widget;

Modules§

accessibility
Accessibility tree for screen readers and other assistive technology.
animation
Springs. Everything that moves in the framework runs on a spring, so a motion can be interrupted or retargeted at any time without a jump.
app
Window host: event loop, surface, clipboard, input method and the bridge to screen readers. Draws only when something changes; an idle window uses no CPU or GPU time.
color
Colors.
context
The state of one window: input, theme, layers, widget memory and the measurements glass adapts to.
geometry
Points, sizes and rectangles.
guide
How to build an app with rust-glass, with examples for every part of the API.
headless
Runs an app without a window: scripted input, fixed time steps, pixels back. Use it for tests and to render screenshots.
icon
Built in icon set, drawn as vector paths on a 24 by 24 grid and rasterized on demand at the exact pixel size in use.
input
Keyboard, pointer and text input.
material
The glass material: corner shapes, material parameters and presets, and glass elements ready to paint.
paint
Painting: shapes, text, images, masks and glass. Widgets paint in points. The draw list stores pixels, ready for the GPU.
prelude
Everything an app usually needs: use rust_glass::prelude::*;
text
Text layout. Text uses the interface font of the platform, shaped by cosmic-text. Layouts are cached, so laying out the same text every frame is cheap.
theme
Appearance and accessibility settings shared by every widget.
ui
Layout. A Ui is a region that hands out rectangles to widgets.
widgets
Built in widgets, one module per component. The prelude exports all of them.