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

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
apicici
Prole
Posts: 29
Joined: Wed Dec 18, 2019 9:25 pm

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

Post 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!
Attachments
cimgui-love-test.love
(1.85 MiB) Downloaded 667 times
Last edited by apicici on Sat Dec 09, 2023 10:47 pm, edited 1 time in total.
User avatar
pgimeno
Party member
Posts: 3672
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

Works great! (Linux-x64, recompiled from sources).
User avatar
XHH
Citizen
Posts: 85
Joined: Thu Jun 20, 2013 6:43 pm
Location: US
Contact:

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

Post by XHH »

Do you have an example on how to use imgui::Combo? I'm very new to ffi.
I like to draw and program :)
apicici
Prole
Posts: 29
Joined: Wed Dec 18, 2019 9:25 pm

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

Post 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.
User avatar
luarocks
Prole
Posts: 4
Joined: Thu Jan 30, 2020 8:49 am

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

Post 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.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests