egui-pop 0.2.0

Themable, accessible, agent-drivable application framework and component library for egui: design tokens and visual kits, plugins, commands and keymaps, a workbench of panels, dialogs, palettes, inputs and sliders, trees and tables, editors, an image viewport (not an official egui crate)
Documentation

egui-pop

Latest version Documentation unsafe: platform crates only Demo Build Status MIT Apache

egui-pop is an application framework and component library on egui for desktop applications. It wraps your application's kernel through a host contract and gives it design tokens, themes and visual kits, commands with shortcuts, a workbench of panels, components (dialogs, palettes, sliders and inputs, trees and tables, text and code editors, an image viewport), and hooks at every step of its life: observe, veto, replace, extend. Your egui code keeps working inside it: egui-pop lays out and draws around it, and styles egui's own widgets from the theme. It is for people building a real tool on egui (an editor, a viewer, a control panel) who want that plumbing done once. Not an official egui crate.

The egui-pop gallery in pop-dark: the theme overview

Quickstart

cargo add egui-pop
use egui_pop::eframe;
use egui_pop::prelude::*;

struct Hello;

impl Plugin for Hello {
    fn id(&self) -> PluginId { PluginId::from_static("hello") }

    fn connect(&mut self, ctx: &mut Ctx<'_>) -> Result<(), PluginError> {
        ctx.block(zones::MAIN, Block::add(BlockId::from_static("hello.text"), 0, |ui, _| {
            ui.heading("Hello");
        }));
        Ok(())
    }
}

fn main() -> eframe::Result {
    App::builder()
        .plugins(DefaultPlugins)
        .plugin(Hello)
        .run_native("Hello", eframe::NativeOptions::default())
}

DefaultPlugins brings the command palette, dialogs, toasts, the settings window, the window's place and saved layouts. For a fuller start (a panel, a setting, a command), see Getting started.

A command with a shortcut

Declared once: its key, menu entry, palette entry and agent surface come from it. More in Plugins, commands and steps.

use egui_pop::egui;
use egui_pop::prelude::*;

struct Greeter;

impl Plugin for Greeter {
    fn id(&self) -> PluginId { PluginId::from_static("greeter") }

    fn connect(&mut self, ctx: &mut Ctx<'_>) -> Result<(), PluginError> {
        let greet = CommandSpec::new(CommandId::from_static("greeter.greet"), "Greet", "Greeter");
        ctx.command(greet.key("Ctrl+G"), |_| Ok(serde_json::json!("hello")))?;
        Ok(())
    }
}

let mut app = App::builder().plugin(Greeter).build(&egui::Context::default()).unwrap();
let out = app.run(&CommandId::from_static("greeter.greet"), serde_json::Value::Null, Origin::User);
assert_eq!(out.now(), Some(Ok(serde_json::json!("hello"))));

A theme

Fifteen built-in themes, two densities, five accents, any token overridden. More in Themes.

use egui_pop::egui;
use egui_pop::prelude::*;
use serde_json::json;

let spec = ThemeSpec::new("catppuccin-mocha")
    .density(Density::Compact)
    .accent("blue")
    .override_token("radius.widget", json!({ "value": 2, "unit": "px" }));
let app = App::builder().theme(spec).build(&egui::Context::default()).unwrap();

// Later, from a command or a settings page: installed before the next frame.
app.handle().theme().set(ThemeSpec::new("pop-light"));

A visual kit

What a component looks like is data: a box per state (rest, hover, active, focus, selected, disabled) and per tone, and the handler that draws it, compiled once when the theme is installed. A kit changes it with tokens alone, or brings handlers of its own. More in Visual kits and Kits as packages.

use egui_pop::egui;
use egui_pop::prelude::*;
use egui_pop::tokens::kit::KitData;

