fix: cursor to time conversion was half a pixel imprecise (#152)

When clicking at a pixel, one would expect to click at the middle of
that pixel instead of the left edge of that pixel.
Add 0.5 to the cursor position to be in the middle.
This commit is contained in:
christoph-heinrich
2022-08-31 10:56:52 +02:00
committed by GitHub
parent f363879f04
commit c94914cca1

View File

@@ -1728,7 +1728,8 @@ function render_timeline(this)
-- Hovered time and chapter
if (this.proximity_raw == 0 or this.pressed) and not (elements.speed and elements.speed.dragging) then
local hovered_seconds = this:get_time_at_x(cursor.x)
-- add 0.5 to be in the middle of the pixel
local hovered_seconds = this:get_time_at_x(cursor.x + 0.5)
local chapter_title = ''
local chapter_title_width = 0
if (options.timeline_chapters ~= 'never' and state.chapters) then
@@ -2418,7 +2419,8 @@ elements:add('timeline', Element.new({
return state.duration * progress
end,
set_from_cursor = function(this)
mp.commandv('seek', this:get_time_at_x(cursor.x), 'absolute+exact')
-- add 0.5 to be in the middle of the pixel
mp.commandv('seek', this:get_time_at_x(cursor.x + 0.5), 'absolute+exact')
end,
on_mbtn_left_down = function(this)
this.pressed = true