Skip to content

Conversation

@weshoke
Copy link
Contributor

@weshoke weshoke commented Aug 15, 2024

  • Extracted ImGui API (functions and enums) as a JSON structure
  • Created a Python script to generate bindings to generate the C++ bindings with Pybind11
  • Changed the way ImVec2 and ImVec4 are bound to use type_caster

There are still some functions listed as #TODO for the bindings, but this covers 95% of them.

Before I continue further, looking for feedback on this idea.

@nmwsharp
Copy link
Owner

This is awesome!! Thanks as always for the contribution!

Sorry for not saying anything sooner, I went down a rabbit hole of checking out the pre-existing community ImGui bindings generators. Mainly (https://github.com/cimgui/cimgui/tree/docking_inter/generator/output and https://pthom.github.io/litgen/litgen_book/00_00_intro.html#). However, I don't think either makes sense out of the box for our needs. The cimgui C-interface is a bit too much work to bind to, and the litgen is a little to new for me to bet on it, plus its naming schemes are different which would break all existing code.

Anyway, onto this contribution. Generally I think it looks very reasonable. I certainly can't say I checked everything, but the functions and generator setups I spot-checked seem reasonable.

My high-level question is what work would be necessary to maintain these bindings in the future? (Especially in a hypothetical situation if you were to sadly stop contributing). Where doesimgui-bindings.json come from and how should we updated it as ImGui evolves?

Do you anticipate any backwards compatibility-breaks with these changes? (I think small breaks are fine for the imgui bindings, especially if we are moving to a standard that should not break in the future)

@weshoke
Copy link
Contributor Author

weshoke commented Nov 20, 2024

@nmwsharp Shortly after I made this PR, I found out about https://github.com/dearimgui/dear_bindings . This will be a maintainable source for generating the imgui bindings I'm pretty sure. I haven't looked in to how to use it, but I think making use of it instead of the JSON data I generated would be best.

@nmwsharp
Copy link
Owner

I looked into that one as well (along with the cimgui & litgen projects linked above). I'm a little wary of depending on an external project that could be abandoned, but that may be the lesser-evil compared to doing it ourselves.

Are you thinking to write a Python generator from their .json file? That could definitely work although it's hard to judge just how much work that would be.

I like that the cimgui project has a .json for ImPlot as well, it looks like this one is just ImGui proper. Unfortunately cimgui's json files seem to only hold their C-translated names, whereas Polyscope's existing bindings use the true ImGUI C++ names verbatim.

Very interested in your thoughts here :) I'd love to set up an automated solution but am wary about long-term maintainability.

@nmwsharp
Copy link
Owner

Oh actually I lied, it looks like the cimgui .json does indeed have the original function name as a field. We'd have to do some translating, but I think it could work. I'm a bit more inclined to trust that project given that it has persisted for almost a decade, and seems to have the most uesrs.

@weshoke
Copy link
Contributor Author

weshoke commented Nov 21, 2024

It was really a trivial amount of work to generate the JSON file in this PR. Although the frontier LLM models change over time, one way to help would be to include a prompt with instructions for how to generate the JSON file, or at least get most of the data out so that it could be added to the JSON file.

ImGui isn't changing that fast. A prompt could easily take as input the JSON file and a query against ImGui.h that asks for an enums or functions not found in the JSON. That would be a quick way to see what needs to be updated.

@nmwsharp
Copy link
Owner

Any updated thoughts on this? I'm looking to release a new version soon and it would be a good time to update these bindings.

I spent a little while looking into manual bindings generators (you can see some experiments in this branch). Main takeaway is that will require a fair amount of work to massage C-style bindings back into Pythonic or even C++-style pybind11-friendly form. I'm sure it's possible, but it was goin to take more time than I have.

I'm still a little wary about maintainability/editability of this setup by folks other than you, but as you say ImGui is not rapidly-changing or anything :) I'd be okay with merging this setup (or something like it) if you think it's good-to-go.

@nmwsharp
Copy link
Owner

By the way I'm also looking to include bindings ImPlot. I suppose it should be easy to generate bindings for that too with a similar setup?

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

Successfully merging this pull request may close these issues.

2 participants