From 6ccf58d527d6161bb58ea16d10857bb9eb417ecc Mon Sep 17 00:00:00 2001 From: Insality Date: Wed, 30 Oct 2024 23:46:39 +0200 Subject: [PATCH] Update docs --- druid/extended/swipe.lua | 7 +- druid/helper.lua | 12 ++-- druid/system/druid_instance.lua | 84 ++++------------------ example/components/container/container.lua | 1 + 4 files changed, 25 insertions(+), 79 deletions(-) diff --git a/druid/extended/swipe.lua b/druid/extended/swipe.lua index c153ce7..6d900a1 100644 --- a/druid/extended/swipe.lua +++ b/druid/extended/swipe.lua @@ -95,11 +95,6 @@ function M:on_style_change(style) end ---- The Swipe constructor --- @tparam Swipe self Swipe --- @tparam node node Gui node --- @tparam function on_swipe_callback Swipe callback for on_swipe_end event - ---Swipe constructor ---@param node_or_node_id node|string ---@param on_swipe_callback function @@ -125,6 +120,8 @@ function M:on_late_init() end +---@param action_id hash +---@param action action function M:on_input(action_id, action) if action_id ~= const.ACTION_TOUCH then return false diff --git a/druid/helper.lua b/druid/helper.lua index 8d54cee..7560fe7 100644 --- a/druid/helper.lua +++ b/druid/helper.lua @@ -3,7 +3,8 @@ local const = require("druid.const") local gui_get_node = gui.get_node - +local gui_get = gui.get +local gui_pick_node = gui.pick_node ---@class druid.system.helper local M = {} @@ -16,7 +17,7 @@ local SIZE_X = hash("size.x") local function get_text_width(text_node) if text_node then local text_metrics = M.get_text_metrics_from_node(text_node) - local text_scale = gui.get(text_node, SCALE_X) + local text_scale = gui_get(text_node, SCALE_X) return text_metrics.width * text_scale end @@ -26,7 +27,7 @@ end local function get_icon_width(icon_node) if icon_node then - return gui.get(icon_node, SIZE_X) * gui.get(icon_node, SCALE_X) -- icon width + return gui_get(icon_node, SIZE_X) * gui_get(icon_node, SCALE_X) -- icon width end return 0 @@ -55,6 +56,7 @@ function M.centrate_text_with_icon(text_node, icon_node, margin) return M.centrate_nodes(margin, text_node, icon_node) end + ---Center two nodes. --Nodes will be center around 0 x position --icon_node will be first (at left side) @@ -286,10 +288,10 @@ end ---@param node_click_area node|nil ---@local function M.pick_node(node, x, y, node_click_area) - local is_pick = gui.pick_node(node, x, y) + local is_pick = gui_pick_node(node, x, y) if node_click_area then - is_pick = is_pick and gui.pick_node(node_click_area, x, y) + is_pick = is_pick and gui_pick_node(node_click_area, x, y) end return is_pick diff --git a/druid/system/druid_instance.lua b/druid/system/druid_instance.lua index 176caff..62f2323 100755 --- a/druid/system/druid_instance.lua +++ b/druid/system/druid_instance.lua @@ -1,13 +1,4 @@ --- Copyright (c) 2021 Maksim Tuprikov . This code is licensed under MIT license ---- Druid Instance which you use for component creation. --- --- # Component List # --- --- For a list of all available components, please refer to the "See Also" section. --- --- # Notes # --- -- Please review the following API pages: -- -- Helper - A useful set of functions for working with GUI nodes, such as centering nodes, get GUI scale ratio, etc @@ -23,49 +14,6 @@ -- • When using Druid components, provide the node name as a string argument directly. Avoid calling gui.get_node() before passing it to the component. Because Druid can get nodes from template and cloned gui nodes. -- -- • All Druid and component methods are called using the colon operator (e.g., self.druid:new_button()). --- @usage --- local druid = require("druid.druid") --- --- local function close_window(self) --- print("Yeah! You closed the game!") --- end --- --- function init(self) --- self.druid = druid.new(self) --- --- -- Call all druid instance function with ":" syntax: --- local text = self.druid:new_text("text_header", "Hello Druid!") --- local button = self.druid:new_button("button_close", close_window) --- --- -- You not need to save component reference if not need it --- self.druid:new_back_handler(close_window) --- end --- --- @module DruidInstance --- @alias druid_instance --- @see BackHandler --- @see Blocker --- @see Button --- @see Checkbox --- @see CheckboxGroup --- @see DataList --- @see Drag --- @see DynamicGrid --- @see Hotkey --- @see Hover --- @see Input --- @see LangText --- @see Layout --- @see Progress --- @see RadioGroup --- @see RichInput --- @see RichText --- @see Scroll --- @see Slider --- @see StaticGrid --- @see Swipe --- @see Text --- @see Timer local const = require("druid.const") local helper = require("druid.helper") @@ -283,8 +231,8 @@ end --- Druid class constructor --- @tparam table context Druid context. Usually it is self of gui script --- @tparam table style Druid style table +---@param table context Druid context. Usually it is self of gui script +---@param table style Druid style table -- @local function M:initialize(context, style) self._context = context @@ -343,8 +291,8 @@ end --- Remove created component from Druid instance. -- -- Component `on_remove` function will be invoked, if exist. --- @tparam BaseComponent component Component instance --- @treturn boolean True if component was removed +---@param BaseComponent component Component instance +---@return boolean True if component was removed function M:remove(component) if self._is_late_remove_enabled then table.insert(self._late_remove, component) @@ -412,7 +360,7 @@ end --- Call this in gui_script update function. -- -- Used for: scroll, progress, timer components --- @tparam number dt Delta time +---@param dt number Delta time function M:update(dt) self._is_late_remove_enabled = true @@ -429,9 +377,9 @@ end --- Call this in gui_script on_input function. -- -- Used for almost all components --- @tparam hash action_id Action_id from on_input --- @tparam table action Action from on_input --- @treturn boolean The boolean value is input was consumed +---@param action_id hash Action_id from on_input +---@param action table Action from on_input +---@return boolean The boolean value is input was consumed function M:on_input(action_id, action) self._is_late_remove_enabled = true @@ -449,9 +397,9 @@ end --- Call this in gui_script on_message function. -- -- Used for special actions. See SPECIFIC_UI_MESSAGES table --- @tparam hash message_id Message_id from on_message --- @tparam table message Message from on_message --- @tparam url sender Sender from on_message +---@param message_id hash Message_id from on_message +---@param message table Message from on_message +---@param sender url Sender from on_message function M:on_message(message_id, message, sender) local specific_ui_message = base_component.SPECIFIC_UI_MESSAGES[message_id] @@ -520,11 +468,10 @@ 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 --- @tparam table|BaseComponent|nil whitelist_components The array of component to whitelist --- @treturn self DruidInstance +---@param whitelist_components table|druid.base_component[]|nil The array of component to whitelist +---@return druid_instance function M:set_whitelist(whitelist_components) if whitelist_components and whitelist_components._component then whitelist_components = { whitelist_components } @@ -541,11 +488,10 @@ 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 --- @tparam table|BaseComponent|nil blacklist_components The array of component to blacklist --- @treturn self DruidInstance +---@param blacklist_components table|druid.base_component[]|nil The array of component to blacklist +---@return druid_instance function M:set_blacklist(blacklist_components) if blacklist_components and blacklist_components._component then blacklist_components = { blacklist_components } diff --git a/example/components/container/container.lua b/example/components/container/container.lua index ffacc27..d425c45 100644 --- a/example/components/container/container.lua +++ b/example/components/container/container.lua @@ -195,6 +195,7 @@ end function M:fit_into_size(target_size) self.fit_size = target_size self:refresh() + return self end