Files
LoveDOS-Dungeon-Crawler/src/ui/layout.lua
Wally Hackenslacker 777b70d1ab Added dialog windows and control settings.
Lots of comments and changes in UI code in general.
2025-10-13 00:28:12 -04:00

119 lines
2.6 KiB
Lua

------------------------------------------------------------------------------
-- Imports
------------------------------------------------------------------------------
local make_class = require 'src.utils.classes'
local UIElement = require 'src.ui.element'
------------------------------------------------------------------------------
-- Class definitions
------------------------------------------------------------------------------
---@class Layout: UIElement
local Layout = make_class(UIElement)
------------------------------------------------------------------------------
-- Class methods
------------------------------------------------------------------------------
function Layout:_init(x, y, w, h, spacing, float)
UIElement._init(self, x, y, float, false)
self.x = x ~= nil and x or 0
self.y = y ~= nil and y or 0
self.w = w
self.h = h
self.spacing = spacing ~= nil and spacing or 10
self.elements = {}
end
function Layout:add(element)
table.insert(self.elements, element)
end
function Layout:load()
-- Load required assets if needed and then compute the coordinates of each button.
for _, v in pairs(self.elements) do
if v.is_a[UIElement] then
v:load()
end
end
self:set_dimensions()
end
function Layout:unload()
for _, v in pairs(self.elements) do
if v.is_a[UIElement] then
v:unload()
end
end
end
function Layout:update(dt)
for _, v in pairs(self.elements) do
v:update(dt)
end
end
function Layout:draw()
for _, v in pairs(self.elements) do
v:draw()
end
end
function Layout:keypressed(key, code, isrepeat)
for _, v in pairs(self.elements) do
v:keypressed(key, code, isrepeat)
end
end
function Layout:textinput(text)
for _, v in pairs(self.elements) do
v:textinput(text)
end
end
function Layout:keyreleased(key, code)
for _, v in pairs(self.elements) do
v:keyreleased(key, code)
end
end
function Layout:mousemoved(x, y, dx, dy)
for _, v in pairs(self.elements) do
v:mousemoved(x, y, dx, dy)
end
end
function Layout:mousepressed(x, y, btn)
for _, v in pairs(self.elements) do
v:mousepressed(x, y, btn)
end
end
function Layout:mousereleased(x, y, btn)
for _, v in pairs(self.elements) do
v:mousereleased(x, y, btn)
end
end
------------------------------------------------------------------------------
-- Module return
------------------------------------------------------------------------------
return Layout