41 lines
1.3 KiB
Lua
41 lines
1.3 KiB
Lua
local Rect = require "lib.simple_ui.rect"
|
|
local Constraints = require "lib.simple_ui.constraints"
|
|
local Vec3 = require "lib.utils.vec3"
|
|
|
|
--- @class UIElement
|
|
--- @field type string
|
|
--- @field key? any Must be convertible to string
|
|
--- @field parent? UIElement
|
|
--- @field constraints Constraints
|
|
--- @field offset Vec3 Положение левого верхнего угла элемента в экранных координатах {x, y}. Устанавливается родительским элементом.
|
|
--- @field size Vec3 Размеры элемента в экранных координатах {x, y}
|
|
--- @field build? fun(self)
|
|
local element = {}
|
|
element.__index = element
|
|
element.type = "Element"
|
|
element.constraints = Constraints {}
|
|
element.offset = Vec3 {}
|
|
element.size = Vec3 {}
|
|
|
|
--- "Constraints go down. Sizes go up. Parent sets position."
|
|
---
|
|
--- Karl Marx, probably.
|
|
function element:layout() end
|
|
|
|
function element:update(dt) end
|
|
|
|
function element:draw() end
|
|
|
|
--- @generic T : UIElement
|
|
--- @param values table
|
|
--- @param self T
|
|
--- @return T
|
|
function element.new(self, values)
|
|
values.bounds = values.bounds or Rect {}
|
|
values.transform = values.transform or love.math.newTransform()
|
|
if values.child then values.child.parent = values end
|
|
return setmetatable(values, self)
|
|
end
|
|
|
|
return element
|