From a5e579ddaa1f988b66d0fd26511f7876b6e01144 Mon Sep 17 00:00:00 2001 From: Insality Date: Tue, 15 Oct 2024 02:48:41 +0300 Subject: [PATCH] Update button hold callback --- druid/annotations.lua | 2 ++ druid/base/button.lua | 7 ++++++- druid/editor_scripts/component.lua_template | 2 +- utils/annotations_manual.lua | 2 ++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/druid/annotations.lua b/druid/annotations.lua index e614543..e8395b4 100644 --- a/druid/annotations.lua +++ b/druid/annotations.lua @@ -1952,6 +1952,8 @@ function helper.table_to_string(t) end -- Manual Annotations -- +---@class druid.component: druid.base_component + ---@class druid.rich_text.metrics ---@field width number ---@field height number diff --git a/druid/base/button.lua b/druid/base/button.lua index f406801..b08d897 100755 --- a/druid/base/button.lua +++ b/druid/base/button.lua @@ -240,7 +240,12 @@ local function on_button_release(self) is_double_click = is_double_click and self.on_double_click:is_exist() if is_long_click then - on_button_long_click(self) + local is_hold_complete = (time - self.last_pressed_time) >= self.style.AUTOHOLD_TRIGGER + if is_hold_complete then + on_button_long_click(self) + else + self.on_click_outside:trigger(self:get_context(), self.params, self) + end elseif is_double_click then on_button_double_click(self) else diff --git a/druid/editor_scripts/component.lua_template b/druid/editor_scripts/component.lua_template index 560dc2a..f33bae3 100644 --- a/druid/editor_scripts/component.lua_template +++ b/druid/editor_scripts/component.lua_template @@ -7,7 +7,7 @@ local component = require("druid.component") ----@class {COMPONENT_TYPE}: druid.base_component +---@class {COMPONENT_TYPE}: druid.component ---@field druid druid_instance{COMPONENT_ANNOTATIONS} local M = component.create("{COMPONENT_TYPE}") diff --git a/utils/annotations_manual.lua b/utils/annotations_manual.lua index 6f6547a..cc258b2 100644 --- a/utils/annotations_manual.lua +++ b/utils/annotations_manual.lua @@ -1,5 +1,7 @@ -- Manual Annotations -- +---@class druid.component: druid.base_component + ---@class druid.rich_text.metrics ---@field width number ---@field height number