30 lines
843 B
Lua
30 lines
843 B
Lua
local SingleChildElement = require "lib.simple_ui.core.single_child_element"
|
|
|
|
--- @class SizedBox : SingleChildElement
|
|
local element = setmetatable({}, require "lib.simple_ui.core.single_child_element")
|
|
local Constraints = require("lib.simple_ui.core.constraints")
|
|
element.type = "SizedBox"
|
|
element.__index = element
|
|
element.width = 0
|
|
element.height = 0
|
|
|
|
function element:layout()
|
|
self.size = Vec3 { self.width, self.height }
|
|
|
|
if not self.child then return end
|
|
self.child.constraints = Constraints {
|
|
maxWidth = self.width,
|
|
maxHeight = self.height,
|
|
}
|
|
self.child:layout()
|
|
self.child.offset = self.offset:copy()
|
|
end
|
|
|
|
--- @return SizedBox
|
|
--- @param values {width: number?, height: number?, child: UIElement?}
|
|
function element:new(values)
|
|
return SingleChildElement.new(self, values)
|
|
end
|
|
|
|
return element
|