From d6bec60ba94bb157cefdc386687e6404be78b4fd Mon Sep 17 00:00:00 2001 From: Insality Date: Wed, 5 Mar 2025 21:52:18 +0200 Subject: [PATCH] Update --- druid/base/scroll.lua | 3 - druid/custom/rich_input/rich_input.lua | 9 --- druid/custom/rich_text/rich_text.lua | 20 ++---- druid/editor_scripts/component.lua_template | 22 ------- druid/extended/data_list.lua | 42 +------------ druid/extended/hotkey.lua | 52 +++++----------- druid/extended/lang_text.lua | 34 +---------- druid/extended/layout.lua | 4 +- druid/extended/progress.lua | 68 +++------------------ druid/extended/slider.lua | 48 ++------------- druid/extended/swipe.lua | 15 ++--- druid/extended/timer.lua | 1 - 12 files changed, 48 insertions(+), 270 deletions(-) delete mode 100644 druid/editor_scripts/component.lua_template diff --git a/druid/base/scroll.lua b/druid/base/scroll.lua index fd41fe5..0be5564 100755 --- a/druid/base/scroll.lua +++ b/druid/base/scroll.lua @@ -183,8 +183,6 @@ end ---Start scroll to target point. ---@param point vector3 Target point ---@param is_instant boolean|nil Instant scroll flag --- @usage scroll:scroll_to(vmath.vector3(0, 50, 0)) --- @usage scroll:scroll_to(vmath.vector3(0), true) function M:scroll_to(point, is_instant) local b = self.available_pos local target = vmath.vector3( @@ -238,7 +236,6 @@ end ---Start scroll to target scroll percent ---@param percent vector3 target percent ---@param is_instant boolean|nil instant scroll flag --- @usage scroll:scroll_to_percent(vmath.vector3(0.5, 0, 0)) function M:scroll_to_percent(percent, is_instant) local border = self.available_pos diff --git a/druid/custom/rich_input/rich_input.lua b/druid/custom/rich_input/rich_input.lua index 307a337..a72bcb7 100644 --- a/druid/custom/rich_input/rich_input.lua +++ b/druid/custom/rich_input/rich_input.lua @@ -51,15 +51,6 @@ local utf8 = utf8 or utf8_lua ---@field cursor_position vector3 local M = component.create("druid.rich_input") ---local SCHEME = { --- ROOT = "root", --- BUTTON = "button", --- PLACEHOLDER = "placeholder_text", --- INPUT = "input_text", --- CURSOR = "cursor_node", --- CURSOR_TEXT = "cursor_text", ---} - local DOUBLE_CLICK_TIME = 0.35 local function animate_cursor(self) diff --git a/druid/custom/rich_text/rich_text.lua b/druid/custom/rich_text/rich_text.lua index 962ad37..ed95e52 100644 --- a/druid/custom/rich_text/rich_text.lua +++ b/druid/custom/rich_text/rich_text.lua @@ -127,8 +127,6 @@ local rich_text = require("druid.custom.rich_text.module.rt") ---@field COLORS table ---@field ADJUST_STEPS number ---@field ADJUST_SCALE_DELTA number ----@field ADJUST_TYPE string ----@field ADJUST_SCALE number ---@class druid.rich_text.lines_metrics ---@field text_width number @@ -150,7 +148,6 @@ local rich_text = require("druid.custom.rich_text.module.rt") local M = component.create("rich_text") ----The RichText constructor ---@param text_node node|string The text node to make Rich Text ---@param value string|nil The initial text value. Default will be gui.get_text(text_node) function M:init(text_node, value) @@ -175,18 +172,13 @@ function M:on_layout_change() end ----Component style params. --- You can override this component styles params in Druid styles table --- or create your own style --- @table style --- @tfield table|nil COLORS Rich Text color aliases. Default: {} --- @tfield number|nil ADJUST_STEPS Amount steps of attemps text adjust by height. Default: 20 --- @tfield number|nil ADJUST_SCALE_DELTA Scale step on each height adjust step. Default: 0.02 +---@param style druid.rich_text.style function M:on_style_change(style) - self.style = {} - self.style.COLORS = style.COLORS or {} - self.style.ADJUST_STEPS = style.ADJUST_STEPS or 20 - self.style.ADJUST_SCALE_DELTA = style.ADJUST_SCALE_DELTA or 0.02 + self.style = { + COLORS = style.COLORS or {}, + ADJUST_STEPS = style.ADJUST_STEPS or 20, + ADJUST_SCALE_DELTA = style.ADJUST_SCALE_DELTA or 0.02, + } end diff --git a/druid/editor_scripts/component.lua_template b/druid/editor_scripts/component.lua_template deleted file mode 100644 index 560dc2a..0000000 --- a/druid/editor_scripts/component.lua_template +++ /dev/null @@ -1,22 +0,0 @@ ---- For component interest functions ---- see https://github.com/Insality/druid/blob/master/docs_md/02-creating_custom_components.md ---- Require this component in you gui file: ---- $ local {COMPONENT_NAME} = require("{COMPONENT_PATH}") ---- And create this component via: ---- $ self.{COMPONENT_TYPE} = self.druid:new({COMPONENT_NAME}, template, nodes) - -local component = require("druid.component") - ----@class {COMPONENT_TYPE}: druid.base_component ----@field druid druid_instance{COMPONENT_ANNOTATIONS} -local M = component.create("{COMPONENT_TYPE}") - - ----@param template string ----@param nodes table -function M:init(template, nodes) - self.druid = self:get_druid(template, nodes){COMPONENT_DEFINE} -end - -{COMPONENT_FUNCTIONS} -return M diff --git a/druid/extended/data_list.lua b/druid/extended/data_list.lua index 7e9953b..f4d77bd 100644 --- a/druid/extended/data_list.lua +++ b/druid/extended/data_list.lua @@ -1,40 +1,3 @@ --- Copyright (c) 2021 Maksim Tuprikov . This code is licensed under MIT license - ----Component to manage data for huge dataset in scroll. --- It requires Druid Scroll and Druid Grid (Static or Dynamic) components --- --- Example Link --- @module DataList --- @within BaseComponent --- @alias druid.data_list - - ----The Druid scroll component --- @tfield Scroll scroll Scroll - ----The Druid Grid component --- @tfield StaticGrid grid StaticGrid}, @{DynamicGrid - ----The current progress of scroll posititon --- @tfield number scroll_progress - ----The current top index of visual elements --- @tfield number top_index - ----The current last index of visual elements --- @tfield number last_index - ----Event triggered when scroll progress is changed; event(self, progress_value) --- @tfield event on_scroll_progress_change event - ----On DataList visual element created Event callback(self, index, node, instance) --- @tfield event on_element_add event - ----On DataList visual element created Event callback(self, index) --- @tfield event on_element_remove event - ---- - local const = require("druid.const") local helper = require("druid.helper") local component = require("druid.component") @@ -46,16 +9,17 @@ local event = require("event.event") ---@field on_scroll_progress_change event ---@field on_element_add event ---@field on_element_remove event +---@field top_index number +---@field last_index number +---@field scroll_progress number ---@field private _create_function function ---@field private _is_use_cache boolean ---@field private _cache table ---@field private _data table ---@field private _data_visual table ----@field top_index number local M = component.create("data_list") ----The DataList constructor ---@param scroll druid.scroll The Scroll instance for Data List component ---@param grid druid.grid The StaticGrid} or @{DynamicGrid instance for Data List component ---@param create_function function The create function callback(self, data, index, data_list). Function should return (node, [component]) diff --git a/druid/extended/hotkey.lua b/druid/extended/hotkey.lua index 7a7d20f..d32419c 100644 --- a/druid/extended/hotkey.lua +++ b/druid/extended/hotkey.lua @@ -1,37 +1,14 @@ --- Copyright (c) 2021 Maksim Tuprikov . This code is licensed under MIT license - ----Druid hotkey component --- --- Example Link --- @module Hotkey --- @within BaseComponent --- @alias druid.hotkey - ----On hotkey released callback(self, argument) --- @tfield event on_hotkey_pressed event - ----On hotkey released callback(self, argument) --- @tfield event on_hotkey_released event - ----Visual node --- @tfield node node - ----Button trigger node --- @tfield node|nil click_node - ----Button component from click_node --- @tfield Button button Button - ---- - +local event = require("event.event") local helper = require("druid.helper") local component = require("druid.component") -local event = require("event.event") + +---@class druid.hotkey.style +---@field MODIFICATORS string[]|hash[] The list of action_id as hotkey modificators ---@class druid.hotkey: druid.component ---@field on_hotkey_pressed event ---@field on_hotkey_released event ----@field style table +---@field style druid.hotkey.style ---@field private _hotkeys table ---@field private _modificators table local M = component.create("hotkey") @@ -56,17 +33,17 @@ function M:init(keys, callback, callback_argument) end ----Component style params. --- You can override this component styles params in druid styles table --- or create your own style --- @table style --- @tfield string[] MODIFICATORS The list of action_id as hotkey modificators +---@param style druid.hotkey.style function M:on_style_change(style) - self.style = {} - self.style.MODIFICATORS = style.MODIFICATORS or {} + self.style = { + MODIFICATORS = style.MODIFICATORS or {}, + } for index = 1, #style.MODIFICATORS do - self.style.MODIFICATORS[index] = hash(self.style.MODIFICATORS[index]) + local modificator = style.MODIFICATORS[index] + if type(modificator) == "string" then + self.style.MODIFICATORS[index] = hash(modificator) + end end end @@ -132,6 +109,9 @@ function M:on_focus_gained() end +---@param action_id hash|nil +---@param action action +---@return boolean function M:on_input(action_id, action) if not action_id then return false diff --git a/druid/extended/lang_text.lua b/druid/extended/lang_text.lua index 2b29add..940bb61 100755 --- a/druid/extended/lang_text.lua +++ b/druid/extended/lang_text.lua @@ -1,36 +1,6 @@ --- Copyright (c) 2021 Maksim Tuprikov . This code is licensed under MIT license - ----Component to wrap over GUI Text nodes with localization helpers --- --- # Overview # --- --- • The initialization of druid.set_text_function is required to enable localization --- using the localization ID. --- --- • The LangText component supports up to 7 string format parameters. --- This limitation exists due to certain issues with using ... arguments. --- --- # Notes # --- --- Example Link --- @module LangText --- @within BaseComponent --- @alias druid.lang_text - ----On change text callback --- @tfield event on_change event - ----The text component --- @tfield Text text Text - ----Text node --- @tfield node node - ---- - local event = require("event.event") -local settings = require("druid.system.settings") local component = require("druid.component") +local settings = require("druid.system.settings") ---@class druid.lang_text: druid.component ---@field text druid.text @@ -41,7 +11,6 @@ local component = require("druid.component") local M = component.create("lang_text") ----The LangText constructor ---@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. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference @@ -110,4 +79,5 @@ function M:format(...) return self end + return M diff --git a/druid/extended/layout.lua b/druid/extended/layout.lua index 610e723..057e451 100644 --- a/druid/extended/layout.lua +++ b/druid/extended/layout.lua @@ -33,8 +33,7 @@ local component = require("druid.component") ---@field on_size_changed event.on_size_changed local M = component.create("layout") ----Layout component constructor ----@local + ---@param node_or_node_id node|string ---@param layout_type druid.layout.mode function M:init(node_or_node_id, layout_type) @@ -60,7 +59,6 @@ function M:init(node_or_node_id, layout_type) end ----@local function M:update() if not self.is_dirty then return diff --git a/druid/extended/progress.lua b/druid/extended/progress.lua index 5f3a677..dd11d9e 100644 --- a/druid/extended/progress.lua +++ b/druid/extended/progress.lua @@ -1,58 +1,16 @@ --- Copyright (c) 2021 Maksim Tuprikov . This code is licensed under MIT license - ----Druid component to handle the progress bars. --- # Overview # --- --- # Notes # --- --- • Progress Node should be fully filled in your GUI scene node. It will be the progress maximum size --- --- • Progress correct working with Slice9 nodes, it trying to set size by _set_size_ first, if it is not possible, it set up sizing via _set_scale_ --- --- • Progress bar can fill only by vertical or horizontal size. If you want make diagonal progress bar, just rotate node in GUI scene --- --- • If you have glitchy or dark texture bug with progress bar, try to disable mipmaps in your texture profiles --- --- --- Example Link --- @module Progress --- @within BaseComponent --- @alias druid.progress - ----On progress bar change callback(self, new_value) --- @tfield event on_change event - ----Progress bar fill node --- @tfield node node - ----The progress bar direction. --- --- The values are: "x" or "y". (const.SIDE.X or const.SIDE.Y) --- @tfield string key - ----Current progress bar scale --- @tfield vector3 scale - ----Current progress bar size --- @tfield vector3 size - ----Maximum size of progress bar --- @tfield number max_size - ----Progress bar slice9 settings --- @tfield vector4 slice - ---- - local event = require("event.event") local const = require("druid.const") 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 MIN_DELTA number|nil Minimum step to fill progress bar. Default: 0.005 + ---@class druid.progress: druid.component ---@field node node ---@field on_change event ----@field style table +---@field style druid.progress.style ---@field key string ---@field prop hash local M = component.create("progress") @@ -117,16 +75,12 @@ local function set_bar_to(self, set_to, is_silent) end ----Component style params. --- You can override this component styles params in druid styles table --- or create your own style --- @table style --- @tfield number|nil SPEED Progress bas fill rate. More -> faster. Default: 5 --- @tfield number|nil MIN_DELTA Minimum step to fill progress bar. Default: 0.005 +---@param style druid.progress.style function M:on_style_change(style) - self.style = {} - self.style.SPEED = style.SPEED or 5 - self.style.MIN_DELTA = style.MIN_DELTA or 0.005 + self.style = { + SPEED = style.SPEED or 5, + MIN_DELTA = style.MIN_DELTA or 0.005, + } end @@ -166,7 +120,6 @@ end function M:on_remove() - -- Return default size gui.set_size(self.node, self.max_size) end @@ -220,7 +173,6 @@ end ---Set points on progress bar to fire the callback ---@param steps number[] Array of progress bar values ---@param callback function Callback on intersect step value --- @usage progress:set_steps({0, 0.3, 0.6, 1}, function(self, step) end) function M:set_steps(steps, callback) self.steps = steps self.step_callback = callback diff --git a/druid/extended/slider.lua b/druid/extended/slider.lua index ff781e1..57fd082 100644 --- a/druid/extended/slider.lua +++ b/druid/extended/slider.lua @@ -1,42 +1,3 @@ --- Copyright (c) 2021 Maksim Tuprikov . This code is licensed under MIT license - ----Druid slider component --- --- Example Link --- @module Slider --- @within BaseComponent --- @alias druid.slider - ----On change value callback(self, value) --- @tfield event on_change_value event - ----Slider pin node --- @tfield node node - ----Start pin node position --- @tfield vector3 start_pos - ----Current pin node position --- @tfield vector3 pos - ----Targer pin node position --- @tfield vector3 target_pos - ----End pin node position --- @tfield vector3 end_pos - ----Length between start and end position --- @tfield vector3 dist - ----Current drag state --- @tfield boolean is_drag - ----Current slider value --- @tfield number value - ---- - - local event = require("event.event") local helper = require("druid.helper") local const = require("druid.const") @@ -209,9 +170,8 @@ end ---Set slider steps. Pin node will --- apply closest step position +---apply closest step position ---@param steps number[] Array of steps --- @usage slider:set_steps({0, 0.2, 0.6, 1}) ---@return druid.slider Slider function M:set_steps(steps) self.steps = steps @@ -220,9 +180,9 @@ end ---Set input zone for slider. --- User can touch any place of node, pin instantly will --- move at this position and node drag will start. --- This function require the Defold version 1.3.0+ +---User can touch any place of node, pin instantly will +---move at this position and node drag will start. +---This function require the Defold version 1.3.0+ ---@param input_node node|string|nil ---@return druid.slider Slider function M:set_input_node(input_node) diff --git a/druid/extended/swipe.lua b/druid/extended/swipe.lua index b37f589..8c6cf69 100644 --- a/druid/extended/swipe.lua +++ b/druid/extended/swipe.lua @@ -3,9 +3,6 @@ local const = require("druid.const") local helper = require("druid.helper") local component = require("druid.component") ----Component style params. ----You can override this component styles params in druid styles table ----or create your own style ---@class druid.swipe.style ---@field SWIPE_TIME number|nil Maximum time for swipe trigger. Default: 0.4 ---@field SWIPE_THRESHOLD number|nil Minimum distance for swipe trigger. Default: 50 @@ -26,14 +23,14 @@ local M = component.create("swipe") ---@param style druid.swipe.style function M:on_style_change(style) - self.style = {} - self.style.SWIPE_TIME = style.SWIPE_TIME or 0.4 - self.style.SWIPE_THRESHOLD = style.SWIPE_THRESHOLD or 50 - self.style.SWIPE_TRIGGER_ON_MOVE = style.SWIPE_TRIGGER_ON_MOVE or false + self.style = { + SWIPE_TIME = style.SWIPE_TIME or 0.4, + SWIPE_THRESHOLD = style.SWIPE_THRESHOLD or 50, + SWIPE_TRIGGER_ON_MOVE = style.SWIPE_TRIGGER_ON_MOVE or false, + } end ----Swipe constructor ---@param node_or_node_id node|string ---@param on_swipe_callback function function M:init(node_or_node_id, on_swipe_callback) @@ -97,7 +94,7 @@ end ---Strict swipe click area. Useful for --- restrict events outside stencil node +---restrict events outside stencil node ---@param zone node|string|nil Gui node function M:set_click_zone(zone) if not zone then diff --git a/druid/extended/timer.lua b/druid/extended/timer.lua index 9ce6210..c2599fa 100644 --- a/druid/extended/timer.lua +++ b/druid/extended/timer.lua @@ -6,7 +6,6 @@ local component = require("druid.component") ---@field on_tick event ---@field on_set_enabled event ---@field on_timer_end event ----@field style table ---@field node node ---@field from number ---@field target number