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

Simplify egui_winit::State (#3678)

By storing a clone of the egui context in it, we can be sure to always
use the correct `pixels_per_point`
This commit is contained in:
Emil Ernerfeldt
2023-12-05 11:45:25 +01:00
committed by GitHub
parent 80d7143b15
commit a4e389431d
6 changed files with 70 additions and 84 deletions

View File

@@ -34,7 +34,10 @@ impl EguiGlow {
})
.unwrap();
let egui_ctx = egui::Context::default();
let egui_winit = egui_winit::State::new(
egui_ctx.clone(),
ViewportId::ROOT,
event_loop,
native_pixels_per_point,
@@ -42,7 +45,7 @@ impl EguiGlow {
);
Self {
egui_ctx: Default::default(),
egui_ctx,
egui_winit,
painter,
viewport_info: Default::default(),
@@ -52,8 +55,12 @@ impl EguiGlow {
}
}
pub fn on_window_event(&mut self, event: &winit::event::WindowEvent<'_>) -> EventResponse {
self.egui_winit.on_window_event(&self.egui_ctx, event)
pub fn on_window_event(
&mut self,
window: &winit::window::Window,
event: &winit::event::WindowEvent<'_>,
) -> EventResponse {
self.egui_winit.on_window_event(window, event)
}
/// Call [`Self::paint`] later to paint.
@@ -87,7 +94,7 @@ impl EguiGlow {
}
self.egui_winit
.handle_platform_output(window, &self.egui_ctx, platform_output);
.handle_platform_output(window, platform_output);
self.shapes = shapes;
self.pixels_per_point = pixels_per_point;