From d774aeae440400c131892aff5dd476183a5b695a Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 24 Feb 2021 10:29:47 -0800 Subject: [PATCH] rename toggle/checkbox --- fifteen_min/src/find_home.rs | 6 ++--- fifteen_min/src/viewer.rs | 10 ++++---- game/src/common/mod.rs | 7 +++--- game/src/debug/mod.rs | 16 ++++++------- game/src/devtools/collisions.rs | 6 ++--- game/src/devtools/destinations.rs | 6 ++--- game/src/edit/traffic_signals/edits.rs | 6 ++--- game/src/info/intersection.rs | 6 ++--- game/src/info/mod.rs | 10 ++++---- game/src/layer/pandemic.rs | 6 ++--- game/src/layer/parking.rs | 14 +++++------ game/src/layer/population.rs | 6 ++--- game/src/layer/traffic.rs | 10 ++++---- game/src/layer/transit.rs | 8 +++---- game/src/sandbox/dashboards/commuter.rs | 9 ++++--- .../sandbox/dashboards/parking_overhead.rs | 6 ++--- game/src/sandbox/dashboards/summaries.rs | 6 ++--- game/src/sandbox/dashboards/trip_table.rs | 18 +++++++------- game/src/sandbox/time_warp.rs | 8 +++---- game/src/sandbox/uber_turns.rs | 6 ++--- map_editor/src/main.rs | 6 ++--- map_gui/src/options.rs | 18 +++++++------- map_gui/src/render/agents.rs | 19 ++++++++------- map_gui/src/tools/heatmap.rs | 6 ++--- map_gui/src/tools/updater.rs | 4 ++-- osm_viewer/src/viewer.rs | 8 +++---- parking_mapper/src/mapper.rs | 6 ++--- santa/src/music.rs | 5 ++-- widgetry/src/lib.rs | 4 ++-- widgetry/src/widgets/line_plot.rs | 6 ++--- widgetry/src/widgets/mod.rs | 10 ++++---- widgetry/src/widgets/panel.rs | 8 +++---- .../src/widgets/{checkbox.rs => toggle.rs} | 24 +++++++++---------- widgetry_demo/src/lib.rs | 16 ++++++------- 34 files changed, 154 insertions(+), 156 deletions(-) rename widgetry/src/widgets/{checkbox.rs => toggle.rs} (94%) diff --git a/fifteen_min/src/find_home.rs b/fifteen_min/src/find_home.rs index 02a46a7097..42dc23bfd0 100644 --- a/fifteen_min/src/find_home.rs +++ b/fifteen_min/src/find_home.rs @@ -5,8 +5,8 @@ use geom::Percent; use map_gui::tools::PopupMsg; use map_model::{AmenityType, BuildingID}; use widgetry::{ - Checkbox, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Panel, - SimpleState, State, StyledButtons, TextExt, Transition, VerticalAlignment, Widget, + Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Panel, + SimpleState, State, StyledButtons, TextExt, Toggle, Transition, VerticalAlignment, Widget, }; use crate::isochrone::Options; @@ -30,7 +30,7 @@ impl FindHome { Widget::custom_row( AmenityType::all() .into_iter() - .map(|at| Checkbox::switch(ctx, &at.to_string(), None, false)) + .map(|at| Toggle::switch(ctx, &at.to_string(), None, false)) .collect(), ) .flex_wrap(ctx, Percent::int(50)), diff --git a/fifteen_min/src/viewer.rs b/fifteen_min/src/viewer.rs index 8da8083f47..25cbbedeb7 100644 --- a/fifteen_min/src/viewer.rs +++ b/fifteen_min/src/viewer.rs @@ -12,9 +12,9 @@ use map_model::connectivity::WalkingOptions; use map_model::{AmenityType, Building, BuildingID, LaneType}; use widgetry::table::{Col, Filter, Table}; use widgetry::{ - lctrl, Cached, Checkbox, Choice, Color, Drawable, EventCtx, GeomBatch, GfxCtx, - HorizontalAlignment, Key, Line, Outcome, Panel, RewriteColor, State, StyledButtons, Text, - Transition, VerticalAlignment, Widget, + lctrl, Cached, Choice, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, + Line, Outcome, Panel, RewriteColor, State, StyledButtons, Text, Toggle, Transition, + VerticalAlignment, Widget, }; use crate::find_home::FindHome; @@ -201,7 +201,7 @@ impl State for Viewer { } fn options_to_controls(ctx: &mut EventCtx, opts: &Options) -> Widget { - let mut rows = vec![Checkbox::toggle( + let mut rows = vec![Toggle::choice( ctx, "walking / biking", "walking", @@ -214,7 +214,7 @@ fn options_to_controls(ctx: &mut EventCtx, opts: &Options) -> Widget { )]; match opts { Options::Walking(ref opts) => { - rows.push(Checkbox::switch( + rows.push(Toggle::switch( ctx, "Allow walking on the shoulder of the road without a sidewalk", None, diff --git a/game/src/common/mod.rs b/game/src/common/mod.rs index c61c3b4fdc..ba7af96a78 100644 --- a/game/src/common/mod.rs +++ b/game/src/common/mod.rs @@ -7,9 +7,8 @@ use map_gui::ID; use map_model::{IntersectionID, Map, RoadID}; use sim::{AgentType, TripMode, TripPhaseType}; use widgetry::{ - lctrl, Checkbox, Color, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Panel, - ScreenDims, ScreenPt, ScreenRectangle, StyledButtons, Text, TextSpan, VerticalAlignment, - Widget, + lctrl, Color, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Panel, ScreenDims, + ScreenPt, ScreenRectangle, StyledButtons, Text, TextSpan, Toggle, VerticalAlignment, Widget, }; pub use self::minimap::MinimapController; @@ -397,7 +396,7 @@ pub fn checkbox_per_mode( let mut filters = Vec::new(); for m in TripMode::all() { filters.push( - Checkbox::colored( + Toggle::colored_checkbox( ctx, m.ongoing_verb(), color_for_mode(app, m), diff --git a/game/src/debug/mod.rs b/game/src/debug/mod.rs index f8b9ee1632..ec85cbf6ec 100644 --- a/game/src/debug/mod.rs +++ b/game/src/debug/mod.rs @@ -14,8 +14,8 @@ use map_model::{ }; use sim::{Sim, TripEndpoint}; use widgetry::{ - lctrl, Cached, Checkbox, Choice, Color, DrawBaselayer, Drawable, EventCtx, GeomBatch, GfxCtx, - HorizontalAlignment, Key, Line, Outcome, Panel, ScreenDims, State, StyledButtons, Text, + lctrl, Cached, Choice, Color, DrawBaselayer, Drawable, EventCtx, GeomBatch, GfxCtx, + HorizontalAlignment, Key, Line, Outcome, Panel, ScreenDims, State, StyledButtons, Text, Toggle, UpdateType, VerticalAlignment, Widget, }; @@ -55,12 +55,12 @@ impl DebugMode { ctx.style().btn_close_widget(ctx), ]), Text::new().draw(ctx).named("current info"), - Checkbox::switch(ctx, "show buildings", Key::Num1, true), - Checkbox::switch(ctx, "show intersections", Key::Num2, true), - Checkbox::switch(ctx, "show lanes", Key::Num3, true), - Checkbox::switch(ctx, "show areas", Key::Num4, true), - Checkbox::switch(ctx, "show labels", Key::Num5, false), - Checkbox::switch(ctx, "show route for all agents", lctrl(Key::R), false), + Toggle::switch(ctx, "show buildings", Key::Num1, true), + Toggle::switch(ctx, "show intersections", Key::Num2, true), + Toggle::switch(ctx, "show lanes", Key::Num3, true), + Toggle::switch(ctx, "show areas", Key::Num4, true), + Toggle::switch(ctx, "show labels", Key::Num5, false), + Toggle::switch(ctx, "show route for all agents", lctrl(Key::R), false), Widget::col(vec![ ctx.style() .btn_outline_text("unhide everything") diff --git a/game/src/devtools/collisions.rs b/game/src/devtools/collisions.rs index 011ab954f0..5d488638b4 100644 --- a/game/src/devtools/collisions.rs +++ b/game/src/devtools/collisions.rs @@ -4,8 +4,8 @@ use geom::{Circle, Distance, Duration, FindClosest, Polygon, Time}; use map_gui::tools::ColorNetwork; use map_gui::ID; use widgetry::{ - Checkbox, Choice, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line, - Outcome, Panel, Slider, State, StyledButtons, Text, TextExt, VerticalAlignment, Widget, + Choice, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line, Outcome, + Panel, Slider, State, StyledButtons, Text, TextExt, Toggle, VerticalAlignment, Widget, }; use crate::app::{App, Transition}; @@ -88,7 +88,7 @@ impl Filters { fn to_controls(ctx: &mut EventCtx) -> Widget { Widget::col(vec![ - Checkbox::toggle( + Toggle::choice( ctx, "individual / aggregated", "individual", diff --git a/game/src/devtools/destinations.rs b/game/src/devtools/destinations.rs index 28c4c35ad5..3567f0c35a 100644 --- a/game/src/devtools/destinations.rs +++ b/game/src/devtools/destinations.rs @@ -4,8 +4,8 @@ use map_gui::ID; use map_model::{AmenityType, BuildingID}; use sim::{Scenario, TripEndpoint}; use widgetry::{ - Checkbox, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line, Outcome, - Panel, State, StyledButtons, Text, VerticalAlignment, Widget, + Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line, Outcome, Panel, State, + StyledButtons, Text, Toggle, VerticalAlignment, Widget, }; use crate::app::{App, Transition}; @@ -97,7 +97,7 @@ impl PopularDestinations { Line("Most popular destinations").small_heading().draw(ctx), ctx.style().btn_close_widget(ctx), ]), - Checkbox::switch(ctx, "Show heatmap", None, opts.is_some()), + Toggle::switch(ctx, "Show heatmap", None, opts.is_some()), controls, breakdown.draw(ctx), ])) diff --git a/game/src/edit/traffic_signals/edits.rs b/game/src/edit/traffic_signals/edits.rs index 9b6f89914d..52b1e5c5b7 100644 --- a/game/src/edit/traffic_signals/edits.rs +++ b/game/src/edit/traffic_signals/edits.rs @@ -4,8 +4,8 @@ use map_model::{ ControlStopSign, ControlTrafficSignal, EditCmd, EditIntersection, IntersectionID, StageType, }; use widgetry::{ - Checkbox, Choice, DrawBaselayer, EventCtx, Key, Line, Panel, SimpleState, Spinner, State, - StyledButtons, TextExt, Widget, + Choice, DrawBaselayer, EventCtx, Key, Line, Panel, SimpleState, Spinner, State, StyledButtons, + TextExt, Toggle, Widget, }; use crate::app::{App, Transition}; @@ -47,7 +47,7 @@ impl ChangeDuration { ]), Widget::row(vec![ "Type:".draw_text(ctx), - Checkbox::toggle( + Toggle::choice( ctx, "stage type", "fixed", diff --git a/game/src/info/intersection.rs b/game/src/info/intersection.rs index 6da76d1a2b..e3e441efe6 100644 --- a/game/src/info/intersection.rs +++ b/game/src/info/intersection.rs @@ -7,8 +7,8 @@ use map_gui::render::traffic_signal::draw_signal_stage; use map_model::{IntersectionID, IntersectionType, StageType}; use sim::AgentType; use widgetry::{ - Checkbox, Color, DrawWithTooltips, EventCtx, FanChart, GeomBatch, Line, PlotOptions, - ScatterPlot, Series, StyledButtons, Text, Widget, + Color, DrawWithTooltips, EventCtx, FanChart, GeomBatch, Line, PlotOptions, ScatterPlot, Series, + StyledButtons, Text, Toggle, Widget, }; use crate::app::App; @@ -117,7 +117,7 @@ pub fn delay( assert!(i.is_traffic_signal()); rows.push(opts.to_controls(ctx, app)); - rows.push(Checkbox::toggle( + rows.push(Toggle::choice( ctx, "fan chart / scatter plot", "fan chart", diff --git a/game/src/info/mod.rs b/game/src/info/mod.rs index 90d815a7d5..b936bb0cd8 100644 --- a/game/src/info/mod.rs +++ b/game/src/info/mod.rs @@ -11,9 +11,9 @@ use sim::{ VehicleType, }; use widgetry::{ - Checkbox, Color, ControlState, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, - Line, LinePlot, Outcome, Panel, PlotOptions, Series, StyledButtons, TextExt, VerticalAlignment, - Widget, + Color, ControlState, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, + LinePlot, Outcome, Panel, PlotOptions, Series, StyledButtons, TextExt, Toggle, + VerticalAlignment, Widget, }; use crate::app::{App, Transition}; @@ -765,7 +765,7 @@ impl DataOptions { return Widget::nothing(); } Widget::row(vec![ - Checkbox::custom_checkbox( + Toggle::custom_checkbox( ctx, "Show before changes", vec![ @@ -776,7 +776,7 @@ impl DataOptions { self.show_before, ), if self.show_before { - Checkbox::switch(ctx, "Show full day", None, self.show_end_of_day) + Toggle::switch(ctx, "Show full day", None, self.show_end_of_day) } else { Widget::nothing() }, diff --git a/game/src/layer/pandemic.rs b/game/src/layer/pandemic.rs index 18f1d77a9c..a77230053f 100644 --- a/game/src/layer/pandemic.rs +++ b/game/src/layer/pandemic.rs @@ -5,8 +5,8 @@ use geom::{Circle, Distance, Pt2D, Time}; use map_gui::tools::{make_heatmap, HeatmapOptions}; use sim::PersonState; use widgetry::{ - Checkbox, Choice, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line, - Outcome, Panel, Text, TextExt, VerticalAlignment, Widget, + Choice, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line, Outcome, + Panel, Text, TextExt, Toggle, VerticalAlignment, Widget, }; use crate::app::App; @@ -223,7 +223,7 @@ fn make_controls(ctx: &mut EventCtx, app: &App, opts: &Options, legend: Option Panel { Line("Commute map by block").small_heading().draw(ctx), ctx.style().btn_close_widget(ctx), ]), - Checkbox::toggle(ctx, "from / to this block", "from", "to", Key::Space, true), - Checkbox::switch(ctx, "include borders", None, true), + Toggle::choice(ctx, "from / to this block", "from", "to", Key::Space, true), + Toggle::switch(ctx, "include borders", None, true), Widget::row(vec![ "Departing from:".draw_text(ctx).margin_right(20), Slider::area(ctx, 0.15 * ctx.canvas.window_width, 0.0).named("depart from"), diff --git a/game/src/sandbox/dashboards/parking_overhead.rs b/game/src/sandbox/dashboards/parking_overhead.rs index daa7ee18ec..1f10d6a371 100644 --- a/game/src/sandbox/dashboards/parking_overhead.rs +++ b/game/src/sandbox/dashboards/parking_overhead.rs @@ -1,7 +1,7 @@ use geom::Duration; use sim::{TripEndpoint, TripID, TripPhaseType}; use widgetry::table::{Col, Filter, Table}; -use widgetry::{Checkbox, EventCtx, Filler, Line, Panel, State, Text, Widget}; +use widgetry::{EventCtx, Filler, Line, Panel, State, Text, Toggle, Widget}; use crate::app::App; use crate::sandbox::dashboards::generic_trip_table::GenericTripTable; @@ -100,8 +100,8 @@ fn make_table(app: &App) -> Table { }, to_controls: Box::new(move |ctx, _, state| { Widget::row(vec![ - Checkbox::switch(ctx, "starting off-map", None, state.starts_off_map), - Checkbox::switch(ctx, "ending off-map", None, state.ends_off_map), + Toggle::switch(ctx, "starting off-map", None, state.starts_off_map), + Toggle::switch(ctx, "ending off-map", None, state.ends_off_map), ]) }), from_controls: Box::new(|panel| Filters { diff --git a/game/src/sandbox/dashboards/summaries.rs b/game/src/sandbox/dashboards/summaries.rs index e08ca8830d..f159065ce2 100644 --- a/game/src/sandbox/dashboards/summaries.rs +++ b/game/src/sandbox/dashboards/summaries.rs @@ -9,8 +9,8 @@ use geom::{Distance, Duration, Polygon, Pt2D}; use map_gui::tools::PopupMsg; use sim::TripMode; use widgetry::{ - Checkbox, Choice, Color, CompareTimes, DrawBaselayer, DrawWithTooltips, EventCtx, GeomBatch, - GfxCtx, Line, Outcome, Panel, State, StyledButtons, Text, TextExt, Widget, + Choice, Color, CompareTimes, DrawBaselayer, DrawWithTooltips, EventCtx, GeomBatch, GfxCtx, + Line, Outcome, Panel, State, StyledButtons, Text, TextExt, Toggle, Widget, }; use crate::app::{App, Transition}; @@ -25,7 +25,7 @@ impl TripSummaries { pub fn new(ctx: &mut EventCtx, app: &App, filter: Filter) -> Box> { let mut filters = vec!["Filters".draw_text(ctx)]; for mode in TripMode::all() { - filters.push(Checkbox::colored( + filters.push(Toggle::colored_checkbox( ctx, mode.ongoing_verb(), color_for_mode(app, mode), diff --git a/game/src/sandbox/dashboards/trip_table.rs b/game/src/sandbox/dashboards/trip_table.rs index 51ee836da6..2faa83eab6 100644 --- a/game/src/sandbox/dashboards/trip_table.rs +++ b/game/src/sandbox/dashboards/trip_table.rs @@ -5,7 +5,7 @@ use geom::{Duration, Time}; use sim::{TripEndpoint, TripID, TripMode}; use widgetry::table::{Col, Filter, Table}; use widgetry::{ - Checkbox, ControlState, EventCtx, Filler, Line, Panel, State, StyledButtons, Text, Widget, + ControlState, EventCtx, Filler, Line, Panel, State, StyledButtons, Text, Toggle, Widget, }; use crate::app::App; @@ -190,10 +190,10 @@ fn make_table_finished_trips(app: &App) -> Table { Widget::col(vec![ checkbox_per_mode(ctx, app, &state.modes), Widget::row(vec![ - Checkbox::switch(ctx, "starting off-map", None, state.off_map_starts), - Checkbox::switch(ctx, "ending off-map", None, state.off_map_ends), + Toggle::switch(ctx, "starting off-map", None, state.off_map_starts), + Toggle::switch(ctx, "ending off-map", None, state.off_map_ends), if app.primary.has_modified_trips { - Checkbox::switch( + Toggle::switch( ctx, "trips unmodified by experiment", None, @@ -203,7 +203,7 @@ fn make_table_finished_trips(app: &App) -> Table { Widget::nothing() }, if app.primary.has_modified_trips { - Checkbox::switch( + Toggle::switch( ctx, "trips modified by experiment", None, @@ -213,7 +213,7 @@ fn make_table_finished_trips(app: &App) -> Table { Widget::nothing() }, if any_congestion_caps { - Checkbox::switch( + Toggle::switch( ctx, "trips not affected by congestion caps", None, @@ -223,7 +223,7 @@ fn make_table_finished_trips(app: &App) -> Table { Widget::nothing() }, if any_congestion_caps { - Checkbox::switch( + Toggle::switch( ctx, "trips affected by congestion caps", None, @@ -407,8 +407,8 @@ fn make_table_cancelled_trips(app: &App) -> Table { Widget::col(vec![ checkbox_per_mode(ctx, app, &state.modes), Widget::row(vec![ - Checkbox::switch(ctx, "starting off-map", None, state.off_map_starts), - Checkbox::switch(ctx, "ending off-map", None, state.off_map_ends), + Toggle::switch(ctx, "starting off-map", None, state.off_map_starts), + Toggle::switch(ctx, "ending off-map", None, state.off_map_ends), ]), ]) }), diff --git a/game/src/sandbox/time_warp.rs b/game/src/sandbox/time_warp.rs index 7246ae84f9..025cda19fb 100644 --- a/game/src/sandbox/time_warp.rs +++ b/game/src/sandbox/time_warp.rs @@ -6,8 +6,8 @@ use map_gui::render::DrawOptions; use map_gui::tools::{grey_out_map, PopupMsg}; use map_gui::ID; use widgetry::{ - Checkbox, Choice, Color, DrawBaselayer, EventCtx, GeomBatch, GfxCtx, Key, Line, Outcome, Panel, - Slider, State, StyledButtons, Text, UpdateType, Widget, + Choice, Color, DrawBaselayer, EventCtx, GeomBatch, GfxCtx, Key, Line, Outcome, Panel, Slider, + State, StyledButtons, Text, Toggle, UpdateType, Widget, }; use crate::app::{App, FindDelayedIntersections, ShowEverything, Transition}; @@ -69,7 +69,7 @@ impl JumpToTime { target.to_percent(end_of_day).min(1.0), ) .named("time slider"), - Checkbox::checkbox( + Toggle::checkbox( ctx, "skip drawing (for faster simulations)", None, @@ -194,7 +194,7 @@ impl JumpToDelay { ), Line("minute delay").small_heading().draw(ctx), ]), - Checkbox::checkbox( + Toggle::checkbox( ctx, "skip drawing (for faster simulations)", None, diff --git a/game/src/sandbox/uber_turns.rs b/game/src/sandbox/uber_turns.rs index 3f64ac9d21..5b08ebe932 100644 --- a/game/src/sandbox/uber_turns.rs +++ b/game/src/sandbox/uber_turns.rs @@ -6,8 +6,8 @@ use map_gui::tools::PopupMsg; use map_gui::ID; use map_model::{IntersectionCluster, IntersectionID, Map, PathConstraints, RoadID}; use widgetry::{ - Checkbox, Color, DrawBaselayer, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, - Key, Line, Panel, SimpleState, State, StyledButtons, Text, TextExt, VerticalAlignment, Widget, + Color, DrawBaselayer, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, + Panel, SimpleState, State, StyledButtons, Text, TextExt, Toggle, VerticalAlignment, Widget, }; use crate::app::{App, ShowEverything, Transition}; @@ -201,7 +201,7 @@ impl UberTurnViewer { ]), format!("driving_cost for a Car: {}", sum_cost).draw_text(ctx), Widget::row(vec![ - Checkbox::toggle( + Toggle::choice( ctx, "legal / illegal movements", "legal", diff --git a/map_editor/src/main.rs b/map_editor/src/main.rs index 1cb07011e8..1282c4cef2 100644 --- a/map_editor/src/main.rs +++ b/map_editor/src/main.rs @@ -13,8 +13,8 @@ use map_gui::tools::CameraState; use map_model::osm; use map_model::raw::OriginalRoad; use widgetry::{ - Canvas, Checkbox, Color, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel, - SharedAppState, State, StyledButtons, Text, Transition, VerticalAlignment, Widget, + Canvas, Color, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel, + SharedAppState, State, StyledButtons, Text, Toggle, Transition, VerticalAlignment, Widget, }; mod edit; @@ -109,7 +109,7 @@ impl MainState { ]), Text::new().draw(ctx).named("instructions"), Widget::col(vec![ - Checkbox::switch(ctx, "intersection geometry", Key::G, false), + Toggle::switch(ctx, "intersection geometry", Key::G, false), ctx.style() .btn_outline_text("adjust boundary") .build_def(ctx), diff --git a/map_gui/src/options.rs b/map_gui/src/options.rs index b5fa7b8683..6fc887d2c5 100644 --- a/map_gui/src/options.rs +++ b/map_gui/src/options.rs @@ -1,8 +1,8 @@ use abstutil::CmdArgs; use geom::{Duration, UnitFmt}; use widgetry::{ - Checkbox, Choice, EventCtx, GeomBatch, GfxCtx, Key, Line, Outcome, Panel, Spinner, State, - StyledButtons, TextExt, Widget, + Choice, EventCtx, GeomBatch, GfxCtx, Key, Line, Outcome, Panel, Spinner, State, StyledButtons, + TextExt, Toggle, Widget, }; use crate::colors::ColorSchemeChoice; @@ -133,26 +133,26 @@ impl OptionsPanel { ]), "Camera controls".draw_text(ctx), Widget::col(vec![ - Checkbox::checkbox( + Toggle::checkbox( ctx, "Invert direction of vertical scrolling", None, ctx.canvas.invert_scroll, ), - Checkbox::checkbox( + Toggle::checkbox( ctx, "Pan map when cursor is at edge of screen", None, ctx.canvas.edge_auto_panning, ) .named("autopan"), - Checkbox::checkbox( + Toggle::checkbox( ctx, "Use touchpad to pan and hold Control to zoom", None, ctx.canvas.touchpad_to_move, ), - Checkbox::checkbox( + Toggle::checkbox( ctx, "Use arrow keys to pan and Q/W to zoom", None, @@ -236,7 +236,7 @@ impl OptionsPanel { choices }), ]), - Checkbox::toggle( + Toggle::choice( ctx, "metric / imperial units", "metric", @@ -249,8 +249,8 @@ impl OptionsPanel { .padding(8), "Debug".draw_text(ctx), Widget::col(vec![ - Checkbox::checkbox(ctx, "Enable developer mode", None, app.opts().dev), - Checkbox::checkbox( + Toggle::checkbox(ctx, "Enable developer mode", None, app.opts().dev), + Toggle::checkbox( ctx, "Draw all agents to debug geometry (Slow!)", None, diff --git a/map_gui/src/render/agents.rs b/map_gui/src/render/agents.rs index 57158e7ee0..9a51296ec2 100644 --- a/map_gui/src/render/agents.rs +++ b/map_gui/src/render/agents.rs @@ -6,7 +6,7 @@ use aabb_quadtree::QuadTree; use geom::{Circle, Pt2D, Time}; use map_model::{Map, Traversable}; use sim::{AgentID, Sim, UnzoomedAgent, VehicleType}; -use widgetry::{Checkbox, Color, Drawable, EventCtx, GeomBatch, GfxCtx, Panel, Prerender, Widget}; +use widgetry::{Color, Drawable, EventCtx, GeomBatch, GfxCtx, Panel, Prerender, Toggle, Widget}; use crate::colors::ColorScheme; use crate::render::{ @@ -209,19 +209,20 @@ impl UnzoomedAgents { pub fn make_horiz_viz_panel(&self, ctx: &mut EventCtx) -> Widget { Widget::custom_row(vec![ - Checkbox::colored(ctx, "Car", self.car_color, self.cars).margin_right(24), - Checkbox::colored(ctx, "Bike", self.bike_color, self.bikes).margin_right(24), - Checkbox::colored(ctx, "Bus", self.bus_color, self.buses_and_trains).margin_right(24), - Checkbox::colored(ctx, "Walk", self.ped_color, self.peds).margin_right(8), + Toggle::colored_checkbox(ctx, "Car", self.car_color, self.cars).margin_right(24), + Toggle::colored_checkbox(ctx, "Bike", self.bike_color, self.bikes).margin_right(24), + Toggle::colored_checkbox(ctx, "Bus", self.bus_color, self.buses_and_trains) + .margin_right(24), + Toggle::colored_checkbox(ctx, "Walk", self.ped_color, self.peds).margin_right(8), ]) } pub fn make_vert_viz_panel(&self, ctx: &mut EventCtx) -> Widget { Widget::col(vec![ - Checkbox::colored(ctx, "Car", self.car_color, self.cars), - Checkbox::colored(ctx, "Bike", self.bike_color, self.bikes), - Checkbox::colored(ctx, "Bus", self.bus_color, self.buses_and_trains), - Checkbox::colored(ctx, "Walk", self.ped_color, self.peds), + Toggle::colored_checkbox(ctx, "Car", self.car_color, self.cars), + Toggle::colored_checkbox(ctx, "Bike", self.bike_color, self.bikes), + Toggle::colored_checkbox(ctx, "Bus", self.bus_color, self.buses_and_trains), + Toggle::colored_checkbox(ctx, "Walk", self.ped_color, self.peds), ]) } diff --git a/map_gui/src/tools/heatmap.rs b/map_gui/src/tools/heatmap.rs index bbe0de9f07..e717819ed2 100644 --- a/map_gui/src/tools/heatmap.rs +++ b/map_gui/src/tools/heatmap.rs @@ -1,5 +1,5 @@ use geom::{Bounds, Histogram, Polygon, Pt2D, Statistic}; -use widgetry::{Checkbox, Choice, Color, EventCtx, GeomBatch, Panel, Spinner, TextExt, Widget}; +use widgetry::{Choice, Color, EventCtx, GeomBatch, Panel, Spinner, TextExt, Toggle, Widget}; use crate::tools::{ColorLegend, ColorScale}; @@ -53,8 +53,8 @@ impl HeatmapOptions { .named("radius") .align_right(), ]), - Checkbox::switch(ctx, "smoothing", None, self.smoothing), - Checkbox::switch(ctx, "contours", None, self.contours), + Toggle::switch(ctx, "smoothing", None, self.smoothing), + Toggle::switch(ctx, "contours", None, self.contours), Widget::row(vec![ "Color scheme".draw_text(ctx).centered_vert(), Widget::dropdown( diff --git a/map_gui/src/tools/updater.rs b/map_gui/src/tools/updater.rs index c8a834f7ce..f9e159f0e7 100644 --- a/map_gui/src/tools/updater.rs +++ b/map_gui/src/tools/updater.rs @@ -6,7 +6,7 @@ use anyhow::Result; use abstio::{DataPacks, Manifest}; use abstutil::Timer; use widgetry::{ - Checkbox, EventCtx, GfxCtx, Line, Outcome, Panel, State, StyledButtons, TextExt, Transition, + EventCtx, GfxCtx, Line, Outcome, Panel, State, StyledButtons, TextExt, Toggle, Transition, Widget, }; @@ -44,7 +44,7 @@ impl Picker { ]; for (city, bytes) in size_per_city(&manifest) { col.push(Widget::row(vec![ - Checkbox::checkbox(ctx, &city, None, data_packs.runtime.contains(&city)), + Toggle::checkbox(ctx, &city, None, data_packs.runtime.contains(&city)), prettyprint_bytes(bytes).draw_text(ctx).centered_vert(), ])); } diff --git a/osm_viewer/src/viewer.rs b/osm_viewer/src/viewer.rs index c890ffb776..c41081d7d5 100644 --- a/osm_viewer/src/viewer.rs +++ b/osm_viewer/src/viewer.rs @@ -11,9 +11,9 @@ use map_gui::tools::{ use map_gui::{SimpleApp, ID}; use map_model::osm; use widgetry::{ - lctrl, Checkbox, Color, DrawBaselayer, Drawable, EventCtx, GeomBatch, GfxCtx, - HorizontalAlignment, Key, Line, Outcome, Panel, State, StyledButtons, Text, TextExt, - Transition, VerticalAlignment, Widget, + lctrl, Color, DrawBaselayer, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, + Line, Outcome, Panel, State, StyledButtons, Text, TextExt, Toggle, Transition, + VerticalAlignment, Widget, }; type App = SimpleApp<()>; @@ -444,7 +444,7 @@ impl BusinessSearch { format!("{} businesses total", prettyprint_usize(self.counts.sum())).draw_text(ctx), ); for (amenity, cnt) in self.counts.borrow() { - col.push(Checkbox::custom_checkbox( + col.push(Toggle::custom_checkbox( ctx, amenity, vec![Line(format!("{}: {}", amenity, prettyprint_usize(*cnt)))], diff --git a/parking_mapper/src/mapper.rs b/parking_mapper/src/mapper.rs index a60327c78e..1061188b26 100644 --- a/parking_mapper/src/mapper.rs +++ b/parking_mapper/src/mapper.rs @@ -9,8 +9,8 @@ use map_gui::{SimpleApp, ID}; use map_model::{osm, RoadID}; use osm::WayID; use widgetry::{ - lctrl, Checkbox, Choice, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, - Key, Line, Menu, Outcome, Panel, State, StyledButtons, Text, TextExt, Transition, + lctrl, Choice, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, + Menu, Outcome, Panel, State, StyledButtons, Text, TextExt, Toggle, Transition, VerticalAlignment, Widget, }; @@ -176,7 +176,7 @@ impl ParkingMapper { }, ), ]), - Checkbox::checkbox(ctx, "max 3 days parking (default in Seattle)", None, false), + Toggle::checkbox(ctx, "max 3 days parking (default in Seattle)", None, false), ctx.style() .btn_outline_text("Generate OsmChange file") .build_def(ctx), diff --git a/santa/src/music.rs b/santa/src/music.rs index 9d71b3f3a0..456b2c7156 100644 --- a/santa/src/music.rs +++ b/santa/src/music.rs @@ -4,8 +4,7 @@ use anyhow::Result; use rodio::{Decoder, OutputStream, OutputStreamHandle, Sink}; use widgetry::{ - Checkbox, EventCtx, GfxCtx, HorizontalAlignment, Outcome, Panel, StyledButtons, - VerticalAlignment, + EventCtx, GfxCtx, HorizontalAlignment, Outcome, Panel, StyledButtons, Toggle, VerticalAlignment, }; // TODO Speed up when we're almost out of time, slow down when we're low on energy @@ -108,7 +107,7 @@ impl Inner { } let panel = Panel::new( - Checkbox::new( + Toggle::new( play_music, ctx.style() .btn_solid_icon("system/assets/tools/volume_off.svg") diff --git a/widgetry/src/lib.rs b/widgetry/src/lib.rs index b77a0224e7..2696f166a8 100644 --- a/widgetry/src/lib.rs +++ b/widgetry/src/lib.rs @@ -6,7 +6,7 @@ //! //! * [`Autocomplete`] - select predefined value by combining text entry with menus //! * [`Button`] - clickable buttons with keybindings and tooltips -//! * [`Checkbox`] - toggle between two buttons +//! * [`Toggle`] - checkboxes, switches, and other toggles //! * [`CompareTimes`] - a scatter plot specialized for comparing times //! * [`DrawWithTooltips`] - draw static geometry, with mouse tooltips in certain regions //! * [`Dropdown`] - a button that expands into a menu @@ -48,7 +48,6 @@ pub use crate::tools::Cached; pub use crate::widgets::autocomplete::Autocomplete; pub(crate) use crate::widgets::button::Button; pub use crate::widgets::button::{ButtonBuilder, MultiButton}; -pub use crate::widgets::checkbox::Checkbox; pub use crate::widgets::compare_times::CompareTimes; pub(crate) use crate::widgets::dropdown::Dropdown; pub use crate::widgets::fan_chart::FanChart; @@ -63,6 +62,7 @@ pub use crate::widgets::slider::Slider; pub use crate::widgets::spinner::Spinner; pub use crate::widgets::table; pub(crate) use crate::widgets::text_box::TextBox; +pub use crate::widgets::toggle::Toggle; pub use crate::widgets::{ CornerRounding, EdgeInsets, Outcome, Panel, Widget, WidgetImpl, WidgetOutput, }; diff --git a/widgetry/src/widgets/line_plot.rs b/widgetry/src/widgets/line_plot.rs index f3a5f2be79..545c047ede 100644 --- a/widgetry/src/widgets/line_plot.rs +++ b/widgetry/src/widgets/line_plot.rs @@ -7,8 +7,8 @@ use geom::{ }; use crate::{ - Checkbox, Color, Drawable, EventCtx, GeomBatch, GfxCtx, JustDraw, Line, ScreenDims, ScreenPt, - ScreenRectangle, Text, TextExt, Widget, WidgetImpl, WidgetOutput, + Color, Drawable, EventCtx, GeomBatch, GfxCtx, JustDraw, Line, ScreenDims, ScreenPt, + ScreenRectangle, Text, TextExt, Toggle, Widget, WidgetImpl, WidgetOutput, }; // The X is always time @@ -332,7 +332,7 @@ pub fn make_legend>( } seen.insert(s.label.clone()); if opts.filterable { - row.push(Checkbox::colored( + row.push(Toggle::colored_checkbox( ctx, &s.label, s.color, diff --git a/widgetry/src/widgets/mod.rs b/widgetry/src/widgets/mod.rs index fd8292189e..79f831f962 100644 --- a/widgetry/src/widgets/mod.rs +++ b/widgetry/src/widgets/mod.rs @@ -12,14 +12,13 @@ use geom::{CornerRadii, Distance, Percent, Polygon}; use crate::widgets::containers::{Container, Nothing}; pub use crate::widgets::panel::Panel; use crate::{ - Button, Checkbox, Choice, Color, DeferDraw, DrawWithTooltips, Drawable, Dropdown, EventCtx, - GeomBatch, GfxCtx, JustDraw, Menu, RewriteColor, ScreenDims, ScreenPt, ScreenRectangle, Text, - TextBox, + Button, Choice, Color, DeferDraw, DrawWithTooltips, Drawable, Dropdown, EventCtx, GeomBatch, + GfxCtx, JustDraw, Menu, RewriteColor, ScreenDims, ScreenPt, ScreenRectangle, Text, TextBox, + Toggle, }; pub mod autocomplete; pub mod button; -pub mod checkbox; pub mod compare_times; pub mod containers; pub mod dropdown; @@ -35,6 +34,7 @@ pub mod slider; pub mod spinner; pub mod table; pub mod text_box; +pub mod toggle; /// Create a new widget by implementing this trait. You can instantiate your widget by calling /// `Widget::new(Box::new(instance of your new widget))`, which gives you the usual style options. @@ -660,7 +660,7 @@ impl Widget { if btn.hovering { return Some(&btn.action); } - } else if let Some(checkbox) = self.widget.downcast_ref::() { + } else if let Some(checkbox) = self.widget.downcast_ref::() { if checkbox.btn.hovering { return Some(&checkbox.btn.action); } diff --git a/widgetry/src/widgets/panel.rs b/widgetry/src/widgets/panel.rs index bdf6d729b2..4a2a3cd7f8 100644 --- a/widgetry/src/widgets/panel.rs +++ b/widgetry/src/widgets/panel.rs @@ -10,8 +10,8 @@ use geom::{Percent, Polygon}; use crate::widgets::slider; use crate::widgets::Container; use crate::{ - Autocomplete, Button, Checkbox, Color, Dropdown, EventCtx, GfxCtx, HorizontalAlignment, Menu, - Outcome, PersistentSplit, ScreenDims, ScreenPt, ScreenRectangle, Slider, Spinner, TextBox, + Autocomplete, Button, Color, Dropdown, EventCtx, GfxCtx, HorizontalAlignment, Menu, Outcome, + PersistentSplit, ScreenDims, ScreenPt, ScreenRectangle, Slider, Spinner, TextBox, Toggle, VerticalAlignment, Widget, WidgetImpl, WidgetOutput, }; @@ -360,11 +360,11 @@ impl Panel { } pub fn is_checked(&self, name: &str) -> bool { - self.find::(name).enabled + self.find::(name).enabled } pub fn maybe_is_checked(&self, name: &str) -> Option { if self.has_widget(name) { - Some(self.find::(name).enabled) + Some(self.find::(name).enabled) } else { None } diff --git a/widgetry/src/widgets/checkbox.rs b/widgetry/src/widgets/toggle.rs similarity index 94% rename from widgetry/src/widgets/checkbox.rs rename to widgetry/src/widgets/toggle.rs index 1d64d61261..56f08f530e 100644 --- a/widgetry/src/widgets/checkbox.rs +++ b/widgetry/src/widgets/toggle.rs @@ -4,22 +4,22 @@ use crate::{ WidgetOutput, }; -pub struct Checkbox { +pub struct Toggle { pub(crate) enabled: bool, pub(crate) btn: Button, other_btn: Button, } -impl Checkbox { +impl Toggle { pub fn new(enabled: bool, false_btn: Button, true_btn: Button) -> Widget { if enabled { - Widget::new(Box::new(Checkbox { + Widget::new(Box::new(Toggle { enabled, btn: true_btn, other_btn: false_btn, })) } else { - Widget::new(Box::new(Checkbox { + Widget::new(Box::new(Toggle { enabled, btn: false_btn, other_btn: true_btn, @@ -50,7 +50,7 @@ impl Checkbox { .image_bytes(include_labeled_bytes!("../../icons/toggle_on.svg")) .build(ctx, label); - Checkbox::new(enabled, off_button, on_button).named(label) + Toggle::new(enabled, off_button, on_button).named(label) } pub fn checkbox>>( @@ -84,7 +84,7 @@ impl Checkbox { .clone() .image_bytes(include_labeled_bytes!("../../icons/checkbox_checked.svg")); - Checkbox::new( + Toggle::new( enabled, false_btn.build(ctx, label), true_btn.build(ctx, label), @@ -124,7 +124,7 @@ impl Checkbox { .clone() .image_bytes(include_labeled_bytes!("../../icons/checkbox_checked.svg")); - Checkbox::new( + Toggle::new( enabled, false_btn.build(ctx, action), true_btn.build(ctx, action), @@ -132,7 +132,7 @@ impl Checkbox { .named(action) } - pub fn colored(ctx: &EventCtx, label: &str, color: Color, enabled: bool) -> Widget { + pub fn colored_checkbox(ctx: &EventCtx, label: &str, color: Color, enabled: bool) -> Widget { let buttons = ctx.style().btn_plain().label_text(label).padding(4.0); let false_btn = buttons @@ -154,7 +154,7 @@ impl Checkbox { ControlState::Default, ); - Checkbox::new( + Toggle::new( enabled, false_btn.build(ctx, label), true_btn.build(ctx, label), @@ -163,7 +163,7 @@ impl Checkbox { } // TODO These should actually be radio buttons - pub fn toggle>>( + pub fn choice>>( ctx: &EventCtx, label: &str, left_label: &str, @@ -203,7 +203,7 @@ impl Checkbox { let right_text_button = left_text_button.clone().label_text(right_label); Widget::row(vec![ left_text_button.build_def(ctx).centered_vert(), - Checkbox::new( + Toggle::new( enabled, toggle_right_button.build(ctx, right_label), toggle_left_button.build(ctx, left_label), @@ -215,7 +215,7 @@ impl Checkbox { } } -impl WidgetImpl for Checkbox { +impl WidgetImpl for Toggle { fn get_dims(&self) -> ScreenDims { self.btn.get_dims() } diff --git a/widgetry_demo/src/lib.rs b/widgetry_demo/src/lib.rs index d07ab56e4d..2716721b5d 100644 --- a/widgetry_demo/src/lib.rs +++ b/widgetry_demo/src/lib.rs @@ -5,10 +5,10 @@ use rand_xorshift::XorShiftRng; use geom::{Angle, Duration, Percent, Polygon, Pt2D, Time}; use widgetry::{ - lctrl, Checkbox, Choice, Color, Drawable, EventCtx, Fill, GeomBatch, GfxCtx, - HorizontalAlignment, Key, Line, LinePlot, Outcome, Panel, PersistentSplit, PlotOptions, Series, - SharedAppState, State, StyledButtons, Text, TextExt, Texture, Transition, UpdateType, - VerticalAlignment, Widget, + lctrl, Choice, Color, Drawable, EventCtx, Fill, GeomBatch, GfxCtx, HorizontalAlignment, Key, + Line, LinePlot, Outcome, Panel, PersistentSplit, PlotOptions, Series, SharedAppState, State, + StyledButtons, Text, TextExt, Texture, Toggle, Transition, UpdateType, VerticalAlignment, + Widget, }; pub fn main() { @@ -342,15 +342,15 @@ fn make_controls(ctx: &mut EventCtx) -> Panel { .btn_outline_text("New faces") .hotkey(Key::F) .build_widget(ctx, "generate new faces"), - Checkbox::switch(ctx, "Draw scrollable canvas", None, true), - Checkbox::switch(ctx, "Show timeseries", lctrl(Key::T), false), + Toggle::switch(ctx, "Draw scrollable canvas", None, true), + Toggle::switch(ctx, "Show timeseries", lctrl(Key::T), false), ]), "Stopwatch: ..." .draw_text(ctx) .named("stopwatch") .margin_above(30), Widget::row(vec![ - Checkbox::new( + Toggle::new( false, ctx.style() .btn_solid_text("Pause") @@ -471,7 +471,7 @@ fn make_controls(ctx: &mut EventCtx) -> Panel { ), Widget::col( (0..row_height) - .map(|_| widgetry::Checkbox::checkbox(ctx, "checkbox", None, true)) + .map(|_| widgetry::Toggle::checkbox(ctx, "checkbox", None, true)) .collect::>(), ), ])