refactor: cursor events consolidated into one interface (#483)

`mbtn_left` and `wheel` events are now only fired on a `cursor.on_{event}` object, which resets at the beginning of each frame, so elements need to bind these listeners in their render functions. These properties are overwritable which allows elements to take over cursor event handling from their parents if necessary.
This commit is contained in:
Tomas Klaen
2023-03-29 09:08:18 +02:00
committed by GitHub
parent 9839e7b726
commit f635df18f7
9 changed files with 155 additions and 123 deletions

View File

@@ -93,6 +93,11 @@ function get_point_to_rectangle_proximity(point, rect)
return math.sqrt(dx * dx + dy * dy)
end
-- Call function with args if it exists
function call_maybe(fn, ...)
if type(fn) == 'function' then fn(...) end
end
-- Extracts the properties used by property expansion of that string.
---@param str string
---@param res { [string] : boolean } | nil
@@ -553,6 +558,8 @@ function render()
if not display.initialized then return end
state.render_last_time = mp.get_time()
cursor.reset_handlers()
-- Actual rendering
local ass = assdraw.ass_new()
@@ -566,6 +573,8 @@ function render()
end
end
cursor.decide_keybinds()
-- submit
if osd.res_x == display.width and osd.res_y == display.height and osd.data == ass.text then
return