Expand description
§egui-sdl2
Integration between egui and
sdl2.
§Features
- Translate SDL2 events into
eguievents. - Handle
egui::PlatformOutput(clipboard, cursor updates, links). - Render with the SDL2 software renderer via
sdl2::render::Canvas(canvas-backendfeature). - Render with OpenGL via
glow(glow-backendfeature). - Render with WebGPU via
wgpu(wgpu-backendfeature). - Or let
EguiWindowpick: it walks a list of renderers and keeps the first the device actually supports.
§Usage
// Create SDL2 window and canvas:
let sdl = sdl2::init().unwrap();
let video = sdl.video().unwrap();
let window = video.window("Egui SDL2 Canvas", 800, 600).build().unwrap();
let mut canvas = window.into_canvas().build().unwrap();
// Create egui renderer; the canvas stays yours:
let mut egui = egui_sdl2::EguiCanvas::new(&canvas);
let mut event_pump = sdl.event_pump().unwrap();
loop {
// Feed SDL2 events into egui:
for event in event_pump.poll_iter() {
egui.on_event(&canvas, &event);
}
// Call `run` + `paint` each frame, over anything you drew yourself:
egui.run(|ctx: &egui::Context| {});
canvas.clear();
egui.paint(&mut canvas);
canvas.present();
std::thread::sleep(std::time::Duration::from_secs_f64(1.0 / 60.0));
}Re-exports§
pub use canvas::EguiCanvas;pub use rotation::Rotation;pub use wgpu::EguiWgpu;pub use window::EguiWindow;pub use window::Renderer;pub use egui;pub use egui_glow;pub use sdl2;pub use glow::*;pub use state::*;
Modules§
- canvas
- Integration between
eguiand SDL2’ssdl2::render::CanvasAPI. - glow
- Integration between
eguiandglowfor SDL2 applications. - rotation
- Presenting the UI at a quarter turn to the window, for a panel that is not mounted the way it is read: egui lays out for the turned screen, and the backend puts that frame on the window the other way round.
- state
- State management for egui + SDL2 integration.
- wgpu
- Integration between
eguiandwgpuAPI. - window
- A window plus the best renderer it can get:
EguiWindowwalks a list ofRenderers and keeps the first that comes up, so an app on a device with missing or broken GL drivers still shows a UI instead of exiting.
Structs§
- Egui
RunOutput - The results of running one frame of
egui.