Update tests

This commit is contained in:
Insality
2025-04-17 19:18:40 +03:00
parent d1d54896fb
commit 0d0581b108
25 changed files with 1672 additions and 320 deletions

View File

@@ -243,15 +243,15 @@ end
---Get button enabled state.
---By default all Buttons is enabled on creating.
---@return boolean is_enabled True, if button is enabled now, False overwise
---By default all Buttons are enabled on creating.
---@return boolean is_enabled True, if button is enabled now, False otherwise
function M:is_enabled()
return not self.disabled
end
---Set additional button click area.
---Useful to restrict click outside out stencil node or scrollable content.
---Useful to restrict click outside of stencil node or scrollable content.
---If button node placed inside stencil node, it will be automatically set to this stencil node.
---@param zone node|string|nil Gui node
---@return druid.button self The current button instance
@@ -284,9 +284,9 @@ function M:get_key_trigger()
end
---Set function for additional check for button click availability
---Set function for additional check for button click availability.
---@param check_function function|nil Should return true or false. If true - button can be pressed.
---@param failure_callback function|nil Function will be called on button click, if check function return false
---@param failure_callback function|nil Function will be called on button click, if check function returns false
---@return druid.button self The current button instance
function M:set_check_function(check_function, failure_callback)
self._check_function = check_function
@@ -299,7 +299,7 @@ end
---Set Button mode to work inside user HTML5 interaction event.
---
---It's required to make protected things like copy & paste text, show mobile keyboard, etc
---The HTML5 button's doesn't call any events except on_click event.
---The HTML5 button doesn't call any events except on_click event.
---
---If the game is not HTML, html mode will be not enabled
---@param is_web_mode boolean|nil If true - button will be called inside html5 callback

View File

@@ -289,7 +289,7 @@ end
---Set allowed charaters for input field.
-- See: https://defold.com/ref/stable/string/
-- ex: [%a%d] for alpha and numeric
---@param characters string Regulax exp. for validate user input
---@param characters string Regular expression for validate user input
---@return druid.rich_input self Current instance
function M:set_allowed_characters(characters)
self.input:set_allowed_characters(characters)

View File

@@ -110,10 +110,10 @@ local function wrap_widget(widget)
end
---Create a widget from the binded Druid GUI instance.
---Create a widget from the bound Druid GUI instance.
---The widget will be created and all widget functions can be called from Game Object contexts.
---This allow use only `druid_widget.gui_script` for GUI files and call this widget functions from Game Object script file.
---Widget class here is a your lua file for the GUI scene (a widgets in Druid)
---This allows using only `druid_widget.gui_script` for GUI files and call this widget functions from Game Object script file.
---Widget class here is your lua file for the GUI scene (widgets in Druid)
--- msg.url(nil, nil, "gui_widget") -- current game object
--- msg.url(nil, object_url, "gui_widget") -- other game object
---@generic T: druid.widget

View File

@@ -152,7 +152,7 @@ end
---Set new size of layout node
---@param width number|nil The width to set
---@param height number|nil The height to set
---@param anchor_pivot constant|nil If set will keep the corner possition relative to the new size
---@param anchor_pivot constant|nil If set will keep the corner position relative to the new size
---@return druid.container Container
function M:set_size(width, height, anchor_pivot)
width = width or self.size.x

View File

@@ -162,7 +162,7 @@ function M:get_index(data)
end
---Return all currenly created nodes in DataList
---Return all currently created nodes in DataList
---@return node[] List of created nodes
function M:get_created_nodes()
local nodes = {}
@@ -175,7 +175,7 @@ function M:get_created_nodes()
end
---Return all currenly created components in DataList
---Return all currently created components in DataList
---@return druid.component[] components List of created components
function M:get_created_components()
local components = {}

View File

