Skip to content

Commit

Permalink
Derive list of sketches, and allow sketch selection in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
kneitinger committed Nov 3, 2021
1 parent 8faa5f0 commit e772631
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
13 changes: 13 additions & 0 deletions sketch_derive/src/codegen/sketchlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ pub fn sketchlist_struct_tokens(sketches: &[SketchListEntry]) -> proc_macro2::To
})
.collect();

let sketch_names: Vec<proc_macro2::TokenStream> = sketches
.iter()
.map(|sketch| {
let s_name = sketch.sketch.to_string();
quote! { #s_name.to_string() }
})
.collect();

quote! {
pub struct SketchList {}

Expand All @@ -92,6 +100,11 @@ pub fn sketchlist_struct_tokens(sketches: &[SketchListEntry]) -> proc_macro2::To
_ => Err(SketchError::Todo("sdfs".to_string())),
}
}
pub fn sketch_names() -> Vec<String> {
vec![
#(#sketch_names),*
]
}
}
}
}
24 changes: 24 additions & 0 deletions ui/src/app/sketch_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,48 @@ use nightsketch::*;

pub struct SketchControl {
sketch: Box<dyn Sketch>,
sketch_name: String,
params: Vec<ParamMetadata>,
sketch_names: Vec<String>,
pub needs_render: bool,
}

impl Default for SketchControl {
fn default() -> Self {
let sketch = SketchList::default_sketch();
let sketch_name = "Blossom".to_string();
let params = sketch.param_metadata();
let sketch_names = SketchList::sketch_names();
SketchControl {
sketch,
sketch_name,
params,
sketch_names,
needs_render: true,
}
}
}

impl SketchControl {
fn param_grid_contents(&mut self, ui: &mut egui::Ui) {
ui.label("Sketch");
let val = self.sketch_name.to_string();
egui::ComboBox::from_label("")
.selected_text(self.sketch_name.to_string())
.show_ui(ui, |ui| {
for n in &self.sketch_names {
ui.selectable_value(&mut self.sketch_name, n.to_string(), n);
}
});
if val != self.sketch_name {
self.sketch = SketchList::sketch_by_name(&self.sketch_name).unwrap();
self.needs_render = true;
self.params = self.sketch.param_metadata();
}
ui.end_row();
// Leave some visual space without a separator
ui.end_row();

for param in &self.params {
let sketch = &mut self.sketch;
let id = param.id;
Expand Down

0 comments on commit e772631

Please sign in to comment.