mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
Plumb back the widget name in Outcome::Changed
This commit is contained in:
parent
babdc9e384
commit
bc591c1b5f
@ -184,7 +184,7 @@ impl State<App> for Viewer {
|
||||
}
|
||||
}
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
let options = options_from_controls(&self.panel);
|
||||
self.draw_unwalkable_roads = draw_unwalkable_roads(ctx, app, &options);
|
||||
self.isochrone = Isochrone::new(ctx, app, self.isochrone.start, options);
|
||||
@ -522,7 +522,7 @@ impl State<App> for ExploreAmenities {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
self.table.panel_changed(&self.panel);
|
||||
self.table.replace_render(ctx, app, &mut self.panel)
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ impl State<App> for Floodfiller {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
return Transition::Replace(Floodfiller::new(
|
||||
ctx,
|
||||
app,
|
||||
|
@ -372,7 +372,7 @@ impl State<App> for DebugMode {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
// TODO We should really recalculate current_selection when these change. Meh.
|
||||
self.layers.show_buildings = self.panel.is_checked("show buildings");
|
||||
self.layers.show_intersections = self.panel.is_checked("show intersections");
|
||||
|
@ -98,7 +98,7 @@ impl State<App> for RouteExplorer {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
self.recalc_paths(ctx, app);
|
||||
}
|
||||
_ => {}
|
||||
|
@ -127,7 +127,7 @@ impl State<App> for PopularDestinations {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
return Transition::Replace(PopularDestinations::make(
|
||||
ctx,
|
||||
app,
|
||||
|
@ -168,7 +168,7 @@ impl State<App> for ViewKML {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
let mut query: String = self.panel.dropdown_value("query");
|
||||
let filter = self.panel.text_box("filter");
|
||||
if query == "None" && !filter.is_empty() {
|
||||
|
@ -192,9 +192,9 @@ impl State<App> for RoadEditor {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
Outcome::Changed => {
|
||||
let speed_limit = self.main_panel.dropdown_value("speed limit");
|
||||
if speed_limit != app.primary.map.get_r(self.r).speed_limit {
|
||||
Outcome::Changed(x) => match x.as_ref() {
|
||||
"speed limit" => {
|
||||
let speed_limit = self.main_panel.dropdown_value("speed limit");
|
||||
let mut edits = app.primary.map.get_edits().clone();
|
||||
edits
|
||||
.commands
|
||||
@ -213,13 +213,15 @@ impl State<App> for RoadEditor {
|
||||
self.num_edit_cmds_originally,
|
||||
self.redo_stack.is_empty(),
|
||||
);
|
||||
} else {
|
||||
}
|
||||
"width" => {
|
||||
let width = self.main_panel.dropdown_value("width");
|
||||
self.modify_current_lane(ctx, app, Some(0), |new, idx| {
|
||||
new.lanes_ltr[idx].width = width;
|
||||
});
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ impl State<App> for ZoneEditor {
|
||||
}
|
||||
}
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
let mut new_allow_through_traffic = BTreeSet::new();
|
||||
for m in TripMode::all() {
|
||||
if self.panel.is_checked(m.ongoing_verb()) {
|
||||
|
@ -49,7 +49,7 @@ impl Layer for Occupancy {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
*self = Occupancy::new(
|
||||
ctx,
|
||||
app,
|
||||
|
@ -157,7 +157,7 @@ impl Layer for Throughput {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
if self
|
||||
.panel
|
||||
.maybe_is_checked("Compare before proposal")
|
||||
@ -322,7 +322,7 @@ impl Layer for CompareThroughput {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
return Some(LayerOutcome::Replace(Box::new(Throughput::new(
|
||||
ctx,
|
||||
app,
|
||||
|
@ -23,7 +23,7 @@ impl Layer for TransitNetwork {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
*self = TransitNetwork::new(
|
||||
ctx,
|
||||
app,
|
||||
|
@ -60,7 +60,7 @@ impl State<App> for ActiveTraffic {
|
||||
"close" => Transition::Pop,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => DashTab::ActiveTraffic
|
||||
Outcome::Changed(_) => DashTab::ActiveTraffic
|
||||
.transition(ctx, app, &self.panel)
|
||||
.unwrap(),
|
||||
_ => Transition::Keep,
|
||||
@ -204,7 +204,7 @@ impl State<App> for TransitRoutes {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
if let Some(t) = DashTab::TransitRoutes.transition(ctx, app, &self.panel) {
|
||||
return t;
|
||||
} else {
|
||||
|
@ -82,7 +82,7 @@ impl State<App> for ParkingOverhead {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
if let Some(t) = self.tab.transition(ctx, app, &self.panel) {
|
||||
return t;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ impl State<App> for TripSummaries {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
if let Some(t) = DashTab::TripSummaries.transition(ctx, app, &self.panel) {
|
||||
return t;
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ impl State<App> for TrafficSignalDemand {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
changed = true;
|
||||
}
|
||||
_ => {}
|
||||
|
@ -158,7 +158,7 @@ impl State<App> for TripTable {
|
||||
unreachable!("unhandled action: {}", x)
|
||||
}
|
||||
}
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
if let Some(t) = self.tab.transition(ctx, app, &self.panel) {
|
||||
return t;
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ impl GameplayState for Actdev {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
// Background traffic was toggled
|
||||
return Some(Transition::Replace(SandboxMode::async_new(
|
||||
app,
|
||||
|
@ -154,7 +154,7 @@ impl State<App> for AgentSpawner {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
// We need to recalculate the path to see if this is sane. Otherwise we could trick
|
||||
// a pedestrian into wandering on/off a highway border.
|
||||
if self.goal.is_some() {
|
||||
|
@ -172,7 +172,7 @@ impl State<App> for JumpToTime {
|
||||
}
|
||||
}
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
app.opts.dont_draw_time_warp = self.panel.is_checked("don't draw");
|
||||
if self.tabs.active_tab_idx() == 1 {
|
||||
self.panel.replace(
|
||||
|
@ -315,7 +315,7 @@ impl State<App> for MainState {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
app.model.show_intersection_geometry(
|
||||
ctx,
|
||||
self.panel.is_checked("intersection geometry"),
|
||||
|
@ -364,7 +364,7 @@ impl<A: AppLike + 'static, T: MinimapControls<A>> Minimap<A, T> {
|
||||
}
|
||||
}
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
self.controls.panel_changed(ctx, app, &self.panel);
|
||||
if self.panel.has_widget("zorder") {
|
||||
app.mut_draw_map().show_zorder = self.panel.spinner("zorder");
|
||||
|
@ -339,7 +339,7 @@ impl State<App> for Viewer {
|
||||
}
|
||||
}
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
let b = self.businesses.as_mut().unwrap();
|
||||
// Update state from checkboxes
|
||||
b.show.clear();
|
||||
|
@ -355,7 +355,7 @@ impl State<App> for ParkingMapper {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
return Transition::Replace(ParkingMapper::make(
|
||||
ctx,
|
||||
app,
|
||||
|
@ -51,7 +51,7 @@ impl Music {
|
||||
if let Some(ref mut inner) = self.inner {
|
||||
match inner.panel.event(ctx) {
|
||||
Outcome::Clicked(_) => unreachable!(),
|
||||
Outcome::Changed => {
|
||||
Outcome::Changed(_) => {
|
||||
if inner.panel.is_checked("play music") {
|
||||
*play_music = true;
|
||||
inner.unmute();
|
||||
|
@ -260,7 +260,7 @@ impl<A: 'static> State<A> for SimpleStateWrapper<A> {
|
||||
}
|
||||
match self.panel.event(ctx) {
|
||||
Outcome::Clicked(action) => self.inner.on_click(ctx, app, &action, &self.panel),
|
||||
Outcome::Changed => self
|
||||
Outcome::Changed(_) => self
|
||||
.inner
|
||||
.panel_changed(ctx, app, &mut self.panel)
|
||||
.unwrap_or_else(|| self.inner.other_event(ctx, app)),
|
||||
|
@ -95,7 +95,7 @@ impl<T: 'static + Clone> WidgetImpl for Dropdown<T> {
|
||||
m.event(ctx, &mut tmp_ouput);
|
||||
if let Outcome::Clicked(_) = tmp_ouput.outcome {
|
||||
self.current_idx = self.menu.take().unwrap().take_current_choice();
|
||||
output.outcome = Outcome::Changed;
|
||||
output.outcome = Outcome::Changed(self.label.clone());
|
||||
let top_left = self.btn.top_left;
|
||||
self.btn = make_btn(
|
||||
ctx,
|
||||
|
@ -66,13 +66,14 @@ pub trait WidgetImpl: downcast_rs::Downcast {
|
||||
}
|
||||
}
|
||||
|
||||
/// The result of a Panel handling an event
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Outcome {
|
||||
/// An action was done
|
||||
Clicked(String),
|
||||
/// A dropdown, checkbox, spinner, etc changed values. Usually this triggers a refresh of
|
||||
/// everything, so not useful to plumb along what changed.
|
||||
Changed,
|
||||
/// A dropdown, checkbox, spinner, etc changed values. The name of the changed widget is
|
||||
/// returned, but not the value, since its type is generic.
|
||||
Changed(String),
|
||||
/// Nothing happened
|
||||
Nothing,
|
||||
}
|
||||
|
@ -28,9 +28,9 @@ pub struct Spinner {
|
||||
}
|
||||
|
||||
impl Spinner {
|
||||
pub fn widget<S: Into<String>>(
|
||||
pub fn widget(
|
||||
ctx: &EventCtx,
|
||||
label: S,
|
||||
label: impl Into<String>,
|
||||
(low, high): (isize, isize),
|
||||
current: isize,
|
||||
) -> Widget {
|
||||
@ -161,7 +161,7 @@ impl WidgetImpl for Spinner {
|
||||
fn event(&mut self, ctx: &mut EventCtx, output: &mut WidgetOutput) {
|
||||
self.up.event(ctx, output);
|
||||
if let Outcome::Clicked(_) = output.outcome {
|
||||
output.outcome = Outcome::Changed;
|
||||
output.outcome = Outcome::Changed(self.label.clone());
|
||||
self.current = (self.current + 1).min(self.high);
|
||||
self.drawable = self.drawable(&ctx.prerender, ctx.style());
|
||||
ctx.no_op_event(true, |ctx| self.up.event(ctx, output));
|
||||
@ -170,7 +170,7 @@ impl WidgetImpl for Spinner {
|
||||
|
||||
self.down.event(ctx, output);
|
||||
if let Outcome::Clicked(_) = output.outcome {
|
||||
output.outcome = Outcome::Changed;
|
||||
output.outcome = Outcome::Changed(self.label.clone());
|
||||
self.current = (self.current - 1).max(self.low);
|
||||
self.drawable = self.drawable(&ctx.prerender, ctx.style());
|
||||
ctx.no_op_event(true, |ctx| self.down.event(ctx, output));
|
||||
@ -182,12 +182,12 @@ impl WidgetImpl for Spinner {
|
||||
if let Some((_, dy)) = ctx.input.get_mouse_scroll() {
|
||||
if dy > 0.0 && self.current != self.high {
|
||||
self.current += 1;
|
||||
output.outcome = Outcome::Changed;
|
||||
output.outcome = Outcome::Changed(self.label.clone());
|
||||
self.drawable = self.drawable(&ctx.prerender, ctx.style());
|
||||
}
|
||||
if dy < 0.0 && self.current != self.low {
|
||||
self.current -= 1;
|
||||
output.outcome = Outcome::Changed;
|
||||
output.outcome = Outcome::Changed(self.label.clone());
|
||||
self.drawable = self.drawable(&ctx.prerender, ctx.style());
|
||||
}
|
||||
}
|
||||
|
@ -129,14 +129,14 @@ impl WidgetImpl for TextBox {
|
||||
}
|
||||
Key::Backspace => {
|
||||
if self.cursor_x > 0 {
|
||||
output.outcome = Outcome::Changed;
|
||||
output.outcome = Outcome::Changed(self.label.clone());
|
||||
self.line.remove(self.cursor_x - 1);
|
||||
self.cursor_x -= 1;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if let Some(c) = key.to_char(ctx.is_key_down(Key::LeftShift)) {
|
||||
output.outcome = Outcome::Changed;
|
||||
output.outcome = Outcome::Changed(self.label.clone());
|
||||
self.line.insert(self.cursor_x, c);
|
||||
self.cursor_x += 1;
|
||||
} else {
|
||||
|
@ -271,7 +271,8 @@ impl WidgetImpl for Toggle {
|
||||
fn event(&mut self, ctx: &mut EventCtx, output: &mut WidgetOutput) {
|
||||
self.btn.event(ctx, output);
|
||||
if let Outcome::Clicked(_) = output.outcome {
|
||||
output.outcome = Outcome::Changed;
|
||||
// Both buttons have the same label
|
||||
output.outcome = Outcome::Changed(self.btn.action.clone());
|
||||
std::mem::swap(&mut self.btn, &mut self.other_btn);
|
||||
self.btn.set_pos(self.other_btn.top_left);
|
||||
self.enabled = !self.enabled;
|
||||
|
Loading…
Reference in New Issue
Block a user