@@ -3,7 +3,7 @@ local helper = require("druid.helper")
local component = require("druid.component")
---@class druid.progress.style
---@field SPEED number|nil Progress bas fill rate. More -> faster. Default: 5
---@field SPEED number|nil Progress bar fill rate. Higher value means faster fill. Default: 5
---@field MIN_DELTA number|nil Minimum step to fill progress bar. Default: 0.005
---Basic Druid progress bar component. Changes the size or scale of a node to represent progress.
@@ -12,10 +12,10 @@ local component = require("druid.component")
---Create progress bar component with druid: `progress = druid:new_progress(node_name, key, init_value)`
---
---### Notes
---- Node should have maximum node size in GUI scene, it's represent the progress bar maximum size
---- Node should have maximum node size in GUI scene, it represents the progress bar's maximum size
---- Key is value from druid const: "x" or "y"
---- Progress works correctly with 9slice nodes, it tries to set size by _set_size_ first, until minimum size is reached, then it sizing via _set_scale_
---- Progress bar can fill only by vertical or horizontal size. For diagonal progress bar, just rotate node in GUI scene
---- Progress works correctly with 9slice nodes, it tries to set size by _set_size_ first until minimum size is reached, then it continues sizing via _set_scale_
---- Progress bar can fill only by vertical or horizontal size. For diagonal progress bar, just rotate the node in GUI scene
---- If you have glitchy or dark texture bugs with progress bar, try to disable mipmaps in your texture profiles
---@class druid.progress: druid.component
---@field node node The progress bar node

View File

@@ -51,6 +51,7 @@ end
---@param text_node node|nil Gui text node
---@param icon_node node|nil Gui box node
---@param margin number Offset between nodes
---@return number width Total width of the centrated elements
---@local
function M.centrate_text_with_icon(text_node, icon_node, margin)
return M.centrate_nodes(margin, text_node, icon_node)
@@ -63,6 +64,7 @@ end
---@param icon_node node|nil Gui box node
---@param text_node node|nil Gui text node
---@param margin number|nil Offset between nodes
---@return number width Total width of the centrated elements
---@local
function M.centrate_icon_with_text(icon_node, text_node, margin)
return M.centrate_nodes(margin, icon_node, text_node)
@@ -75,6 +77,7 @@ end
---The centrate will be around 0 x position.
---@param margin number|nil Offset between nodes
---@param ... node Nodes to centrate
---@return number width Total width of the centrated elements
function M.centrate_nodes(margin, ...)
margin = margin or 0
@@ -109,10 +112,11 @@ function M.centrate_nodes(margin, ...)
end
---@param node_id string|node
---@param template string|nil Full Path to the template
---@param nodes table<hash, node>|nil Nodes what created with gui.clone_tree
---@return node
---Get GUI node from string name, node itself, or template/nodes structure
---@param node_id string|node The node name or node itself
---@param template string|nil Full path to the template
---@param nodes table<hash, node>|nil Nodes created with gui.clone_tree
---@return node The requested node
function M.get_node(node_id, template, nodes)
if type(node_id) ~= "string" then
-- Assume it's already node from gui.get_node
@@ -152,6 +156,7 @@ end
---Get current GUI scale for each side
---@return number scale_x
---@return number scale_y
function M.get_gui_scale()
local window_x, window_y = window.get_size()
return math.min(window_x / gui.get_width(), window_y / gui.get_height())

View File

