collapsable rule editors
This commit is contained in:
parent
5c282a28ed
commit
c345d671dd
2 changed files with 163 additions and 143 deletions
|
@ -27,8 +27,8 @@ pub struct Rule {
|
|||
variants: Vec<SubRule>,
|
||||
pub enabled: bool,
|
||||
// probability: u8
|
||||
pub flip_h: bool,
|
||||
pub flip_v: bool,
|
||||
pub flip_x: bool,
|
||||
pub flip_y: bool,
|
||||
pub rotate: bool,
|
||||
}
|
||||
|
||||
|
@ -121,8 +121,8 @@ impl Rule {
|
|||
enabled: false,
|
||||
base: SubRule::new(),
|
||||
variants: vec![SubRule::new()],
|
||||
flip_h: false,
|
||||
flip_v: false,
|
||||
flip_x: false,
|
||||
flip_y: false,
|
||||
rotate: false,
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ impl Rule {
|
|||
variants.extend_from_slice(&new);
|
||||
}
|
||||
|
||||
if self.flip_h {
|
||||
if self.flip_x {
|
||||
transform_variants(&mut self.variants, |b| {
|
||||
let mut new = b.clone();
|
||||
for y in 0..new.height {
|
||||
|
@ -204,7 +204,7 @@ impl Rule {
|
|||
new
|
||||
});
|
||||
}
|
||||
if self.flip_v {
|
||||
if self.flip_y {
|
||||
transform_variants(&mut self.variants, |b| {
|
||||
let mut new = b.clone();
|
||||
for y in 0..new.height {
|
||||
|
@ -302,7 +302,7 @@ impl Dish {
|
|||
(RuleCellFrom::One(Cell(0)), RuleCellTo::One(Cell(1))),
|
||||
],
|
||||
},
|
||||
flip_h: true,
|
||||
flip_x: true,
|
||||
..Rule::new()
|
||||
},
|
||||
];
|
||||
|
|
|
@ -10,7 +10,7 @@ use eframe::{
|
|||
epaint::Hsva,
|
||||
NativeOptions,
|
||||
};
|
||||
use egui::PointerButton;
|
||||
use egui::{collapsing_header::CollapsingState, PointerButton};
|
||||
use native_dialog::FileDialog;
|
||||
use rand::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -176,16 +176,16 @@ impl eframe::App for UScope {
|
|||
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);
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("delete").clicked() {
|
||||
to_remove = Some(i);
|
||||
}
|
||||
if ui.button("copy").clicked() {
|
||||
to_clone = Some(i);
|
||||
}
|
||||
});
|
||||
// ui.separator();
|
||||
rule_editor(
|
||||
ui,
|
||||
rule,
|
||||
i,
|
||||
&self.cell_types,
|
||||
&self.dish.cell_groups,
|
||||
&mut to_remove,
|
||||
&mut to_clone,
|
||||
);
|
||||
}
|
||||
if let Some(i) = to_remove {
|
||||
self.dish.rules.remove(i);
|
||||
|
@ -246,14 +246,33 @@ const CSIZE: f32 = 24.;
|
|||
const RESIZE_BUTTON_WIDTH: f32 = 8.;
|
||||
|
||||
const OUTLINE: (f32, Color32) = (2., Color32::GRAY);
|
||||
fn rule_editor(ui: &mut Ui, rule: &mut Rule, cells: &[CellData], groups: &[Vec<Option<Cell>>]) {
|
||||
ui.checkbox(&mut rule.enabled, "enable rule");
|
||||
fn rule_editor(
|
||||
ui: &mut Ui,
|
||||
rule: &mut Rule,
|
||||
index: usize,
|
||||
cells: &[CellData],
|
||||
groups: &[Vec<Option<Cell>>],
|
||||
to_remove: &mut Option<usize>,
|
||||
to_clone: &mut Option<usize>,
|
||||
) {
|
||||
let id = ui.make_persistent_id(format!("rule {index}"));
|
||||
CollapsingState::load_with_default_open(ui.ctx(), id, true)
|
||||
.show_header(ui, |ui| {
|
||||
ui.checkbox(&mut rule.enabled, &rule.name);
|
||||
if ui.button("delete").clicked() {
|
||||
*to_remove = Some(index);
|
||||
}
|
||||
if ui.button("copy").clicked() {
|
||||
*to_clone = Some(index);
|
||||
}
|
||||
})
|
||||
.body(|ui| {
|
||||
ui.text_edit_singleline(&mut rule.name);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("flip");
|
||||
if ui.checkbox(&mut rule.flip_h, "H").changed() {
|
||||
if ui.checkbox(&mut rule.flip_x, "flip X").changed() {
|
||||
rule.generate_variants();
|
||||
}
|
||||
if ui.checkbox(&mut rule.flip_v, "V").changed() {
|
||||
if ui.checkbox(&mut rule.flip_y, "flip Y").changed() {
|
||||
rule.generate_variants();
|
||||
}
|
||||
});
|
||||
|
@ -378,6 +397,7 @@ fn rule_editor(ui: &mut Ui, rule: &mut Rule, cells: &[CellData], groups: &[Vec<O
|
|||
for (a, b) in overlay_lines {
|
||||
ui.painter().line_segment([a, b], (2., Color32::WHITE));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn rule_cell_edit_from(
|
||||
|
|
Loading…
Reference in a new issue