add new cell types

This commit is contained in:
Crispy 2024-05-01 22:43:03 +02:00
parent 611d53c453
commit 79cd0a8fe4
3 changed files with 13 additions and 1 deletions

1
Cargo.lock generated
View file

@ -2744,6 +2744,7 @@ version = "0.1.0"
dependencies = [
"eframe",
"petri",
"rand",
]
[[package]]

View file

@ -8,3 +8,4 @@ edition = "2021"
[dependencies]
petri = { path = "../petri" }
eframe = "0.27.2"
rand = "0.8.5"

View file

@ -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::<f32>();
let s = random::<f32>() * 0.5 + 0.5;
let v = random::<f32>() * 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);