jakobhellermann / bevy-inspector-egui

Inspector plugin for the bevy game engine
Apache License 2.0
1.19k stars 173 forks source link

`Option<T>` not handled properly #10

Closed thorlucas closed 3 years ago

thorlucas commented 3 years ago

It seems that, while we can revert an Option<T> back to None, there is no way to convert it back to Some(...).

Screen Shot 2021-04-11 at 6 48 18 PM Screen Shot 2021-04-11 at 6 48 27 PM

Perhaps Option<T> should be handled by a checkbox (indicating None when off, and Some when on), and a textbox that appears to the right of it when on.

jakobhellermann commented 3 years ago

The option inspectable can be configured using the OptionAttributes which have a replacement field.

You can do

#[derive(Inspectable)]
struct Data {
    #[inspectable(replacement = option_replacement as fn() -> f32)]
    option: Option<f32>,
    #[inspectable(replacement = String::default as fn() -> String)]
    option2: Option<String>,
}
fn option_replacement() -> f32 {
    0.0
}

(the as fn() -> _ is because of some rustc type inference quirk)

thorlucas commented 3 years ago

I somehow missed this in the demo. Thanks!