dear-imgui.hs icon indicating copy to clipboard operation
dear-imgui.hs copied to clipboard

Auto-generation of bindings

Open sheaf opened this issue 4 years ago • 9 comments

I started looking at imgui.h. It's large. I don't think it's reasonable to achieve feature completeness, even less maintainability, without auto-generating at least some portion of the bindings. We could rely on cimgui, or generate directly from the headers. This would also allow easier access to different branches of ImGui, such as the docking branch which supports multi-viewport.

I haven't looked too much into it, but for cimgui here are some possible steps:

  • parse structs_and_enums and define corresponding Haskell types
    • a newtype around CInt for each enum type, with the corresponding pattern synonyms
    • ADTs for structs
  • parse typedefs_dicts and define Haskell type synonyms
  • (the hard part) parse definitions and use them to generate bindings like the ones that currently exist in the main DearImGui.hs file.

sheaf avatar Jan 27 '21 00:01 sheaf

The definitions doesn't seem to contains all the imgui.h functions, for example it doesn't have SliderFloat. Should we add an extra step to also generate the user facing functions?

TristanCacqueray avatar Jan 27 '21 15:01 TristanCacqueray

I'll also add that there's always the option pre-generate a starting point and then maintain by hand

ocharles avatar Jan 27 '21 15:01 ocharles

Honestly I'm leaning towards using the headers, the cimgui stuff seems a bit limited...

sheaf avatar Jan 27 '21 17:01 sheaf

The definitions doesn't seem to contains all the imgui.h functions, for example it doesn't have SliderFloat. Should we add an extra step to also generate the user facing functions?

SliderFloat seems to be included:

  "igSliderFloat": [
    {
      "args": "(const char* label,float* v,float v_min,float v_max,const char* format,ImGuiSliderFlags flags)",
      "argsT": [
        {
          "name": "label",
          "type": "const char*"
        },
        {
          "name": "v",
          "type": "float*"
        },
        {
          "name": "v_min",
          "type": "float"
        },
        {
          "name": "v_max",
          "type": "float"
        },
        {
          "name": "format",
          "type": "const char*"
        },
        {
          "name": "flags",
          "type": "ImGuiSliderFlags"
        }
      ],
      "argsoriginal": "(const char* label,float* v,float v_min,float v_max,const char* format=\"%.3f\",ImGuiSliderFlags flags=0)",
      "call_args": "(label,v,v_min,v_max,format,flags)",
      "cimguiname": "igSliderFloat",
      "defaults": {
        "flags": "0",
        "format": "\"%.3f\""
      },
      "funcname": "SliderFloat",
      "location": "imgui:511",
      "namespace": "ImGui",
      "ov_cimguiname": "igSliderFloat",
      "ret": "bool",
      "signature": "(const char*,float*,float,float,const char*,ImGuiSliderFlags)",
      "stname": ""
    }

sheaf avatar Jan 27 '21 17:01 sheaf

Code generation would be of great help of course. However, the documentation will be lacking, since it is so unstructured and ad hoc in the headers.

dpwiz avatar Apr 16 '21 14:04 dpwiz

If I understood correctly, in dear-imgui's latest release (5 hours ago) they announced a new "exciting project": Dear Bindings: alternative binding generator for C and other languages.

I thought it might be relevant to this thread 🙂

alt-romes avatar Jul 04 '23 20:07 alt-romes

They've been around for a while, yes. Perhaps they are more mature now and it is worth taking a look again.

(Also #146)

dpwiz avatar Jul 04 '23 20:07 dpwiz

I think I can hack a package for both of the JSON formats and then we'll see how process it into Haskell code.

When the bulk is automated away, maybe it would be even worth it to have multiple packages in different styles.

dpwiz avatar Jul 04 '23 20:07 dpwiz

I've made the parser and now trying to get a handle on its C-based bindings and how to generate them.

dpwiz avatar Jul 10 '23 07:07 dpwiz