mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +03:00
Uniform heights for legend items
This commit is contained in:
parent
df242871b5
commit
f15a40efd9
@ -6,8 +6,7 @@ use map_model::osm::RoadRank;
|
|||||||
use map_model::LaneType;
|
use map_model::LaneType;
|
||||||
use widgetry::{
|
use widgetry::{
|
||||||
ButtonBuilder, Color, ControlState, Drawable, EdgeInsets, EventCtx, GeomBatch, GfxCtx,
|
ButtonBuilder, Color, ControlState, Drawable, EdgeInsets, EventCtx, GeomBatch, GfxCtx,
|
||||||
HorizontalAlignment, Image, Key, Line, Outcome, Panel, RewriteColor, Text, Toggle,
|
HorizontalAlignment, Image, Key, Line, Outcome, Panel, Text, Toggle, VerticalAlignment, Widget,
|
||||||
VerticalAlignment, Widget,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::app::{App, Transition};
|
use crate::app::{App, Transition};
|
||||||
@ -147,8 +146,10 @@ impl Layers {
|
|||||||
.categories
|
.categories
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(label, color)| {
|
.map(|(label, color)| {
|
||||||
legend_batch(ctx, *color, Text::from(Line(label).fg(Color::WHITE)))
|
legend_btn(*color, label)
|
||||||
.into_widget(ctx)
|
.label_color(Color::WHITE, ControlState::Default)
|
||||||
|
.disabled(true)
|
||||||
|
.build_def(ctx)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
legend.push(uphill_legend);
|
legend.push(uphill_legend);
|
||||||
@ -229,9 +230,9 @@ impl Layers {
|
|||||||
.centered_vert(),
|
.centered_vert(),
|
||||||
Widget::custom_row(vec![
|
Widget::custom_row(vec![
|
||||||
// TODO Looks too close to access restrictions
|
// TODO Looks too close to access restrictions
|
||||||
legend_item(ctx, app.cs.unzoomed_highway, "highway"),
|
legend_btn(app.cs.unzoomed_highway, "highway").build_def(ctx),
|
||||||
legend_item(ctx, app.cs.unzoomed_arterial, "major street"),
|
legend_btn(app.cs.unzoomed_arterial, "major street").build_def(ctx),
|
||||||
legend_item(ctx, app.cs.unzoomed_residential, "minor street"),
|
legend_btn(app.cs.unzoomed_residential, "minor street").build_def(ctx),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
Widget::custom_row({
|
Widget::custom_row({
|
||||||
@ -242,18 +243,16 @@ impl Layers {
|
|||||||
self.bike_network.is_some(),
|
self.bike_network.is_some(),
|
||||||
)];
|
)];
|
||||||
if self.bike_network.is_some() {
|
if self.bike_network.is_some() {
|
||||||
row.push(legend_item(ctx, *bike_network::DEDICATED_TRAIL, "trail"));
|
row.push(legend_btn(*bike_network::DEDICATED_TRAIL, "trail").build_def(ctx));
|
||||||
row.push(legend_item(
|
row.push(
|
||||||
ctx,
|
legend_btn(*bike_network::PROTECTED_BIKE_LANE, "protected bike lane")
|
||||||
*bike_network::PROTECTED_BIKE_LANE,
|
.build_def(ctx),
|
||||||
"protected bike lane",
|
);
|
||||||
));
|
row.push(
|
||||||
row.push(legend_item(
|
legend_btn(*bike_network::PAINTED_BIKE_LANE, "painted bike lane")
|
||||||
ctx,
|
.build_def(ctx),
|
||||||
*bike_network::PAINTED_BIKE_LANE,
|
);
|
||||||
"painted bike lane",
|
row.push(legend_btn(*bike_network::GREENWAY, "greenway").build_def(ctx));
|
||||||
));
|
|
||||||
row.push(legend_item(ctx, *bike_network::GREENWAY, "greenway"));
|
|
||||||
}
|
}
|
||||||
row
|
row
|
||||||
}),
|
}),
|
||||||
@ -363,33 +362,18 @@ fn make_zoom_controls(ctx: &mut EventCtx) -> Widget {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn legend_batch(ctx: &mut EventCtx, color: Color, txt: Text) -> GeomBatch {
|
fn legend_btn(color: Color, label: &str) -> ButtonBuilder {
|
||||||
// TODO Height of the "trail" button is slightly too low!
|
ButtonBuilder::new()
|
||||||
// Text with padding and a background color
|
.label_text(label)
|
||||||
let (mut batch, hitbox) = txt
|
.bg_color(color, ControlState::Default)
|
||||||
.render(ctx)
|
.bg_color(color.alpha(0.6), ControlState::Hovered)
|
||||||
.batch()
|
|
||||||
.container()
|
|
||||||
.padding(EdgeInsets {
|
.padding(EdgeInsets {
|
||||||
top: 10.0,
|
top: 10.0,
|
||||||
bottom: 10.0,
|
bottom: 10.0,
|
||||||
left: 20.0,
|
left: 20.0,
|
||||||
right: 20.0,
|
right: 20.0,
|
||||||
})
|
})
|
||||||
.into_geom(ctx, None);
|
.corner_rounding(0.0)
|
||||||
batch.unshift(color, hitbox);
|
|
||||||
batch
|
|
||||||
}
|
|
||||||
|
|
||||||
fn legend_item(ctx: &mut EventCtx, color: Color, label: &str) -> Widget {
|
|
||||||
let batch = legend_batch(ctx, color, Text::from(Line(label)));
|
|
||||||
return ButtonBuilder::new()
|
|
||||||
.custom_batch(batch.clone(), ControlState::Default)
|
|
||||||
.custom_batch(
|
|
||||||
batch.color(RewriteColor::Change(color, color.alpha(0.6))),
|
|
||||||
ControlState::Hovered,
|
|
||||||
)
|
|
||||||
.build_widget(ctx, label);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn zoom_enabled_cache_key(ctx: &EventCtx) -> (bool, bool) {
|
fn zoom_enabled_cache_key(ctx: &EventCtx) -> (bool, bool) {
|
||||||
|
Loading…
Reference in New Issue
Block a user