5个版本
新 0.1.4 | 2024年8月20日 |
---|---|
0.1.3 | 2024年8月20日 |
0.1.2 | 2024年8月19日 |
0.1.1 | 2024年8月18日 |
0.1.0 | 2024年8月10日 |
#1176 in WebAssembly
每月307次下载
85KB
1.5K SLoC
egui_wings
此crate便于在主机和多个访客WASM模块之间共享egui::Context
。这允许WASM插件绘制UI并通过主机轻松显示。
用法
以下代码片段展示了如何从WASM插件(完整示例可在egui_wings_example
文件夹中找到)中使用egui_wings
。它定义了一个WingsSystem
,该系统将存储WASM插件的状态。在每一帧,都会调用draw_ui
方法。它通过系统依赖访问主机egui::Context
,然后通过正常的egui
调用绘制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 }
}
}
依赖
~7–14MB
~173K SLoC