From 6738de24888f0dd7b68718f3eca9ea57316bf261 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 20 Jun 2019 14:26:49 -0700 Subject: [PATCH] draw text beneath Sliders, not in the ModalMenu --- editor/src/abtest/mod.rs | 1 - editor/src/common/mod.rs | 35 ++++++++++++++-------------- editor/src/mission/all_trips.rs | 5 ++-- editor/src/sandbox/mod.rs | 1 - ezgui/src/drawing.rs | 18 +++++++-------- ezgui/src/widgets/menu.rs | 8 ------- ezgui/src/widgets/slider.rs | 41 ++++++++++++++++++++------------- 7 files changed, 53 insertions(+), 56 deletions(-) diff --git a/editor/src/abtest/mod.rs b/editor/src/abtest/mod.rs index 82f04b98a7..3260136834 100644 --- a/editor/src/abtest/mod.rs +++ b/editor/src/abtest/mod.rs @@ -91,7 +91,6 @@ impl ABTestMode { )); } txt.add_line(state.ui.primary.sim.summary()); - txt.add_line(mode.speed.modal_status_line()); mode.menu.handle_event(ctx, Some(txt)); ctx.canvas.handle_event(ctx.input); diff --git a/editor/src/common/mod.rs b/editor/src/common/mod.rs index c526866f61..6305f330f3 100644 --- a/editor/src/common/mod.rs +++ b/editor/src/common/mod.rs @@ -218,22 +218,6 @@ impl SpeedControls { } } - pub fn modal_status_line(&self) -> String { - if let State::Running { - ref speed_description, - .. - } = self.state - { - format!( - "Speed: {} / desired {:.2}x", - speed_description, - self.desired_speed() - ) - } else { - format!("Speed: paused / desired {:.2}x", self.desired_speed()) - } - } - // Returns the amount of simulation time to step, if running. pub fn event( &mut self, @@ -296,7 +280,24 @@ impl SpeedControls { } pub fn draw(&self, g: &mut GfxCtx) { - self.slider.draw(g); + let mut txt = Text::new(); + if let State::Running { + ref speed_description, + .. + } = self.state + { + txt.add_line(format!( + "Speed: {} / desired {:.2}x", + speed_description, + self.desired_speed() + )) + } else { + txt.add_line(format!( + "Speed: paused / desired {:.2}x", + self.desired_speed() + )) + } + self.slider.draw(g, Some(txt)); } pub fn pause(&mut self) { diff --git a/editor/src/mission/all_trips.rs b/editor/src/mission/all_trips.rs index dbd29f17ec..196363a893 100644 --- a/editor/src/mission/all_trips.rs +++ b/editor/src/mission/all_trips.rs @@ -93,8 +93,6 @@ impl TripsVisualizer { "{} active trips", prettyprint_usize(self.active_trips.len()) )); - txt.add_line(format!("At {}", time)); - txt.add_line(self.speed.modal_status_line()); self.menu.handle_event(ctx, Some(txt)); ctx.canvas.handle_event(ctx.input); @@ -186,7 +184,8 @@ impl TripsVisualizer { batch.draw(g); self.menu.draw(g); - self.time_slider.draw(g); + self.time_slider + .draw(g, Some(Text::from_line(format!("At {}", time)))); self.speed.draw(g); CommonState::draw_osd(g, ui, ui.primary.current_selection); } diff --git a/editor/src/sandbox/mod.rs b/editor/src/sandbox/mod.rs index 3877546709..1da4b3565c 100644 --- a/editor/src/sandbox/mod.rs +++ b/editor/src/sandbox/mod.rs @@ -161,7 +161,6 @@ impl SandboxMode { let mut txt = Text::prompt("Sandbox Mode"); txt.add_line(state.ui.primary.sim.summary()); - txt.add_line(mode.speed.modal_status_line()); if let Some(trip) = mode.following { txt.add_line(format!("Following {}", trip)); } diff --git a/ezgui/src/drawing.rs b/ezgui/src/drawing.rs index 5304efd505..beb9715485 100644 --- a/ezgui/src/drawing.rs +++ b/ezgui/src/drawing.rs @@ -194,15 +194,12 @@ impl<'a> GfxCtx<'a> { VerticalAlignment::Center => (self.canvas.window_height - height) / 2.0, VerticalAlignment::Bottom => self.canvas.window_height - height, }; - self.canvas - .covered_areas - .borrow_mut() - .push(text::draw_text_bubble( - self, - ScreenPt::new(x1, y1), - txt, - (width, height), - )); + self.canvas.mark_covered_area(text::draw_text_bubble( + self, + ScreenPt::new(x1, y1), + txt, + (width, height), + )); } pub fn get_screen_bounds(&self) -> Bounds { @@ -237,7 +234,8 @@ impl<'a> GfxCtx<'a> { pub fn draw_text_at_screenspace_topleft(&mut self, txt: &Text, pt: ScreenPt) { let dims = self.text_dims(&txt); - text::draw_text_bubble(self, pt, txt, dims); + self.canvas + .mark_covered_area(text::draw_text_bubble(self, pt, txt, dims)); } pub fn draw_mouse_tooltip(&mut self, txt: &Text) { diff --git a/ezgui/src/widgets/menu.rs b/ezgui/src/widgets/menu.rs index 7c099f4e48..5868c0c016 100644 --- a/ezgui/src/widgets/menu.rs +++ b/ezgui/src/widgets/menu.rs @@ -22,7 +22,6 @@ struct Geometry { row_height: f64, top_left: ScreenPt, first_choice_row: ScreenRectangle, - total_height: f64, } #[derive(Clone)] @@ -93,7 +92,6 @@ impl Position { x2: top_left.x + total_width, y2: top_left.y + prompt_height + row_height, }, - total_height, } } } @@ -281,12 +279,6 @@ impl Menu { } } } - g.canvas.mark_covered_area(ScreenRectangle { - x1: self.geom.top_left.x, - y1: self.geom.top_left.y, - x2: self.geom.first_choice_row.x2, - y2: self.geom.top_left.y + self.geom.total_height, - }); g.draw_text_at_screenspace_topleft(&txt, self.geom.top_left); } diff --git a/ezgui/src/widgets/slider.rs b/ezgui/src/widgets/slider.rs index 6fe43a0273..d5c8f2a504 100644 --- a/ezgui/src/widgets/slider.rs +++ b/ezgui/src/widgets/slider.rs @@ -99,7 +99,7 @@ impl Slider { false } - pub fn draw(&self, g: &mut GfxCtx) { + pub fn draw(&self, g: &mut GfxCtx, label: Option) { g.fork_screenspace(); // A nice background for the entire thing @@ -155,6 +155,16 @@ impl Slider { }, &self.slider_geom(), ); + + if let Some(ref txt) = label { + g.draw_text_at_screenspace_topleft( + txt, + ScreenPt::new( + self.top_left.x, + self.top_left.y + BAR_HEIGHT + 2.0 * VERT_PADDING, + ), + ); + } } fn slider_geom(&self) -> Polygon { @@ -174,8 +184,8 @@ pub struct ItemSlider { items: Vec<(T, Text)>, slider: Slider, menu: ModalMenu, - menu_title: String, + noun: String, prev: String, next: String, first: String, @@ -208,8 +218,8 @@ impl ItemSlider { items, slider: Slider::new(None), menu: ModalMenu::new(menu_title, choices, ctx), - menu_title: menu_title.to_string(), + noun: noun.to_string(), prev, next, first, @@ -219,19 +229,9 @@ impl ItemSlider { // Returns true if the value changed. pub fn event(&mut self, ctx: &mut EventCtx) -> bool { - let current = { - let idx = self.slider.get_value(self.items.len()); - let mut txt = Text::prompt(&self.menu_title); - txt.add_line(format!( - "{}/{}", - abstutil::prettyprint_usize(idx + 1), - abstutil::prettyprint_usize(self.items.len()) - )); - txt.extend(&self.items[idx].1); - self.menu.handle_event(ctx, Some(txt)); - idx - }; + self.menu.handle_event(ctx, None); + let current = self.slider.get_value(self.items.len()); if current != self.items.len() - 1 && self.menu.action(&self.next) { self.slider.set_value(ctx, current + 1, self.items.len()); } else if current != self.items.len() - 1 && self.menu.action(&self.last) { @@ -249,7 +249,16 @@ impl ItemSlider { pub fn draw(&self, g: &mut GfxCtx) { self.menu.draw(g); - self.slider.draw(g); + + let idx = self.slider.get_value(self.items.len()); + let mut txt = Text::from_line(format!( + "{} {}/{}", + self.noun, + abstutil::prettyprint_usize(idx + 1), + abstutil::prettyprint_usize(self.items.len()) + )); + txt.extend(&self.items[idx].1); + self.slider.draw(g, Some(txt)); } pub fn get(&self) -> (usize, &T) {