Closed kithf closed 1 year ago
That's not how the bool*
input of Begin
works. From the documentation in imgui.h
:
Passing 'bool* p_open != NULL' shows a window-closing widget in the upper-right corner of the window, which clicking will set the boolean to false when clicked.
You should do this to achieve what you want:
love.draw = function()
if some_bool[0] then
if imgui.Begin("Test", some_bool) then
if imgui.Button "Close" then
some_bool[0] = false -- note that you don't have to create a new bool[1], you can just change the value of the existing one
end
end
imgui.End()
end
imgui.Render()
imgui.love.RenderDrawLists()
end
Two things to note:
imgui.End
after calling imgui.Begin
, not only if imgui.Begin
return true (I fixed that in the snippet above)bool*
to imgui.Begin
makes the window close button in the top right appear, which behaves exactly as your custom button. If you don't want that to appear pass nil
to imgui.Begin
instead.
When I change value of the boolean, or even create new boolean, imgui doesn't react to changes. But when I use FFI booleans with Checkbox, Checkbox works as expected.