From daa7a2bdb25dc8e4655f09bfcaffa815c2c74867 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 24 Oct 2020 18:49:44 +0200 Subject: [PATCH] [egui_glium] refactor --- egui_glium/src/backend.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/egui_glium/src/backend.rs b/egui_glium/src/backend.rs index 82a2f4c48..49b83a3f5 100644 --- a/egui_glium/src/backend.rs +++ b/egui_glium/src/backend.rs @@ -20,35 +20,40 @@ impl egui::app::TextureAllocator for Painter { } } -/// Run an egui app -pub fn run( +fn create_display( title: &str, - mut storage: Box, - mut app: impl App + 'static, -) -> ! { - let event_loop = glutin::event_loop::EventLoop::new(); - let mut window = glutin::window::WindowBuilder::new() + window_settings: Option, + event_loop: &glutin::event_loop::EventLoop<()>, +) -> glium::Display { + let mut window_builder = glutin::window::WindowBuilder::new() .with_decorations(true) .with_resizable(true) .with_title(title) .with_transparent(false); - let window_settings: Option = - egui::app::get_value(storage.as_ref(), WINDOW_KEY); if let Some(window_settings) = &window_settings { - window = window_settings.initialize_size(window); + window_builder = window_settings.initialize_size(window_builder); } - let context = glutin::ContextBuilder::new() + let context_builder = glutin::ContextBuilder::new() .with_depth_buffer(0) .with_srgb(true) .with_stencil_buffer(0) .with_vsync(true); - let display = glium::Display::new(window, context, &event_loop).unwrap(); - if let Some(window_settings) = &window_settings { - window_settings.restore_positions(&display); - } + glium::Display::new(window_builder, context_builder, &event_loop).unwrap() +} + +/// Run an egui app +pub fn run( + title: &str, + mut storage: Box, + mut app: impl App + 'static, +) -> ! { + let window_settings: Option = + egui::app::get_value(storage.as_ref(), WINDOW_KEY); + let event_loop = glutin::event_loop::EventLoop::new(); + let display = create_display(title, window_settings, &event_loop); let mut ctx = egui::Context::new(); *ctx.memory() = egui::app::get_value(storage.as_ref(), EGUI_MEMORY_KEY).unwrap_or_default();