Expand description
Optional egui host for one wgame drawing area.
Wrap a window, build controls in the layout callback, and hand the result to
code generic over WindowHost. The callback returns the response from
Canvas::show; its widget ID stays stable across frames. Input and camera
coordinates are local logical pixels, including egui zoom. Clicking the canvas
gives it keyboard focus. UI controls own their events; a captured canvas drag
retains its release outside the canvas. Geometry/focus loss cancels gestures.
Lifting a touch preserves its completed release and clears pointer hover;
a cancelled touch aborts the gesture instead.
use wgame::{ContentFrame, WindowHost, gfx::{Target, types::color}};
use wgame_egui::{egui, EguiWindow};
async fn run(window: wgame::Window<'_>) -> wgame::Result<()> {
let mut host = EguiWindow::new(window, |ui, canvas| {
egui::Panel::top("toolbar").show(ui, |ui| { ui.label("My playground"); });
egui::CentralPanel::default().show(ui, |ui| canvas.show(ui)).inner
});
while let Some(mut frame) = host.next_frame().await? {
frame.clear(color::BLACK);
// Update once here, then render with frame.logical_camera().
}
Ok(())
}Create renderers from the wrapper’s WindowHost::graphics: its RGBA canvas
target can have a different format from the OS surface. Composition uses one
offscreen texture and an additional pass. Layout callbacks may run repeatedly;
keep simulation updates outside them. Normal frame drop presents once;
discard/panic drops all encoded commands (texture uploads may already occur).
A hidden/empty canvas yields a minimal target with visible() == false, so
application updates and UI actions can still run.
For static content, call host.wait_for_update(None).await between frames.
This wakes on input, OS redraws, and egui repaint deadlines (including animation
and tooltip delays). Pass a timeout for application timers or zero for animation.
After changing application state outside layout, request one more repaint with
host.context().request_repaint() so the controls display the new state.
This integration owns one OS window. Native secondary viewports and viewport
screenshot/clipboard-image requests are not supported. Use embedded egui
windows instead. The desktop feature enables native clipboard and links;
web uses WebGL2 and a winit event adapter for pointer, touch, keyboard and
wheel input. Browser text entry requires a hardware keyboard: mobile virtual
keyboards, IME, system clipboard and file drops are not integrated. The web
adapter provides an in-app text clipboard.
Re-exports§
pub use egui;
Structs§
- Canvas
- The content texture, allocated to the available UI rectangle.
- Egui
Window - A window decorated with an egui layout containing one
Canvas. - Frame
- Borrowed canvas target; presentation composites it with the UI.