1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

Refactor integrations (#871)

* Unify code in egui_glium and egui_glow into egui_winit::EpiIntegration
* Simplify `EguiGlium` interface
* Simplify `EguiGlow` interface
* egui_web refactor: merge `WebBackend` into `AppRunner`
This commit is contained in:
Emil Ernerfeldt
2021-11-03 13:45:51 +01:00
committed by GitHub
parent b1716be745
commit 1dbe608e73
14 changed files with 381 additions and 479 deletions

View File

@@ -40,23 +40,21 @@ fn main() {
let event_loop = glutin::event_loop::EventLoop::with_user_event();
let (gl_window, gl) = create_display(&event_loop);
let mut egui = egui_glow::EguiGlow::new(&gl_window, &gl);
let mut egui_glow = egui_glow::EguiGlow::new(&gl_window, &gl);
event_loop.run(move |event, _, control_flow| {
let mut redraw = || {
egui.begin_frame(gl_window.window());
let mut quit = false;
egui::SidePanel::left("my_side_panel").show(egui.ctx(), |ui| {
ui.heading("Hello World!");
if ui.button("Quit").clicked() {
quit = true;
}
let (needs_repaint, shapes) = egui_glow.run(gl_window.window(), |egui_ctx| {
egui::SidePanel::left("my_side_panel").show(egui_ctx, |ui| {
ui.heading("Hello World!");
if ui.button("Quit").clicked() {
quit = true;
}
});
});
let (needs_repaint, shapes) = egui.end_frame(gl_window.window());
*control_flow = if quit {
glutin::event_loop::ControlFlow::Exit
} else if needs_repaint {
@@ -76,7 +74,7 @@ fn main() {
// draw things behind egui here
egui.paint(&gl_window, &gl, shapes);
egui_glow.paint(&gl_window, &gl, shapes);
// draw things on top of egui here
@@ -92,7 +90,7 @@ fn main() {
glutin::event::Event::RedrawRequested(_) if !cfg!(windows) => redraw(),
glutin::event::Event::WindowEvent { event, .. } => {
if egui.is_quit_event(&event) {
if egui_glow.is_quit_event(&event) {
*control_flow = glutin::event_loop::ControlFlow::Exit;
}
@@ -100,12 +98,12 @@ fn main() {
gl_window.resize(physical_size);
}
egui.on_event(&event);
egui_glow.on_event(&event);
gl_window.window().request_redraw(); // TODO: ask egui if the events warrants a repaint instead
}
glutin::event::Event::LoopDestroyed => {
egui.destroy(&gl);
egui_glow.destroy(&gl);
}
_ => (),