mirror of
https://github.com/Insality/druid
synced 2025-06-27 18:37:45 +02:00
Update annotations, add set_repeat
to hotkey component
This commit is contained in:
parent
97ff6154eb
commit
01d1445511
@ -43,13 +43,20 @@ function druid.set_text_function(callback) end
|
|||||||
|
|
||||||
---@class druid.back_handler : druid.base_component
|
---@class druid.back_handler : druid.base_component
|
||||||
---@field on_back druid.event The @{DruidEvent} Event on back handler action.
|
---@field on_back druid.event The @{DruidEvent} Event on back handler action.
|
||||||
---@field params any Custom args to pass in the callback
|
---@field params any|nil Custom args to pass in the callback
|
||||||
local druid__back_handler = {}
|
local druid__back_handler = {}
|
||||||
|
|
||||||
|
|
||||||
---@class druid.base_component
|
---@class druid.base_component
|
||||||
local druid__base_component = {}
|
local druid__base_component = {}
|
||||||
|
|
||||||
|
--- Set current component style table.
|
||||||
|
--- Invoke `on_style_change` on component, if exist. Component should handle their style changing and store all style params
|
||||||
|
---@param self druid.base_component @{BaseComponent}
|
||||||
|
---@param druid_style table|nil Druid style module
|
||||||
|
---@return druid.base_component @{BaseComponent}
|
||||||
|
function druid__base_component.component:set_style(self, druid_style) end
|
||||||
|
|
||||||
--- Return all children components, recursive
|
--- Return all children components, recursive
|
||||||
---@param self druid.base_component @{BaseComponent}
|
---@param self druid.base_component @{BaseComponent}
|
||||||
---@return table Array of childrens if the Druid component instance
|
---@return table Array of childrens if the Druid component instance
|
||||||
@ -131,13 +138,6 @@ function druid__base_component.set_input_priority(self, value, is_temporary) end
|
|||||||
---@return druid.base_component @{BaseComponent}
|
---@return druid.base_component @{BaseComponent}
|
||||||
function druid__base_component.set_nodes(self, nodes) end
|
function druid__base_component.set_nodes(self, nodes) end
|
||||||
|
|
||||||
--- Set current component style table.
|
|
||||||
--- Invoke `on_style_change` on component, if exist. Component should handle their style changing and store all style params
|
|
||||||
---@param self druid.base_component @{BaseComponent}
|
|
||||||
---@param druid_style table|nil Druid style module
|
|
||||||
---@return druid.base_component @{BaseComponent}
|
|
||||||
function druid__base_component.set_style(self, druid_style) end
|
|
||||||
|
|
||||||
--- Set component template name.
|
--- Set component template name.
|
||||||
--- Use on all your custom components with GUI layouts used as templates. It will check parent template name to build full template name in self:get_node()
|
--- Use on all your custom components with GUI layouts used as templates. It will check parent template name to build full template name in self:get_node()
|
||||||
---@param self druid.base_component @{BaseComponent}
|
---@param self druid.base_component @{BaseComponent}
|
||||||
@ -169,7 +169,7 @@ function druid__blocker.set_enabled(self, state) end
|
|||||||
|
|
||||||
---@class druid.button : druid.base_component
|
---@class druid.button : druid.base_component
|
||||||
---@field anim_node node Button animation node.
|
---@field anim_node node Button animation node.
|
||||||
---@field click_zone node Additional button click area, defined by another GUI Node
|
---@field click_zone node|nil Additional button click area, defined by another GUI node
|
||||||
---@field hover druid.hover The @{Hover}: Button Hover component
|
---@field hover druid.hover The @{Hover}: Button Hover component
|
||||||
---@field node node Button trigger node
|
---@field node node Button trigger node
|
||||||
---@field node_id hash The GUI node id from button node
|
---@field node_id hash The GUI node id from button node
|
||||||
@ -226,7 +226,7 @@ function druid__button.set_enabled(self, state) end
|
|||||||
|
|
||||||
--- Set key name to trigger this button by keyboard.
|
--- Set key name to trigger this button by keyboard.
|
||||||
---@param self druid.button @{Button}
|
---@param self druid.button @{Button}
|
||||||
---@param key hash The action_id of the input key
|
---@param key hash|string The action_id of the input key
|
||||||
---@return druid.button Current button instance
|
---@return druid.button Current button instance
|
||||||
function druid__button.set_key_trigger(self, key) end
|
function druid__button.set_key_trigger(self, key) end
|
||||||
|
|
||||||
@ -384,9 +384,10 @@ function druid__data_list.set_data(self, data) end
|
|||||||
---@field can_y boolean Is drag component process horizontal.
|
---@field can_y boolean Is drag component process horizontal.
|
||||||
---@field is_drag boolean Is component now dragging
|
---@field is_drag boolean Is component now dragging
|
||||||
---@field is_touch boolean Is component now touching
|
---@field is_touch boolean Is component now touching
|
||||||
|
---@field node node Drag node
|
||||||
---@field on_drag druid.event on drag progress callback(self, dx, dy, total_x, total_y)
|
---@field on_drag druid.event on drag progress callback(self, dx, dy, total_x, total_y)
|
||||||
---@field on_drag_end druid.event Event on drag end callback(self, total_x, total_y)
|
---@field on_drag_end druid.event Event on drag end callback(self, total_x, total_y)
|
||||||
---@field on_drag_start druid.event Event on drag start callback(self)
|
---@field on_drag_start druid.event Event on drag start callback(self, touch)
|
||||||
---@field on_touch_end druid.event Event on touch end callback(self)
|
---@field on_touch_end druid.event Event on touch end callback(self)
|
||||||
---@field on_touch_start druid.event Event on touch start callback(self)
|
---@field on_touch_start druid.event Event on touch start callback(self)
|
||||||
---@field style druid.drag.style Component style params.
|
---@field style druid.drag.style Component style params.
|
||||||
@ -561,17 +562,22 @@ local druid__hotkey = {}
|
|||||||
--- Add hotkey for component callback
|
--- Add hotkey for component callback
|
||||||
---@param self druid.hotkey @{Hotkey}
|
---@param self druid.hotkey @{Hotkey}
|
||||||
---@param keys string[]|hash[]|string|hash that have to be pressed before key pressed to activate
|
---@param keys string[]|hash[]|string|hash that have to be pressed before key pressed to activate
|
||||||
---@param callback_argument any|nil The argument to pass into the callback function
|
---@param callback_argument value The argument to pass into the callback function
|
||||||
---@return druid.hotkey Current instance
|
|
||||||
function druid__hotkey.add_hotkey(self, keys, callback_argument) end
|
function druid__hotkey.add_hotkey(self, keys, callback_argument) end
|
||||||
|
|
||||||
--- The @{Hotkey} constructor
|
--- Component init function
|
||||||
---@param self druid.hotkey @{Hotkey}
|
---@param self druid.hotkey @{Hotkey}
|
||||||
---@param keys string[]|string The keys to be pressed for trigger callback. Should contains one key and any modificator keys
|
---@param keys string[]|string The keys to be pressed for trigger callback. Should contains one key and any modificator keys
|
||||||
---@param callback function The callback function
|
---@param callback function The callback function
|
||||||
---@param callback_argument any|nil The argument to pass into the callback function
|
---@param callback_argument value The argument to pass into the callback function
|
||||||
function druid__hotkey.init(self, keys, callback, callback_argument) end
|
function druid__hotkey.init(self, keys, callback, callback_argument) end
|
||||||
|
|
||||||
|
--- If true, the callback will be triggered on action.repeated
|
||||||
|
---@param self druid.hotkey @{Hotkey}
|
||||||
|
---@param is_enabled_repeated bool The flag value
|
||||||
|
---@return druid.hotkey
|
||||||
|
function druid__hotkey.set_repeat(self, is_enabled_repeated) end
|
||||||
|
|
||||||
|
|
||||||
---@class druid.hotkey.style
|
---@class druid.hotkey.style
|
||||||
---@field MODIFICATORS string[] The list of action_id as hotkey modificators
|
---@field MODIFICATORS string[] The list of action_id as hotkey modificators
|
||||||
@ -630,12 +636,12 @@ function druid__hover.set_mouse_hover(self, state) end
|
|||||||
|
|
||||||
|
|
||||||
---@class druid.input : druid.base_component
|
---@class druid.input : druid.base_component
|
||||||
---@field allowerd_characters string Pattern matching for user input
|
---@field allowerd_characters string|nil Pattern matching for user input
|
||||||
---@field button druid.button Button component
|
---@field button druid.button Button component
|
||||||
---@field is_empty boolean Is current input is empty now
|
---@field is_empty boolean Is current input is empty now
|
||||||
---@field is_selected boolean Is current input selected now
|
---@field is_selected boolean Is current input selected now
|
||||||
---@field keyboard_type number Gui keyboard type for input field
|
---@field keyboard_type number Gui keyboard type for input field
|
||||||
---@field max_length number Max length for input text
|
---@field max_length number|nil Max length for input text
|
||||||
---@field on_input_empty druid.event On input field text change to empty string callback(self, input_text)
|
---@field on_input_empty druid.event On input field text change to empty string callback(self, input_text)
|
||||||
---@field on_input_full druid.event On input field text change to max length string callback(self, input_text)
|
---@field on_input_full druid.event On input field text change to max length string callback(self, input_text)
|
||||||
---@field on_input_select druid.event On input field select callback(self, button_node)
|
---@field on_input_select druid.event On input field select callback(self, button_node)
|
||||||
@ -1002,6 +1008,7 @@ local druid__rich_text__style = {}
|
|||||||
|
|
||||||
|
|
||||||
---@class druid.scroll : druid.base_component
|
---@class druid.scroll : druid.base_component
|
||||||
|
---@field _is_inert bool Flag, if scroll now moving by inertion
|
||||||
---@field available_pos vector4 Available position for content node: (min_x, max_y, max_x, min_y)
|
---@field available_pos vector4 Available position for content node: (min_x, max_y, max_x, min_y)
|
||||||
---@field available_size vector3 Size of available positions: (width, height, 0)
|
---@field available_size vector3 Size of available positions: (width, height, 0)
|
||||||
---@field content_node node Scroll content node
|
---@field content_node node Scroll content node
|
||||||
@ -1012,7 +1019,7 @@ local druid__rich_text__style = {}
|
|||||||
---@field on_scroll druid.event On scroll move callback(self, position)
|
---@field on_scroll druid.event On scroll move callback(self, position)
|
||||||
---@field on_scroll_to druid.event On scroll_to function callback(self, target, is_instant)
|
---@field on_scroll_to druid.event On scroll_to function callback(self, target, is_instant)
|
||||||
---@field position vector3 Current scroll posisition
|
---@field position vector3 Current scroll posisition
|
||||||
---@field selected number Current index of points of interests
|
---@field selected number|nil Current index of points of interests
|
||||||
---@field style druid.scroll.style Component style params.
|
---@field style druid.scroll.style Component style params.
|
||||||
---@field target_position vector3 Current scroll target position
|
---@field target_position vector3 Current scroll target position
|
||||||
---@field view_node node Scroll view node
|
---@field view_node node Scroll view node
|
||||||
@ -1394,7 +1401,7 @@ function druid__text.set_size(self, size) end
|
|||||||
|
|
||||||
--- Set text adjust, refresh the current text visuals, if needed
|
--- Set text adjust, refresh the current text visuals, if needed
|
||||||
---@param self druid.text @{Text}
|
---@param self druid.text @{Text}
|
||||||
---@param adjust_type number|nil See const.TEXT_ADJUST. If pass nil - use current adjust type
|
---@param adjust_type string|nil See const.TEXT_ADJUST. If pass nil - use current adjust type
|
||||||
---@param minimal_scale number|nil If pass nil - not use minimal scale
|
---@param minimal_scale number|nil If pass nil - not use minimal scale
|
||||||
---@return druid.text Current text instance
|
---@return druid.text Current text instance
|
||||||
function druid__text.set_text_adjust(self, adjust_type, minimal_scale) end
|
function druid__text.set_text_adjust(self, adjust_type, minimal_scale) end
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
-- @usage
|
-- @usage
|
||||||
-- -- Replace params on runtime:
|
-- -- Replace params on runtime:
|
||||||
-- back_handler.params = { ... }
|
-- back_handler.params = { ... }
|
||||||
-- @tfield[opt] any params
|
-- @tfield any|nil params
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
-- print("Also the button component is passed in callback params")
|
-- print("Also the button component is passed in callback params")
|
||||||
-- end
|
-- end
|
||||||
--
|
--
|
||||||
-- local custom_args = "any variable to pass inside callback"
|
-- local custom_args = "Any variable to pass inside callback"
|
||||||
-- local button = self.druid:new_button("button_name", on_button_click, custom_args)
|
-- local button = self.druid:new_button("button_name", on_button_click, custom_args)
|
||||||
--
|
--
|
||||||
-- @module Button
|
-- @module Button
|
||||||
@ -131,8 +131,8 @@
|
|||||||
--- The @{Hover}: Button Hover component
|
--- The @{Hover}: Button Hover component
|
||||||
-- @tfield Hover hover @{Hover}
|
-- @tfield Hover hover @{Hover}
|
||||||
|
|
||||||
--- Additional button click area, defined by another GUI Node
|
--- Additional button click area, defined by another GUI node
|
||||||
-- @tfield[opt] node click_zone
|
-- @tfield node|nil click_zone
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -257,6 +257,7 @@ end
|
|||||||
--- Component style params.
|
--- Component style params.
|
||||||
-- You can override this component styles params in Druid styles table
|
-- You can override this component styles params in Druid styles table
|
||||||
-- or create your own style
|
-- or create your own style
|
||||||
|
-- @table style
|
||||||
-- @tfield[opt=0.4] number LONGTAP_TIME Minimum time to trigger on_hold_callback
|
-- @tfield[opt=0.4] number LONGTAP_TIME Minimum time to trigger on_hold_callback
|
||||||
-- @tfield[opt=0.8] number AUTOHOLD_TRIGGER Maximum hold time to trigger button release while holding
|
-- @tfield[opt=0.8] number AUTOHOLD_TRIGGER Maximum hold time to trigger button release while holding
|
||||||
-- @tfield[opt=0.4] number DOUBLETAP_TIME Time between double taps
|
-- @tfield[opt=0.4] number DOUBLETAP_TIME Time between double taps
|
||||||
@ -265,7 +266,6 @@ end
|
|||||||
-- @tfield function on_hover function(self, node, hover_state)
|
-- @tfield function on_hover function(self, node, hover_state)
|
||||||
-- @tfield function on_mouse_hover function(self, node, hover_state)
|
-- @tfield function on_mouse_hover function(self, node, hover_state)
|
||||||
-- @tfield function on_set_enabled function(self, node, enabled_state)
|
-- @tfield function on_set_enabled function(self, node, enabled_state)
|
||||||
-- @table style
|
|
||||||
function Button.on_style_change(self, style)
|
function Button.on_style_change(self, style)
|
||||||
self.style = {}
|
self.style = {}
|
||||||
self.style.LONGTAP_TIME = style.LONGTAP_TIME or 0.4
|
self.style.LONGTAP_TIME = style.LONGTAP_TIME or 0.4
|
||||||
@ -492,7 +492,7 @@ end
|
|||||||
|
|
||||||
--- Set key name to trigger this button by keyboard.
|
--- Set key name to trigger this button by keyboard.
|
||||||
-- @tparam Button self @{Button}
|
-- @tparam Button self @{Button}
|
||||||
-- @tparam hash key The action_id of the input key
|
-- @tparam hash|string key The action_id of the input key
|
||||||
-- @treturn Button Current button instance
|
-- @treturn Button Current button instance
|
||||||
-- @usage
|
-- @usage
|
||||||
-- button:set_key_trigger("key_space")
|
-- button:set_key_trigger("key_space")
|
||||||
|
@ -10,13 +10,16 @@
|
|||||||
-- @within BaseComponent
|
-- @within BaseComponent
|
||||||
-- @alias druid.drag
|
-- @alias druid.drag
|
||||||
|
|
||||||
|
--- Drag node
|
||||||
|
-- @tfield node node
|
||||||
|
|
||||||
--- Event on touch start callback(self)
|
--- Event on touch start callback(self)
|
||||||
-- @tfield DruidEvent on_touch_start @{DruidEvent}
|
-- @tfield DruidEvent on_touch_start @{DruidEvent}
|
||||||
|
|
||||||
--- Event on touch end callback(self)
|
--- Event on touch end callback(self)
|
||||||
-- @tfield DruidEvent on_touch_end @{DruidEvent}
|
-- @tfield DruidEvent on_touch_end @{DruidEvent}
|
||||||
|
|
||||||
--- Event on drag start callback(self)
|
--- Event on drag start callback(self, touch)
|
||||||
-- @tfield DruidEvent on_drag_start @{DruidEvent}
|
-- @tfield DruidEvent on_drag_start @{DruidEvent}
|
||||||
|
|
||||||
--- on drag progress callback(self, dx, dy, total_x, total_y)
|
--- on drag progress callback(self, dx, dy, total_x, total_y)
|
||||||
@ -67,23 +70,24 @@ local function start_touch(self, touch)
|
|||||||
self.y = touch.y
|
self.y = touch.y
|
||||||
self._scene_scale = helper.get_scene_scale(self.node)
|
self._scene_scale = helper.get_scene_scale(self.node)
|
||||||
|
|
||||||
self.on_touch_start:trigger(self:get_context())
|
self.on_touch_start:trigger(self:get_context(), touch)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function end_touch(self)
|
local function end_touch(self, touch)
|
||||||
if self.is_drag then
|
if self.is_drag then
|
||||||
self.on_drag_end:trigger(
|
self.on_drag_end:trigger(
|
||||||
self:get_context(),
|
self:get_context(),
|
||||||
self.x - self.touch_start_pos.x,
|
self.x - self.touch_start_pos.x,
|
||||||
self.y - self.touch_start_pos.y
|
self.y - self.touch_start_pos.y,
|
||||||
|
touch
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.is_drag = false
|
self.is_drag = false
|
||||||
if self.is_touch then
|
if self.is_touch then
|
||||||
self.is_touch = false
|
self.is_touch = false
|
||||||
self.on_touch_end:trigger(self:get_context())
|
self.on_touch_end:trigger(self:get_context(), touch)
|
||||||
end
|
end
|
||||||
self:reset_input_priority()
|
self:reset_input_priority()
|
||||||
self.touch_id = 0
|
self.touch_id = 0
|
||||||
@ -102,7 +106,7 @@ local function process_touch(self, touch)
|
|||||||
local distance = helper.distance(touch.x, touch.y, self.touch_start_pos.x, self.touch_start_pos.y)
|
local distance = helper.distance(touch.x, touch.y, self.touch_start_pos.x, self.touch_start_pos.y)
|
||||||
if not self.is_drag and distance >= self.style.DRAG_DEADZONE then
|
if not self.is_drag and distance >= self.style.DRAG_DEADZONE then
|
||||||
self.is_drag = true
|
self.is_drag = true
|
||||||
self.on_drag_start:trigger(self:get_context())
|
self.on_drag_start:trigger(self:get_context(), touch)
|
||||||
self:set_input_priority(const.PRIORITY_INPUT_MAX, true)
|
self:set_input_priority(const.PRIORITY_INPUT_MAX, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -266,7 +270,7 @@ function Drag.on_input(self, action_id, action)
|
|||||||
on_touch_release(self, action_id, action)
|
on_touch_release(self, action_id, action)
|
||||||
else
|
else
|
||||||
-- PC
|
-- PC
|
||||||
end_touch(self)
|
end_touch(self, touch)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -285,7 +289,7 @@ function Drag.on_input(self, action_id, action)
|
|||||||
self.y = touch_modified.y
|
self.y = touch_modified.y
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.is_drag then
|
if self.is_drag and (self.dx ~= 0 or self.dy ~= 0) then
|
||||||
local x_koef, y_koef = self._x_koef, self._y_koef
|
local x_koef, y_koef = self._x_koef, self._y_koef
|
||||||
if self.style.NO_USE_SCREEN_KOEF then
|
if self.style.NO_USE_SCREEN_KOEF then
|
||||||
x_koef, y_koef = 1, 1
|
x_koef, y_koef = 1, 1
|
||||||
@ -295,7 +299,7 @@ function Drag.on_input(self, action_id, action)
|
|||||||
self.dx * x_koef / self._scene_scale.x,
|
self.dx * x_koef / self._scene_scale.x,
|
||||||
self.dy * y_koef / self._scene_scale.y,
|
self.dy * y_koef / self._scene_scale.y,
|
||||||
(self.x - self.touch_start_pos.x) * x_koef / self._scene_scale.x,
|
(self.x - self.touch_start_pos.x) * x_koef / self._scene_scale.x,
|
||||||
(self.y - self.touch_start_pos.y) * y_koef / self._scene_scale.y)
|
(self.y - self.touch_start_pos.y) * y_koef / self._scene_scale.y, touch_modified)
|
||||||
end
|
end
|
||||||
|
|
||||||
return self.is_drag
|
return self.is_drag
|
||||||
|
@ -53,6 +53,9 @@
|
|||||||
--- Scroll content node
|
--- Scroll content node
|
||||||
-- @tfield node content_node
|
-- @tfield node content_node
|
||||||
|
|
||||||
|
--- Flag, if scroll now moving by inertion
|
||||||
|
-- @tfield bool _is_inert
|
||||||
|
|
||||||
--- Current inert speed
|
--- Current inert speed
|
||||||
-- @tfield vector3 inertion
|
-- @tfield vector3 inertion
|
||||||
|
|
||||||
@ -72,7 +75,7 @@
|
|||||||
-- @tfield Drag drag @{Drag}
|
-- @tfield Drag drag @{Drag}
|
||||||
|
|
||||||
--- Current index of points of interests
|
--- Current index of points of interests
|
||||||
-- @tfield[opt] number selected
|
-- @tfield number|nil selected
|
||||||
|
|
||||||
--- Flag, if scroll now animating by gui.animate
|
--- Flag, if scroll now animating by gui.animate
|
||||||
-- @tfield boolean is_animate
|
-- @tfield boolean is_animate
|
||||||
|
@ -408,7 +408,7 @@ end
|
|||||||
|
|
||||||
--- Set text adjust, refresh the current text visuals, if needed
|
--- Set text adjust, refresh the current text visuals, if needed
|
||||||
-- @tparam Text self @{Text}
|
-- @tparam Text self @{Text}
|
||||||
-- @tparam number|nil adjust_type See const.TEXT_ADJUST. If pass nil - use current adjust type
|
-- @tparam string|nil adjust_type See const.TEXT_ADJUST. If pass nil - use current adjust type
|
||||||
-- @tparam number|nil minimal_scale If pass nil - not use minimal scale
|
-- @tparam number|nil minimal_scale If pass nil - not use minimal scale
|
||||||
-- @treturn Text Current text instance
|
-- @treturn Text Current text instance
|
||||||
function Text.set_text_adjust(self, adjust_type, minimal_scale)
|
function Text.set_text_adjust(self, adjust_type, minimal_scale)
|
||||||
|
@ -74,6 +74,7 @@ end
|
|||||||
--
|
--
|
||||||
-- Invoke `on_style_change` on component, if exist. Component should handle
|
-- Invoke `on_style_change` on component, if exist. Component should handle
|
||||||
-- their style changing and store all style params
|
-- their style changing and store all style params
|
||||||
|
-- @function component:set_style
|
||||||
-- @tparam BaseComponent self @{BaseComponent}
|
-- @tparam BaseComponent self @{BaseComponent}
|
||||||
-- @tparam table|nil druid_style Druid style module
|
-- @tparam table|nil druid_style Druid style module
|
||||||
-- @treturn BaseComponent @{BaseComponent}
|
-- @treturn BaseComponent @{BaseComponent}
|
||||||
|
@ -85,6 +85,8 @@ function M.register(name, module)
|
|||||||
druid_instance["new_" .. name] = function(self, ...)
|
druid_instance["new_" .. name] = function(self, ...)
|
||||||
return druid_instance.new(self, module, ...)
|
return druid_instance.new(self, module, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return druid_instance["new_" .. name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.component")
|
local component = require("druid.component")
|
||||||
|
local Event = require("druid.event")
|
||||||
|
local const = require("druid.const")
|
||||||
|
|
||||||
local Hotkey = component.create("hotkey")
|
local Hotkey = component.create("hotkey")
|
||||||
|
|
||||||
@ -37,7 +39,9 @@ function Hotkey.init(self, keys, callback, callback_argument)
|
|||||||
|
|
||||||
self._hotkeys = {}
|
self._hotkeys = {}
|
||||||
self._modificators = {}
|
self._modificators = {}
|
||||||
self._callback = callback
|
|
||||||
|
self.on_hotkey_pressed = Event()
|
||||||
|
self.on_hotkey_released = Event(callback)
|
||||||
|
|
||||||
if keys then
|
if keys then
|
||||||
self:add_hotkey(keys, callback_argument)
|
self:add_hotkey(keys, callback_argument)
|
||||||
@ -104,8 +108,15 @@ function Hotkey.add_hotkey(self, keys, callback_argument)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function Hotkey.on_focus_gained(self)
|
||||||
|
for k, v in pairs(self._modificators) do
|
||||||
|
self._modificators[k] = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function Hotkey.on_input(self, action_id, action)
|
function Hotkey.on_input(self, action_id, action)
|
||||||
if not action_id then
|
if not action_id or #self._hotkeys == 0 then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -136,16 +147,16 @@ function Hotkey.on_input(self, action_id, action)
|
|||||||
|
|
||||||
if action.pressed and is_modificator_ok then
|
if action.pressed and is_modificator_ok then
|
||||||
hotkey.is_processing = true
|
hotkey.is_processing = true
|
||||||
|
self.on_hotkey_pressed:trigger(self:get_context(), hotkey.callback_argument)
|
||||||
|
end
|
||||||
|
if not action.pressed and self._is_process_repeated and action.repeated and is_modificator_ok and hotkey.is_processing then
|
||||||
|
self.on_hotkey_released:trigger(self:get_context(), hotkey.callback_argument)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
if action.released and is_modificator_ok and hotkey.is_processing then
|
if action.released and is_modificator_ok and hotkey.is_processing then
|
||||||
hotkey.is_processing = false
|
hotkey.is_processing = false
|
||||||
if hotkey.callback_argument then
|
self.on_hotkey_released:trigger(self:get_context(), hotkey.callback_argument)
|
||||||
self._callback(self:get_context(), hotkey.callback_argument)
|
return true
|
||||||
return true
|
|
||||||
else
|
|
||||||
self._callback(self:get_context())
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -154,4 +165,14 @@ function Hotkey.on_input(self, action_id, action)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- If true, the callback will be triggered on action.repeated
|
||||||
|
-- @tparam Hotkey self @{Hotkey}
|
||||||
|
-- @tparam bool is_enabled_repeated The flag value
|
||||||
|
-- @treturn Hotkey
|
||||||
|
function Hotkey.set_repeat(self, is_enabled_repeated)
|
||||||
|
self._is_process_repeated = is_enabled_repeated
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return Hotkey
|
return Hotkey
|
||||||
|
@ -40,10 +40,10 @@
|
|||||||
-- @tfield boolean is_empty
|
-- @tfield boolean is_empty
|
||||||
|
|
||||||
--- Max length for input text
|
--- Max length for input text
|
||||||
-- @tfield[opt] number max_length
|
-- @tfield number|nil max_length
|
||||||
|
|
||||||
--- Pattern matching for user input
|
--- Pattern matching for user input
|
||||||
-- @tfield[opt] string allowerd_characters
|
-- @tfield string|nil allowerd_characters
|
||||||
|
|
||||||
--- Gui keyboard type for input field
|
--- Gui keyboard type for input field
|
||||||
-- @tfield number keyboard_type
|
-- @tfield number keyboard_type
|
||||||
|
@ -96,7 +96,6 @@ local back_handler = require("druid.base.back_handler")
|
|||||||
|
|
||||||
local DruidInstance = class("druid.druid_instance")
|
local DruidInstance = class("druid.druid_instance")
|
||||||
|
|
||||||
local PATH_OBJ = "."
|
|
||||||
local MSG_ADD_FOCUS = hash("acquire_input_focus")
|
local MSG_ADD_FOCUS = hash("acquire_input_focus")
|
||||||
local MSG_REMOVE_FOCUS = hash("release_input_focus")
|
local MSG_REMOVE_FOCUS = hash("release_input_focus")
|
||||||
local IS_NO_AUTO_INPUT = sys.get_config_int("druid.no_auto_input", 0) == 1
|
local IS_NO_AUTO_INPUT = sys.get_config_int("druid.no_auto_input", 0) == 1
|
||||||
@ -107,11 +106,7 @@ local function set_input_state(self, is_input_inited)
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.input_inited = is_input_inited
|
self.input_inited = is_input_inited
|
||||||
if is_input_inited then
|
msg.post(".", is_input_inited and MSG_ADD_FOCUS or MSG_REMOVE_FOCUS)
|
||||||
msg.post(PATH_OBJ, MSG_ADD_FOCUS)
|
|
||||||
else
|
|
||||||
msg.post(PATH_OBJ, MSG_REMOVE_FOCUS)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -207,10 +202,10 @@ local function process_input(self, action_id, action, components)
|
|||||||
local meta = component._meta
|
local meta = component._meta
|
||||||
if meta.input_enabled and can_use_input_component(self, component) then
|
if meta.input_enabled and can_use_input_component(self, component) then
|
||||||
if not is_input_consumed then
|
if not is_input_consumed then
|
||||||
is_input_consumed = component:on_input(action_id, action)
|
is_input_consumed = component:on_input(action_id, action) or false
|
||||||
else
|
else
|
||||||
if component.on_input_interrupt then
|
if component.on_input_interrupt then
|
||||||
component:on_input_interrupt()
|
component:on_input_interrupt(action_id, action)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user