add rule copy button

This commit is contained in:
Crispy 2024-05-04 11:22:18 +02:00
parent e2869af4a7
commit 3d9fd8d311
2 changed files with 15 additions and 4 deletions

View file

@ -18,7 +18,7 @@ pub struct Chunk {
pub contents: Box<[[Cell; CHUNK_SIZE]; CHUNK_SIZE]>,
}
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Rule {
#[serde(default)]
pub name: String,

View file

@ -174,16 +174,27 @@ impl eframe::App for UScope {
ui.heading("Rules");
let mut to_remove = None;
let mut to_clone = None;
for (i, rule) in self.dish.rules.iter_mut().enumerate() {
ui.separator();
rule_editor(ui, rule, &self.cell_types, &self.dish.cell_groups);
if ui.button("delete").clicked() {
to_remove = Some(i);
}
ui.horizontal(|ui| {
if ui.button("delete").clicked() {
to_remove = Some(i);
}
if ui.button("copy").clicked() {
to_clone = Some(i);
}
});
}
if let Some(i) = to_remove {
self.dish.rules.remove(i);
}
if let Some(i) = to_clone {
let mut new_rule = self.dish.rules[i].clone();
new_rule.enabled = false;
self.dish.rules.push(new_rule);
}
ui.separator();
if ui.button("add rule").clicked() {
self.dish.rules.push(Rule::new());