GithubHelp home page GithubHelp logo

love-imgui's Introduction

LOVE-IMGUI

imgui module for the LÖVE game engine including lua bindings based on this project. The main difference is that now by default in this version the return values ordering is reverted. For instance to retrieve the value from a slider, you need to do:

floatValue, status = imgui.SliderFloat("SliderFloat", floatValue, 0.0, 1.0);

Or if you're not interested to know if the field was modified, just:

floatValue = imgui.SliderFloat("SliderFloat", floatValue, 0.0, 1.0);

To reverse this behavior and receive back the return values from a function first before the modified fields, just call at the beginning of your application:

imgui.SetReturnValueLast(false)

Another notable difference is that enum values are handled using strings (and array of strings) instead of numerical values, for instance to create a window:

imgui.Begin("Test Window", true, { "ImGuiWindowFlags_AlwaysAutoResize", "ImGuiWindowFlags_NoTitleBar" });

Or for a single flag:

imgui.Begin("Test Window", true, "ImGuiWindowFlags_AlwaysAutoResize");

It uses imgui 1.53 and supports 275 functions (43 unsupported), and is based on LÖVE 11.1.

It also includes the docks extension by @adcox (https://github.com/adcox/imgui) (it's deprecated and will be replaced by imgui native dock management as soon as it's available).

Getting Started

Just build the project, and copy the generated dynamic module next to your love executable or into the LÖVE application data folder (for instance "C:/Users//AppData/Roaming/LOVE" on Windows or ~/.local/shared/love on Linux).

Pre-built binaries for Windows and Mas OSX are provided in the releases page.

Examples

Simple integration:

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 = 1
local textValue = "text"

--
-- LOVE callbacks
--
function love.load(arg)
end

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

function love.draw()

    -- 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!");
    clearColor[1], clearColor[2], clearColor[3] = imgui.ColorEdit3("Clear color", clearColor[1], clearColor[2], clearColor[3]);
    
    -- Sliders
    floatValue = imgui.SliderFloat("SliderFloat", floatValue, 0.0, 1.0);
    sliderFloat[1], sliderFloat[2] = imgui.SliderFloat2("SliderFloat2", sliderFloat[1], sliderFloat[2], 0.0, 1.0);
    
    -- Combo
    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, "ImGuiCond_FirstUseEver")
        showAnotherWindow = imgui.Begin("Another Window", true, { "ImGuiWindowFlags_AlwaysAutoResize", "ImGuiWindowFlags_NoTitleBar" });
        imgui.Text("Hello");
        -- Input text
        textValue = imgui.InputTextMultiline("InputText", textValue, 200, 300, 200);
        imgui.End();
    end

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

    love.graphics.clear(clearColor[1], clearColor[2], clearColor[3])
    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

Docks:

require "imgui"

--
-- LOVE callbacks
--
function love.load(arg)
end

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

function love.draw()
    imgui.SetNextWindowPos(0, 0)
    imgui.SetNextWindowSize(love.graphics.getWidth(), love.graphics.getHeight())
    if imgui.Begin("DockArea", nil, { "ImGuiWindowFlags_NoTitleBar", "ImGuiWindowFlags_NoResize", "ImGuiWindowFlags_NoMove", "ImGuiWindowFlags_NoBringToFrontOnFocus" }) then
        imgui.BeginDockspace()

        -- Create 10 docks
        for i = 1, 10 do
            if imgui.BeginDock("dock_"..i) then
                imgui.Text("Hello, dock "..i.."!");
            end
            imgui.EndDock()
        end

        imgui.EndDockspace()
    end
    imgui.End()

    love.graphics.clear(0.2, 0.2, 0.2)
    imgui.Render();
end

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

--
-- User inputs
--
function love.textinput(t)
    imgui.TextInput(t)
end

function love.keypressed(key)
    imgui.KeyPressed(key)
end

function love.keyreleased(key)
    imgui.KeyReleased(key)
end

function love.mousemoved(x, y)
    imgui.MouseMoved(x, y)
end

function love.mousepressed(x, y, button)
    imgui.MousePressed(button)
end

function love.mousereleased(x, y, button)
    imgui.MouseReleased(button)
end

function love.wheelmoved(x, y)
    imgui.WheelMoved(y)
end

License

This project is licensed under the MIT License - see the LICENSE file for details

love-imgui's People

Contributors

alloyed avatar camchenry avatar eiyeron avatar nkorth avatar nuthen avatar s-ol avatar samulus avatar shakesoda avatar slages avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

love-imgui's Issues

Cannot change default font at runtime

I recently found about Love2D, Lua, and this library and quite happy to play with my small app these days and tonight I wanted to add UpArrow/DownArrow = change font size functionality.

