This commit is contained in:
Insality 2025-02-08 00:28:20 +02:00
parent 96ce3eee95
commit 7a6f529c82
7 changed files with 27 additions and 14 deletions

View File

@ -528,11 +528,12 @@ function M:bind_grid(grid)
end end
self._grid_on_change = grid.on_change_items self._grid_on_change = grid.on_change_items
self._grid_on_change_callback = self._grid_on_change:subscribe(function() self._grid_on_change_callback = function()
local size = grid:get_size() local size = grid:get_size()
local offset = grid:get_offset() local offset = grid:get_offset()
self:set_size(size, offset) self:set_size(size, offset)
end) end
self._grid_on_change:subscribe(self._grid_on_change_callback)
self:set_size(grid:get_size(), grid:get_offset()) self:set_size(grid:get_size(), grid:get_offset())
return self return self

View File

@ -201,7 +201,7 @@ end
--- Return grid index by node --- Return grid index by node
---@param node node The gui node in the grid ---@param node node The gui node in the grid
---@return number The node index ---@return number|nil index The node index
function M:get_index_by_node(node) function M:get_index_by_node(node)
for index, grid_node in pairs(self.nodes) do for index, grid_node in pairs(self.nodes) do
if node == grid_node then if node == grid_node then
@ -356,7 +356,7 @@ end
--- Return grid content borders --- Return grid content borders
---@return vector3 The grid content borders ---@return vector4 The grid content borders
function M:get_borders() function M:get_borders()
return self.border return self.border
end end
@ -463,10 +463,12 @@ end
--- Sort grid nodes by custom comparator function --- Sort grid nodes by custom comparator function
---@param comparator function The comparator function. (a, b) -> boolean ---@param comparator function The comparator function. (a, b) -> boolean
---@return druid.grid Current grid instance ---@return druid.grid self Current grid instance
function M:sort_nodes(comparator) function M:sort_nodes(comparator)
table.sort(self.nodes, comparator) table.sort(self.nodes, comparator)
self:_update(true) self:_update(true)
return self
end end

View File

@ -25,7 +25,7 @@ local helper = require("druid.helper")
---@field update fun(self:druid.base_component, dt:number)|nil ---@field update fun(self:druid.base_component, dt:number)|nil
---@field on_remove fun(self:druid.base_component)|nil ---@field on_remove fun(self:druid.base_component)|nil
---@field on_input fun(self:druid.base_component, action_id:number, action:table)|nil ---@field on_input fun(self:druid.base_component, action_id:number, action:table)|nil
---@field on_message fun(self:druid.base_component, message_id:hash, message:table, sender:userdata)|nil ---@field on_message fun(self:druid.base_component, message_id:hash, message:table, sender:url)|nil
---@field on_late_init fun(self:druid.base_component)|nil ---@field on_late_init fun(self:druid.base_component)|nil
---@field on_focus_lost fun(self:druid.base_component)|nil ---@field on_focus_lost fun(self:druid.base_component)|nil
---@field on_focus_gained fun(self:druid.base_component)|nil ---@field on_focus_gained fun(self:druid.base_component)|nil

View File

@ -121,6 +121,13 @@ local rich_text = require("druid.custom.rich_text.module.rt")
---@field width number ---@field width number
---@field height number ---@field height number
---@class druid.rich_text.style
---@field COLORS table<string, vector4>
---@field ADJUST_STEPS number
---@field ADJUST_SCALE_DELTA number
---@field ADJUST_TYPE string
---@field ADJUST_SCALE number
---@class druid.rich_text.lines_metrics ---@class druid.rich_text.lines_metrics
---@field text_width number ---@field text_width number
---@field text_height number ---@field text_height number

View File

@ -71,7 +71,7 @@ end
---@param text string Text for text node ---@param text string Text for text node
---@return druid.lang_text Current instance ---@return druid.lang_text Current instance
function M:set_to(text) function M:set_to(text)
self.last_locale = false self.last_locale = nil
self.text:set_text(text) self.text:set_text(text)
self.on_change:trigger() self.on_change:trigger()

View File

@ -474,14 +474,14 @@ end
---@generic T: druid.base_component ---@generic T: druid.base_component
---@param widget T ---@param widget T
---@param template string|nil The template name used by widget ---@param template string|nil The template name used by widget
---@param nodes table<string|hash, node>|node|nil The nodes table from gui.clone_tree or prefab node to use for clone ---@param nodes table<hash, node>|node|nil The nodes table from gui.clone_tree or prefab node to use for clone
---@vararg any ---@vararg any
---@return T ---@return T
function M:new_widget(widget, template, nodes, ...) function M:new_widget(widget, template, nodes, ...)
local instance = create_widget(self, widget) local instance = create_widget(self, widget)
if type(nodes) == "userdata" then if type(nodes) == "userdata" then
nodes = gui.clone_tree(nodes) nodes = gui.clone_tree(nodes) --[[@as table<hash, node>]]
end end
instance.druid = instance:get_druid(template, nodes) instance.druid = instance:get_druid(template, nodes)
@ -543,10 +543,10 @@ local text = require("druid.base.text")
---Create Text component ---Create Text component
---@param node string|node The node_id or gui.get_node(node_id) ---@param node string|node The node_id or gui.get_node(node_id)
---@param value string|nil Initial text. Default value is node text from GUI scene. ---@param value string|nil Initial text. Default value is node text from GUI scene.
---@param no_adjust boolean|nil If true, text will be not auto-adjust size ---@param adjust_type string|nil Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference
---@return druid.text Text component ---@return druid.text Text component
function M:new_text(node, value, no_adjust) function M:new_text(node, value, adjust_type)
return self:new(text, node, value, no_adjust) return self:new(text, node, value, adjust_type)
end end

View File

@ -136,7 +136,10 @@ function M:on_size_changed(new_size)
local width = self.layout:get_size().x - self.layout.padding.x - self.layout.padding.z local width = self.layout:get_size().x - self.layout.padding.x - self.layout.padding.z
for index = 1, #self.properties do for index = 1, #self.properties do
self.properties[index].container:set_size(width) local property = self.properties[index]
if property.container then
property.container:set_size(width)
end
end end
self.paginator.container:set_size(width) self.paginator.container:set_size(width)
end end
@ -216,7 +219,7 @@ end
---@generic T: druid.widget ---@generic T: druid.widget
---@param widget_class T ---@param widget_class T
---@param template string|nil ---@param template string|nil
---@param nodes table<string, node>|node|nil ---@param nodes table<hash, node>|node|nil
---@param on_create fun(widget: T)|nil ---@param on_create fun(widget: T)|nil
---@return widget.properties_panel ---@return widget.properties_panel
function M:add_inner_widget(widget_class, template, nodes, on_create) function M:add_inner_widget(widget_class, template, nodes, on_create)