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日 |
#310 in WebAssembly
每月635次下载
用于 egui_wings_host
82KB
1.5K SLoC
egui_wings
此crate简化了主机和多个客人WASM模块之间共享egui::Context
的过程。这使得WASM插件能够绘制UI并通过主机轻松显示。
用法
以下代码片段展示了如何从WASM插件中使用egui_wings
(完整的示例可在egui_wings_example
文件夹中找到)。它定义了一个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 }
}
}
依赖项
~5–11MB
~111K SLoC