Skip to content

Commit

Permalink
console.lua: calculate the max width more accurately
Browse files Browse the repository at this point in the history
  • Loading branch information
guidocella committed Jun 22, 2024
1 parent 940854c commit f366a4c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ local function update()
return
end

local margin = 6
local coordinate_top = math.floor(global_margins.t * screeny + 0.5)
local clipping_coordinates = '0,' .. coordinate_top .. ',' ..
screenx .. ',' .. screeny
Expand Down Expand Up @@ -546,7 +547,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 - margin) / 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 +567,7 @@ local function update()

ass:new_event()
ass:an(1)
ass:pos(6, screeny - 6 - global_margins.b * screeny)
ass:pos(margin, screeny - margin - global_margins.b * screeny)
ass:append(log_ass .. '\\N')
if #suggestions > 0 then
ass:append(suggestion_ass .. '\\N')
Expand All @@ -579,7 +580,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(margin, screeny - 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 f366a4c

Please sign in to comment.