zmitchell / splatter

A Rust framework for creating generative art
0 stars 0 forks source link

Make a macro for creating `egui` control panels from `Model` structs #49

Open zmitchell opened 11 months ago

zmitchell commented 11 months ago

Creating a little control panel for each sketch is tedious and repetitive. You're likely to just want a slider, a text box, etc to tweak the values in your model. I'm imagining a derive macro that would generate this for you.

The usage of the macro would look something like this:

#[derive(Debug, splatter::ControlPanel)]
pub struct Model {
    /// Would generate a slider with range [0.0, 1.0] and label "foo"
    #[control(type = "slider", max = 1.0, min = 0.0)]
    foo: f32,

    /// Would generate a text box with label "bar" and a "Set" button
    #[control(type = "box")]
    bar: usize

    /// A field that we don't want to appear in the control panel
    baz: SomeType
}

Then in update and view you would do something like:

fn update(...) {
    model.update_from_control_panel();
}

fn view(...) {
    model.draw_control_panel();
}

We also need to think about how you could use the derive macro and also add other controls like "start", "stop", "reset", etc without needing to do the entire control panel manually.