Page 1 of 1

cimgui-love: another LÖVE module for DearImGui using LuaJIT FFI

Posted: Sun May 23, 2021 7:28 pm
by apicici
Hi everyone,

I put together a new LÖVE module for Dear ImGui. The module uses LuaJIT FFI instead of the Lua/C api, and wraps cimgui (a programmatically generated C-api for Dear ImGui). You can find it here.

The module is currently on version 1.82 (docking branch) of Dear ImGui and all functions exposed by cimgui should work in LÖVE. The wrappers are generated automatically (like cimgui itself) and can be easily updated for new versions of Dear ImGui.

Prebuilt binaries for the cimgui shared library and the LauJIT module are available at https://codeberg.org/apicici/cimgui-love/releases for the following systems:
  • Linux x64
  • Windows x86 and x64
  • macos x64
See the git repository for instructions on how to use the module. An example of the module in action is attached to the post.

--------------------------

The module was inspired by LuaJIT-ImGui, but does not share code with it. In particular cimgui-love it does not require any shared libraries other than cimgui, while LuaJIT-ImGui needs SDL for the LÖVE implementation.

Part of the LÖVE implementation of DearImGui is based on love-imgui, although it's done diractly in Lua.

--------------------------

Note: I only tested the module on Linux and Windows, I have no idea if it works on macos. Let me know if you are able to test it!

Re: cimgui-love: another LÖVE module for DearImGui using LuaJIT FFI

Posted: Tue May 25, 2021 10:06 am
by pgimeno
Works great! (Linux-x64, recompiled from sources).

Re: cimgui-love: another LÖVE module for DearImGui using LuaJIT FFI

Posted: Sun Aug 22, 2021 10:30 pm
by XHH
Do you have an example on how to use imgui::Combo? I'm very new to ffi.

Re: cimgui-love: another LÖVE module for DearImGui using LuaJIT FFI

Posted: Mon Aug 23, 2021 5:14 pm
by apicici
XHH wrote: Sun Aug 22, 2021 10:30 pm Do you have an example on how to use imgui::Combo? I'm very new to ffi.
This one is a bit tricky because of the way strings are treated in C. There are two options:

Code: Select all

-- option 1: items passed as a string, separated by zeros
local imgui = require "cimgui"
local ffi = require "ffi"

local current_item = ffi.new("int[1]", 0)
local lua_items = {"option 1", "option 2", "option 3"}
local items = table.concat(lua_items, "\0")

function love.draw()
    imgui.Combo_Str("combo test", current_item, items)
    
    imgui.Render()
    imgui.RenderDrawLists()
end

Code: Select all

-- option 2: items passed as an array of const char*
local imgui = require "cimgui"
local ffi = require "ffi"

local current_item = ffi.new("int[1]", 0)
local lua_items = {"option 1", "option 2", "option 3"}

function love.draw()
    local items = ffi.new("const char*[?]", #lua_items, lua_items)
    imgui.Combo_Str_arr("combo test", current_item, items, #lua_items)
    
    imgui.Render()
    imgui.RenderDrawLists()
end
I would recommend the first option, the second one requires to be careful about garbage collection of the items to avoid unexpected results.

Re: cimgui-love: another LÖVE module for DearImGui using LuaJIT FFI

Posted: Tue Oct 26, 2021 5:50 pm
by luarocks
The library looks very cool, but is it possible to decorate windows using texture atlases?
I think it is very important feature for game GUI.

Re: cimgui-love: another LÖVE module for DearImGui using LuaJIT FFI

Posted: Tue Oct 26, 2021 6:17 pm
by grump
luarocks wrote: Tue Oct 26, 2021 5:50 pm The library looks very cool, but is it possible to decorate windows using texture atlases?
I think it is very important feature for game GUI.
You can restyle stuff in Dear Imgui with some effort, at least in the C code. It's not really meant to be used as a pretty game UI though.