Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Insality committed Oct 30, 2024
1 parent 72cf310 commit 6ccf58d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 79 deletions.
7 changes: 2 additions & 5 deletions druid/extended/swipe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions druid/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
84 changes: 15 additions & 69 deletions druid/system/druid_instance.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
-- Copyright (c) 2021 Maksim Tuprikov <[email protected]>. 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.
--
-- <b># Notes #</b>
--
-- 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
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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]

Expand Down Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions example/components/container/container.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ end
function M:fit_into_size(target_size)
self.fit_size = target_size
self:refresh()

return self
end

Expand Down

0 comments on commit 6ccf58d

Please sign in to comment.