From da92518d62200caba6d1a357ca74a75742824729 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 30 Jan 2020 14:38:26 -0800 Subject: [PATCH] align all overlay panels above the minimap --- ezgui/src/canvas.rs | 2 + ezgui/src/managed.rs | 5 ++ game/src/common/colors.rs | 2 +- game/src/common/overlays.rs | 97 +++++++++++++++++++++---------------- game/src/sandbox/mod.rs | 2 +- game/src/tutorial.rs | 2 +- 6 files changed, 64 insertions(+), 46 deletions(-) diff --git a/ezgui/src/canvas.rs b/ezgui/src/canvas.rs index 84811abcca..262166c563 100644 --- a/ezgui/src/canvas.rs +++ b/ezgui/src/canvas.rs @@ -252,6 +252,7 @@ impl Canvas { // TODO Hack VerticalAlignment::BottomAboveOSD => self.window_height - dims.height - 40.0, VerticalAlignment::Percent(pct) => pct * self.window_height, + VerticalAlignment::TopAt(y) => y - dims.height, }; ScreenPt::new(x1, y1) } @@ -273,6 +274,7 @@ pub enum VerticalAlignment { Bottom, BottomAboveOSD, Percent(f64), + TopAt(f64), } #[derive(Serialize, Deserialize, Debug)] diff --git a/ezgui/src/managed.rs b/ezgui/src/managed.rs index 1282dbe015..fc009c32a1 100644 --- a/ezgui/src/managed.rs +++ b/ezgui/src/managed.rs @@ -815,6 +815,11 @@ impl Composite { pub fn center_of_panel(&self) -> ScreenPt { self.top_level.rect.center() } + + pub fn align_above(&mut self, ctx: &mut EventCtx, other: &Composite) { + self.vert = VerticalAlignment::TopAt(other.top_level.rect.y1); + self.recompute_layout(ctx); + } } impl CompositeBuilder { diff --git a/game/src/common/colors.rs b/game/src/common/colors.rs index 1d59f8d2b8..a2ee3dac0e 100644 --- a/game/src/common/colors.rs +++ b/game/src/common/colors.rs @@ -22,7 +22,7 @@ pub struct ColorerBuilder { pub struct Colorer { zoomed: Drawable, pub unzoomed: Drawable, - legend: Composite, + pub legend: Composite, } impl Colorer { diff --git a/game/src/common/overlays.rs b/game/src/common/overlays.rs index fc324e6a57..a44cc820a6 100644 --- a/game/src/common/overlays.rs +++ b/game/src/common/overlays.rs @@ -33,7 +33,7 @@ pub enum Overlays { impl Overlays { // Since Overlays is embedded in UI, we have to do this slight trick - pub fn update(ctx: &mut EventCtx, ui: &mut UI) -> Option { + pub fn update(ctx: &mut EventCtx, ui: &mut UI, minimap: &Composite) -> Option { let now = ui.primary.sim.time(); match ui.overlay { Overlays::ParkingAvailability(t, _) => { @@ -94,6 +94,7 @@ impl Overlays { | Overlays::IntersectionDelay(_, ref mut heatmap) | Overlays::CumulativeThroughput(_, ref mut heatmap) | Overlays::Edits(ref mut heatmap) => { + heatmap.legend.align_above(ctx, minimap); if heatmap.event(ctx) { ui.overlay = Overlays::Inactive; } else { @@ -101,61 +102,71 @@ impl Overlays { } } Overlays::BusRoute(_, _, ref mut c) => { + c.colorer.legend.align_above(ctx, minimap); if c.colorer.event(ctx) { ui.overlay = Overlays::Inactive; } else { ui.overlay = orig_overlay; } } - Overlays::BusPassengers(_, _, ref mut c) => match c.event(ctx, ui) { - Some(WrappedOutcome::Transition(t)) => { - ui.overlay = orig_overlay; - return Some(t); - } - Some(WrappedOutcome::Clicked(x)) => match x.as_ref() { - "X" => { - ui.overlay = Overlays::Inactive; - } - _ => unreachable!(), - }, - None => { - ui.overlay = orig_overlay; - } - }, - Overlays::IntersectionDemand(_, i, _, ref mut c) => match c.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { - "intersection demand" => { - let id = ID::Intersection(i); + Overlays::BusPassengers(_, _, ref mut c) => { + c.inner.align_above(ctx, minimap); + match c.event(ctx, ui) { + Some(WrappedOutcome::Transition(t)) => { ui.overlay = orig_overlay; - return Some(Transition::Push(Warping::new( - ctx, - id.canonical_point(&ui.primary).unwrap(), - Some(10.0), - Some(id.clone()), - &mut ui.primary, - ))); + return Some(t); } - "X" => { - ui.overlay = Overlays::Inactive; + Some(WrappedOutcome::Clicked(x)) => match x.as_ref() { + "X" => { + ui.overlay = Overlays::Inactive; + } + _ => unreachable!(), + }, + None => { + ui.overlay = orig_overlay; } - _ => unreachable!(), - }, - None => { - ui.overlay = orig_overlay; } - }, + } + Overlays::IntersectionDemand(_, i, _, ref mut c) => { + c.align_above(ctx, minimap); + match c.event(ctx) { + Some(Outcome::Clicked(x)) => match x.as_ref() { + "intersection demand" => { + let id = ID::Intersection(i); + ui.overlay = orig_overlay; + return Some(Transition::Push(Warping::new( + ctx, + id.canonical_point(&ui.primary).unwrap(), + Some(10.0), + Some(id.clone()), + &mut ui.primary, + ))); + } + "X" => { + ui.overlay = Overlays::Inactive; + } + _ => unreachable!(), + }, + None => { + ui.overlay = orig_overlay; + } + } + } Overlays::FinishedTripsHistogram(_, ref mut c) - | Overlays::BusDelaysOverTime(_, _, ref mut c) => match c.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { - "X" => { - ui.overlay = Overlays::Inactive; + | Overlays::BusDelaysOverTime(_, _, ref mut c) => { + c.align_above(ctx, minimap); + match c.event(ctx) { + Some(Outcome::Clicked(x)) => match x.as_ref() { + "X" => { + ui.overlay = Overlays::Inactive; + } + _ => unreachable!(), + }, + None => { + ui.overlay = orig_overlay; } - _ => unreachable!(), - }, - None => { - ui.overlay = orig_overlay; } - }, + } Overlays::Inactive => {} } diff --git a/game/src/sandbox/mod.rs b/game/src/sandbox/mod.rs index d4220e16f2..d7e54d156b 100644 --- a/game/src/sandbox/mod.rs +++ b/game/src/sandbox/mod.rs @@ -109,7 +109,7 @@ impl State for SandboxMode { if let Some(t) = self.common.event(ctx, ui, Some(&mut self.speed)) { return t; } - if let Some(t) = Overlays::update(ctx, ui) { + if let Some(t) = Overlays::update(ctx, ui, &self.minimap.composite) { return t; } match self.tool_panel.event(ctx, ui) { diff --git a/game/src/tutorial.rs b/game/src/tutorial.rs index 434aaa1ac1..62559e50d5 100644 --- a/game/src/tutorial.rs +++ b/game/src/tutorial.rs @@ -172,7 +172,7 @@ impl State for TutorialMode { if let Some(t) = m.event(ui, ctx) { return t; } - if let Some(t) = Overlays::update(ctx, ui) { + if let Some(t) = Overlays::update(ctx, ui, &m.composite) { return t; } }