cimgui

用于 imgui 的 c-api(https://github.com/ocornut/imgui)查找:https://github... for imgui (https://github.com/ocornut/imgui) lookat: https://github.com/cimgui for other widgets」

Github stars Tracking Chart

cimgui

这是为出色的 C++ 立即模式 gui Dear ImGui 编程生成的一个瘦 c-api 包装器。所有 imgui.h 函数都以编程方式包装。生成的文件为:cimgui.cpp,用于 C 编译的 cimgui.h。另外,还可以使用函数定义信息和 structs_and_enums.lua 来帮助创建绑定。该库旨在作为中间层,以便能够使用其他可以与 C 交互的语言的 Dear ImGui(例如 D -- 参见 D-binding)。

历史:

cimgui 最初是由 Stephan Dilly 作为手写代码开发的,但后来由 sonoro1234 变成了自动生成的版本,以便更轻松地跟上 imgui(让用户选择所需的分支并提交)

注意:

编译

使用 generator

  • 仅当您想要的 imgui 版本不同于所提供的 imgui 版本时才需要(在编译之前),否则已经完成了生成。
  • 您将需要 LuaJIT(https://github.com/LuaJIT/LuaJIT.git 最好是 2.1 分支)或在 https://luapower.com/luajit/download 中为 linux/macOS/windows 预编译
  • 您还需要使用 C++ 编译器进行预处理:gcc(例如,在 Windows MinGW-W64-builds 中)、clang 或 cl(MSVC)。 (此仓库是用 gcc 完成的)
  • 将 imgui 文件夹更新为所需的版本。
  • 在 Windows 上编辑 generator/generator.bat,在 Linux 上编辑 generator/generator.sh,以便在 gcc、clang 或 cl 之间进行选择,并选择所需的实现以及是否生成 imgui_internal。
  • 编辑 config_generator.lua 以添加您选择的实现所需的 includes(vulkan 需要)。
  • 在您的 PATH 上运行使用了 gcc、clang 或 cl 和 LuaJIT 的 generator.bat 或 generator.sh。
  • 结果生成了一些文件:cimgui.cpp 和 cimgui.h 用于编译,以及一些 lua/json 文件,其中包含有关绑定的信息:带有函数信息的 definitions.json,带有结构和枚举信息的 structs_and_enums.json,带有函数的 impl_definitions.json 从实施信息。

生成绑定

用法

  • 通过在 ig 前面添加 ig 来使用原始 imgui.h 中 ImGui C++ 命名空间中的任何方法
  • 方法具有相同的参数列表和返回值(如果可能)
  • 属于一个结构的函数具有一个额外的第一个参数,该第一个参数带有指向该结构的指针。
  • 在函数按值返回 UDT(用户定义类型)的情况下,一些编译器抱怨说,因此生成该函数时将指向 UDT 类型的指针作为第一个参数(如果属于结构则为第二个)。

基于 cimgui 的示例绑定

基于 cimgui 的 C 示例



(The first version translated by vz on 2020.08.08)

Overview

Name With Ownercimgui/cimgui
Primary LanguageLua
Program languageC++ (Language Count: 7)
PlatformLinux, Mac, Windows
License:MIT License
Release Count94
Last Release Name1.90.6 (Posted on )
First Release Namev1.38 (Posted on 2015-04-21 23:46:29)
Created At2015-04-07 14:06:21
Pushed At2024-05-10 15:12:06
Last Commit At2024-05-10 17:11:32
Stargazers Count1.4k
Watchers Count42
Fork Count269
Commits Count872
Has Issues Enabled
Issues Count166
Issue Open Count12
Pull Requests Count76
Pull Requests Open Count2
Pull Requests Close Count18
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

cimgui Build Status

This is a thin c-api wrapper programmatically generated for the excellent C++ immediate mode gui Dear ImGui.
All imgui.h functions are programmatically wrapped.
Generated files are: cimgui.cpp, cimgui.h for C compilation. Also for helping in bindings creation, definitions.lua with function definition information and structs_and_enums.lua.
This library is intended as a intermediate layer to be able to use Dear ImGui from other languages that can interface with C (like D - see D-binding)

History:

Initially cimgui was developed by Stephan Dilly as hand-written code but lately turned into an auto-generated version by sonoro1234 in order to keep up with imgui more easily (letting the user select the desired branch and commit)

Notes:

compilation

using generator

  • this is only needed (before compilation) if you want an imgui version different from the one provided, otherwise generation is already done.
  • you will need LuaJIT (https://github.com/LuaJIT/LuaJIT.git better 2.1 branch) or precompiled for linux/macOS/windows in https://luapower.com/luajit/download
  • you can use also a C++ compiler for doing preprocessing: gcc (In windows MinGW-W64-builds for example), clang or cl (MSVC) or not use a compiler (experimental nocompiler option) at all. (this repo was done with gcc)
  • update imgui folder to the version you desire.
  • edit generator/generator.bat on windows, or generator/generator.sh on linux, to choose between gcc, clang, cl or nocompiler and to choose desired implementations.
  • edit config_generator.lua for adding includes needed by your chosen implementations.
  • Run generator.bat or generator.sh with gcc, clang or cl and LuaJIT on your PATH.
  • as a result some files are generated: cimgui.cpp and cimgui.h for compiling and some lua/json files with information about the binding: definitions.json with function info, structs_and_enums.json with struct and enum info, impl_definitions.json with functions from the implementations info.

generate binding

definitions description

  • It is a collection in which key is the cimgui name that would result without overloadings and the value is an array of overloadings (may be only one overloading)
  • Each overloading is a collection. Some relevant keys and values are:
    • stname : the name of the struct the function belongs to (will be "" if it is top level in ImGui namespace)
    • ov_cimguiname : the overloaded cimgui name (if absent it would be taken from cimguiname)
    • cimguiname : the name without overloading (this should be used if there is not ov_cimguiname)
    • ret : the return type
    • retref : is set if original return type is a reference. (will be a pointer in cimgui)
    • argsT : an array of collections (each one with type: argument type and name: the argument name)
    • args : a string of argsT concatenated and separated by commas
    • call_args : a string with the argument names separated by commas for calling imgui function
    • defaults : a collection in which key is argument name and value is the default value.
    • manual : will be true if this function is hand-written (not generated)
    • isvararg : is set if some argument is a vararg
    • constructor : is set if the function is a constructor for a class
    • destructor : is set if the function is a destructor for a class
    • templated : is set if the function belongs to a templated class (ImVector)
    • templatedgen: is set if the function belongs to a struct generated from template (ImVector_ImWchar)
    • nonUDT : if present can be 1 or 2 (explained meaning in usage) if return type was a user defined type

structs_and_enums description

  • Is is a collection with two items:
    • under key enums we get the enums collection in which each key is the enum tagname and the value is an array of the ordered values represented as a collection with keys
      • name : the name of this enum value
      • value : the C string
      • calc_value : the numeric value corresponding to value
    • under key structs we get the structs collection in which the key is the struct name and the value is an array of the struct members. Each one given as a collection with keys
      • type : the type of the struct member
      • template_type : if type has a template argument (as ImVector) here will be
      • name : the name of the struct member

usage

  • use whatever method is in ImGui c++ namespace in the original imgui.h by prepending ig
  • methods have the same parameter list and return values (where possible)
  • functions that belong to a struct have an extra first argument with a pointer to the struct.
  • where a function returns UDT (user defined type) by value some compilers complain so another function with the name function_name_nonUDT is generated accepting a pointer to the UDT type as the first argument.
  • also is generated function_name_nonUDT2 which instead of returning the UDT type returns a simple version (without functions) called UDTType_Simple (ImVec2_Simple for ImVec2)

example bindings based on cimgui

To the top