diff --git a/Cargo.lock b/Cargo.lock index 68886af..6c19a55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2744,6 +2744,7 @@ version = "0.1.0" dependencies = [ "eframe", "petri", + "rand", ] [[package]] diff --git a/uscope/Cargo.toml b/uscope/Cargo.toml index df2f989..c5f5ad4 100644 --- a/uscope/Cargo.toml +++ b/uscope/Cargo.toml @@ -8,3 +8,4 @@ edition = "2021" [dependencies] petri = { path = "../petri" } eframe = "0.27.2" +rand = "0.8.5" diff --git a/uscope/src/main.rs b/uscope/src/main.rs index 7c26fb9..a71cb9d 100644 --- a/uscope/src/main.rs +++ b/uscope/src/main.rs @@ -1,8 +1,10 @@ use eframe::{ egui::{CentralPanel, Color32, Painter, Pos2, Rect, Sense, SidePanel, Slider, Ui, Vec2}, + epaint::Hsva, NativeOptions, }; use petri::{Cell, Chunk, Dish, Rule, RulePattern, CHUNK_SIZE}; +use rand::prelude::*; fn main() { eframe::run_native( @@ -53,12 +55,20 @@ impl eframe::App for UScope { ui.heading("Cells"); for (i, cell) in self.celltypes.iter_mut().enumerate() { ui.horizontal(|ui| { - ui.set_width(100.); + ui.set_width(120.); ui.radio_value(&mut self.brush.0, i as u16, ""); ui.text_edit_singleline(&mut cell.name); ui.color_edit_button_srgba(&mut cell.color); }); } + if ui.button("add cell").clicked() { + let h = random::(); + let s = random::() * 0.5 + 0.5; + let v = random::() * 0.5 + 0.5; + let color = Hsva::new(h, s, v, 1.).into(); + let name = format!("cell #{}", self.celltypes.len()); + self.celltypes.push(CellData { name, color }) + } ui.heading("Rules"); for rule in &mut self.dish.rules { rule_editor(ui, rule, &self.celltypes);