30 lines
838 B
Lua
30 lines
838 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_ = Vec3 {}
|
|
end
|
|
|
|
--- @return SizedBox
|
|
--- @param values {width: number?, height: number?, child: UIElement?}
|
|
function element:new(values)
|
|
return SingleChildElement.new(self, values)
|
|
end
|
|
|
|
return element
|