I quickly discovered, this binding does not have ImFont, ImAtlas etc. which in turn means there is no way to easily add and use new fonts (unless I'm mistaken somehow?).
After much googling I just added it myself, it's hacky but seems to work.
Sharing in a pull request, in case someone else finds this useful.

There is a gist pseudo code in the pull request.

Add screenshot in README

Could you please add a sceenshot in the readme?

This would make it easier to see if this package suits your needs.

I can't change the colors of the themes after the new update.

So, the title says everything.
After the last update, i'm not able to change the colors using the function imgui.PushStyleColor("ButtonHovered", 0.20, 0.38, 0.04, 1.00) anymore

I tried changing the string that defines the object that i'm modifing ("ButtonHovered" >"ImGuiCol_ButtonHovered") but nothing happens.

What i "discovered" is that now the parametters for that function only reads the first value ingresed
From this:
imgui.PushStyleColor("ChildWindowBg", 0.13, 0.13, 0.13, 1.00)

Only returns this:
imgui.PushStyleColor("ChildWindowBg", 0.13)

And even if i try to modify all the colors from the theme, the program simply does not respond. Leaving me with some sort of black and unresponsive menu.

Is this some kind of bug? Or there is a new way to apply colors to the theme and this way is deprecated?

love 0.11 support

the module doesn't work at all with love 0.11, it just errors out when you try to do anything.

I don't know what your policy on supporting pre-release builds is, but AFAIK the rendering-related stuff for 0.11 is pretty stable now.

Love 11.1 Builds?

Hi, having some trouble building the latest version. I'm sure my issues are machine specific but if you can upload the latest build I'd appreciate it.

Grey screen

Fully grey screen with nothing else. using demo code

imgui_lua_bindings.pl improvements

I posted a bunch of PRs to patrickriordan/imgui_lua_bindings.

I see that you have your own improvements here too. Are you interested in merging some of these changes:
https://github.com/idbrii/imgui_lua_bindings/tree/all-the-pr

Most changes are in their own branch, but I've given up keeping them tidy and independent unless someone's interested in merging.

Summary:

  • combine-shared-logic
    • (DrawList and standard imgui functions
  • iterate-enums
    • provide all imgui enums under imgui.constant (e.g., imgui.constant.SetCond.Appearing)
  • lua-51
    • define to use lua 5.1 API
  • optional-strings
    • support default values for strings
  • string-return
    • support returning strings (I think you have this)
  • update-to-1.50
    • update to imgui 1.50 (final release is out!)

imgui does not shutdown cleanly

Calling love.quit() or imgui.ShutDown() from anywhere causes a crash. Unfortunately, I don't have much to go on, since the only output to terminal is Segmentation fault (core dumped)

Not a major issue of course, since whether it crashes, or closes cleanly, the desired result of the application closing still occurs :)

Archlinux x86_64
Love 0.10.2

Restarting on Linux segfaults

When restarting with love.event.quit("restart"), LÖVE segfaults while loading. This doesn't happen on Windows, where restarting works as expected.

I'm using the code from master, not a release.

prebuild linux64?

There a possilbilty to get some precompiled linux64 of the library for latest love2d?

superfluous args break enums silently

This is a bug report, but it's also a walk through my attempt to resolve a specific problem I have on the off-chance you have some advice/might want to help :P

So I want to have a complex InputText widget, tab completion, history, etc. first thing's first, lets see what the callbacks return:

imgui.InputText("test", str, 255, {"CallbackAlways"}, print)

and it never triggers, either from the print function, or as an error: exciting. Maybe there's something wrong with callbacks, let's try a different flag:

changed = imgui.InputText("test", str, 255, {"EnterReturnsTrue", "CallbackAlways"}, print)

nothing either. somehow, the callback is interfering with the enum demarshaller in a way that silently fails. (also btw it'd be nice if callbacks worked). The same thing happens with Begin, which doesn't have extra args, so I'm pretty sure something is up in the definition of OPTIONAL_ENUM.

maybe love-imgui should throw errors if there are unused arguments at the end?

SetGlobalFontFromFileTTF doesn't work

calling imgui.SetGlobalFontFromFileTTF results in love throwing the error attempt to call field 'SetGlobalFontFromFileTTF' (a nil value)

I am on Mac running love 0.10.2 and have tried both the latest precompiled binary and self-compiled binaries pulled from Git.

expose draw list user callback

I've got a bunch of custom views, but without a way to set callbacks on the draw lists I have to draw them to a canvas and draw them as images... it's awkward and a lot slower than just being able to give it a draw function.

image

^ this involves a ton of canvases, but most of them wouldn't be needed if I had a render callback (I'd just need the one for shaded view)

short of fully exposing ImDrawList, something like imgui.AddCallback(fn) which just gets the window draw list and adds the callback (i.e. GetWindowDrawList()->AddCallback(...)) would be wonderful

Rendering canvas on windows causes visual glitch

Ok, so I'm creating a database font editor, and I'm using a canvas to render the fonts using love's rendering functions because it's easier than figuring out how to use fonts with imgui (which is my bad).

But here's the thing: when the canvas makes the window become big enough to have a scrollbar, it causes this:
screen shot 2017-12-27 at 9 20 16 pm

But when you scroll down all the way, or when you set focus to other imgui windows, or even when a tooltip shows up, it goes back to what it's supposed to render:
screen shot 2017-12-27 at 9 20 21 pm

Note that the background also becomes white, when it was supposed to be gray. It looks like the canvas is not unsetting itself, maybe?

the code looks like this:

-- let's assume canvas is declared elsewhere
love.graphics.setCanvas(canvas)
love.graphics.setFont(font)
love.graphics.setColor(255, 255, 255)
love.graphics.printf(text, 0, 0, canvas_width)
love.graphics.setCanvas()
imgui.Image(canvas, canvas_width, canvas_height)

Since this is a problem with love2d's canvases, I assumed this would be an issue in the wrapper for love2d, and not necessarily imgui itself. There are many workarounds I can think of, but if there is an actual problem with the actual wrapper I thought it'd be better to address it. I hope it's ok to post this issue.

Cannot build when LuaJIT 2.1.0-beta is installed but LuaJIT 2.0 does not.

It seems that Ubuntu 18.04 ships with LuaJIT 2.1.0-beta3 instead of LuaJIT 2.0.x, and the FindLuaJIT.cmake script doesn't look for include/luajit-2.1 and include/luajit2.1, thus the configure script fails.

I have to modify FindLuaJIT.cmake to search also in include/luajit-2.1 and include/luajit2.1 to fix this problem.

iPhone and Android support? build instructions?

Hi, I'm investigating which UI library I can use for my game. I want it to work on all desktop platforms + mobile (iPhone and Android). Does this library support these platforms?

Also I'm looking for build instructions to build from source but can't seem to locate them. Can someone help me out with my questions?

Ta

Attempt to index a string value (imgui.Render())

Hello!

I compiled lib from sources and installed it. Then I copied first exaple code.
Love 2d says:

Error
Attempt to index a string value

Traceback
[C]: In function 'Render'
main.lua:29: in function 'draw'
[C]: in function 'xpcall'

Please, fix that.

Thanks.

MouseMoved, strange interactions when moving out of window

When following the example on the intro page, one gets a strange effect when moving things outside the window. It seems to solve itself by adding a extra (not nil or false) parameters to the input of MouseMoved. Could someone explain why it works?

Expected behavior:
no bug

Behavior without extra parameter:
with bug

Code used to demonstrate:

EnableBugg = false

require "imgui"

function love.load(arg)
    love.window.setMode(512, 512)
end


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

function love.draw()
    imgui.Render()

    -- Debbugging --
    love.graphics.print(
        "Version:          " .. imgui.GetVersion() .. "\n" ..
        "Mouse xy:         " .. love.mouse.getX() .. ", " .. love.mouse.getY() .. "\n" ..
        "Window has focus: " .. tostring(love.window.hasFocus()) .. "\n" ..
        "Mouse focus:      " .. tostring(love.window.hasMouseFocus()) .. "\n" ..
        "Mouse Pressed:    " .. tostring(love.mouse.isDown(1)),
        10, 10
    )
end


    ---------------
    -- Callbacks --
    ---------------

function love.mousemoved(x, y, dx, dy, istouch)
    if EnableBugg then
        imgui.MouseMoved(x, y)
    else
        imgui.MouseMoved(x, y, true)
    end

    if not imgui.GetWantCaptureMouse() then
        -- Pass event to the game
    end
end


love.textinput   = imgui.TextInput
love.keypressed  = imgui.KeyPressed
love.keyreleased = imgui.KeyReleased
love.mousepressed  = function(x, y, button) imgui.MousePressed(button) end
love.mousereleased = function(x, y, button) imgui.MouseReleased(button) end
love.wheelmoved    = function(x, y)         imgui.WheelMoved(y) end

README examples not working

Whenever I try to run either of the examples in the README, I get an error similar to this:

Error

main.lua:18: bad argument #1 to 'NewFrame' (string expected, got table)


Traceback

[C]: in function 'NewFrame'
main.lua:18: in function 'update'
[C]: in function 'xpcall'

Broken docks on master

Hello, I wanted to make a prototype on Love 11.1 and it seems that docks are broken on the master branch. When using docks, nothing in them are visible. No text, button, image... I tested it both on windows and linux versions and nothing changed. One can see barely some garbage one frame or two after clicking on a dock's tab to bring focus on it, but nothing more.

The example code looks like this (don't take account of the deprecation warnings, they're caused by an old loverocks install)
image

Add Mac build to latest release

Previous releases have had an OS X binary supplied. The latest release only has one for Windows.

It'd be nice to have a macOS build too, for easy Mac distribution of games that use love-imgui.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.