ImGui LÖVE module

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

ImGui LÖVE module

Post by Fenrir »

EDIT:
github project:
https://github.com/slages/love-imgui

Pre-built binaries for Windows, Linux (Ubuntu i386) and MacOSX:
https://github.com/slages/love-imgui/releases

---------------------------
Galery of examples:

Image

Image
(sandsmas : viewtopic.php?f=5&t=82881)

Image

Image

Image

Image

Image


Original post:
---------------------------

Hi guys,

Recently I've been desperately in need to switch from löveframes to a more flexible, powerful and still maintained library for all the game debug and editor tools. I directly thought about ImGui (https://github.com/ocornut/imgui) as it's clearly as far as I know the best dev oriented GUI library around. And as it's a C++ library, I took the path of directly integrating it into the löve sources instead of using ffi, as a Lua wrapping was already available. So after a bit of work and improvements to the wrapping part, I'm finally having something meeting the expectations and needs I had.

So for instance, something like that:

Code: Select all

require "imgui"

local showTestWindow = false
local showAnotherWindow = false
local floatValue = 0;
local sliderFloat = { 0.1, 0.5 }
local clearColor = { 0.2, 0.2, 0.2 }
local comboSelection = 0
local textValue = "text"

--
-- LOVE callbacks
--

function love.load(arg)
end

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

function love.draw()
    local status

    -- Menu
    if imgui.BeginMainMenuBar() then
        if imgui.BeginMenu("File") then
            imgui.MenuItem("Test")
            imgui.EndMenu()
        end
        imgui.EndMainMenuBar()
    end

    -- Debug window
    imgui.Text("Hello, world!");
    status, clearColor[1], clearColor[2], clearColor[3] = imgui.ColorEdit3("Clear color", clearColor[1], clearColor[2], clearColor[3]);
    
    -- Sliders
    status, floatValue = imgui.SliderFloat("SliderFloat", floatValue, 0.0, 1.0);
    status, sliderFloat[1], sliderFloat[2] = imgui.SliderFloat2("SliderFloat2", sliderFloat[1], sliderFloat[2], 0.0, 1.0);
    
    -- Combo
    status, comboSelection = imgui.Combo("Combo", comboSelection, { "combo1", "combo2", "combo3", "combo4" }, 4);

    -- Windows
    if imgui.Button("Test Window") then
        showTestWindow = not showTestWindow;
    end
    
    if imgui.Button("Another Window") then
        showAnotherWindow = not showAnotherWindow;
    end
    
    if showAnotherWindow then
        imgui.SetNextWindowPos(50, 50, ImGuiSetCond_FirstUseEver)
        status, showAnotherWindow = imgui.Begin("Another Window", true, ImGuiWindowFlags_AlwaysAutoResize);
        imgui.Text("Hello");
        -- Input text
        status, textValue = imgui.InputTextMultiline("InputText", textValue, 200, 300, 200);
        imgui.End();
    end

    if showTestWindow then
        showTestWindow = imgui.ShowTestWindow(true)
    end

    love.graphics.clear(clearColor[1] * 255, clearColor[2] * 255, clearColor[3] * 255, 255)
    imgui.Render();
end

function love.quit()
    imgui.ShutDown();
end

--
-- User inputs
--
function love.textinput(t)
    imgui.TextInput(t)
    if not imgui.GetWantCaptureKeyboard() then
        -- Pass event to the game
    end
end

function love.keypressed(key)
    imgui.KeyPressed(key)
    if not imgui.GetWantCaptureKeyboard() then
        -- Pass event to the game
    end
end

function love.keyreleased(key)
    imgui.KeyReleased(key)
    if not imgui.GetWantCaptureKeyboard() then
        -- Pass event to the game
    end
end

function love.mousemoved(x, y)
    imgui.MouseMoved(x, y)
    if not imgui.GetWantCaptureMouse() then
        -- Pass event to the game
    end
end

function love.mousepressed(x, y, button)
    imgui.MousePressed(button)
    if not imgui.GetWantCaptureMouse() then
        -- Pass event to the game
    end
end

function love.mousereleased(x, y, button)
    imgui.MouseReleased(button)
    if not imgui.GetWantCaptureMouse() then
        -- Pass event to the game
    end
end

function love.wheelmoved(x, y)
    imgui.WheelMoved(y)
    if not imgui.GetWantCaptureMouse() then
        -- Pass event to the game
    end
end
Will produce:
Image

I already started integrating it into the game:
Image

And I must admit that so far it's a life changer, it made it a lot easier to create debug and test tools. So the next step will be to migrate my whole scenario editor to it, I'll try to do it as soon as I can (probably before the end of July).

