overlays: include layer icon, adjust padding, try a horizontal scale for

pop map, smaller text, better "X" buttons
This commit is contained in:
Dustin Carlino 2020-04-04 16:35:53 -07:00
parent d995a494dd
commit 2c38a945e9
4 changed files with 66 additions and 43 deletions

View File

@ -2,9 +2,9 @@ use crate::app::App;
use crate::render::MIN_ZOOM_FOR_DETAIL;
use ezgui::{
Btn, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Outcome,
Text, VerticalAlignment, Widget,
Text, TextExt, VerticalAlignment, Widget,
};
use geom::{Circle, Distance, Pt2D};
use geom::{Circle, Distance, Polygon, Pt2D};
use map_model::{BuildingID, BusStopID, IntersectionID, LaneID, Map, RoadID};
use std::collections::HashMap;
@ -137,13 +137,14 @@ impl ColorerBuilder {
// Build the legend
let mut col = vec![Widget::row(vec![
self.header.draw(ctx),
Btn::text_fg("X").build_def(ctx, None).align_right(),
Widget::draw_svg(ctx, "../data/system/assets/tools/layers.svg").margin_right(10),
self.header.draw(ctx).margin_right(5),
Btn::plaintext("X").build_def(ctx, None).align_right(),
])];
for (label, color) in self.prioritized_colors {
col.push(ColorLegend::row(ctx, color, label));
}
let legend = Composite::new(Widget::col(col).bg(app.cs.panel_bg))
let legend = Composite::new(Widget::col(col).bg(app.cs.panel_bg).padding(16))
.aligned(HorizontalAlignment::Right, VerticalAlignment::Center)
.build(ctx);
@ -188,4 +189,20 @@ impl ColorLegend {
txt.draw(ctx),
])
}
pub fn scale(ctx: &mut EventCtx, entries: Vec<(Color, String)>) -> Widget {
let mut batch = GeomBatch::new();
let mut labels = Vec::new();
for (color, lbl) in entries {
batch.push(
color,
Polygon::rectangle(64.0, 32.0).translate(64.0 * (labels.len() as f64), 0.0),
);
labels.push(lbl.draw_text(ctx));
}
Widget::col(vec![
Widget::draw_batch(ctx, batch),
Widget::row(labels).evenly_spaced(),
])
}
}

View File

@ -127,7 +127,8 @@ pub fn make_heatmap(
}
batch.push(
color,
// Don't block the map underneath
color.alpha(0.6),
square.translate((x * opts.resolution) as f64, (y * opts.resolution) as f64),
);
}

View File

@ -341,11 +341,7 @@ fn make_tool_panel(ctx: &mut EventCtx, app: &App) -> Widget {
.margin_below(16),
Btn::svg_def("../data/system/assets/tools/layers.svg")
.build(ctx, "change overlay", hotkey(Key::L))
.bg(if app.overlay.is_empty() {
app.cs.inner_panel
} else {
app.cs.hovering
})
.bg(app.cs.inner_panel)
.margin_below(16),
Btn::svg_def("../data/system/assets/tools/search.svg")
.build(ctx, "search", hotkey(Key::K))

View File

@ -384,14 +384,20 @@ impl Overlays {
fn parking_availability(ctx: &mut EventCtx, app: &App) -> Overlays {
let (filled_spots, avail_spots) = app.primary.sim.get_all_parking_spots();
let mut txt = Text::from(Line("parking availability"));
txt.add(Line(format!(
"{} spots filled",
prettyprint_usize(filled_spots.len())
)));
txt.add(Line(format!(
"{} spots available ",
prettyprint_usize(avail_spots.len())
)));
txt.add(
Line(format!(
"{} spots filled",
prettyprint_usize(filled_spots.len())
))
.small(),
);
txt.add(
Line(format!(
"{} spots available ",
prettyprint_usize(avail_spots.len())
))
.small(),
);
let awful = Color::hex("#801F1C");
let bad = Color::hex("#EB5757");
@ -616,7 +622,7 @@ impl Overlays {
max = max.max(pct);
}
let mut txt = Text::from(Line("elevation change"));
txt.add(Line(format!("Steepest road: {:.0}%", max * 100.0)));
txt.add(Line(format!("Steepest road: {:.0}%", max * 100.0)).small());
let awful = Color::hex("#801F1C");
let bad = Color::hex("#EB5757");
@ -787,18 +793,15 @@ impl Overlays {
let edits = app.primary.map.get_edits();
let mut txt = Text::from(Line(format!("map edits ({})", edits.edits_name)));
txt.add(Line(format!(
"{} lane types changed",
edits.original_lts.len()
)));
txt.add(Line(format!(
"{} lanes reversed",
edits.reversed_lanes.len()
)));
txt.add(Line(format!(
"{} intersections changed",
edits.original_intersections.len()
)));
txt.add(Line(format!("{} lane types changed", edits.original_lts.len())).small());
txt.add(Line(format!("{} lanes reversed", edits.reversed_lanes.len())).small());
txt.add(
Line(format!(
"{} intersections changed",
edits.original_intersections.len()
))
.small(),
);
let changed = Color::CYAN;
let mut colorer = Colorer::new(txt, vec![("modified lane/intersection", changed)]);
@ -917,18 +920,20 @@ fn population_controls(
let mut col = vec![
Widget::row(vec![
// TODO Only bold the first part
Line(format!("Population: {}", prettyprint_usize(total_ppl)))
.small_heading()
.draw(ctx),
Btn::text_fg("X")
Widget::draw_svg(ctx, "../data/system/assets/tools/layers.svg").margin_right(10),
Line(format!("Population: {}", prettyprint_usize(total_ppl))).draw(ctx),
Btn::plaintext("X")
.build(ctx, "close", hotkey(Key::Escape))
.align_right(),
]),
Widget::row(vec![
Widget::draw_svg(ctx, "../data/system/assets/tools/home.svg"),
prettyprint_usize(ppl_in_bldg).draw_text(ctx),
format!("Off-map: {}", prettyprint_usize(ppl_off_map)).draw_text(ctx),
Widget::row(vec![
Widget::draw_svg(ctx, "../data/system/assets/tools/home.svg"),
Line(prettyprint_usize(ppl_in_bldg)).small().draw(ctx),
]),
Line(format!("Off-map: {}", prettyprint_usize(ppl_off_map)))
.small()
.draw(ctx),
])
.centered(),
if app.primary.sim.get_pandemic_model().is_some() {
@ -979,9 +984,13 @@ fn population_controls(
]));
// Legend for the heatmap colors
for (max, color) in max_per_color {
col.push(ColorLegend::row(ctx, color, format!("<= {}", max)));
}
col.push(ColorLegend::scale(
ctx,
max_per_color
.into_iter()
.map(|(max, c)| (c, max.to_string()))
.collect(),
));
}
Composite::new(Widget::col(col).padding(5).bg(app.cs.panel_bg))