Vertically line up the header for layer panels.

This commit is contained in:
Dustin Carlino 2021-01-24 13:23:30 -08:00
parent 7d8c818eea
commit ab801b8ae1
10 changed files with 57 additions and 107 deletions

View File

@ -1,12 +1,12 @@
use geom::{ArrowCap, Distance, PolyLine};
use map_gui::tools::{ColorLegend, ColorNetwork};
use widgetry::{
Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line, Panel, StyledButtons,
Text, TextExt, VerticalAlignment, Widget,
Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line, Panel, Text,
VerticalAlignment, Widget,
};
use crate::app::App;
use crate::layer::{Layer, LayerOutcome};
use crate::layer::{header, Layer, LayerOutcome};
pub struct Elevation {
unzoomed: Drawable,
@ -88,11 +88,7 @@ impl Elevation {
colorer.unzoomed.append(batch);
let panel = Panel::new(Widget::col(vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
"Elevation change".draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]),
header(ctx, "Elevation change"),
Text::from_multiline(vec![
Line(format!("Steepest road: {:.0}% grade", max * 100.0)),
Line("Note: elevation data is currently wrong!").secondary(),

View File

@ -7,11 +7,11 @@ use map_model::osm::OsmID;
use map_model::BuildingID;
use widgetry::{
Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Panel, RewriteColor,
StyledButtons, TextExt, VerticalAlignment, Widget,
VerticalAlignment,
};
use crate::app::App;
use crate::layer::{Layer, LayerOutcome};
use crate::layer::{header, Layer, LayerOutcome};
/// A set of buildings that the player has starred, persisted as player data.
#[derive(Serialize, Deserialize)]
@ -85,13 +85,9 @@ impl ShowFavorites {
}
}
let panel = Panel::new(Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
"Your favorite buildings".draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]))
.aligned(HorizontalAlignment::Right, VerticalAlignment::Center)
.build(ctx);
let panel = Panel::new(header(ctx, "Your favorite buildings"))
.aligned(HorizontalAlignment::Right, VerticalAlignment::Center)
.build(ctx);
ShowFavorites {
panel,

View File

@ -5,12 +5,12 @@ use map_gui::ID;
use map_model::{AmenityType, LaneType, PathConstraints};
use sim::AgentType;
use widgetry::{
Color, Drawable, EventCtx, GfxCtx, HorizontalAlignment, Line, Panel, StyledButtons, Text,
TextExt, VerticalAlignment, Widget,
Color, Drawable, EventCtx, GfxCtx, HorizontalAlignment, Line, Panel, Text, TextExt,
VerticalAlignment, Widget,
};
use crate::app::App;
use crate::layer::{Layer, LayerOutcome};
use crate::layer::{header, Layer, LayerOutcome};
pub struct BikeNetwork {
panel: Panel,
@ -106,11 +106,7 @@ impl BikeNetwork {
}
let panel = Panel::new(Widget::col(vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
"Bike network".draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]),
header(ctx, "Bike network"),
Text::from_multiline(vec![
Line(format!("{} lanes", num_lanes)),
Line(format!(
@ -187,17 +183,9 @@ impl Static {
extra: Widget,
) -> Static {
let (unzoomed, zoomed, legend) = colorer.build(ctx);
let panel = Panel::new(Widget::col(vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
title.draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]),
extra,
legend,
]))
.aligned(HorizontalAlignment::Right, VerticalAlignment::Center)
.build(ctx);
let panel = Panel::new(Widget::col(vec![header(ctx, &title), extra, legend]))
.aligned(HorizontalAlignment::Right, VerticalAlignment::Center)
.build(ctx);
Static {
panel,
@ -417,11 +405,7 @@ impl CongestionCaps {
}
let panel = Panel::new(Widget::col(vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
"Congestion caps".draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]),
header(ctx, "Congestion caps"),
format!("{} roads have caps", prettyprint_usize(num_roads)).draw_text(ctx),
ColorLegend::gradient(ctx, &app.cs.good_to_bad_red, vec!["available", "full"]),
]))

View File

@ -258,3 +258,12 @@ impl State<App> for PickLayer {
self.panel.draw(g);
}
}
/// Creates the top row for any layer panel.
pub fn header(ctx: &mut EventCtx, name: &str) -> Widget {
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg").centered_vert(),
name.draw_text(ctx).centered_vert(),
ctx.style().btn_close_widget(ctx),
])
}

