better Checkbox::colored

This commit is contained in:
Dustin Carlino 2020-07-29 15:11:10 -07:00
parent 28c3d0ef8e
commit de45fb5c07
5 changed files with 54 additions and 69 deletions

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0V0z" fill="black"/><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z" fill="white"/></svg>

After

Width:  |  Height:  |  Size: 212 B

View File

@ -2,7 +2,6 @@ use crate::{
Btn, Button, Color, EventCtx, GeomBatch, GfxCtx, Line, MultiKey, RewriteColor, ScreenDims,
ScreenPt, Text, TextExt, TextSpan, Widget, WidgetImpl, WidgetOutput,
};
use geom::{Polygon, Pt2D, Ring};
pub struct Checkbox {
pub(crate) enabled: bool,
@ -115,48 +114,47 @@ impl Checkbox {
}
pub fn colored(ctx: &EventCtx, label: &str, color: Color, enabled: bool) -> Widget {
let vert_pad = 4.0;
let horiz_pad = 4.0;
// TODO What was I thinking...
let checkmark = Ring::must_new(vec![
Pt2D::new(11.4528, 22.1072),
Pt2D::new(5.89284, 16.5472),
Pt2D::new(3.99951, 18.4272),
Pt2D::new(11.4528, 25.8805),
Pt2D::new(27.4528, 9.88049),
Pt2D::new(25.5728, 8.00049),
Pt2D::new(11.4528, 22.1072),
let off = Widget::row(vec![
GeomBatch::screenspace_svg(ctx.prerender, "system/assets/tools/checkbox.svg")
.color(RewriteColor::ChangeAll(color.alpha(0.3)))
.batch()
.centered_vert(),
label.batch_text(ctx),
])
.to_polygon()
.translate(0.0, -4.0);
let bounds = checkmark.get_bounds();
let hitbox = Polygon::rectangle(
bounds.width() + 2.0 * horiz_pad,
bounds.height() + 2.0 * vert_pad,
);
.to_geom(ctx, None);
let on = Widget::row(vec![
GeomBatch::screenspace_svg(ctx.prerender, "system/assets/tools/checkbox.svg")
.color(RewriteColor::Change(Color::BLACK, color))
.batch()
.centered_vert(),
label.batch_text(ctx),
])
.to_geom(ctx, None);
// Dims should be the same for both
let hitbox = off.get_bounds().get_rectangle();
let true_btn = Btn::custom(
GeomBatch::from(vec![
(color, hitbox.clone()),
(Color::WHITE, checkmark.clone()),
]),
GeomBatch::from(vec![
(color, hitbox.clone()),
(ctx.style().hovering_color, checkmark),
]),
hitbox.clone(),
Checkbox::new(
enabled,
Btn::custom(
off.clone(),
off.color(RewriteColor::Change(
Color::WHITE,
ctx.style().hovering_color,
)),
hitbox.clone(),
)
.build(ctx, label, None),
Btn::custom(
on.clone(),
on.color(RewriteColor::Change(
Color::WHITE,
ctx.style().hovering_color,
)),
hitbox,
)
.build(ctx, label, None),
)
.build(ctx, format!("hide {}", label), None);
let false_btn = Btn::custom(
GeomBatch::from(vec![(color.alpha(0.3), hitbox.clone())]),
GeomBatch::from(vec![(color, hitbox.clone())]),
hitbox,
)
.build(ctx, format!("show {}", label), None);
Checkbox::new(enabled, false_btn, true_btn).named(label)
.named(label)
}
// TODO These should actually be radio buttons

View File

@ -322,10 +322,12 @@ pub fn make_legend<T: Yvalue<T>>(
}
seen.insert(s.label.clone());
if opts.filterable {
row.push(Widget::row(vec![
Checkbox::colored(ctx, &s.label, s.color, !opts.disabled.contains(&s.label)),
Line(&s.label).draw(ctx),
]));
row.push(Checkbox::colored(
ctx,
&s.label,
s.color,
!opts.disabled.contains(&s.label),
));
} else {
let radius = 15.0;
row.push(Widget::row(vec![

View File

@ -5,8 +5,7 @@ use crate::layer::PickLayer;
use abstutil::clamp;
use ezgui::{
hotkey, Btn, Checkbox, Color, Composite, EventCtx, Filler, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, Outcome, ScreenDims, ScreenPt, Spinner, VerticalAlignment,
Widget,
HorizontalAlignment, Key, Outcome, ScreenDims, ScreenPt, Spinner, VerticalAlignment, Widget,
};
use geom::{Distance, Polygon, Pt2D, Ring};
@ -431,14 +430,10 @@ fn make_horiz_viz_panel(ctx: &mut EventCtx, app: &App) -> Widget {
let a = &app.unzoomed_agents;
Widget::custom_row(vec![
Checkbox::colored(ctx, "Car", a.car_color, a.cars).margin_right(8),
Line("Car").draw(ctx).margin_right(8),
Widget::draw_svg(ctx, "system/assets/timeline/parking.svg").margin_right(24),
Checkbox::colored(ctx, "Bike", a.bike_color, a.bikes).margin_right(8),
Line("Bike").draw(ctx).margin_right(24),
Checkbox::colored(ctx, "Bus", a.bus_color, a.buses_and_trains).margin_right(8),
Line("Bus").draw(ctx).margin_right(24),
Checkbox::colored(ctx, "Bike", a.bike_color, a.bikes).margin_right(24),
Checkbox::colored(ctx, "Bus", a.bus_color, a.buses_and_trains).margin_right(24),
Checkbox::colored(ctx, "Pedestrian", a.ped_color, a.peds).margin_right(8),
Line("Pedestrian").draw(ctx),
])
}
@ -447,20 +442,10 @@ fn make_vert_viz_panel(ctx: &mut EventCtx, app: &App) -> Widget {
Widget::col(vec![
Widget::custom_row(vec![
Checkbox::colored(ctx, "Car", a.car_color, a.cars).margin_right(8),
Line("Car").draw(ctx).margin_right(8),
Widget::draw_svg(ctx, "system/assets/timeline/parking.svg").margin_right(24),
]),
Widget::custom_row(vec![
Checkbox::colored(ctx, "Bike", a.bike_color, a.bikes).margin_right(8),
Line("Bike").draw(ctx),
]),
Widget::custom_row(vec![
Checkbox::colored(ctx, "Bus", a.bus_color, a.buses_and_trains).margin_right(8),
Line("Bus").draw(ctx),
]),
Widget::custom_row(vec![
Checkbox::colored(ctx, "Pedestrian", a.ped_color, a.peds).margin_right(8),
Line("Pedestrian").draw(ctx),
Widget::draw_svg(ctx, "system/assets/timeline/parking.svg"),
]),
Checkbox::colored(ctx, "Bike", a.bike_color, a.bikes),
Checkbox::colored(ctx, "Bus", a.bus_color, a.buses_and_trains),
Checkbox::colored(ctx, "Pedestrian", a.ped_color, a.peds),
])
}

View File

@ -1,5 +1,5 @@
use crate::app::{App, PerMap};
use ezgui::{hotkey, Btn, Checkbox, Color, EventCtx, Key, Line, Text, TextExt, TextSpan, Widget};
use ezgui::{hotkey, Btn, Checkbox, Color, EventCtx, Key, Line, Text, TextSpan, Widget};
use geom::{Duration, Pt2D};
use map_model::{AreaID, BuildingID, BusStopID, IntersectionID, LaneID, Map, ParkingLotID, RoadID};
use sim::{AgentID, AgentType, CarID, PedestrianID, TripMode, TripPhaseType};
@ -274,9 +274,8 @@ pub fn checkbox_per_mode(
color_for_mode(app, m),
current_state.contains(&m),
)
.margin_right(5),
.margin_right(24),
);
filters.push(m.ongoing_verb().draw_text(ctx).margin_right(10));
}
Widget::custom_row(filters)
}