apicici / cimgui-love

LÖVE module for Dear ImGui obtained by wrapping cimgui with LuaJIT FFI.
MIT License
76 stars 6 forks source link

Cannot convert bool to bool* #2

Closed Jarodwr closed 3 years ago

Jarodwr commented 3 years ago

I'm trying to use igBegin and I'm not sure how to add a bool*

image

apicici commented 3 years ago

To pass a bool* you can use the following LuaJIT workaround:

-- create a bool array with 1 element, which you can use as a pointer to the allocated first element
local bool_p = ffi.new("bool[1]")
bool_p[0] = true

-- bool_p is the pointer, use bool_p[0] to dereference it.
BinarySpike commented 2 years ago

Doesn't seem to be working.

local myTest

love.load = function()
  love.window.setMode(1920, 1080)
    imgui.love.Init() -- or imgui.love.Init("RGBA32") or imgui.love.Init("Alpha8")

    myTest = ffi.new("bool[1]")
    myTest[0] = false
end
love.draw = function()
    -- example window

    imgui.ShowDemoWindow()

    imgui.Begin("Hello", myTest)

    if imgui.Button("My Button") then
      myTest[0] = false
    end

    imgui.End()

    -- code to render imgui
    love.graphics.setColor(1,1,1,1)
    imgui.Render()
    imgui.love.RenderDrawLists()
end
BinarySpike commented 2 years ago

Sorry, it's working. I just got the structure wrong. This is the correct code:

local myTest

love.load = function()
  love.window.setMode(1920, 1080)
  imgui.love.Init() -- or imgui.love.Init("RGBA32") or imgui.love.Init("Alpha8")

  myTest = ffi.new("bool[1]")
  myTest[0] = true
end

love.draw = function()
  -- example window

  imgui.ShowDemoWindow()

  if myTest[0] then --<-- the correct structure
    imgui.Begin("Hello", myTest)

    if imgui.Button("My Button") then
      myTest[0] = false
    end

    imgui.End()
  end

  -- code to render imgui
  love.graphics.setColor(1,1,1,1)
  imgui.Render()
  imgui.love.RenderDrawLists()
end