dearimgui / dear_bindings

C header (and language binding metadata) generator for Dear ImGui
MIT License
221 stars 12 forks source link

Default struct values #55

Open pdoane opened 8 months ago

pdoane commented 8 months ago

There are not many struct inputs to ImGui, but default values would be helpful (e.g. ImFontConfig).

The comments have the default values made by the C++ constructor, so maybe it's possible to parse/extract?

ShironekoBen commented 8 months ago

That's a nice idea, definitely, but I'm not sure the comments are consistent enough to make parsing them reliable. Do you actually need the values themselves, or would exposing the ImFontConfig() constructor be enough for your use-case?

I'm thinking that might be possible with some in-place new shenanigans - something like:

void ImFontConfig_Construct(ImFontConfig* config)
{
    new (config) ImFontConfig();
}
pdoane commented 8 months ago

The values are better as they can go directly into the struct definition but exposing the constructor works and future-proofs things.

ocornut commented 8 months ago

I’m also not against making comments more consistent. In theory would be using more default value at member declaration site (now that the library requires c++11), but when i tried using those assignments i found it often led to assigning half in headers and the other half requires constructor code either way, so its not easy applicable consistently and it doesn’t feel nice to have that split. I also don’t think we can assign default values for bitfield variables.

Enforcing a constructor call seems like the robust and easier thing to do, and people would naturally understand it, and possibly if constructor bames are standardized some bindings may automate or wrap the call in a way that’s more natural to the language?