6 releases

0.2.0 Nov 13, 2024
0.1.4 Aug 20, 2024

#325 in WebAssembly

Download history 443/week @ 2024-08-14 173/week @ 2024-08-21 13/week @ 2024-08-28 10/week @ 2024-09-11 10/week @ 2024-09-18 15/week @ 2024-09-25 8/week @ 2024-10-02 4/week @ 2024-10-09 2/week @ 2024-10-16 4/week @ 2024-10-30 5/week @ 2024-11-06 126/week @ 2024-11-13 10/week @ 2024-11-20 2/week @ 2024-11-27

144 downloads per month
Used in 3 crates

MIT/Apache

87KB
2K SLoC

egui_wings

Crates.io Docs.rs

This crate facilitates sharing an egui::Context between a host and multiple guest WASM modules. This allows WASM plugins to draw UI and easily display it via the host.


Usage

The following code snippet shows how to use egui_wings from a WASM plugin (the complete example may be found in the egui_wings_example folder). It defines a WingsSystem which will store the WASM plugin's state. Each frame, the draw_ui method is invoked. It accesses the host egui::Context via a system dependency and then makes normal egui calls to draw a UI.

use egui_wings::*;
use example_host::*;
use wings::*;

instantiate_systems!(ExampleHost, [PluginSystem]);

/// An object that will be instantiated inside a WASM plugin.
#[export_system]
pub struct PluginSystem {
    /// A handle for accessing system dependencies.
    ctx: WingsContextHandle<Self>,
}

impl PluginSystem {
    /// Submits the `egui` commands to draw the debug windows.
    fn draw_ui(&mut self, _: &example_host::on::Render) {
        let egui = self.ctx.get::<dyn Egui>();
        Window::new("webassembly says hello!")
            .resizable(true)
            .vscroll(true)
            .default_open(false)
        .show(&egui.context(), |ui| {
            ui.label("Hello there!");
        });
    }
}

impl WingsSystem for PluginSystem {
    const DEPENDENCIES: Dependencies = dependencies().with::<dyn Egui>();

    const EVENT_HANDLERS: EventHandlers<Self> = event_handlers().with(Self::draw_ui);

    fn new(ctx: WingsContextHandle<Self>) -> Self {
        Self { ctx }
    }
}

Dependencies

~5–10MB
~112K SLoC