Update docs

This commit is contained in:
Insality
2025-03-18 21:23:30 +02:00
parent 5348561d68
commit 1bc916e187
25 changed files with 937 additions and 380 deletions

View File

@@ -19,18 +19,19 @@ local component = require("druid.component")
---@field nodes_height table<node, number>
---@field rows druid.layout.row_data[]>
---The component used for managing the layout of nodes, placing them inside the node size with respect to the size and pivot of each node
---@class druid.layout: druid.component
---@field node node
---@field node node The node to manage the layout of
---@field rows_data druid.layout.rows_data Last calculated rows data
---@field is_dirty boolean
---@field entities node[]
---@field margin {x: number, y: number}
---@field padding vector4
---@field type string
---@field is_resize_width boolean
---@field is_resize_height boolean
---@field is_justify boolean
---@field on_size_changed event.on_size_changed
---@field entities node[] The entities to manage the layout of
---@field margin {x: number, y: number} The margin of the layout
---@field padding vector4 The padding of the layout
---@field type string The type of the layout
---@field is_resize_width boolean True if the layout should resize the width of the node
---@field is_resize_height boolean True if the layout should resize the height of the node
---@field is_justify boolean True if the layout should justify the nodes
---@field on_size_changed event.on_size_changed The event triggered when the size of the layout is changed
local M = component.create("layout")
@@ -68,11 +69,15 @@ function M:update()
end
---@return node[] entities The entities to manage the layout of
function M:get_entities()
return self.entities
end
---@param node node The node to set the index of
---@param index number The index to set the node to
---@return druid.layout self for chaining
function M:set_node_index(node, index)
for i = 1, #self.entities do
if self.entities[i] == node then
@@ -81,12 +86,15 @@ function M:set_node_index(node, index)
break
end
end
return self
end
---@param margin_x number|nil
---@param margin_y number|nil
---@return druid.layout
---Set the margin of the layout
---@param margin_x number|nil The margin x
---@param margin_y number|nil The margin y
---@return druid.layout self Current layout instance
function M:set_margin(margin_x, margin_y)
self.margin.x = margin_x or self.margin.x
self.margin.y = margin_y or self.margin.y
@@ -96,11 +104,11 @@ function M:set_margin(margin_x, margin_y)
end
---@param padding_x number|nil
---@param padding_y number|nil
---@param padding_z number|nil
---@param padding_w number|nil
---@return druid.layout
---@param padding_x number|nil The padding x
---@param padding_y number|nil The padding y
---@param padding_z number|nil The padding z
---@param padding_w number|nil The padding w
---@return druid.layout self Current layout instance
function M:set_padding(padding_x, padding_y, padding_z, padding_w)
self.padding.x = padding_x or self.padding.x
self.padding.y = padding_y or self.padding.y
@@ -112,7 +120,7 @@ function M:set_padding(padding_x, padding_y, padding_z, padding_w)
end
---@return druid.layout
---@return druid.layout self Current layout instance
function M:set_dirty()
self.is_dirty = true
@@ -121,7 +129,7 @@ end
---@param is_justify boolean
---@return druid.layout
---@return druid.layout self Current layout instance
function M:set_justify(is_justify)
self.is_justify = is_justify
self.is_dirty = true
@@ -131,7 +139,7 @@ end
---@param type string The layout type: "horizontal", "vertical", "horizontal_wrap"
---@return druid.layout
---@return druid.layout self Current layout instance
function M:set_type(type)
self.type = type
self.is_dirty = true
@@ -142,7 +150,7 @@ end
---@param is_hug_width boolean
---@param is_hug_height boolean
---@return druid.layout
---@return druid.layout self Current layout instance
function M:set_hug_content(is_hug_width, is_hug_height)
self.is_resize_width = is_hug_width or false
self.is_resize_height = is_hug_height or false
@@ -154,7 +162,7 @@ end
---Add node to layout
---@param node_or_node_id node|string node_or_node_id
---@return druid.layout
---@return druid.layout self Current layout instance
function M:add(node_or_node_id)
-- Acquire node from entity or by id
local node = node_or_node_id
@@ -207,7 +215,7 @@ function M:get_content_size()
end
---@return druid.layout
---@return druid.layout self Current layout instance
function M:refresh_layout()
local layout_node = self.node
@@ -349,7 +357,7 @@ function M:refresh_layout()
end
---@return druid.layout
---@return druid.layout self Current layout instance
function M:clear_layout()
for index = #self.entities, 1, -1 do
self.entities[index] = nil
@@ -362,7 +370,8 @@ end
---@param node node
---@return number, number
---@return number width The width of the node
---@return number height The height of the node
function M:get_node_size(node)
if not gui.is_enabled(node, false) then
return 0, 0