align all overlay panels above the minimap

This commit is contained in:
Dustin Carlino 2020-01-30 14:38:26 -08:00
parent e96fa0f96f
commit da92518d62
6 changed files with 64 additions and 46 deletions

View File

@ -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)]

View File

@ -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 {

View File

@ -22,7 +22,7 @@ pub struct ColorerBuilder {
pub struct Colorer {
zoomed: Drawable,
pub unzoomed: Drawable,
legend: Composite,
pub legend: Composite,
}
impl Colorer {

View File

@ -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<Transition> {
pub fn update(ctx: &mut EventCtx, ui: &mut UI, minimap: &Composite) -> Option<Transition> {
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 => {}
}

View File

@ -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) {

View File

@ -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;
}
}