From 2c27d660b328c3e4e24966f2e46e4f7473dfcd3c Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Mon, 7 Oct 2024 12:57:32 +0200 Subject: [PATCH] add step button --- assets/step.png | Bin 0 -> 191 bytes src/editor.rs | 34 +++++++++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 assets/step.png diff --git a/assets/step.png b/assets/step.png new file mode 100644 index 0000000000000000000000000000000000000000..ddb7dc98a83f54ee0e3bec4e803d450c4aacc3c7 GIT binary patch literal 191 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`ZJsWUAr`%B&mH7#P~c&`@QAhi zfMLu5UYUlEG7Y>D4Tc5mHdli=)dILSs!zKAU*kZ0^Em~p=DmAGY?r;*U;Tn7=z!uE z&rThYR|$^n+~?~Y-wVm+)ah>xXfkOGT*B3(;Oo$}fkE-I_=Odp!!9#~zhl~K#O-m) o*CFbhL*#=~soV0}e+ZYw9S#X(?q~GT1iFa9)78&qol`;+08(p2m;e9( literal 0 HcmV?d00001 diff --git a/src/editor.rs b/src/editor.rs index 869a708..84f05b7 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -128,6 +128,18 @@ impl Editor { self.machine.set_board(self.source_board.clone()); } + fn step_pressed(&mut self){ + match self.sim_state { + SimState::Editing => { + self.start_sim(); + self.step(); + } + SimState::Running => (), + SimState::Stepping => self.step(), + } + self.sim_state = SimState::Stepping; + } + fn step(&mut self) { self.machine.step(); if !self.level.outputs().is_empty() @@ -211,15 +223,7 @@ impl Editor { } } if rl.is_key_pressed(KeyboardKey::KEY_SPACE) { - match self.sim_state { - SimState::Editing => { - self.start_sim(); - self.step(); - } - SimState::Running => (), - SimState::Stepping => self.step(), - } - self.sim_state = SimState::Stepping; + self.step_pressed() } if rl.is_key_pressed(KeyboardKey::KEY_ENTER) { match self.sim_state { @@ -392,24 +396,28 @@ impl Editor { self.sim_state = SimState::Stepping; } draw_scaled_texture(d, textures.get("pause"), 260, 4, 2.); - if simple_button(d, 260 + 36, 4, 32, 32) { + if simple_button(d, 296, 4, 32, 32) { self.sim_state = SimState::Editing; self.complete_popup = Popup::Start; } - draw_scaled_texture(d, textures.get("stop"), 260 + 36, 4, 2.); + draw_scaled_texture(d, textures.get("stop"), 296, 4, 2.); } SimState::Stepping => { if simple_button(d, 260, 4, 32, 32) { self.sim_state = SimState::Running; } draw_scaled_texture(d, textures.get("play"), 260, 4, 2.); - if simple_button(d, 260 + 36, 4, 32, 32) { + if simple_button(d, 296, 4, 32, 32) { self.sim_state = SimState::Editing; self.complete_popup = Popup::Start; } - draw_scaled_texture(d, textures.get("stop"), 260 + 36, 4, 2.); + draw_scaled_texture(d, textures.get("stop"), 296, 4, 2.); } } + if simple_button(d, 332, 4, 32, 32) { + self.step_pressed(); + } + draw_scaled_texture(d, textures.get("step"), 332, 4, 2.); let mut input_text = String::from_utf8_lossy(self.machine.input()).to_string(); let width = d.get_screen_width();