Skip to content

Auto generated Go wrapper for Dear ImGui via cimgui

License

Notifications You must be signed in to change notification settings

gucio321/cimgui-go

 
 

Repository files navigation

Go Report Card Build Status Linter Status GoDoc Mentioned in Awesome Go

cimgui-go

This project aims to generate go wrapper for Dear ImGui.

It comes with several default backends implemented.

It works on macOS(arm64/x86), windows(x64), Arch Linux (Gnome/KDE) and Fedora Workstation 36+, idealy other linux GUI should works as well. Check out examples: cd in and go run ..

Setup

There are several dependencies you might need to install on your linux machine. Take a look here

Current solution is:

  1. Use cimgui's lua generator to generate function and struct definition as json.
  2. Generate proper go code from the definition (via manual crafted go program).
  3. Use the backend implementation from imgui.
  4. Use github workflow to compile cimgui, glfw and other C dependencies to static lib and place them in ./lib folder for further link.

Supported Backends

In order to make it easy in use, cimgui-go implemented a few imgui backends. All of them are placed in backend/ sub-packages. To see more details about usage of a specific backend, take a look at the examples.

We support the following backends:

  • GLFW. (GLFW 3.3 + OpenGL)
  • SDL2. (SDL 2 + OpenGL)
  • Ebitengine (import "github.com/AllenDang/cimgui-go/backend/ebitenbackend").

Important: Remember that various solution use different C libraries that can conflict with each other. It is recommended to not enable e.g. GLFW and SDL backends at the same time as it may result in linker crash.

Naming convention

  • For functions, 'Im/ImGui/ig' is trimmed.
  • Get prefix is also removed.
  • If function comes from imgui_internal.h, Internal prefix is added.

Pointers and Slices

Unfortunately, in C there is no way to ditinguish between a pointer and a slice. We had to bring this unpleasantness to Go as well. Our code defaults to pointers, but you can easily convert your slice to a pointer by simply &(slice[0]). You can also use imgui.SliceToPtr.

Callbacks

Please note that at the moment (November 2024) go (1.23) does not support passing annonymous functions to C via CGO. We have it workarounded by pre-generating large amount of global functions and a pool. For details see AllenDang#224 . Just be aware of the limitation that you may run out of pre-generated pool and experience a crash.

Function coverage

Currently most of the functions are generated, except memory related stuff (eg. memory allocator, storage management, etc...). If you find any function is missing, report an issue.

Generate binding

Install GNU make and run make to re-generate bunding.

Update

To update to the latest version of dependencies, run make update. After doing this, commit changes and navigate to GitHub. In Actions tab, manually trigger Compile cimgui workflows.

How does it work?

  • cwrappers/ directory holds C binding for C++ Dear ImGui libraries
  • generator bases on cwrappers/{package_name}_templates and generates all necessary GO/C code placing it in {pkgname}/ directories in the root of cimgui-go
  • libs/ contains pre-built shared libraries. cflags.go includes and uses to decrease building time.

About

Auto generated Go wrapper for Dear ImGui via cimgui

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 73.9%
  • C 16.5%
  • CMake 4.6%
  • Go 1.7%
  • PowerShell 1.4%
  • Objective-C++ 1.0%
  • Other 0.9%