Browse Source

[egui_glium] refactor

pull/30/head
Emil Ernerfeldt 4 years ago
parent
commit
daa7a2bdb2
  1. 35
      egui_glium/src/backend.rs

35
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<dyn egui::app::Storage>,
mut app: impl App + 'static,
) -> ! {
let event_loop = glutin::event_loop::EventLoop::new();
let mut window = glutin::window::WindowBuilder::new()
window_settings: Option<WindowSettings>,
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<WindowSettings> =
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<dyn egui::app::Storage>,
mut app: impl App + 'static,
) -> ! {
let window_settings: Option<WindowSettings> =
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();

Loading…
Cancel
Save