From 272503873ca9faed678476410cba612612cef4a4 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 5 May 2019 18:19:19 -0700 Subject: [PATCH] avoid menu flickering and incorrect entries by sending a NoOp after used events --- docs/TODO_refactoring.md | 5 +++++ docs/TODO_ux.md | 8 +++++--- ezgui/src/event.rs | 4 +++- ezgui/src/runner.rs | 12 +++++++----- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/docs/TODO_refactoring.md b/docs/TODO_refactoring.md index 9e3bc7466f..6338226a7b 100644 --- a/docs/TODO_refactoring.md +++ b/docs/TODO_refactoring.md @@ -33,3 +33,8 @@ - canvas owning text-drawing is maybe a bit weird, at least API-wise - 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 +- loading screen + - cleanup hack: dont put glyphbrush in canvas at all + - FileWithProgress should go directly into Timer + - need to understand lifetimes + - cleanup abstutil Timer stuff generally diff --git a/docs/TODO_ux.md b/docs/TODO_ux.md index e333295849..a2d636a86f 100644 --- a/docs/TODO_ux.md +++ b/docs/TODO_ux.md @@ -26,11 +26,14 @@ ## General ezgui stuff - optionally limit canvas scrolling/zooming to some map bounds -- X on all menus - when dragging, dont give mouse movement to UI elements - start context menu when left click releases and we're not dragging - can we change labels in modal or top menu? show/hide -- bold hotkey letters +- label sections of modal menus +- distinguish hints from status of modal menus, for hiding purposes +- move context menus out of ezgui + - simplify/remove UserInput. + - maybe separate impls for context, wizard, modal menu make sense. ## New features @@ -110,4 +113,3 @@ - highlight a region, draw counts to/from it in some meaningful way - timer slider (except timeslices arent neatly in hour blocks, though they maybe should be) - a table (with color-coded entries) is actually perfect - diff --git a/ezgui/src/event.rs b/ezgui/src/event.rs index b3facbb7f3..7fed1b419b 100644 --- a/ezgui/src/event.rs +++ b/ezgui/src/event.rs @@ -3,7 +3,9 @@ use glium::glutin; #[derive(Debug, Clone, Copy, PartialEq)] pub enum Event { - InitializeApplication, + // Used to initialize the application and also to recalculate menu state when some other event + // is used. + NoOp, LeftMouseButtonDown, LeftMouseButtonUp, RightMouseButtonDown, diff --git a/ezgui/src/runner.rs b/ezgui/src/runner.rs index e9ec77cdf1..925aac0ff2 100644 --- a/ezgui/src/runner.rs +++ b/ezgui/src/runner.rs @@ -191,11 +191,7 @@ pub fn run G>( }; let gui = make_gui(&mut EventCtx { - input: &mut UserInput::new( - Event::InitializeApplication, - ContextMenu::new(), - &mut canvas, - ), + input: &mut UserInput::new(Event::NoOp, ContextMenu::new(), &mut canvas), canvas: &mut canvas, prerender: &prerender, program: &program, @@ -296,6 +292,12 @@ fn loop_forever( // Don't draw if an event was ignored. Every keypress also fires a release event, most of // which are ignored. if any_input_used { + // But if the event caused a state-change, the drawing state might be different too. + // Need to recalculate what menu entries and such are valid. So send through a no-op + // event. + let (new_state, _, _) = state.event(Event::NoOp, &prerender, &program); + state = new_state; + state.draw(&prerender.display, &program, &prerender, false); prerender.num_uploads.set(0); }