View File

@ -6,11 +6,11 @@ use map_gui::tools::{make_heatmap, HeatmapOptions};
use sim::PersonState;
use widgetry::{
Checkbox, Choice, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line,
Outcome, Panel, StyledButtons, Text, TextExt, VerticalAlignment, Widget,
Outcome, Panel, Text, TextExt, VerticalAlignment, Widget,
};
use crate::app::App;
use crate::layer::{Layer, LayerOutcome};
use crate::layer::{header, Layer, LayerOutcome};
// TODO Disable drawing unzoomed agents... or alternatively, implement this by asking Sim to
// return this kind of data instead!
@ -176,11 +176,7 @@ fn make_controls(ctx: &mut EventCtx, app: &App, opts: &Options, legend: Option<W
let pct = 100.0 / (model.count_total() as f64);
let mut col = vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
"Pandemic model".draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]),
header(ctx, "Pandemic model"),
Text::from_multiline(vec![
Line(format!(
"{} Sane ({:.1}%)",

View File

@ -10,11 +10,11 @@ use map_model::{
use sim::{ParkingSpot, Scenario, VehicleType};
use widgetry::{
Checkbox, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line, Outcome, Panel,
StyledButtons, Text, TextExt, VerticalAlignment, Widget,
Text, VerticalAlignment, Widget,
};
use crate::app::App;
use crate::layer::{Layer, LayerOutcome};
use crate::layer::{header, Layer, LayerOutcome};
pub struct Occupancy {
time: Time,
@ -111,11 +111,7 @@ impl Occupancy {
if app.primary.sim.infinite_parking() {
let panel = Panel::new(Widget::col(vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
"Parking occupancy".draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]),
header(ctx, "Parking occupancy"),
Text::from_multiline(vec![
Line(format!(
"{:.0}% of the population owns a car",
@ -209,11 +205,7 @@ impl Occupancy {
}
let panel = Panel::new(Widget::col(vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
"Parking occupancy".draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]),
header(ctx, "Parking occupancy"),
Text::from_multiline(vec![
Line(format!(
"{:.0}% of the population owns a car",
@ -368,11 +360,7 @@ impl Layer for Efficiency {
impl Efficiency {
pub fn new(ctx: &mut EventCtx, app: &App) -> Efficiency {
let panel = Panel::new(Widget::col(vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
"Parking efficiency".draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]),
header(ctx, "Parking efficiency"),
Text::from(Line("How far away are people parked? (minutes)").secondary())
.wrap_to_pct(ctx, 15)
.draw(ctx),

View File

@ -6,11 +6,11 @@ use map_gui::tools::{make_heatmap, HeatmapOptions};
use sim::PersonState;
use widgetry::{
Checkbox, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line, Outcome,
Panel, StyledButtons, VerticalAlignment, Widget,
Panel, VerticalAlignment, Widget,
};
use crate::app::App;
use crate::layer::{Layer, LayerOutcome};
use crate::layer::{header, Layer, LayerOutcome};
// TODO Disable drawing unzoomed agents... or alternatively, implement this by asking Sim to
// return this kind of data instead!
@ -146,11 +146,10 @@ fn make_controls(ctx: &mut EventCtx, app: &App, opts: &Options, legend: Option<W
let (total_ppl, ppl_in_bldg, ppl_off_map) = app.primary.sim.num_ppl();
let mut col = vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
Line(format!("Population: {}", prettyprint_usize(total_ppl))).draw(ctx),
ctx.style().btn_close_widget(ctx),
]),
header(
ctx,
&format!("Population: {}", prettyprint_usize(total_ppl)),
),
Widget::row(vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/home.svg"),

View File

@ -11,11 +11,11 @@ use map_model::{IntersectionID, Map, Traversable};
use sim::VehicleType;
use widgetry::{
Checkbox, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line, Outcome,
Panel, StyledButtons, Text, TextExt, VerticalAlignment, Widget,
Panel, Text, TextExt, VerticalAlignment, Widget,
};
use crate::app::App;
use crate::layer::{Layer, LayerOutcome};
use crate::layer::{header, Layer, LayerOutcome};
pub struct Backpressure {
time: Time,
@ -71,11 +71,7 @@ impl Backpressure {
}
let panel = Panel::new(Widget::col(vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
"Backpressure".draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]),
header(ctx, "Backpressure"),
Text::from(
Line("This counts all active trips passing through a road in the future")
.secondary(),
@ -198,11 +194,7 @@ impl Throughput {
let road_counter = stats.road_thruput.all_total_counts();
let intersection_counter = stats.intersection_thruput.all_total_counts();
let panel = Panel::new(Widget::col(vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
"Throughput".draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]),
header(ctx, "Throughput"),
Text::from(Line("This counts all people crossing since midnight").secondary())
.wrap_to_pct(ctx, 15)
.draw(ctx),
@ -331,11 +323,7 @@ impl CompareThroughput {
}
let panel = Panel::new(Widget::col(vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
"Relative Throughput".draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]),
header(ctx, "Relative Throughput"),
Checkbox::switch(ctx, "Compare before proposal", None, true),
scale.make_legend(ctx, vec!["less traffic", "same", "more"]),
]))
@ -419,11 +407,7 @@ impl TrafficJams {
}
let panel = Panel::new(Widget::col(vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
"Traffic jams".draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]),
header(ctx, "Traffic jams"),
Text::from(
Line("A jam starts when delay exceeds 5 mins, then spreads out").secondary(),
)
@ -571,11 +555,7 @@ impl Delay {
time: app.primary.sim.time(),
unzoomed: ctx.upload(unzoomed),
panel: Panel::new(Widget::col(vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
"Delay per agent (minutes)".draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]),
header(ctx, "Delay per agent (minutes)"),
ColorLegend::gradient(ctx, &app.cs.good_to_bad_red, vec!["0", "5", "10", "15+"]),
]))
.aligned(HorizontalAlignment::Right, VerticalAlignment::Center)

View File

@ -1,12 +1,12 @@
use map_gui::tools::ColorDiscrete;
use map_model::{PathConstraints, PathStep};
use widgetry::{
Checkbox, Drawable, EventCtx, GfxCtx, HorizontalAlignment, Outcome, Panel, StyledButtons,
TextExt, VerticalAlignment, Widget,
Checkbox, Drawable, EventCtx, GfxCtx, HorizontalAlignment, Outcome, Panel, VerticalAlignment,
Widget,
};
use crate::app::App;
use crate::layer::{Layer, LayerOutcome};
use crate::layer::{header, Layer, LayerOutcome};
pub struct TransitNetwork {
panel: Panel,
@ -115,11 +115,7 @@ impl TransitNetwork {
let (unzoomed, zoomed, legend) = colorer.build(ctx);
let panel = Panel::new(Widget::col(vec![
Widget::row(vec![
Widget::draw_svg(ctx, "system/assets/tools/layers.svg"),
"Transit network".draw_text(ctx),
ctx.style().btn_close_widget(ctx),
]),
header(ctx, "Transit network"),
Checkbox::switch(ctx, "show all routes", None, show_all_routes),
Checkbox::switch(ctx, "show buses", None, show_buses),
Checkbox::switch(ctx, "show trains", None, show_trains),

View File

@ -380,9 +380,12 @@ impl Widget {
.named(label)
}
/// Creates a row with the specified widgets. No margins or other layouting is applied.
pub fn custom_row(widgets: Vec<Widget>) -> Widget {
Widget::new(Box::new(Container::new(true, widgets)))
}
/// Creates a row with the specified widgets. Every member gets a default horizontal margin.
pub fn row(widgets: Vec<Widget>) -> Widget {
let mut new = Vec::new();
let len = widgets.len();
@ -397,9 +400,12 @@ impl Widget {
Widget::new(Box::new(Container::new(true, new)))
}
/// Creates a column with the specified widgets. No margins or other layouting is applied.
pub fn custom_col(widgets: Vec<Widget>) -> Widget {
Widget::new(Box::new(Container::new(false, widgets)))
}
/// Creates a column with the specified widgets. Every member gets a default vertical margin.
pub fn col(widgets: Vec<Widget>) -> Widget {
let mut new = Vec::new();
let len = widgets.len();