Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/slages/love-imgui
imgui module for the LÖVE game engine
https://github.com/slages/love-imgui
Last synced: 6 days ago
JSON representation
imgui module for the LÖVE game engine
- Host: GitHub
- URL: https://github.com/slages/love-imgui
- Owner: slages
- License: mit
- Created: 2016-07-14T11:27:01.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-12-03T04:30:39.000Z (11 months ago)
- Last Synced: 2024-08-02T06:20:56.712Z (3 months ago)
- Language: C++
- Homepage:
- Size: 760 KB
- Stars: 315
- Watchers: 19
- Forks: 62
- Open Issues: 26
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-love2d - Love Imgui - Imgui module for the LÖVE game engine. (UI)
README
# 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 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](https://github.com/slages/love-imgui/releases) page.
## Examples
Simple integration:
```lua
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)
endfunction love.update(dt)
imgui.NewFrame()
endfunction 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();
endif showTestWindow then
showTestWindow = imgui.ShowDemoWindow(true)
endlove.graphics.clear(clearColor[1], clearColor[2], clearColor[3])
imgui.Render();
endfunction 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
endfunction love.keypressed(key)
imgui.KeyPressed(key)
if not imgui.GetWantCaptureKeyboard() then
-- Pass event to the game
end
endfunction love.keyreleased(key)
imgui.KeyReleased(key)
if not imgui.GetWantCaptureKeyboard() then
-- Pass event to the game
end
endfunction love.mousemoved(x, y)
imgui.MouseMoved(x, y)
if not imgui.GetWantCaptureMouse() then
-- Pass event to the game
end
endfunction love.mousepressed(x, y, button)
imgui.MousePressed(button)
if not imgui.GetWantCaptureMouse() then
-- Pass event to the game
end
endfunction love.mousereleased(x, y, button)
imgui.MouseReleased(button)
if not imgui.GetWantCaptureMouse() then
-- Pass event to the game
end
endfunction love.wheelmoved(x, y)
imgui.WheelMoved(y)
if not imgui.GetWantCaptureMouse() then
-- Pass event to the game
end
end
```Docks:
```lua
require "imgui"--
-- LOVE callbacks
--
function love.load(arg)
endfunction love.update(dt)
imgui.NewFrame()
endfunction 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()
endimgui.EndDockspace()
end
imgui.End()love.graphics.clear(0.2, 0.2, 0.2)
imgui.Render();
endfunction love.quit()
imgui.ShutDown();
end--
-- User inputs
--
function love.textinput(t)
imgui.TextInput(t)
endfunction love.keypressed(key)
imgui.KeyPressed(key)
endfunction love.keyreleased(key)
imgui.KeyReleased(key)
endfunction love.mousemoved(x, y)
imgui.MouseMoved(x, y)
endfunction love.mousepressed(x, y, button)
imgui.MousePressed(button)
endfunction love.mousereleased(x, y, button)
imgui.MouseReleased(button)
endfunction love.wheelmoved(x, y)
imgui.WheelMoved(y)
end
```## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details