Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zmitchell opened this issue Sep 28, 2023 · 0 comments
Open

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

zmitchell opened this issue Sep 28, 2023 · 0 comments

Comments

@zmitchell
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant