From 50021f8d850b81e7ec27b0e048dafb693fb49a6c Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 20 Jan 2026 01:19:36 -0800 Subject: support clicking in scrollbar to move cursor/view --- osd.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'osd.lua') 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 -- cgit v1.2.3-70-g09d2