update
This commit is contained in:
@@ -36,7 +36,7 @@ end
|
||||
function Button:render()
|
||||
local visibility = self:get_visibility()
|
||||
if visibility <= 0 then return end
|
||||
cursor:zone('primary_down', self, function() self:handle_cursor_click() end)
|
||||
cursor:zone('primary_click', self, function() self:handle_cursor_click() end)
|
||||
|
||||
local ass = assdraw.ass_new()
|
||||
local is_clickable = self.is_clickable and self.on_click ~= nil
|
||||
|
||||
@@ -108,6 +108,7 @@ function Menu:init(data, callback, opts)
|
||||
self.opts = opts or {}
|
||||
self.offset_x = 0 -- Used for submenu transition animation.
|
||||
self.mouse_nav = self.opts.mouse_nav -- Stops pre-selecting items
|
||||
self.mouse_hovered_index = nil -- Current menu's item being hovered by mouse, ignoring it's selectable or not.
|
||||
self.item_height = nil
|
||||
self.min_width = nil
|
||||
self.item_spacing = 1
|
||||
@@ -700,7 +701,8 @@ end
|
||||
|
||||
---@param shortcut? Shortcut
|
||||
function Menu:handle_cursor_up(shortcut)
|
||||
if self.proximity_raw <= -self.padding and self.drag_last_y and not self.is_dragging then
|
||||
if self.proximity_raw <= -self.padding and self.drag_last_y and not self.is_dragging
|
||||
and self.mouse_hovered_index == self.current.selected_index then
|
||||
self:activate_selected_item(shortcut, true)
|
||||
end
|
||||
if self.is_dragging then
|
||||
@@ -1456,14 +1458,16 @@ function Menu:render()
|
||||
}
|
||||
|
||||
-- Select hovered item
|
||||
if is_current and self.mouse_nav and item.selectable ~= false
|
||||
-- Do not select items if cursor is moving towards a submenu
|
||||
and (not submenu_rect or not cursor:direction_to_rectangle_distance(submenu_rect))
|
||||
if is_current and self.mouse_nav
|
||||
and (submenu_is_hovered or get_point_to_rectangle_proximity(cursor, item_rect_hitbox) <= 0) then
|
||||
menu.selected_index = index
|
||||
if not is_selected then
|
||||
is_selected = true
|
||||
request_render()
|
||||
self.mouse_hovered_index = index
|
||||
-- Do not select items if cursor is moving towards a submenu
|
||||
if item.selectable ~= false and (not submenu_rect or not cursor:direction_to_rectangle_distance(submenu_rect)) then
|
||||
menu.selected_index = index
|
||||
if not is_selected then
|
||||
is_selected = true
|
||||
request_render()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1555,7 +1559,7 @@ function Menu:render()
|
||||
|
||||
-- Select action on cursor hover
|
||||
if self.mouse_nav and get_point_to_rectangle_proximity(cursor, rect) <= 0 then
|
||||
cursor:zone('primary_down', rect, self:create_action(function(shortcut)
|
||||
cursor:zone('primary_click', rect, self:create_action(function(shortcut)
|
||||
self:activate_selected_item(shortcut, true)
|
||||
end))
|
||||
blur_action_index = false
|
||||
|
||||
@@ -249,7 +249,7 @@ function TopBar:render()
|
||||
local button_fg = is_hover and (button.hover_fg or bg) or fg
|
||||
local button_bg = is_hover and (button.hover_bg or fg) or bg
|
||||
|
||||
cursor:zone('primary_down', rect, button.command)
|
||||
cursor:zone('primary_click', rect, button.command)
|
||||
|
||||
local bg_size = self.size - margin
|
||||
local bg_ax, bg_ay = rect.ax + (is_left and margin or 0), rect.ay + margin
|
||||
@@ -302,7 +302,7 @@ function TopBar:render()
|
||||
if left_aligned then title_bx = rect.ax - margin else title_ax = rect.bx + margin end
|
||||
|
||||
-- Click action
|
||||
cursor:zone('primary_down', rect, function() mp.command('script-binding uosc/playlist') end)
|
||||
cursor:zone('primary_click', rect, function() mp.command('script-binding uosc/playlist') end)
|
||||
end
|
||||
|
||||
-- Skip rendering titles if there's not enough horizontal space
|
||||
@@ -325,7 +325,7 @@ function TopBar:render()
|
||||
local title_rect = {ax = ax, ay = title_ay, bx = ax + rect_width, by = by}
|
||||
|
||||
if options.top_bar_alt_title_place == 'toggle' then
|
||||
cursor:zone('primary_down', title_rect, function() self:toggle_title() end)
|
||||
cursor:zone('primary_click', title_rect, function() self:toggle_title() end)
|
||||
end
|
||||
|
||||
ass:rect(title_rect.ax, title_rect.ay, title_rect.bx, title_rect.by, {
|
||||
@@ -415,7 +415,7 @@ function TopBar:render()
|
||||
|
||||
-- Click action
|
||||
rect.bx = time_bx
|
||||
cursor:zone('primary_down', rect, function() mp.command('script-binding uosc/chapters') end)
|
||||
cursor:zone('primary_click', rect, function() mp.command('script-binding uosc/chapters') end)
|
||||
|
||||
title_ay = rect.by + self.title_spacing
|
||||
end
|
||||
|
||||
@@ -4,6 +4,8 @@ local cursor = {
|
||||
x = math.huge,
|
||||
y = math.huge,
|
||||
hidden = true,
|
||||
disabled = false,
|
||||
disablers = {}, -- List of ids. When not empty, the cursor handling is disabled.
|
||||
distance = 0, -- Distance traveled during current move. Reset by `cursor.distance_reset_timer`.
|
||||
last_hover = false, -- Stores `mouse.hover` boolean of the last mouse event for enter/leave detection.
|
||||
-- Event handlers that are only fired on zones defined during render loop.
|
||||
@@ -404,11 +406,27 @@ function cursor:direction_to_rectangle_distance(rect)
|
||||
return get_ray_to_rectangle_distance(self.x, self.y, end_x, end_y, rect)
|
||||
end
|
||||
|
||||
---@param id string
|
||||
function cursor:register_disabler(id)
|
||||
self.disablers[#self.disablers + 1] = id
|
||||
if #self.disablers > 0 then
|
||||
cursor.disabled = true
|
||||
self:leave()
|
||||
end
|
||||
end
|
||||
|
||||
---@param id string
|
||||
function cursor:unregister_disabler(id)
|
||||
self.disablers = itable_filter(self.disablers, function(item) return item ~= id end)
|
||||
if #self.disablers == 0 then cursor.disabled = false end
|
||||
end
|
||||
|
||||
---@param event string
|
||||
---@param shortcut Shortcut
|
||||
---@param cb? fun(shortcut: Shortcut)
|
||||
function cursor:create_handler(event, shortcut, cb)
|
||||
return function()
|
||||
if self.disabled then return end
|
||||
if cb then cb(shortcut) end
|
||||
self:trigger(event, shortcut)
|
||||
end
|
||||
@@ -416,7 +434,7 @@ end
|
||||
|
||||
-- Movement
|
||||
local function handle_mouse_pos(_, mouse)
|
||||
if not mouse then return end
|
||||
if not mouse or cursor.disabled then return end
|
||||
if cursor.last_hover and not mouse.hover then
|
||||
cursor:leave()
|
||||
elseif not (cursor.last_hover == false and mouse.hover == false) then -- filters out duplicate mouse out events
|
||||
@@ -426,7 +444,7 @@ local function handle_mouse_pos(_, mouse)
|
||||
end
|
||||
|
||||
local function handle_touch_pos(_, touches)
|
||||
if not touches then return end
|
||||
if not touches or cursor.disabled then return end
|
||||
local touch = touches[1]
|
||||
if touch then
|
||||
cursor:move(touch.x, touch.y)
|
||||
@@ -466,4 +484,14 @@ mp.set_key_bindings({
|
||||
{'wheel_down', cursor:create_handler('wheel_down', create_shortcut('wheel_down'))},
|
||||
}, 'wheel', 'force')
|
||||
|
||||
-- Monitor mpv UI's and disable uosc's cursor handling when any are open
|
||||
mp.observe_property('user-data/mpv/context-menu/open', 'bool', function(_, value)
|
||||
if value == true then cursor:register_disabler('context-menu')
|
||||
else cursor:unregister_disabler('context-menu') end
|
||||
end)
|
||||
mp.observe_property('user-data/mpv/console/open', 'bool', function(_, value)
|
||||
if value == true then cursor:register_disabler('console')
|
||||
else cursor:unregister_disabler('console') end
|
||||
end)
|
||||
|
||||
return cursor
|
||||
@@ -54,15 +54,14 @@ do
|
||||
|
||||
-- alphanum sorting for humans in Lua
|
||||
-- http://notebook.kulchenko.com/algorithms/alphanumeric-natural-sorting-for-humans-in-lua
|
||||
local function padnum(n, d)
|
||||
return #d > 0 and ('%03d%s%.12f'):format(#n, n, tonumber(d) / (10 ^ #d))
|
||||
or ('%03d%s'):format(#n, n)
|
||||
local function padnum(n)
|
||||
return ("%03d%s"):format(#n, n)
|
||||
end
|
||||
|
||||
local function sort_lua(strings)
|
||||
local tuples = {}
|
||||
for i, f in ipairs(strings) do
|
||||
tuples[i] = {f:lower():gsub('0*(%d+)%.?(%d*)', padnum), f}
|
||||
tuples[i] = {f:lower():gsub('0*(%d+)', padnum), f}
|
||||
end
|
||||
table.sort(tuples, function(a, b)
|
||||
return a[1] == b[1] and #b[2] < #a[2] or a[1] < b[1]
|
||||
|
||||
Reference in New Issue
Block a user