From a232d023ff94101fb70abcceee4abee9d7530c32 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 26 Dec 2018 19:01:36 -0600 Subject: [PATCH] draw signal diagram exactly below modal menu --- editor/src/plugins/edit/traffic_signal_editor.rs | 9 +++++++-- ezgui/src/input.rs | 15 ++++++++++++--- ezgui/src/menu.rs | 6 ++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/editor/src/plugins/edit/traffic_signal_editor.rs b/editor/src/plugins/edit/traffic_signal_editor.rs index 7aabf18d7c..179000209f 100644 --- a/editor/src/plugins/edit/traffic_signal_editor.rs +++ b/editor/src/plugins/edit/traffic_signal_editor.rs @@ -2,7 +2,7 @@ use crate::objects::{Ctx, ID}; use crate::plugins::{Plugin, PluginCtx}; use crate::render::{draw_signal_cycle, draw_signal_diagram, DrawTurn}; use dimensioned::si; -use ezgui::{Color, GfxCtx, Key, Wizard, WrappedWizard, TOP_MENU_HEIGHT}; +use ezgui::{Color, GfxCtx, Key, ScreenPt, Wizard, WrappedWizard}; use map_model::{ControlTrafficSignal, Cycle, IntersectionID, Map, TurnID, TurnPriority, TurnType}; // TODO Warn if there are empty cycles or if some turn is completely absent from the signal. @@ -14,6 +14,8 @@ pub struct TrafficSignalEditor { cycle_duration_wizard: Option, preset_wizard: Option, icon_selected: Option, + + diagram_top_left: ScreenPt, } impl TrafficSignalEditor { @@ -24,12 +26,15 @@ impl TrafficSignalEditor { .input .contextual_action(Key::E, &format!("edit traffic signal for {}", id)) { + let diagram_top_left = ctx.input.set_mode("Traffic Signal Editor", &ctx.canvas); + return Some(TrafficSignalEditor { i: id, current_cycle: 0, cycle_duration_wizard: None, preset_wizard: None, icon_selected: None, + diagram_top_left, }); } } @@ -219,7 +224,7 @@ impl Plugin for TrafficSignalEditor { self.i, self.current_cycle, None, - TOP_MENU_HEIGHT + 400.0, + self.diagram_top_left.y, g, ctx, ); diff --git a/ezgui/src/input.rs b/ezgui/src/input.rs index 9503d2e88d..544de6f5e3 100644 --- a/ezgui/src/input.rs +++ b/ezgui/src/input.rs @@ -229,12 +229,19 @@ impl UserInput { } } - pub fn set_mode_with_prompt(&mut self, mode: &str, prompt: String, canvas: &Canvas) { + // Returns the bottom left of the modal menu. + pub fn set_mode_with_prompt( + &mut self, + mode: &str, + prompt: String, + canvas: &Canvas, + ) -> ScreenPt { self.set_mode_called.insert(mode.to_string()); self.current_mode = Some(mode.to_string()); if let Some(ref mut menu) = self.modal_state.mut_active_mode(mode) { menu.mark_all_inactive(); menu.change_prompt(prompt); + menu.get_bottom_left() } else { if let Some(ref m) = self.modal_state.modes.get(mode) { let mut menu = Menu::new( @@ -248,15 +255,17 @@ impl UserInput { canvas, ); menu.mark_all_inactive(); + let corner = menu.get_bottom_left(); self.modal_state.active.push((mode.to_string(), menu)); + corner } else { panic!("set_mode called on unknown {}", mode); } } } - pub fn set_mode(&mut self, mode: &str, canvas: &Canvas) { - self.set_mode_with_prompt(mode, mode.to_string(), canvas); + pub fn set_mode(&mut self, mode: &str, canvas: &Canvas) -> ScreenPt { + self.set_mode_with_prompt(mode, mode.to_string(), canvas) } pub fn modal_action(&mut self, action: &str) -> bool { diff --git a/ezgui/src/menu.rs b/ezgui/src/menu.rs index c2a934b36d..376697ca7a 100644 --- a/ezgui/src/menu.rs +++ b/ezgui/src/menu.rs @@ -14,6 +14,7 @@ pub struct Menu { row_height: f64, top_left: ScreenPt, first_choice_row: ScreenRectangle, + total_height: f64, } #[derive(Clone)] @@ -91,6 +92,7 @@ impl Menu { y2: top_left.y + row_height, } }, + total_height, } } @@ -250,4 +252,8 @@ impl Menu { assert!(self.prompt.is_some()); self.prompt = Some(prompt); } + + pub fn get_bottom_left(&self) -> ScreenPt { + ScreenPt::new(self.top_left.x, self.top_left.y + self.total_height) + } }