From c435d96f336dee032f1ded53045a6424100aa5aa Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Wed, 1 May 2024 23:15:44 +0200 Subject: [PATCH] allow removing rules --- petri/src/lib.rs | 4 +++- uscope/src/main.rs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/petri/src/lib.rs b/petri/src/lib.rs index 66521e1..39d25ee 100644 --- a/petri/src/lib.rs +++ b/petri/src/lib.rs @@ -112,7 +112,9 @@ impl Dish { } pub fn fire_blindly(&mut self) { - assert!(!self.rules.is_empty()); + if self.rules.is_empty() { + return; + } let x = random::() % CHUNK_SIZE; let y = random::() % CHUNK_SIZE; let rule = random::() % self.rules.len(); diff --git a/uscope/src/main.rs b/uscope/src/main.rs index a71cb9d..39312ca 100644 --- a/uscope/src/main.rs +++ b/uscope/src/main.rs @@ -61,6 +61,7 @@ impl eframe::App for UScope { ui.color_edit_button_srgba(&mut cell.color); }); } + if ui.button("add cell").clicked() { let h = random::(); let s = random::() * 0.5 + 0.5; @@ -70,9 +71,16 @@ impl eframe::App for UScope { self.celltypes.push(CellData { name, color }) } ui.heading("Rules"); - for rule in &mut self.dish.rules { + let mut to_remove = None; + for (i, rule) in self.dish.rules.iter_mut().enumerate() { + if ui.button("x").clicked() { + to_remove = Some(i); + } rule_editor(ui, rule, &self.celltypes); } + if let Some(i) = to_remove { + self.dish.rules.remove(i); + } if ui.button("add rule").clicked() { self.dish.rules.push(Rule::new()); } @@ -108,7 +116,7 @@ fn paint_chunk(painter: Painter, chunk: &Chunk, cells: &[CellData]) { } const CSIZE: f32 = 24.; -const OUTLINE: (f32, Color32) = (1., Color32::GRAY); +const OUTLINE: (f32, Color32) = (3., Color32::GRAY); fn rule_editor(ui: &mut Ui, rule: &mut Rule, cells: &[CellData]) { let cells_y = rule.from.height(); let cells_x = rule.from.width();