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星跟蹤圖

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)

主要指標

概覽
名稱與所有者cimgui/cimgui
主編程語言Lua
編程語言C++ (語言數: 7)
平台Linux, Mac, Windows
許可證MIT License
所有者活动
創建於2015-04-07 14:06:21
推送於2025-07-14 09:30:45
最后一次提交2025-07-14 09:41:32
發布數125
最新版本名稱1.92.1 (發布於 )
第一版名稱v1.38 (發布於 2015-04-21 23:46:29)
用户参与
星數1.7k
關注者數42
派生數331
提交數1k
已啟用問題?
問題數191
打開的問題數15
拉請求數79
打開的拉請求數2
關閉的拉請求數26
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

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