So, is it something some of you would be interested in? On my side I think that it would be well suited for löve, as it's really a dev oriented GUI library, it won't replace any fancy lib for a game GUI (and I'm not planning to use it for the in-game GUI, this part will be in pure Lua), but it can really help speed up the development of a project by making the edition and debug tools a lot more easier to create.

Anyway if you're interested, here's my current version of the module:
https://dl.dropboxusercontent.com/u/674 ... -imgui.zip
You'll find in this zip the module and the only modifications I've made to löve (by adding it to love.cpp and into the config file to enable/disable it), and the Windows CMake file. I would actually be quite interested to know if it builds without problems on the other platforms (ImGui is totally cross-platform, but my part has not been tested on something else than Windows). Don't hesitate if you want me to provide a compiled love.dll.

So I'll probably continue to improve it while I'll migrate my editor to it, meanwhile don't hesitate to let me know if it's something you would be interested seeing added to löve!
Last edited by Fenrir on Tue Sep 13, 2016 8:13 am, edited 11 times in total.
Trebgarta
Prole
Posts: 33
Joined: Mon May 23, 2016 5:21 pm

Re: ImGui löve module

Post by Trebgarta »

This is wonderful, except... Imgui has C API, so I'd love an ffi implementation :)

Im very interested but I'd rather an external library through ffi.
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: ImGui löve module

Post by davisdude »

I would definitely support this! Looks great so far.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
Jack5500
Party member
Posts: 148
Joined: Wed Dec 07, 2011 8:38 pm
Location: Hamburg, Germany

Re: ImGui löve module

Post by Jack5500 »

This would be great. If you're still developing it, maybe consider moving it to a repo instead of a dropbox file?
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

Re: ImGui löve module

Post by Fenrir »

Jack5500 wrote:This would be great. If you're still developing it, maybe consider moving it to a repo instead of a dropbox file?
Yep good point, as soon as I have time I'll try to move it to a git repo.
Trebgarta wrote:This is wonderful, except... Imgui has C API, so I'd love an ffi implementation :)
Im very interested but I'd rather an external library through ffi.
It would probably be possible to take this route too, maybe a bit more tricky to get the rendering properly done but clearly possible. But well, the philosophy behind imgui is actually to be quite lightweight and self contained to be able to be integrated easily directly into any project, that's why integrating it directly into löve seemed more natural to me (and made it quite easier to get access to ressources useful for imgui like the SDL window handler or graphic context).
Trebgarta
Prole
Posts: 33
Joined: Mon May 23, 2016 5:21 pm

Re: ImGui löve module

Post by Trebgarta »

Fenrir wrote: It would probably be possible to take this route too, maybe a bit more tricky to get the rendering properly done but clearly possible. But well, the philosophy behind imgui is actually to be quite lightweight and self contained to be able to be integrated easily directly into any project, that's why integrating it directly into löve seemed more natural to me (and made it quite easier to get access to ressources useful for imgui like the SDL window handler or graphic context).
I'd like there to be one version of löve personally, so either löve team could adopt imgui in core repo like they did with box2D, or I'd rather have imgui seperately.

SDL can also be loaded with ffi, like löve3D does, and you can get context and window handle through that.
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

Re: ImGui löve module

Post by Fenrir »

Trebgarta wrote: I'd like there to be one version of löve personally, so either löve team could adopt imgui in core repo like they did with box2D, or I'd rather have imgui seperately.
I would love to integrate it (and maintain it) into the core repo of course, I'll probably make an official pull request as soon as I think it can be ready for that.
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: ImGui löve module

Post by rmcode »

Wow this is nice! I'd love to see it as a library though.
User avatar
AntonioModer
Party member
Posts: 202
Joined: Fri Jun 15, 2012 5:31 pm
Location: Belarus
Contact:

Re: ImGui löve module

Post by AntonioModer »

I like it ! :awesome:
ImGUI is awesome GUI.
Fenrir, please give binaries! :)
I want use ImGui in my game and game editor, if it can coded from Lua, not C++.
alloyed
Citizen
Posts: 80
Joined: Thu May 28, 2015 8:45 pm
Contact:

Re: ImGui löve module

Post by alloyed »

So I tried compiling it as an external lib on Linux, my notes so far:

imgui needs a prerelease copy of love. Love 0.10.2 is missing a function or two.

Compiling as a separate library that links to liblove compiles fine, though I'm not sure if it can share state with the actual love game yet. Right now, it segfaults when trying to call filesystem functions, which at least suggests that maybe it's not been initialized.

There were a few things that looked like errors that I edited to get it to compile:

GetColorU32 is exported by imgui_iterator.cpp, even though its an inline. Commenting it out fixed the problem

OPTIONAL_LABEL_ARG expects 2 arguments but is only defined as having one. Just add an extra arg to fix

EDIT: Figured out what was wrong, it just turns out my version of love-hg was a little outdated. I'll publish my fork on github in a bit once I figure out how I want to deal with getting header files from love
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Google [Bot] and 5 guests