1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -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

@@ -101,9 +101,9 @@ pub use egui_winit;
/// Use [`egui`] from a [`glow`] app.
pub struct EguiGlow {
egui_ctx: egui::CtxRef,
egui_winit: egui_winit::State,
painter: crate::Painter,
pub egui_ctx: egui::CtxRef,
pub egui_winit: egui_winit::State,
pub painter: crate::Painter,
}
impl EguiGlow {
@@ -118,26 +118,6 @@ impl EguiGlow {
}
}
pub fn ctx(&self) -> &egui::CtxRef {
&self.egui_ctx
}
pub fn painter_mut(&mut self) -> &mut crate::Painter {
&mut self.painter
}
pub fn ctx_and_painter_mut(&mut self) -> (&egui::CtxRef, &mut crate::Painter) {
(&self.egui_ctx, &mut self.painter)
}
pub fn pixels_per_point(&self) -> f32 {
self.egui_winit.pixels_per_point()
}
pub fn egui_input(&self) -> &egui::RawInput {
self.egui_winit.egui_input()
}
/// Returns `true` if egui wants exclusive use of this event
/// (e.g. a mouse click on an egui window, or entering text into a text field).
/// For instance, if you use egui for a game, you want to first call this
@@ -153,34 +133,22 @@ impl EguiGlow {
self.egui_winit.is_quit_event(event)
}
pub fn begin_frame(&mut self, window: &glutin::window::Window) {
let raw_input = self.take_raw_input(window);
self.begin_frame_with_input(raw_input);
}
pub fn begin_frame_with_input(&mut self, raw_input: egui::RawInput) {
self.egui_ctx.begin_frame(raw_input);
}
/// Prepare for a new frame. Normally you would call [`Self::begin_frame`] instead.
pub fn take_raw_input(&mut self, window: &glutin::window::Window) -> egui::RawInput {
self.egui_winit.take_egui_input(window)
}
/// Returns `needs_repaint` and shapes to draw.
pub fn end_frame(
pub fn run(
&mut self,
window: &glutin::window::Window,
mut run_ui: impl FnMut(&egui::CtxRef),
) -> (bool, Vec<egui::epaint::ClippedShape>) {
let raw_input = self.egui_winit.take_egui_input(window);
self.egui_ctx.begin_frame(raw_input);
run_ui(&self.egui_ctx);
let (egui_output, shapes) = self.egui_ctx.end_frame();
let needs_repaint = egui_output.needs_repaint;
self.handle_output(window, egui_output);
(needs_repaint, shapes)
}
pub fn handle_output(&mut self, window: &glutin::window::Window, output: egui::Output) {
self.egui_winit
.handle_output(window, &self.egui_ctx, output);
.handle_output(window, &self.egui_ctx, egui_output);
(needs_repaint, shapes)
}
pub fn paint(
@@ -199,6 +167,7 @@ impl EguiGlow {
);
}
/// Call to release the allocated graphics resources.
pub fn destroy(&mut self, gl: &glow::Context) {
self.painter.destroy(gl);
}