honeylisp/editor/imview.lua

47 lines
1.4 KiB
Lua

local imgui = require("imgui")
local enqueue_love_event = system.enqueue_love_event
function system.enqueue_love_event(ev, a, b, c, d, e, f)
local keyevents = {
textinput = function() imgui.TextInput(a) end,
keypressed = function() imgui.KeyPressed(a) end,
keyreleased = function() imgui.KeyReleased(a) end,
}
local mouseevents = {
mousemoved = function() imgui.MouseMoved(a, b) end,
mousepressed = function() imgui.MousePressed(c) end,
mousereleased = function() imgui.MouseReleased(c) end,
wheelmoved = function() imgui.WheelMoved(b) end
}
local pass_event_to_lite = true
if keyevents[ev] then
keyevents[ev]()
pass_event_to_lite = not imgui.GetWantCaptureKeyboard()
elseif mouseevents[ev] then
mouseevents[ev]()
pass_event_to_lite = not imgui.GetWantCaptureMouse()
elseif ev == 'quit' then
imgui.ShutDown()
end
if pass_event_to_lite then enqueue_love_event(ev, a, b, c, d, e, f) end
end
local View = require("core.view")
local ImView = View:extend()
function ImView.gui(self)
end
function ImView.draw(self)
imgui.NewFrame()
imgui.SetNextWindowPos(self.position.x, self.position.y, "Always")
imgui.SetNextWindowSize(self.size.x, self.size.y, "Always")
imgui.Begin(self:get_name(), nil, { "NoTitleBar", "NoResize", "NoMove", "NoCollapse" })
self:gui()
imgui.End()
imgui.EndFrame()
imgui.Render()
end
return ImView