Skip to content

Commit

Permalink
console.lua: fix the max width calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
guidocella committed Jun 23, 2024
1 parent 940854c commit 5b2dc12
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,12 @@ local function update()

dpi_scale = dpi_scale * opts.scale

local screenx, screeny = mp.get_osd_size()
local screenx, screeny, aspect = mp.get_osd_size()
screenx = screenx / dpi_scale
screeny = screeny / dpi_scale

local bottom_left_margin = 6

-- Clear the OSD if the REPL is not active
if not repl_active then
mp.set_osd_ass(screenx, screeny, '')
Expand Down Expand Up @@ -546,7 +548,10 @@ local function update()

local lines_max = calculate_max_log_lines()
-- Estimate how many characters fit in one line
local width_max = math.ceil(screenx / opts.font_size * get_font_hw_ratio())
local width_max = math.floor((screenx - bottom_left_margin / dpi_scale -
mp.get_property_native('osd-margin-x') * screeny
/ 720 / aspect / dpi_scale) /
opts.font_size * get_font_hw_ratio())

local suggestions, rows = format_table(suggestion_buffer, width_max, lines_max)
local suggestion_ass = style .. styles.suggestion .. suggestions
Expand All @@ -566,7 +571,7 @@ local function update()

ass:new_event()
ass:an(1)
ass:pos(6, screeny - 6 - global_margins.b * screeny)
ass:pos(bottom_left_margin, screeny - bottom_left_margin - global_margins.b * screeny)
ass:append(log_ass .. '\\N')
if #suggestions > 0 then
ass:append(suggestion_ass .. '\\N')
Expand All @@ -579,7 +584,7 @@ local function update()
-- cursor appear in front of the text.
ass:new_event()
ass:an(1)
ass:pos(6, screeny - 6 - global_margins.b * screeny)
ass:pos(bottom_left_margin, screeny - bottom_left_margin - global_margins.b * screeny)
ass:append(style .. '{\\alpha&HFF&}' .. ass_escape(prompt) .. ' ' .. before_cur)
ass:append(cglyph)
ass:append(style .. '{\\alpha&HFF&}' .. after_cur)
Expand Down

0 comments on commit 5b2dc12

Please sign in to comment.