split ezgui runner into setup and loop functions

This commit is contained in:
Dustin Carlino 2019-02-01 09:25:59 -08:00
parent bd7d18592b
commit 06b8c26716
2 changed files with 12 additions and 2 deletions

View File

@ -89,6 +89,7 @@
- ezgui passes EventCtx and DrawCtx with appropriate things exposed. - ezgui passes EventCtx and DrawCtx with appropriate things exposed.
- maybe move glyph ownership out of canvas entirely. dont need RefCell. - maybe move glyph ownership out of canvas entirely. dont need RefCell.
- canvas owning text-drawing is maybe a bit weird, at least API-wise - canvas owning text-drawing is maybe a bit weird, at least API-wise
- organize into directories
- hide stuff inside the ctx's? canvas and prerender shouldnt even be known outside of crate - hide stuff inside the ctx's? canvas and prerender shouldnt even be known outside of crate
- generic World with quadtree should have actions on objects - generic World with quadtree should have actions on objects
- more speculative performance ideas - more speculative performance ideas

View File

@ -152,7 +152,7 @@ pub fn run<T, G: GUI<T>, F: FnOnce(&mut Canvas, &Prerender) -> G>(
// DPI is broken on my system; force the old behavior. // DPI is broken on my system; force the old behavior.
env::set_var("WINIT_HIDPI_FACTOR", "1.0"); env::set_var("WINIT_HIDPI_FACTOR", "1.0");
let mut events_loop = glutin::EventsLoop::new(); let events_loop = glutin::EventsLoop::new();
let window = glutin::WindowBuilder::new() let window = glutin::WindowBuilder::new()
.with_title(window_title) .with_title(window_title)
.with_dimensions(glutin::dpi::LogicalSize::new(initial_width, initial_height)); .with_dimensions(glutin::dpi::LogicalSize::new(initial_width, initial_height));
@ -186,7 +186,7 @@ pub fn run<T, G: GUI<T>, F: FnOnce(&mut Canvas, &Prerender) -> G>(
let mut canvas = Canvas::new(initial_width, initial_height, glyphs, line_height); let mut canvas = Canvas::new(initial_width, initial_height, glyphs, line_height);
let gui = make_gui(&mut canvas, &Prerender { display: &display }); let gui = make_gui(&mut canvas, &Prerender { display: &display });
let mut state = State { let state = State {
top_menu: gui.top_menu(&canvas), top_menu: gui.top_menu(&canvas),
canvas, canvas,
context_menu: ContextMenu::Inactive, context_menu: ContextMenu::Inactive,
@ -195,6 +195,15 @@ pub fn run<T, G: GUI<T>, F: FnOnce(&mut Canvas, &Prerender) -> G>(
gui, gui,
}; };
loop_forever(state, events_loop, display, program);
}
fn loop_forever<T, G: GUI<T>>(
mut state: State<T, G>,
mut events_loop: glutin::EventsLoop,
display: glium::Display,
program: glium::Program,
) {
let mut accumulator = Duration::new(0, 0); let mut accumulator = Duration::new(0, 0);
let mut previous_clock = Instant::now(); let mut previous_clock = Instant::now();
let mut wait_for_events = false; let mut wait_for_events = false;