Skip to content

Commit

Permalink
console.lua: deduplicate y position calculation in update()
Browse files Browse the repository at this point in the history
This deduplicates the calculation of the y position by assigning it to a
y variable, which will also be used in the next commit. margin_x is also
renamed to x for consistency.
  • Loading branch information
guidocella authored and sfan5 committed Jan 18, 2025
1 parent a06883f commit 89c42e4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,8 @@ local function update()

local osd_w, osd_h = get_scaled_osd_dimensions()

local margin_x = get_margin_x()
local margin_y = get_margin_y()
local x = get_margin_x()
local y = osd_h * (1 - global_margins.b) - get_margin_y()

local coordinate_top = math.floor(global_margins.t * osd_h + 0.5)
local clipping_coordinates = '0,' .. coordinate_top .. ',' ..
Expand Down Expand Up @@ -589,7 +589,7 @@ local function update()
-- libass/ass_render.c:ass_render_event() subtracts --osd-margin-x from
-- the maximum text width twice.
local width_max = math.floor(
(osd_w - margin_x - mp.get_property_native('osd-margin-x') * 2 / scale_factor())
(osd_w - x - mp.get_property_native('osd-margin-x') * 2 / scale_factor())
/ opts.font_size * get_font_hw_ratio())

local suggestions, rows = format_table(suggestion_buffer, width_max, max_lines)
Expand All @@ -608,7 +608,7 @@ local function update()

ass:new_event()
ass:an(1)
ass:pos(margin_x, osd_h - margin_y - global_margins.b * osd_h)
ass:pos(x, y)
ass:append(log_ass .. '\\N')
ass:append(suggestion_ass)
ass:append(style .. ass_escape(prompt) .. ' ' .. before_cur)
Expand All @@ -619,7 +619,7 @@ local function update()
-- cursor appear in front of the text.
ass:new_event()
ass:an(1)
ass:pos(margin_x, osd_h - margin_y - global_margins.b * osd_h)
ass:pos(x, y)
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 89c42e4

Please sign in to comment.