imgui-java icon indicating copy to clipboard operation
imgui-java copied to clipboard

[Build] Initial implementation with API generation

Open SpaiR opened this issue 2 years ago • 7 comments

Description

At the moment binding is created manually in Java code. And it becomes very frustrating to do, when you need to copy paste the same method 5 more times, just to implement "optional" args behaviour.

The new approach introduces an API for automatic binding generation. All is required is to provide a metadata file in a proper syntax. Stuff still need to be done manually. Yet everything becomes much easier when to implement methods with "optional" args you just need to mark those args as optional.

TODO

  • [ ] Struct fields generation
  • [ ] Enums generation
  • [ ] Convert Dear ImGui binding to the new approach (without extensions)

Since generation API mostly automates things around the old approach, they can co-exist.

Type of change

  • [ ] Minor changes or tweaks (quality of life stuff)
  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [X] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] This change requires a documentation update

SpaiR avatar May 27 '22 09:05 SpaiR

Just saw this, looks very interesting.

tlf30 avatar May 30 '22 15:05 tlf30

Excited for this!

calvertdw avatar Mar 03 '23 15:03 calvertdw

Wondering how this is PR is going, since I want to use some features only available on a more recent ImPlot version :)

Semisol avatar Jul 23 '23 17:07 Semisol

Hi @SpaiR, do you think this binding generator might be helpful? https://github.com/dearimgui/dear_bindings

phraktle avatar Jan 07 '24 21:01 phraktle

Hi @SpaiR, do you think this binding generator might be helpful? https://github.com/dearimgui/dear_bindings

@phraktle

Hello. This is a generator for definitions. It helps to avoid manual routines when you need to go through header files. However, for the purpose of this PR, it's useless since I've already created such a generator. I'm using clang++ and its ast-dump functionality, and I find the result more robust than those of Python scripts.

For example, this is how I extract enums:

{
    "@type" : "AstEnumDecl",
    "offset" : 121559,
    "name" : "ImGuiTreeNodeFlags_",
    "decls" : [ {
      "@type" : "AstFullComment",
      "offset" : 121495,
      "decls" : [ {
        "@type" : "AstParagraphComment",
        "offset" : 121495,
        "decls" : [ {
          "@type" : "AstTextComment",
          "offset" : 121495,
          "text" : " Flags for ImGui::TreeNodeEx(), ImGui::CollapsingHeader*()"
        } ]
      } ]
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 121585,
      "name" : "ImGuiTreeNodeFlags_None",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 0,
      "value" : "0",
      "evaluatedValue" : "0"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 121634,
      "name" : "ImGuiTreeNodeFlags_Selected",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 1,
      "value" : "1 << 0",
      "evaluatedValue" : "1"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 121710,
      "name" : "ImGuiTreeNodeFlags_Framed",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 2,
      "value" : "1 << 1",
      "evaluatedValue" : "2"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 121824,
      "name" : "ImGuiTreeNodeFlags_AllowItemOverlap",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 3,
      "value" : "1 << 2",
      "evaluatedValue" : "4"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 121943,
      "name" : "ImGuiTreeNodeFlags_NoTreePushOnOpen",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 4,
      "value" : "1 << 3",
      "evaluatedValue" : "8"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 122104,
      "name" : "ImGuiTreeNodeFlags_NoAutoOpenOnLog",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 5,
      "value" : "1 << 4",
      "evaluatedValue" : "16"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 122288,
      "name" : "ImGuiTreeNodeFlags_DefaultOpen",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 6,
      "value" : "1 << 5",
      "evaluatedValue" : "32"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 122371,
      "name" : "ImGuiTreeNodeFlags_OpenOnDoubleClick",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 7,
      "value" : "1 << 6",
      "evaluatedValue" : "64"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 122461,
      "name" : "ImGuiTreeNodeFlags_OpenOnArrow",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 8,
      "value" : "1 << 7",
      "evaluatedValue" : "128"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 122668,
      "name" : "ImGuiTreeNodeFlags_Leaf",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 9,
      "value" : "1 << 8",
      "evaluatedValue" : "256"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 122790,
      "name" : "ImGuiTreeNodeFlags_Bullet",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 10,
      "value" : "1 << 9",
      "evaluatedValue" : "512"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 122883,
      "name" : "ImGuiTreeNodeFlags_FramePadding",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 11,
      "value" : "1 << 10",
      "evaluatedValue" : "1024"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 123101,
      "name" : "ImGuiTreeNodeFlags_SpanAvailWidth",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 12,
      "value" : "1 << 11",
      "evaluatedValue" : "2048"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 123428,
      "name" : "ImGuiTreeNodeFlags_SpanFullWidth",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 13,
      "value" : "1 << 12",
      "evaluatedValue" : "4096"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 123568,
      "name" : "ImGuiTreeNodeFlags_NavLeftJumpsBackHere",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 14,
      "value" : "1 << 13",
      "evaluatedValue" : "8192"
    }, {
      "@type" : "AstEnumConstantDecl",
      "offset" : 123910,
      "name" : "ImGuiTreeNodeFlags_CollapsingHeader",
      "qualType" : "ImGuiTreeNodeFlags_",
      "order" : 15,
      "value" : "ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog",
      "evaluatedValue" : "26"
    } ]
  }

There's no need to say that it can generate definitions for any header files, even those not related to Dear ImGui.

I understand your concerns about this PR. I, myself, am not pleased with how it is progressing. The reason for its prolonged development is time. It's hard to find the motivation to work on it in my spare time. During my working hours, I have many more responsibilities. Still, I believe the PR will be completed eventually. After that, tasks like binding updates will become a routine thing.

At the moment, I've fully covered the function generation for the main ImGui class. Now, I need to do the same for struct fields.

SpaiR avatar Jan 08 '24 07:01 SpaiR

Hi @SpaiR, I have increased my monthly contribution to the project, as I find it very useful and would love to see it evolve! Your work is much appreciated.

I would encourage others to show their appreciation as well – even a little goes a long way in motivation: https://ko-fi.com/spair

phraktle avatar Jan 09 '24 08:01 phraktle

We believe in you! :smile:

calvertdw avatar Feb 14 '24 17:02 calvertdw