Skip to content

Commit

Permalink
console.lua: improve the hovered item calculation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
guidocella authored and sfan5 committed Jan 18, 2025
1 parent 89c42e4 commit c438732
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c438732

Please sign in to comment.