mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Update annotations P.1
This commit is contained in:
@@ -14,19 +14,19 @@
|
||||
-- @tfield node node
|
||||
|
||||
--- Event on touch start callback(self)
|
||||
-- @tfield DruidEvent on_touch_start @{DruidEvent}
|
||||
-- @tfield DruidEvent on_touch_start DruidEvent
|
||||
|
||||
--- Event on touch end callback(self)
|
||||
-- @tfield DruidEvent on_touch_end @{DruidEvent}
|
||||
-- @tfield DruidEvent on_touch_end DruidEvent
|
||||
|
||||
--- 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, touch)
|
||||
-- @tfield DruidEvent on_drag Event @{DruidEvent}
|
||||
-- @tfield DruidEvent on_drag Event DruidEvent
|
||||
|
||||
--- Event on drag end callback(self, total_x, total_y, touch)
|
||||
-- @tfield DruidEvent on_drag_end @{DruidEvent}
|
||||
-- @tfield DruidEvent on_drag_end DruidEvent
|
||||
|
||||
--- Is component now touching
|
||||
-- @tfield boolean is_touch
|
||||
@@ -62,7 +62,31 @@ local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
local component = require("druid.component")
|
||||
|
||||
local Drag = component.create("drag", const.PRIORITY_INPUT_HIGH)
|
||||
---@class druid.drag: druid.base_component
|
||||
---@field node node
|
||||
---@field on_touch_start druid.event
|
||||
---@field on_touch_end druid.event
|
||||
---@field on_drag_start druid.event
|
||||
---@field on_drag druid.event
|
||||
---@field on_drag_end druid.event
|
||||
---@field style table
|
||||
---@field click_zone node
|
||||
---@field is_touch boolean
|
||||
---@field is_drag boolean
|
||||
---@field can_x boolean
|
||||
---@field can_y boolean
|
||||
---@field dx number
|
||||
---@field dy number
|
||||
---@field touch_id number
|
||||
---@field x number
|
||||
---@field y number
|
||||
---@field screen_x number
|
||||
---@field screen_y number
|
||||
---@field touch_start_pos vector3
|
||||
---@field private _is_enabled boolean
|
||||
---@field private _x_koef number
|
||||
---@field private _y_koef number
|
||||
local M = component.create("drag", const.PRIORITY_INPUT_HIGH)
|
||||
|
||||
|
||||
local function start_touch(self, touch)
|
||||
@@ -177,19 +201,18 @@ end
|
||||
-- @table style
|
||||
-- @tfield number|nil DRAG_DEADZONE Distance in pixels to start dragging. Default: 10
|
||||
-- @tfield boolean|nil NO_USE_SCREEN_KOEF If screen aspect ratio affects on drag values. Default: false
|
||||
function Drag.on_style_change(self, style)
|
||||
function M:on_style_change(style)
|
||||
self.style = {}
|
||||
self.style.DRAG_DEADZONE = style.DRAG_DEADZONE or 10
|
||||
self.style.NO_USE_SCREEN_KOEF = style.NO_USE_SCREEN_KOEF or false
|
||||
end
|
||||
|
||||
|
||||
--- The @{Drag} constructor
|
||||
-- @tparam Drag self @{Drag}
|
||||
-- @tparam node node GUI node to detect dragging
|
||||
-- @tparam function on_drag_callback Callback for on_drag_event(self, dx, dy)
|
||||
function Drag.init(self, node, on_drag_callback)
|
||||
self.node = self:get_node(node)
|
||||
---Drag constructor
|
||||
---@param node_or_node_id node|string
|
||||
---@param on_drag_callback function
|
||||
function M:init(node_or_node_id, on_drag_callback)
|
||||
self.node = self:get_node(node_or_node_id)
|
||||
|
||||
self.dx = 0
|
||||
self.dy = 0
|
||||
@@ -219,7 +242,7 @@ function Drag.init(self, node, on_drag_callback)
|
||||
end
|
||||
|
||||
|
||||
function Drag.on_late_init(self)
|
||||
function M:on_late_init()
|
||||
if not self.click_zone and const.IS_STENCIL_CHECK then
|
||||
local stencil_node = helper.get_closest_stencil_node(self.node)
|
||||
if stencil_node then
|
||||
@@ -229,7 +252,7 @@ function Drag.on_late_init(self)
|
||||
end
|
||||
|
||||
|
||||
function Drag.on_window_resized(self)
|
||||
function M:on_window_resized()
|
||||
local x_koef, y_koef = helper.get_screen_aspect_koef()
|
||||
self._x_koef = x_koef
|
||||
self._y_koef = y_koef
|
||||
@@ -237,14 +260,17 @@ function Drag.on_window_resized(self)
|
||||
end
|
||||
|
||||
|
||||
function Drag.on_input_interrupt(self)
|
||||
function M:on_input_interrupt()
|
||||
if self.is_drag or self.is_touch then
|
||||
end_touch(self)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function Drag.on_input(self, action_id, action)
|
||||
---@local
|
||||
---@param action_id string
|
||||
---@param action table
|
||||
function M:on_input(action_id, action)
|
||||
if action_id ~= const.ACTION_TOUCH and action_id ~= const.ACTION_MULTITOUCH then
|
||||
return false
|
||||
end
|
||||
@@ -321,29 +347,31 @@ function Drag.on_input(self, action_id, action)
|
||||
end
|
||||
|
||||
|
||||
--- Strict drag click area. Useful for
|
||||
-- restrict events outside stencil node
|
||||
-- @tparam Drag self @{Drag}
|
||||
-- @tparam node|string|nil node Gui node
|
||||
function Drag.set_click_zone(self, node)
|
||||
---Set Drag click zone
|
||||
---@param node node|string|nil
|
||||
---@return druid.drag self
|
||||
function M:set_click_zone(node)
|
||||
self.click_zone = self:get_node(node)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Set Drag input enabled or disabled
|
||||
-- @tparam Drag self @{Drag}
|
||||
-- @tparam boolean|nil is_enabled
|
||||
function Drag.set_enabled(self, is_enabled)
|
||||
---Set Drag component enabled state.
|
||||
---@param is_enabled boolean
|
||||
---@return druid.drag self
|
||||
function M:set_enabled(is_enabled)
|
||||
self._is_enabled = is_enabled
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Check if Drag component is enabled
|
||||
-- @tparam Drag self @{Drag}
|
||||
-- @treturn boolean
|
||||
function Drag.is_enabled(self)
|
||||
---Check if Drag component is enabled
|
||||
---@return boolean
|
||||
function M:is_enabled()
|
||||
return self._is_enabled
|
||||
end
|
||||
|
||||
|
||||
return Drag
|
||||
return M
|
||||
|
Reference in New Issue
Block a user