Skip to content

Commit

Permalink
- Return values ordering reverted (calling imgui.SetReturnValueLast(f…
Browse files Browse the repository at this point in the history
…alse) revert this behavior to how it worked)

- Updated enum names to use the full imgui name to be sure to avoid collisions
  • Loading branch information
slages committed Mar 14, 2018
1 parent 5c836e8 commit f3006c9
Show file tree
Hide file tree
Showing 4 changed files with 467 additions and 44 deletions.
40 changes: 30 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
# LOVE-IMGUI

[imgui](https://github.com/ocornut/imgui) module for the [LÖVE](https://love2d.org/) game engine including lua bindings based on this [project](https://github.com/patrickriordan/imgui_lua_bindings).
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:
```lua
floatValue, status = imgui.SliderFloat("SliderFloat", floatValue, 0.0, 1.0);
```
Or if you're not interested to know if the field was modified, just:
```lua
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:
```lua
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:
```lua
imgui.Begin("Test Window", true, { "ImGuiWindowFlags_AlwaysAutoResize", "ImGuiWindowFlags_NoTitleBar" });
```
Or for a single flag:
```lua
imgui.Begin("Test Window", true, "ImGuiWindowFlags_AlwaysAutoResize");
```

It uses imgui 1.53 and supports 273 functions (45 unsupported), and is based on LÖVE 0.10.2.

It also includes the docks extension by @adcox (https://github.com/adcox/imgui).
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/<user>/AppData/Roaming/LOVE" on Windows or ~/.local/shared/love on Linux).

Pre-built binaries are provided in the [releases](https://github.com/slages/love-imgui/releases) page.
Pre-built binaries for Windows and Mas OSX are provided in the [releases](https://github.com/slages/love-imgui/releases) page.

## Examples

Expand All @@ -37,7 +58,6 @@ function love.update(dt)
end

function love.draw()
local status

-- Menu
if imgui.BeginMainMenuBar() then
Expand All @@ -50,14 +70,14 @@ function love.draw()

-- Debug window
imgui.Text("Hello, world!");
status, clearColor[1], clearColor[2], clearColor[3] = imgui.ColorEdit3("Clear color", clearColor[1], clearColor[2], clearColor[3]);
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);
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
status, comboSelection = imgui.Combo("Combo", comboSelection, { "combo1", "combo2", "combo3", "combo4" }, 4);
comboSelection = imgui.Combo("Combo", comboSelection, { "combo1", "combo2", "combo3", "combo4" }, 4);

-- Windows
if imgui.Button("Test Window") then
Expand All @@ -70,10 +90,10 @@ function love.draw()

if showAnotherWindow then
imgui.SetNextWindowPos(50, 50, "FirstUseEver")
status, showAnotherWindow = imgui.Begin("Another Window", true, { "AlwaysAutoResize", "NoTitleBar" });
showAnotherWindow = imgui.Begin("Another Window", true, { "ImGuiWindowFlags_AlwaysAutoResize", "ImGuiWindowFlags_NoTitleBar" });
imgui.Text("Hello");
-- Input text
status, textValue = imgui.InputTextMultiline("InputText", textValue, 200, 300, 200);
textValue = imgui.InputTextMultiline("InputText", textValue, 200, 300, 200);
imgui.End();
end

Expand Down Expand Up @@ -159,7 +179,7 @@ end
function love.draw()
imgui.SetNextWindowPos(0, 0)
imgui.SetNextWindowSize(love.graphics.getWidth(), love.graphics.getHeight())
if imgui.Begin("DockArea", nil, { "NoTitleBar", "NoResize", "NoMove", "NoBringToFrontOnFocus" }) then
if imgui.Begin("DockArea", nil, { "ImGuiWindowFlags_NoTitleBar", "ImGuiWindowFlags_NoResize", "ImGuiWindowFlags_NoMove", "ImGuiWindowFlags_NoBringToFrontOnFocus" }) then
imgui.BeginDockspace()

-- Create 10 docks
Expand Down
42 changes: 33 additions & 9 deletions generate_imgui_bindings.pl
Original file line number Diff line number Diff line change
Expand Up @@ -76,47 +76,48 @@
$shouldPrint = 0;
}
# c++ type of return value
my $retLine = $1;
my $retType;
# macro used for calling function
my $callMacro;
# if it has a return value (yes I know this is not the cleanest code)
my $hasRet = 1;
if ($1 =~ /^void$/) {
if ($retLine =~ /^void$/) {
$callMacro = "CALL_FUNCTION_NO_RET";
$hasRet = 0;
} elsif ($1 =~ /^bool$/) {
} elsif ($retLine =~ /^bool$/) {
$callMacro = "CALL_FUNCTION";
push(@funcArgs, "bool");
push(@after, "PUSH_BOOL(ret)");
} elsif ($1 =~ /^float$/) {
} elsif ($retLine =~ /^float$/) {
$callMacro = "CALL_FUNCTION";
push(@funcArgs, "float");
push(@after, "PUSH_NUMBER(ret)");
} elsif ($1 =~ /^ImVec2$/) {
} elsif ($retLine =~ /^ImVec2$/) {
$callMacro = "CALL_FUNCTION";
push(@funcArgs, "ImVec2");
push(@after, "PUSH_NUMBER(ret.x)");
push(@after, "PUSH_NUMBER(ret.y)");
} elsif ($1 =~ /^ImVec4$/) {
} elsif ($retLine =~ /^ImVec4$/) {
$callMacro = "CALL_FUNCTION";
push(@funcArgs, "ImVec4");
push(@after, "PUSH_NUMBER(ret.x)");
push(@after, "PUSH_NUMBER(ret.y)");
push(@after, "PUSH_NUMBER(ret.z)");
push(@after, "PUSH_NUMBER(ret.w)");
} elsif ($1 =~ /^(unsigned int|ImGuiID|ImU32)$/) {
} elsif ($retLine =~ /^(unsigned int|ImGuiID|ImU32)$/) {
$callMacro = "CALL_FUNCTION";
push(@funcArgs, "unsigned int");
push(@after, "PUSH_NUMBER(ret)");
} elsif ($1 =~ /^(ImGuiMouseCursor)$/) { # Enums
} elsif ($retLine =~ /^(ImGuiMouseCursor)$/) { # Enums
$callMacro = "CALL_FUNCTION";
push(@funcArgs, "int");
push(@after, "PUSH_NUMBER(ret)");
} elsif ($1 =~ /^int$/) {
} elsif ($retLine =~ /^int$/) {
$callMacro = "CALL_FUNCTION";
push(@funcArgs, "int");
push(@after, "PUSH_NUMBER(ret)");
} elsif ($1 =~ /^const char*\*$/) {
} elsif ($retLine =~ /^const char*\*$/) {
$callMacro = "CALL_FUNCTION";
push(@funcArgs, "const char*");
push(@after, "PUSH_STRING(ret)");
Expand Down Expand Up @@ -284,6 +285,29 @@
$shouldPrint = 0;
}
}

if ($retLine =~ /^bool$/) {
push(@after, "PUSH_LAST_BOOL(ret)");
} elsif ($retLine =~ /^float$/) {
push(@after, "PUSH_LAST_NUMBER(ret)");
} elsif ($retLine =~ /^ImVec2$/) {
push(@after, "PUSH_LAST_NUMBER(ret.x)");
push(@after, "PUSH_LAST_NUMBER(ret.y)");
} elsif ($retLine =~ /^ImVec4$/) {
push(@after, "PUSH_LAST_NUMBER(ret.x)");
push(@after, "PUSH_LAST_NUMBER(ret.y)");
push(@after, "PUSH_LAST_NUMBER(ret.z)");
push(@after, "PUSH_LAST_NUMBER(ret.w)");
} elsif ($retLine =~ /^(unsigned int|ImGuiID|ImU32)$/) {
push(@after, "PUSH_LAST_NUMBER(ret)");
} elsif ($retLine =~ /^(ImGuiMouseCursor)$/) { # Enums
push(@after, "PUSH_LAST_NUMBER(ret)");
} elsif ($retLine =~ /^int$/) {
push(@after, "PUSH_LAST_NUMBER(ret)");
} elsif ($retLine =~ /^const char*\*$/) {
push(@after, "PUSH_LAST_STRING(ret)");
}

my $luaFunc = $funcName;
# Stupid way of implementing overriding
if ($funcNames{$luaFunc}) {
Expand Down
Loading

0 comments on commit f3006c9

Please sign in to comment.