29 lines
820 B
Lua
29 lines
820 B
Lua
local Constraints = require "lib.simple_ui.core.constraints"
|
|
local SingleChildElement = require "lib.simple_ui.core.single_child_element"
|
|
|
|
--- @class Center : SingleChildElement
|
|
local element = setmetatable({}, SingleChildElement)
|
|
element.__index = element
|
|
element.type = "Center"
|
|
|
|
function element:layout()
|
|
self._size_ = Vec3 { self._constraints_.maxWidth, self._constraints_.maxHeight }
|
|
|
|
if not self.child then return end
|
|
self.child._constraints_ = Constraints(self._constraints_)
|
|
self.child:layout()
|
|
|
|
self.child._offset_ = Vec3 {
|
|
(self._size_.x - self.child._size_.x) / 2,
|
|
(self._size_.y - self.child._size_.y) / 2,
|
|
}
|
|
end
|
|
|
|
--- @return Center
|
|
--- @param values {child: UIElement?}
|
|
function element:new(values)
|
|
return SingleChildElement.new(self, values)
|
|
end
|
|
|
|
return element
|