Speed up rat run viewer by not recalculating all of the panel.
@@ -90,6 +90,11 @@ impl BrowseRatRuns {
return;
}
+ // Optimization to avoid recalculating the whole panel
+ if self.panel.has_widget("prev/next controls") && self.current_idx.is_some() {
+ let controls = self.prev_next_controls(ctx);
+ self.panel.replace(ctx, "prev/next controls", controls);
+ } else {
self.panel = Tab::RatRuns
.panel_builder(
ctx,
@@ -114,31 +119,11 @@ impl BrowseRatRuns {
self.current_idx.is_none(),
),
]),
- if let Some(idx) = self.current_idx {
- Widget::row(vec![
- ctx.style()
- .btn_prev()
- .disabled(idx == 0)
- .hotkey(Key::LeftArrow)
- .build_widget(ctx, "previous rat run"),
- Text::from(
- Line(format!("{}/{}", idx + 1, self.rat_runs.paths.len()))
- .secondary(),
- )
- .into_widget(ctx)
- .centered_vert(),
- ctx.style()
- .btn_next()
- .disabled(idx == self.rat_runs.paths.len() - 1)
- .hotkey(Key::RightArrow)
- .build_widget(ctx, "next rat run"),
- ])
- } else {
- Widget::nothing()
- },
+ self.prev_next_controls(ctx),
]),
)
.build(ctx);
+ }
let mut draw_path = ToggleZoomed::builder();
if let Some(pl) = self
@@ -166,6 +151,29 @@ impl BrowseRatRuns {
}
self.draw_path = draw_path.build(ctx);
}
+
+ fn prev_next_controls(&self, ctx: &EventCtx) -> Widget {
+ if let Some(idx) = self.current_idx {
+ Widget::row(vec![
+ ctx.style()
+ .btn_prev()
+ .disabled(idx == 0)
+ .hotkey(Key::LeftArrow)
+ .build_widget(ctx, "previous rat run"),
+ Text::from(Line(format!("{}/{}", idx + 1, self.rat_runs.paths.len())).secondary())
+ .into_widget(ctx)
+ .centered_vert(),
+ ctx.style()
+ .btn_next()
+ .disabled(idx == self.rat_runs.paths.len() - 1)
+ .hotkey(Key::RightArrow)
+ .build_widget(ctx, "next rat run"),
+ ])
+ .named("prev/next controls")
+ } else {
+ Widget::nothing()
+ }
+ }
}
impl State<App> for BrowseRatRuns {