@@ -176,7 +176,7 @@ local function schedule_late_init(self)
end
---Druid class constructor which used to create a Druid's components
---Druid class constructor which used to create Druid components
---@param context table Druid context. Usually it is self of gui script
---@param style table? Druid style table
---@return druid.instance instance The new Druid instance
@@ -420,8 +420,7 @@ end
---Calls the on_language_change function in all related components
---This one called by global druid.on_language_change, but can be
---call manualy to update all translations
---This one called by global druid.on_language_change, but can be called manually to update all translations
---@private
function M:on_language_change()
local components = self.components_interest[const.ON_LANGUAGE_CHANGE]
@@ -433,7 +432,7 @@ end
---Set whitelist components for input processing.
---If whitelist is not empty and component not contains in this list,
---component will be not processed on input step
---component will be not processed on the input step
---@param whitelist_components table|druid.component[] The array of component to whitelist
---@return druid.instance self The Druid instance
function M:set_whitelist(whitelist_components)
@@ -452,8 +451,8 @@ end
---Set blacklist components for input processing.
---If blacklist is not empty and component contains in this list,
---component will be not processed on input step DruidInstance
---If blacklist is not empty and component is contained in this list,
---component will be not processed on the input step DruidInstance
---@param blacklist_components table|druid.component[] The array of component to blacklist
---@return druid.instance self The Druid instance
function M:set_blacklist(blacklist_components)
@@ -572,7 +571,7 @@ local static_grid = require("druid.base.static_grid")
---Create Grid component
---@param parent_node string|node The node_id or gui.get_node(node_id). Parent of all Grid items.
---@param item string|node Item prefab. Required to get grid's item size. Can be adjusted separately.
---@param in_row number|nil How many nodes in row can be placed
---@param in_row number|nil How many nodes can be placed in a row
---@return druid.grid grid The new grid component
function M:new_grid(parent_node, item, in_row)
return self:new(static_grid, parent_node, item, in_row)
@@ -581,8 +580,8 @@ end
local scroll = require("druid.base.scroll")
---Create Scroll component
---@param view_node string|node The node_id or gui.get_node(node_id). Will used as user input node.
---@param content_node string|node The node_id or gui.get_node(node_id). Will used as scrollable node inside view_node.
---@param view_node string|node The node_id or gui.get_node(node_id). Will be used as user input node.
---@param content_node string|node The node_id or gui.get_node(node_id). Will be used as scrollable node inside view_node.
---@return druid.scroll scroll The new scroll component
function M:new_scroll(view_node, content_node)
return self:new(scroll, view_node, content_node)
@@ -591,7 +590,7 @@ end
local drag = require("druid.base.drag")
---Create Drag component
---@param node string|node The node_id or gui.get_node(node_id). Will used as user input node.
---@param node string|node The node_id or gui.get_node(node_id). Will be used as user input node.
---@param on_drag_callback function|nil Callback for on_drag_event(self, dx, dy)
---@return druid.drag drag The new drag component
function M:new_drag(node, on_drag_callback)
@@ -601,7 +600,7 @@ end
local swipe = require("druid.extended.swipe")
---Create Swipe component
---@param node string|node The node_id or gui.get_node(node_id). Will used as user input node.
---@param node string|node The node_id or gui.get_node(node_id). Will be used as user input node.
---@param on_swipe_callback function|nil Swipe callback for on_swipe_end event
---@return druid.swipe swipe The new swipe component
function M:new_swipe(node, on_swipe_callback)
@@ -611,7 +610,7 @@ end
local lang_text = require("druid.extended.lang_text")
---Create LangText 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 locale_id string|nil Default locale id or text from node as default
---@param adjust_type string|nil Adjust type for text node. Default: "downscale"
---@return druid.lang_text lang_text The new lang text component
@@ -622,7 +621,7 @@ end
local slider = require("druid.extended.slider")
---Create Slider component
---@param pin_node string|node The_node id or gui.get_node(node_id).
---@param pin_node string|node The node_id or gui.get_node(node_id).
---@param end_pos vector3 The end position of slider
---@param callback function|nil On slider change callback
---@return druid.slider slider The new slider component
@@ -633,8 +632,8 @@ end
local input = require("druid.extended.input")
---Create Input component
---@param click_node string|node Button node to enabled input component
---@param text_node string|node|druid.text Text node what will be changed on user input
---@param click_node string|node Button node to enable input component
---@param text_node string|node|druid.text Text node that will be changed on user input
---@param keyboard_type number|nil Gui keyboard type for input field
---@return druid.input input The new input component
function M:new_input(click_node, text_node, keyboard_type)
@@ -678,7 +677,7 @@ end
local layout = require("druid.extended.layout")
---Create Layout 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 mode string|nil vertical|horizontal|horizontal_wrap. Default: horizontal
---@return druid.layout layout The new layout component
function M:new_layout(node, mode)
@@ -688,7 +687,7 @@ end
local container = require("druid.extended.container")
---Create Container 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 mode string|nil Layout mode
---@param callback fun(self: druid.container, size: vector3)|nil Callback on size changed
---@return druid.container container The new container component