mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 10:02:18 +02:00
Replace event with event library
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
local event = require("druid.event")
|
||||
local event = require("event.event")
|
||||
local const = require("druid.const")
|
||||
local component = require("druid.component")
|
||||
|
||||
---@class druid.back_handler: druid.base_component
|
||||
---@field on_back druid.event Trigger on back handler action, fun(self, params)
|
||||
---@field on_back event Trigger on back handler action, fun(self, params)
|
||||
---@field params any|nil Custom args to pass in the callback
|
||||
local M = component.create("back_handler")
|
||||
|
||||
|
@@ -35,16 +35,16 @@
|
||||
-- @alias druid.button
|
||||
|
||||
|
||||
--- The druid.event: Event on successful release action over button.
|
||||
--- The event: Event on successful release action over button.
|
||||
-- @usage
|
||||
-- -- Custom args passed in Button constructor
|
||||
-- button.on_click:subscribe(function(self, custom_args, button_instance)
|
||||
-- print("On button click!")
|
||||
-- end)
|
||||
-- @tfield druid.event on_click druid.event
|
||||
-- @tfield event on_click event
|
||||
|
||||
|
||||
--- The druid.event: Event on repeated action over button.
|
||||
--- The event: Event on repeated action over button.
|
||||
--
|
||||
-- This callback will be triggered if user hold the button. The repeat rate pick from `input.repeat_interval` in game.project
|
||||
-- @usage
|
||||
@@ -52,10 +52,10 @@
|
||||
-- button.on_repeated_click:subscribe(function(self, custom_args, button_instance, click_count)
|
||||
-- print("On repeated Button click!")
|
||||
-- end)
|
||||
-- @tfield druid.event on_repeated_click druid.event
|
||||
-- @tfield event on_repeated_click event
|
||||
|
||||
|
||||
--- The druid.event: Event on long tap action over button.
|
||||
--- The event: Event on long tap action over button.
|
||||
--
|
||||
-- This callback will be triggered if user pressed the button and hold the some amount of time.
|
||||
-- The amount of time picked from button style param: LONGTAP_TIME
|
||||
@@ -64,10 +64,10 @@
|
||||
-- button.on_long_click:subscribe(function(self, custom_args, button_instance, hold_time)
|
||||
-- print("On long Button click!")
|
||||
-- end)
|
||||
-- @tfield druid.event on_long_click druid.event
|
||||
-- @tfield event on_long_click event
|
||||
|
||||
|
||||
--- The druid.event: Event on double tap action over button.
|
||||
--- The event: Event on double tap action over button.
|
||||
--
|
||||
-- If secondary click was too fast after previous one, the double
|
||||
-- click will be called instead usual click (if on_double_click subscriber exists)
|
||||
@@ -76,10 +76,10 @@
|
||||
-- button.on_double_click:subscribe(function(self, custom_args, button_instance, click_amount)
|
||||
-- print("On double Button click!")
|
||||
-- end)
|
||||
-- @tfield druid.event on_double_click druid.event
|
||||
-- @tfield event on_double_click event
|
||||
|
||||
|
||||
--- The druid.event: Event calls every frame before on_long_click event.
|
||||
--- The event: Event calls every frame before on_long_click event.
|
||||
--
|
||||
-- If long_click subscriber exists, the on_hold_callback will be called before long_click trigger.
|
||||
--
|
||||
@@ -89,10 +89,10 @@
|
||||
-- button.on_double_click:subscribe(function(self, custom_args, button_instance, time)
|
||||
-- print("On hold Button callback!")
|
||||
-- end)
|
||||
-- @tfield druid.event on_hold_callback druid.event
|
||||
-- @tfield event on_hold_callback event
|
||||
|
||||
|
||||
--- The druid.event: Event calls if click event was outside of button.
|
||||
--- The event: Event calls if click event was outside of button.
|
||||
--
|
||||
-- This event will be triggered for each button what was not clicked on user click action
|
||||
--
|
||||
@@ -102,16 +102,16 @@
|
||||
-- button.on_click_outside:subscribe(function(self, custom_args, button_instance)
|
||||
-- print("On click Button outside!")
|
||||
-- end)
|
||||
-- @tfield druid.event on_click_outside druid.event
|
||||
-- @tfield event on_click_outside event
|
||||
|
||||
|
||||
--- The druid.event: Event triggered if button was pressed by user.
|
||||
--- The event: Event triggered if button was pressed by user.
|
||||
-- @usage
|
||||
-- -- Custom args passed in Button constructor
|
||||
-- button.on_pressed:subscribe(function(self, custom_args, button_instance)
|
||||
-- print("On Button pressed!")
|
||||
-- end)
|
||||
-- @tfield druid.event on_pressed druid.event
|
||||
-- @tfield event on_pressed event
|
||||
|
||||
--- Button trigger node
|
||||
-- @tfield node node
|
||||
@@ -136,19 +136,19 @@
|
||||
|
||||
---
|
||||
|
||||
local Event = require("druid.event")
|
||||
local event = require("event.event")
|
||||
local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
local component = require("druid.component")
|
||||
|
||||
---@class druid.button: druid.base_component
|
||||
---@field on_click druid.event
|
||||
---@field on_pressed druid.event
|
||||
---@field on_repeated_click druid.event
|
||||
---@field on_long_click druid.event
|
||||
---@field on_double_click druid.event
|
||||
---@field on_hold_callback druid.event
|
||||
---@field on_click_outside druid.event
|
||||
---@field on_click event
|
||||
---@field on_pressed event
|
||||
---@field on_repeated_click event
|
||||
---@field on_long_click event
|
||||
---@field on_double_click event
|
||||
---@field on_hold_callback event
|
||||
---@field on_click_outside event
|
||||
---@field node node
|
||||
---@field node_id hash
|
||||
---@field anim_node node
|
||||
@@ -229,6 +229,7 @@ local function on_button_hold(self, press_time)
|
||||
end
|
||||
|
||||
|
||||
---@param self druid.button
|
||||
local function on_button_release(self)
|
||||
if self.is_repeated_started then
|
||||
return false
|
||||
@@ -253,10 +254,10 @@ local function on_button_release(self)
|
||||
|
||||
local time = socket.gettime()
|
||||
local is_long_click = (time - self.last_pressed_time) >= self.style.LONGTAP_TIME
|
||||
is_long_click = is_long_click and self.on_long_click:is_exist()
|
||||
is_long_click = is_long_click and not self.on_long_click:is_empty()
|
||||
|
||||
local is_double_click = (time - self.last_released_time) < self.style.DOUBLETAP_TIME
|
||||
is_double_click = is_double_click and self.on_double_click:is_exist()
|
||||
is_double_click = is_double_click and not self.on_double_click:is_empty()
|
||||
|
||||
if is_long_click then
|
||||
local is_hold_complete = (time - self.last_pressed_time) >= self.style.AUTOHOLD_TRIGGER
|
||||
@@ -335,13 +336,13 @@ function M:init(node_or_node_id, callback, custom_args, anim_node)
|
||||
self._is_html5_listener_set = false
|
||||
|
||||
-- Events
|
||||
self.on_click = Event(callback)
|
||||
self.on_pressed = Event()
|
||||
self.on_repeated_click = Event()
|
||||
self.on_long_click = Event()
|
||||
self.on_double_click = Event()
|
||||
self.on_hold_callback = Event()
|
||||
self.on_click_outside = Event()
|
||||
self.on_click = event.create(callback)
|
||||
self.on_pressed = event.create()
|
||||
self.on_repeated_click = event.create()
|
||||
self.on_long_click = event.create()
|
||||
self.on_double_click = event.create()
|
||||
self.on_hold_callback = event.create()
|
||||
self.on_click_outside = event.create()
|
||||
end
|
||||
|
||||
|
||||
@@ -408,7 +409,7 @@ function M:on_input(action_id, action)
|
||||
|
||||
-- While hold button, repeat rate pick from input.repeat_interval
|
||||
if action.repeated then
|
||||
if self.on_repeated_click:is_exist() and self.can_action then
|
||||
if not self.on_repeated_click:is_empty() and self.can_action then
|
||||
on_button_repeated_click(self)
|
||||
return is_consume
|
||||
end
|
||||
@@ -418,7 +419,7 @@ function M:on_input(action_id, action)
|
||||
return on_button_release(self) and is_consume
|
||||
end
|
||||
|
||||
if self.can_action and self.on_long_click:is_exist() then
|
||||
if self.can_action and not self.on_long_click:is_empty() then
|
||||
local press_time = socket.gettime() - self.last_pressed_time
|
||||
|
||||
if self.style.AUTOHOLD_TRIGGER <= press_time then
|
||||
|
@@ -14,19 +14,19 @@
|
||||
-- @tfield node node
|
||||
|
||||
--- Event on touch start callback(self)
|
||||
-- @tfield druid.event on_touch_start druid.event
|
||||
-- @tfield event on_touch_start event
|
||||
|
||||
--- Event on touch end callback(self)
|
||||
-- @tfield druid.event on_touch_end druid.event
|
||||
-- @tfield event on_touch_end event
|
||||
|
||||
--- Event on drag start callback(self, touch)
|
||||
-- @tfield druid.event on_drag_start druid.event
|
||||
-- @tfield event on_drag_start event
|
||||
|
||||
--- on drag progress callback(self, dx, dy, total_x, total_y, touch)
|
||||
-- @tfield druid.event on_drag Event druid.event
|
||||
-- @tfield event on_drag Event event
|
||||
|
||||
--- Event on drag end callback(self, total_x, total_y, touch)
|
||||
-- @tfield druid.event on_drag_end druid.event
|
||||
-- @tfield event on_drag_end event
|
||||
|
||||
--- Is component now touching
|
||||
-- @tfield boolean is_touch
|
||||
@@ -57,18 +57,18 @@
|
||||
|
||||
---
|
||||
|
||||
local Event = require("druid.event")
|
||||
local event = require("event.event")
|
||||
local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
local component = require("druid.component")
|
||||
|
||||
---@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 on_touch_start event
|
||||
---@field on_touch_end event
|
||||
---@field on_drag_start event
|
||||
---@field on_drag event
|
||||
---@field on_drag_end event
|
||||
---@field style table
|
||||
---@field click_zone node
|
||||
---@field is_touch boolean
|
||||
@@ -234,11 +234,11 @@ function M:init(node_or_node_id, on_drag_callback)
|
||||
self._scene_scale = helper.get_scene_scale(self.node)
|
||||
|
||||
self.click_zone = nil
|
||||
self.on_touch_start = Event()
|
||||
self.on_touch_end = Event()
|
||||
self.on_drag_start = Event()
|
||||
self.on_drag = Event(on_drag_callback)
|
||||
self.on_drag_end = Event()
|
||||
self.on_touch_start = event.create()
|
||||
self.on_touch_end = event.create()
|
||||
self.on_drag_start = event.create()
|
||||
self.on_drag = event.create(on_drag_callback)
|
||||
self.on_drag_end = event.create()
|
||||
|
||||
self:on_window_resized()
|
||||
self:set_drag_cursors(true)
|
||||
|
@@ -9,22 +9,22 @@
|
||||
-- @tfield node node
|
||||
|
||||
--- On hover callback(self, state, hover_instance)
|
||||
-- @tfield druid.event on_hover druid.event
|
||||
-- @tfield event on_hover event
|
||||
|
||||
--- On mouse hover callback(self, state, hover_instance)
|
||||
-- @tfield druid.event on_mouse_hover druid.event
|
||||
-- @tfield event on_mouse_hover event
|
||||
|
||||
---
|
||||
|
||||
local Event = require("druid.event")
|
||||
local event = require("event.event")
|
||||
local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
local component = require("druid.component")
|
||||
|
||||
---@class druid.hover: druid.base_component
|
||||
---@field node node
|
||||
---@field on_hover druid.event
|
||||
---@field on_mouse_hover druid.event
|
||||
---@field on_hover event
|
||||
---@field on_mouse_hover event
|
||||
---@field style table
|
||||
---@field click_zone node
|
||||
---@field private _is_hovered boolean
|
||||
@@ -46,8 +46,8 @@ function M:init(node, on_hover_callback, on_mouse_hover)
|
||||
self._is_enabled = true
|
||||
self._is_mobile = helper.is_mobile()
|
||||
|
||||
self.on_hover = Event(on_hover_callback)
|
||||
self.on_mouse_hover = Event(on_mouse_hover)
|
||||
self.on_hover = event.create(on_hover_callback)
|
||||
self.on_mouse_hover = event.create(on_mouse_hover)
|
||||
end
|
||||
|
||||
|
||||
|
@@ -39,13 +39,13 @@
|
||||
|
||||
|
||||
--- On scroll move callback(self, position)
|
||||
-- @tfield druid.event on_scroll druid.event
|
||||
-- @tfield event on_scroll event
|
||||
|
||||
--- On scroll_to function callback(self, target, is_instant)
|
||||
-- @tfield druid.event on_scroll_to druid.event
|
||||
-- @tfield event on_scroll_to event
|
||||
|
||||
--- On scroll_to_index function callback(self, index, point)
|
||||
-- @tfield druid.event on_point_scroll druid.event
|
||||
-- @tfield event on_point_scroll event
|
||||
|
||||
--- Scroll view node
|
||||
-- @tfield node view_node
|
||||
@@ -85,15 +85,15 @@
|
||||
|
||||
---
|
||||
|
||||
local Event = require("druid.event")
|
||||
local event = require("event.event")
|
||||
local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
local component = require("druid.component")
|
||||
|
||||
---@class druid.scroll: druid.base_component
|
||||
---@field on_scroll druid.event
|
||||
---@field on_scroll_to druid.event
|
||||
---@field on_point_scroll druid.event
|
||||
---@field on_scroll event
|
||||
---@field on_scroll_to event
|
||||
---@field on_point_scroll event
|
||||
---@field view_node node
|
||||
---@field view_border vector4
|
||||
---@field content_node node
|
||||
@@ -194,9 +194,9 @@ function M:init(view_node, content_node)
|
||||
self.hover.on_mouse_hover:subscribe(self._on_mouse_hover)
|
||||
self._is_mouse_hover = false
|
||||
|
||||
self.on_scroll = Event()
|
||||
self.on_scroll_to = Event()
|
||||
self.on_point_scroll = Event()
|
||||
self.on_scroll = event.create()
|
||||
self.on_scroll_to = event.create()
|
||||
self.on_point_scroll = event.create()
|
||||
|
||||
self.selected = nil
|
||||
self.is_animate = false
|
||||
|
@@ -37,19 +37,19 @@
|
||||
-- @alias druid.grid
|
||||
|
||||
--- On item add callback(self, node, index)
|
||||
-- @tfield druid.event on_add_item druid.event
|
||||
-- @tfield event on_add_item event
|
||||
|
||||
--- On item remove callback(self, index)
|
||||
-- @tfield druid.event on_remove_item druid.event
|
||||
-- @tfield event on_remove_item event
|
||||
|
||||
--- On item add, remove or change in_row callback(self, index|nil)
|
||||
-- @tfield druid.event on_change_items druid.event
|
||||
-- @tfield event on_change_items event
|
||||
|
||||
--- On grid clear callback(self)
|
||||
-- @tfield druid.event on_clear druid.event
|
||||
-- @tfield event on_clear event
|
||||
|
||||
--- On update item positions callback(self)
|
||||
-- @tfield druid.event on_update_positions druid.event
|
||||
-- @tfield event on_update_positions event
|
||||
|
||||
--- Parent gui node
|
||||
-- @tfield node parent
|
||||
@@ -78,16 +78,16 @@
|
||||
---
|
||||
|
||||
local const = require("druid.const")
|
||||
local Event = require("druid.event")
|
||||
local event = require("event.event")
|
||||
local helper = require("druid.helper")
|
||||
local component = require("druid.component")
|
||||
|
||||
---@class druid.grid: druid.base_component
|
||||
---@field on_add_item druid.event
|
||||
---@field on_remove_item druid.event
|
||||
---@field on_change_items druid.event
|
||||
---@field on_clear druid.event
|
||||
---@field on_update_positions druid.event
|
||||
---@field on_add_item event
|
||||
---@field on_remove_item event
|
||||
---@field on_change_items event
|
||||
---@field on_clear event
|
||||
---@field on_update_positions event
|
||||
---@field parent node
|
||||
---@field nodes node[]
|
||||
---@field first_index number
|
||||
@@ -152,11 +152,11 @@ function M:init(parent, element, in_row)
|
||||
|
||||
self.border = vmath.vector4(0) -- Current grid content size
|
||||
|
||||
self.on_add_item = Event()
|
||||
self.on_remove_item = Event()
|
||||
self.on_change_items = Event()
|
||||
self.on_clear = Event()
|
||||
self.on_update_positions = Event()
|
||||
self.on_add_item = event.create()
|
||||
self.on_remove_item = event.create()
|
||||
self.on_change_items = event.create()
|
||||
self.on_clear = event.create()
|
||||
self.on_update_positions = event.create()
|
||||
|
||||
self._set_position_function = gui.set_position
|
||||
end
|
||||
|
@@ -36,13 +36,13 @@
|
||||
-- @alias druid.text
|
||||
|
||||
--- On set text callback(self, text)
|
||||
-- @tfield druid.event on_set_text druid.event
|
||||
-- @tfield event on_set_text event
|
||||
|
||||
--- On adjust text size callback(self, new_scale, text_metrics)
|
||||
-- @tfield druid.event on_update_text_scale druid.event
|
||||
-- @tfield event on_update_text_scale event
|
||||
|
||||
--- On change pivot callback(self, pivot)
|
||||
-- @tfield druid.event on_set_pivot druid.event
|
||||
-- @tfield event on_set_pivot event
|
||||
|
||||
--- Text node
|
||||
-- @tfield node node
|
||||
@@ -76,7 +76,7 @@
|
||||
|
||||
---
|
||||
|
||||
local Event = require("druid.event")
|
||||
local event = require("event.event")
|
||||
local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
local utf8_lua = require("druid.system.utf8")
|
||||
@@ -85,9 +85,9 @@ local utf8 = utf8 or utf8_lua --[[@as utf8]]
|
||||
|
||||
---@class druid.text: druid.base_component
|
||||
---@field node node
|
||||
---@field on_set_text druid.event
|
||||
---@field on_update_text_scale druid.event
|
||||
---@field on_set_pivot druid.event
|
||||
---@field on_set_text event
|
||||
---@field on_update_text_scale event
|
||||
---@field on_set_pivot event
|
||||
---@field style table
|
||||
---@field private start_pivot number
|
||||
---@field private start_scale vector3
|
||||
@@ -343,9 +343,9 @@ function M:init(node, value, adjust_type)
|
||||
self.adjust_type = adjust_type or self.style.DEFAULT_ADJUST
|
||||
self.color = gui.get_color(self.node)
|
||||
|
||||
self.on_set_text = Event()
|
||||
self.on_set_pivot = Event()
|
||||
self.on_update_text_scale = Event()
|
||||
self.on_set_text = event.create()
|
||||
self.on_set_pivot = event.create()
|
||||
self.on_update_text_scale = event.create()
|
||||
|
||||
self:set_text(value or gui.get_text(self.node))
|
||||
return self
|
||||
|
Reference in New Issue
Block a user