Skip to content

Commit

Permalink
console.lua: improved 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, though I can't reproduce it.

To fix this place each selectable item in its own ASS event positioned
like determine_hovered_item() expects.
  • Loading branch information
guidocella committed Jan 10, 2025
1 parent 21436ac commit c83aeb8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,16 @@ local function update()
local log_ass = ''
local log_buffer = log_buffers[id]
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)

if selectable_items then
ass:new_event()
ass:an(1)
ass:pos(x, y - 1.5 * opts.font_size - (#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 c83aeb8

Please sign in to comment.