Difference between revisions of "cimgui-love"

(Created page with "{{#set:Description=LÖVE module for Dear ImGui, obtained by wrapping cimgui with LuaJIT FFI.}} {{#set:Keyword=GUI}} {{#set:LOVE Min Version=11.3}} {{#set:LOVE Version=11.3}} {...")
 
(Other Languages)
Line 103: Line 103:
  
 
== Other Languages ==
 
== Other Languages ==
{{i18n|Main_Page}}
+
{{i18n|cimgui-love}}

Revision as of 13:17, 21 June 2021


cimgui-love

LÖVE module for Dear ImGui obtained by wrapping cimgui (programmatically generated C-api) using LuaJIT FFI.

The wrappers are generated automatically (like cimgui itself) and can be easily updated for new versions of Dear ImGui. Currently based on version 1.83 (docking branch) of Dear ImGui and LÖVE 11.3.

Links

Example of usage

See README on github for more detailed instructions.

-- Make sure the shared library can be found through package.cpath before loading the module.
-- For example, if you put it in the LÖVE save directory, you could do something like this:
local lib_path = love.filesystem.getSaveDirectory() .. "/libraries"
local extension = jit.os == "Windows" and "dll" or jit.os == "Linux" and "so" or jit.os == "OSX" and "dylib"
package.cpath = string.format("%s;%s/?.%s", package.cpath, lib_path, extension)

local imgui = require "cimgui" -- cimgui is the folder containing the Lua module (the "src" folder in the github repository)

love.load = function()
    imgui.Init()
end

love.draw = function()
    -- example window
    imgui.ShowDemoWindow()
    
    -- code to render imgui
    imgui.Render()
    imgui.RenderDrawLists()
end

love.update = function(dt)
    imgui.Update(dt)
    imgui.NewFrame()
end

love.mousemoved = function(x, y, ...)
    imgui.MouseMoved(x, y)
    if not imgui.GetWantCaptureMouse() then
        -- your code here
    end
end

love.mousepressed = function(x, y, button, ...)
    imgui.MousePressed(button)
    if not imgui.GetWantCaptureMouse() then
        -- your code here 
    end
end

love.mousereleased = function(x, y, button, ...)
    imgui.MouseReleased(button)
    if not imgui.GetWantCaptureMouse() then
        -- your code here 
    end
end

love.wheelmoved = function(x, y)
    imgui.WheelMoved(x, y)
    if not imgui.GetWantCaptureMouse() then
        -- your code here 
    end
end

love.keypressed = function(key, ...)
    imgui.KeyPressed(key)
    if not imgui.GetWantCaptureKeyboard() then
        -- your code here 
    end
end

love.keyreleased = function(key, ...)
    imgui.KeyReleased(key)
    if not imgui.GetWantCaptureKeyboard() then
        -- your code here 
    end
end

love.textinput = function(t)
    imgui.TextInput(t)
    if not imgui.GetWantCaptureKeyboard() then
        -- your code here 
    end
end

love.quit = function()
    return imgui.Shutdown()
end

Other Languages