Widgets WIP

This commit is contained in:
Insality
2024-11-18 22:50:42 +02:00
parent 99f75dd626
commit 299f8501e8
15 changed files with 181 additions and 265 deletions

View File

@@ -134,8 +134,9 @@ end
--- Set new size of layout node
---@param width number|nil
---@param height number|nil
---@param anchor_pivot constant|nil If set will keep the corner possition relative to the new size
---@return druid.container Container
function M:set_size(width, height)
function M:set_size(width, height, anchor_pivot)
width = width or self.size.x
height = height or self.size.y
@@ -149,11 +150,23 @@ function M:set_size(width, height)
if (width and width ~= self.size.x) or (height and height ~= self.size.y) then
self.center_offset.x = -width * self.pivot_offset.x
self.center_offset.y = -height * self.pivot_offset.y
local dx = self.size.x - width
local dy = self.size.y - height
self.size.x = width
self.size.y = height
self.size.z = 0
gui.set_size(self.node, self.size)
if anchor_pivot then
local pivot = gui.get_pivot(self.node)
local pivot_offset = helper.get_pivot_offset(pivot)
local new_pivot_offset = helper.get_pivot_offset(anchor_pivot)
local position_dx = dx * (pivot_offset.x - new_pivot_offset.x)
local position_dy = dy * (pivot_offset.y - new_pivot_offset.y)
self:set_position(self._position.x + position_dx, self._position.y - position_dy)
end
self:update_child_containers()
self.on_size_changed:trigger(self:get_context(), self.size)
end
@@ -162,6 +175,11 @@ function M:set_size(width, height)
end
function M:get_position()
return self._position
end
---@param pos_x number
---@param pos_y number
function M:set_position(pos_x, pos_y)