Difference between revisions of "cimgui-love"

m
(Example of usage)
Line 31: Line 31:
  
 
love.load = function()
 
love.load = function()
     imgui.Init()
+
     imgui.love.Init() -- or imgui.love.Init("RGBA32") or imgui.love.Init("Alpha8")
 
end
 
end
  
Line 40: Line 40:
 
     -- code to render imgui
 
     -- code to render imgui
 
     imgui.Render()
 
     imgui.Render()
     imgui.RenderDrawLists()
+
     imgui.love.RenderDrawLists()
 
end
 
end
  
 
love.update = function(dt)
 
love.update = function(dt)
     imgui.Update(dt)
+
     imgui.love.Update(dt)
 
     imgui.NewFrame()
 
     imgui.NewFrame()
 
end
 
end
  
 
love.mousemoved = function(x, y, ...)
 
love.mousemoved = function(x, y, ...)
     imgui.MouseMoved(x, y)
+
     imgui.love.MouseMoved(x, y)
     if not imgui.GetWantCaptureMouse() then
+
     if not imgui.love.GetWantCaptureMouse() then
 
         -- your code here
 
         -- your code here
 
     end
 
     end
Line 56: Line 56:
  
 
love.mousepressed = function(x, y, button, ...)
 
love.mousepressed = function(x, y, button, ...)
     imgui.MousePressed(button)
+
     imgui.love.MousePressed(button)
     if not imgui.GetWantCaptureMouse() then
+
     if not imgui.love.GetWantCaptureMouse() then
 
         -- your code here  
 
         -- your code here  
 
     end
 
     end
Line 63: Line 63:
  
 
love.mousereleased = function(x, y, button, ...)
 
love.mousereleased = function(x, y, button, ...)
     imgui.MouseReleased(button)
+
     imgui.love.MouseReleased(button)
     if not imgui.GetWantCaptureMouse() then
+
     if not imgui.love.GetWantCaptureMouse() then
 
         -- your code here  
 
         -- your code here  
 
     end
 
     end
Line 70: Line 70:
  
 
love.wheelmoved = function(x, y)
 
love.wheelmoved = function(x, y)
     imgui.WheelMoved(x, y)
+
     imgui.love.WheelMoved(x, y)
     if not imgui.GetWantCaptureMouse() then
+
     if not imgui.love.GetWantCaptureMouse() then
 
         -- your code here  
 
         -- your code here  
 
     end
 
     end
Line 77: Line 77:
  
 
love.keypressed = function(key, ...)
 
love.keypressed = function(key, ...)
     imgui.KeyPressed(key)
+
     imgui.love.KeyPressed(key)
     if not imgui.GetWantCaptureKeyboard() then
+
     if not imgui.love.GetWantCaptureKeyboard() then
 
         -- your code here  
 
         -- your code here  
 
     end
 
     end
Line 84: Line 84:
  
 
love.keyreleased = function(key, ...)
 
love.keyreleased = function(key, ...)
     imgui.KeyReleased(key)
+
     imgui.love.KeyReleased(key)
     if not imgui.GetWantCaptureKeyboard() then
+
     if not imgui.love.GetWantCaptureKeyboard() then
 
         -- your code here  
 
         -- your code here  
 
     end
 
     end
Line 91: Line 91:
  
 
love.textinput = function(t)
 
love.textinput = function(t)
     imgui.TextInput(t)
+
     imgui.love.TextInput(t)
     if not imgui.GetWantCaptureKeyboard() then
+
     if imgui.love.GetWantCaptureKeyboard() then
 
         -- your code here  
 
         -- your code here  
 
     end
 
     end
Line 98: Line 98:
  
 
love.quit = function()
 
love.quit = function()
     return imgui.Shutdown()
+
     return imgui.love.Shutdown()
 +
end
 +
 
 +
-- for gamepad support also add the following:
 +
 
 +
love.joystickadded = function(joystick)
 +
    imgui.love.JoystickAdded(joystick)
 +
    -- your code here
 +
end
 +
 
 +
love.joystickremoved = function(joystick)
 +
    imgui.love.JoystickRemoved()
 +
    -- your code here
 +
end
 +
 
 +
love.gamepadpressed = function(joystick, button)
 +
    imgui.love.GamepadPressed(button)
 +
    -- your code here
 +
end
 +
 
 +
love.gamepadreleased = function(joystick, button)
 +
    imgui.love.GamepadReleased(button)
 +
    -- your code here
 +
end
 +
 
 +
-- choose threshold for considering analog controllers active, defaults to 0 if unspecified
 +
local threshold = 0.2
 +
 
 +
love.gamepadaxis = function(joystick, axis, value)
 +
    imgui.love.GamepadAxis(axis, value, threshold)
 +
    -- your code here
 
end
 
end
 
</source>
 
</source>

Revision as of 15:32, 28 July 2022


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.love.Init() -- or imgui.love.Init("RGBA32") or imgui.love.Init("Alpha8")
end

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

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

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

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

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

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

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

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

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

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

-- for gamepad support also add the following:

love.joystickadded = function(joystick)
    imgui.love.JoystickAdded(joystick)
    -- your code here 
end

love.joystickremoved = function(joystick)
    imgui.love.JoystickRemoved()
    -- your code here 
end

love.gamepadpressed = function(joystick, button)
    imgui.love.GamepadPressed(button)
    -- your code here 
end

love.gamepadreleased = function(joystick, button)
    imgui.love.GamepadReleased(button)
    -- your code here 
end

-- choose threshold for considering analog controllers active, defaults to 0 if unspecified
local threshold = 0.2 

love.gamepadaxis = function(joystick, axis, value)
    imgui.love.GamepadAxis(axis, value, threshold)
    -- your code here 
end

Other Languages