From c438732b239bf4e7f3d574f8fcc141f92366018a Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sat, 11 Jan 2025 20:33:01 +0100 Subject: [PATCH] console.lua: improve the hovered item calculation Currently determine_hovered_item() assumes that each item is opts.font_size pixels tall, which usually works well. This breaks with fonts that get drawn taller than that, such as Japanese text, which makes the calculation inaccurate for the top items and clips the counter. A couple of users reported that it is inaccurate for them for the top items even with ASCII characters in track selectors, presumably because the circles are taken from a different font and make all lines taller. To fix this place each selectable item in its own ASS event positioned like determine_hovered_item() expects. Unfortunately this breaks --profile=box, so keep placing every item in one ASS event with it. --- player/lua/console.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/player/lua/console.lua b/player/lua/console.lua index 32336aa2cf..170f41b36d 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -601,9 +601,24 @@ local function update() local log_ass = '' local log_buffer = log_buffers[id] + local box = mp.get_property('osd-border-style') == 'background-box' + for i = #log_buffer - math.min(max_lines, #log_buffer) + 1, #log_buffer do - log_ass = log_ass .. style .. log_buffer[i].style .. - ass_escape(log_buffer[i].text) .. '\\N' + local log_item = style .. log_buffer[i].style .. ass_escape(log_buffer[i].text) + + -- Put every selectable item in its own event to prevent libass from + -- drawing them taller than opts.font_size with taller fonts, which + -- makes the hovered item calculation inaccurate and clips the counter. + -- But not with background-box, because it makes it look bad by + -- overlapping the semitransparent backgrounds of every line. + if selectable_items and not box then + ass:new_event() + ass:an(1) + ass:pos(x, y - (1.5 + #log_buffer - i) * opts.font_size) + ass:append(log_item) + else + log_ass = log_ass .. log_item .. '\\N' + end end ass:new_event()