In the travel times dash, retain the scroll state when toggling filters
@@ -24,6 +24,12 @@ pub struct TravelTimes {
impl TravelTimes {
pub fn new_state(ctx: &mut EventCtx, app: &App, filter: Filter) -> Box<dyn State<App>> {
+ Box::new(TravelTimes {
+ panel: TravelTimes::make_panel(ctx, app, filter),
+ })
+ }
+
+ fn make_panel(ctx: &mut EventCtx, app: &App, filter: Filter) -> Panel {
let mut filters = vec!["Filters".text_widget(ctx)];
for mode in TripMode::all() {
filters.push(Toggle::colored_checkbox(
@@ -42,8 +48,7 @@ impl TravelTimes {
.align_bottom(),
);
- Box::new(TravelTimes {
- panel: Panel::new_builder(Widget::col(vec![
+ Panel::new_builder(Widget::col(vec![
DashTab::TravelTimes.picker(ctx, app),
Widget::row(vec![
Widget::col(filters).section(ctx),
@@ -99,8 +104,7 @@ impl TravelTimes {
]),
]))
.exact_size_percent(90, 90)
- .build(ctx),
- })
+ .build(ctx)
}
}
@@ -138,7 +142,10 @@ impl State<App> for TravelTimes {
filter.modes.insert(m);
}
}
- Transition::Replace(TravelTimes::new_state(ctx, app, filter))
+ let mut new_panel = TravelTimes::make_panel(ctx, app, filter);
+ new_panel.restore(ctx, &self.panel);
+ self.panel = new_panel;
+ Transition::Keep
}
_ => Transition::Keep,
}
