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 f986171
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,11 @@ local function update()

dpi_scale = dpi_scale * opts.scale

local screenx, screeny = mp.get_osd_size()
screenx = screenx / dpi_scale
local screenx, screeny, aspect = mp.get_osd_size()
local bottom_left_margin = 6
screenx = (screenx - bottom_left_margin -
mp.get_property_native('osd-margin-x') * screenx / 720 / aspect)
/ dpi_scale
screeny = screeny / dpi_scale

-- Clear the OSD if the REPL is not active
Expand Down Expand Up @@ -546,7 +549,7 @@ 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 / 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 +569,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 +582,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 f986171

Please sign in to comment.