local Constraints = require "lib.simple_ui.core.constraints" local SingleChildElement = require "lib.simple_ui.core.single_child_element" --- @class Padding : SingleChildElement --- @field left number --- @field right number --- @field top number --- @field bottom number local element = setmetatable({}, SingleChildElement) element.__index = element element.type = "Padding" element.left = 0 element.right = 0 element.top = 0 element.bottom = 0 --- "When passing layout constraints to its child, padding shrinks the constraints by the given padding, causing the child to layout at a smaller size. --- Padding then sizes itself to its child's size, inflated by the padding, effectively creating empty space around the child." --- --- as in https://api.flutter.dev/flutter/widgets/Padding-class.html function element:layout() if not self._child_ then return end local c = Constraints(self._constraints_) c.maxWidth = c.maxWidth - self.left - self.right c.maxHeight = c.maxHeight - self.top - self.bottom c.maxWidth = c.maxWidth > 0 and c.maxWidth or 0 c.maxHeight = c.maxHeight > 0 and c.maxHeight or 0 self._child_._constraints_ = c self._child_:layout() self._size_ = Vec3 { self._child_._size_.x + self.left + self.right, self._child_._size_.y + self.top + self.bottom } self._child_._offset_ = Vec3 { self.left, self.top } end --- @return Padding --- @param values {left: number?, top: number?, right: number?, bottom: number?, child: UIElement?} function element:new(values) return SingleChildElement.new(self, values) end return element