aclysma / imgui-inspect

An inspector UI using imgui in Rust
Apache License 2.0
70 stars 9 forks source link

Deriving an empty struct crashes the proc-macro #2

Closed Uriopass closed 4 years ago

Uriopass commented 4 years ago

It also says "Message not implemented" How to reproduce:

#[derive(Inspect)]
struct Empty; // crashes the proc macro

I'm using it because the empty struct is used as a flag component in an ecs. What I guess should be derived:

impl InspectRenderDefault<Empty> for Empty {
    fn render(data: &[&Empty], label: &'static str, ui: &Ui, args: &InspectArgsDefault) {
        ui.text(imgui::im_str!("Empty"));
    }

    fn render_mut(
        data: &mut [&mut Empty],
        label: &'static str,
        ui: &Ui,
        args: &InspectArgsDefault,
    ) -> bool {
        ui.text(imgui::im_str!("Empty");
        false
    }
}

Or something alike.

aclysma commented 4 years ago

I pushed a change https://github.com/aclysma/imgui-inspect/commit/134c848929ead15d6cdb6cfea03758bf37f6fad1 that avoids the panic by treating a unit struct like an empty struct with named fields.

A tuple-style struct is still not implemented i.e. "Struct(x, y)" although I think a more sophisticated implementation might allow for this if the names for the fields are annotated somehow. For the time being, someone would need to manually implement the Inspect trait for such a type.

Happy to push this as 0.3.1 if this works well for you!

Uriopass commented 4 years ago

Thanks ! Works forme, I did a macro in the meantime for this usecase, and I'd be happy to remove it. :)