diff --git a/data/system/assets/tools/checkbox.svg b/data/system/assets/tools/checkbox.svg new file mode 100644 index 0000000000..6ebd0733f2 --- /dev/null +++ b/data/system/assets/tools/checkbox.svg @@ -0,0 +1 @@ + diff --git a/ezgui/src/widgets/checkbox.rs b/ezgui/src/widgets/checkbox.rs index 6d88658807..5fbd174479 100644 --- a/ezgui/src/widgets/checkbox.rs +++ b/ezgui/src/widgets/checkbox.rs @@ -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 diff --git a/ezgui/src/widgets/line_plot.rs b/ezgui/src/widgets/line_plot.rs index a0f28d8708..c8a8f9207a 100644 --- a/ezgui/src/widgets/line_plot.rs +++ b/ezgui/src/widgets/line_plot.rs @@ -322,10 +322,12 @@ pub fn make_legend>( } 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![ diff --git a/game/src/common/minimap.rs b/game/src/common/minimap.rs index 4841d0259a..31ce173a19 100644 --- a/game/src/common/minimap.rs +++ b/game/src/common/minimap.rs @@ -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), ]) } diff --git a/game/src/helpers.rs b/game/src/helpers.rs index 2840468df4..968efabbb2 100644 --- a/game/src/helpers.rs +++ b/game/src/helpers.rs @@ -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) }