MochiLibraries / Mochi.DearImGui

Automatically generated low-level C# bindings for Dear ImGui
MIT License
26 stars 8 forks source link

Duplicate ImGuiKey enum and odd naming when generating ImGui 1.89.1 (docking) #6

Closed marpe closed 1 year ago

marpe commented 1 year ago

The generated bindings for the latest version of ImGui (9964740a47fda96ee937cfea272ccac85dc6a500) results in duplicate ImGuiKey enums.

One that's empty, ImGuiKey_0, and ImGuiKey_1 which contains the expected values except the names are prefixed with yet another ImGuiKey_. So the full name of a key is e.g ImGuiKey_1.ImGuiKey_PrintScreen. It works, but I'd prefer the old naming.

What are your thoughts?

Really appreciate the work you've done, thank you!

PathogenDavid commented 1 year ago

Hello, thank you for the kind words and for the report!

Short version:

I'm pretty swamped right now so a proper fix will have to come later, but I've pushed a workaround for now as https://github.com/MochiLibraries/Mochi.DearImGui/commit/6bf59cb79eb491f8071324adb781473cc453e9dc

I put a prerelease package on NuGet.org Mochi.DearImGui v0.0.3-alpha0

(This package should be fine, but I'm labeling it as prerelease since I didn't test it as thoroughly as I typically would.)


As for the long version, there's actually two issues here:

  1. The ImGuiKey_0 vs ImGuiKey_1: Turns out I'm not handling forward declarations of enums correctly (they aren't common at all since you can't even use them with the bare enum Name {...}; syntax.)
  2. The extra ImGuiKey_: Removing the prefixes is handled by ImGuiEnumTransformation, which identifies candidate enums based on the typedef int ImGuiEnumName;...enum ImGuiEnumName_ pattern Omar usually uses, but 1.89 broke this convention for ImGuiKey as an experiment.

The proper fix for the first one will have to happen in Biohazrd. For now I just special-cased identifying the useless forward declaration and deleting it.

The proper fix for the second one will depend on whether Omar decides to go through with propagating that pattern change to other enums in Dear ImGui. (As that commit notes, this is an experiment to see if it causes any problems.) For now I just special-cased renaming constants in that enum alone.

marpe commented 1 year ago

Thanks for the prompt response! I'll look try out the workaround

marpe commented 1 year ago

Just realized I forgot to loop back on this, the workaround works fine, thank you! 👍🏻