summaryrefslogtreecommitdiff
path: root/osd.lua
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-01-20 01:19:36 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-01-20 01:26:08 -0800
commit50021f8d850b81e7ec27b0e048dafb693fb49a6c (patch)
treeaba9c1ac75903e86640633efbf2e378b5cccef1c /osd.lua
parent0793df89e4a018c6abe662181a564ec137b2487a (diff)
downloadmpv-iptv-menu-50021f8d850b81e7ec27b0e048dafb693fb49a6c.tar.gz
mpv-iptv-menu-50021f8d850b81e7ec27b0e048dafb693fb49a6c.tar.xz
support clicking in scrollbar to move cursor/view
Diffstat (limited to 'osd.lua')
-rw-r--r--osd.lua23
1 files changed, 22 insertions, 1 deletions
diff --git a/osd.lua b/osd.lua
index 3be5e2d..35115a1 100644
--- a/osd.lua
+++ b/osd.lua
@@ -419,6 +419,7 @@ function mt:draw_scrollbar(state)
local opts = #menu.options
local lines = self:menu_lines(state)
if opts <= lines then
+ self.scrollbar_coords = nil
return
end
@@ -427,6 +428,12 @@ function mt:draw_scrollbar(state)
local w = self.padding - 4
local hh = math.max(config.font_size / 2, h * lines / opts)
local pos = (h - hh) * (menu.view_top - 1) / (opts - lines)
+ self.scrollbar_coords = {
+ x1 = 2,
+ y1 = top,
+ x2 = 2 + w,
+ y2 = top + h,
+ }
return (
-- bg
@@ -603,7 +610,7 @@ function mt:is_hidden()
return self.fg.hidden
end
-function mt:get_mouse_line(mpos)
+function mt:mouse_menu_line(mpos)
local x = mpos.x / self.scale
local w = self.width / self.scale
if x < self.padding or x > w - self.padding then
@@ -618,6 +625,20 @@ function mt:get_mouse_line(mpos)
return line
end
+function mt:mouse_scrollbar_ratio(mpos)
+ local x = mpos.x / self.scale
+ local y = mpos.y / self.scale
+ local coords = self.scrollbar_coords
+
+ if not coords or x < coords.x1 or x > coords.x2 or
+ y < coords.y1 or y > coords.y2 then
+ return
+ end
+
+ local ratio = (y - coords.y1) / (coords.y2 - coords.y1)
+ return math.max(0, math.min(1, ratio))
+end
+
function mt:mouse_over_button_area(mpos)
if not mpos.hover then
return false