Skip to content

Commit b54c100

Browse files
committed
add hyperspeed button
1 parent 739d54e commit b54c100

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Diff for: src/app.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ pub struct AppState {
121121
show_cursor: bool,
122122
extra: bool,
123123
text_channel: (Sender<String>, Receiver<String>),
124+
hyperspeed: bool,
124125
}
125126

126127
impl AppState {
@@ -139,6 +140,7 @@ impl AppState {
139140
show_cursor: true,
140141
extra: false,
141142
speed: 5.0,
143+
hyperspeed: false,
142144
}
143145
}
144146

@@ -303,12 +305,17 @@ impl eframe::App for AppState {
303305
let time_per_step = Duration::from_millis((500.0 - 49.0 * self.speed) as u64);
304306
let elapsed = self.time_since_step.elapsed();
305307
if !self.paused {
306-
if elapsed >= time_per_step {
308+
if self.hyperspeed {
307309
self.step();
308-
self.time_since_step = Instant::now();
309-
}
310+
ui.ctx().request_repaint();
311+
} else {
312+
if elapsed >= time_per_step {
313+
self.step();
314+
self.time_since_step = Instant::now();
315+
}
310316

311-
ui.ctx().request_repaint_after(time_per_step);
317+
ui.ctx().request_repaint_after(time_per_step);
318+
}
312319
}
313320

314321
// The central panel the region left after adding TopPanel's and SidePanel's
@@ -359,6 +366,9 @@ impl eframe::App for AppState {
359366
self.paused = true;
360367
}
361368
ui.add(egui::Slider::new(&mut self.speed, 1.0..=10.0).text("speed"));
369+
if ui.button("max speed").clicked() {
370+
self.hyperspeed = !self.hyperspeed;
371+
}
362372
});
363373

364374
ui.separator();

0 commit comments

Comments
 (0)