// The workbench's tabs underlined instead of boxed.
let kit = KitData::from_text(
    "underline",
    r#"
    tab:
      shape: {$type: "string", $value: "underline"}
      selected:
        indicator-color: {$type: "color", $value: "{accent.default}"}
    "#,
);
let ctx = egui::Context::default();
let _app = App::builder().kit(kit).theme(ThemeSpec::new("underline")).build(&ctx).unwrap();
assert_eq!(egui_pop::core::kit::Kit::of(&ctx).tab.shape, "underline");

A hook on a step

egui-pop names the moments of each feature's life (frame.close, workbench.detach, arrangement.switch...). A plugin may observe, veto, replace or extend any of them (ADR 0011). Here a plugin keeps the window open while work is unsaved (frame.close is run by FramePlugin). More in Plugins, commands and steps.

use egui_pop::api::frame::STEP_CLOSE;
use egui_pop::prelude::*;

struct Guard;

impl Plugin for Guard {
    fn id(&self) -> PluginId { PluginId::from_static("guard") }

    fn connect(&mut self, ctx: &mut Ctx<'_>) -> Result<(), PluginError> {
        ctx.before(STEP_CLOSE, |app, _| {
            if app.context().get("unsaved") == "true" { Before::Veto("unsaved work".into()) } else { Before::Go }
        });
        ctx.after(STEP_CLOSE, |_, args, result| eprintln!("closed {args}: {result:?}"));
        Ok(())
    }
}

An image viewport

The viewport feature shows an image your application computes, in tiles, zoomed in physical pixels. You implement the tile source. More in The image viewport.

use egui_pop::viewport::ViewportState;
use egui_pop::viewport::source::{Pixels, Tile, TileRequest, TileSink, TileSource};

struct Grey(TileSink);

impl TileSource for Grey {
    fn size(&self) -> Option<[u32; 2]> { Some([6000, 4000]) }

    fn request(&self, requests: Vec<TileRequest>) {
        for r in requests {
            let n = r.size[0] as usize * r.size[1] as usize;
            self.0.deliver(Tile::answer(&r, Pixels::Scene(vec![0.18; n * 4])));
        }
    }
}

let state = ViewportState::new();
let _source = Grey(state.sink());

Screenshots

Captured from the gallery. Click a thumbnail for the full image; every built-in theme is in Themes.

Refreshing the screenshots

Every screenshot is the gallery's real window, captured headless in a nested compositor with wbox. Nobody opens the gallery on a desktop to capture it. One command refreshes the full images, their thumbnails and the themes gallery:

cargo xtask screenshots              # everything
cargo xtask screenshots palette      # only the shots whose name matches

It builds the gallery in release mode, runs each page and theme in wbox, presses the keys a shot needs, crops to the window, writes docs/screenshots/ and the reduced copies beside it. Review the images in the diff before committing. The steps it automates are in CONTRIBUTING.md.

Documentation

The docs index lists every page: getting started, themes and tokens, plugins and steps, the image viewport, debugging, the gallery, testing, API stability and the design decisions. They are also online, with search, at https://quazardous.github.io/egui-pop/docs/, and the API documentation of every crate, with every feature on (docs.rs shows the default features), at https://quazardous.github.io/egui-pop/api/.

Extensions

Extensions add components and plugins through the same API: start one from the extension template (cargo generate --git https://github.com/quazardous/egui-pop templates/extension), and list it in the registry of extensions.

Versions

egui-pop has its own 0.x version; one egui-pop minor per egui minor, released within days of it. The sub-crates have their own versions, which move only when their code does.

egui-pop egui Rust
0.1.x 0.36 1.95

Contributing

See CONTRIBUTING.md (with a section for extension authors), GOVERNANCE.md, AGENTS.md and CHANGELOG.md.

Unsafe code

unsafe is forbidden in the whole workspace (unsafe_code = "forbid" in the workspace lints), except in the two crates that call the operating system directly:

  • egui-pop-win32, the Windows layer of the window frame (Snap Layouts, rounded corners). Its unsafe code is compiled on Windows only; other platforms get safe stubs.
  • egui-pop-wayland, the Wayland layer of the image viewport (a colour managed subsurface), only with the viewport's wayland feature.

License

Licensed under either of

at your option.