Skip to content

Commit

Permalink
Add chapter title to hovered time
Browse files Browse the repository at this point in the history
Closes #85
  • Loading branch information
christoph-heinrich committed Jul 12, 2022
1 parent 945594b commit 2790c04
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions uosc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1674,15 +1674,27 @@ function render_timeline(this)
end

if (this.proximity_raw == 0 or this.pressed) and not (elements.speed and elements.speed.dragging) then
-- Hovered time
-- Hovered time and chapter
local hovered_seconds = state.duration * (cursor.x / display.width)
local box_half_width_guesstimate = (this.font_size * 4.2) / 2
local chapter_title = ''
if (options.chapters ~= 'none' and state.chapters ~= nil) then
for i = #state.chapters, 1, -1 do
if hovered_seconds >= state.chapters[i].time then
chapter_title = state.chapters[i].title
break
end
end
end
local time_formatted = mp.format_time(hovered_seconds)
local text_len = math.max(time_formatted:len(), chapter_title:len())
local box_half_width_estimate = text_width_estimate(text_len, this.font_size) / 2
ass:new_event()
ass:append('{\\blur0\\bord1\\shad0\\1c&H'..options.color_background_text..'\\3c&H'..options.color_background..'\\fn'..config.font..'\\fs'..this.font_size..bold_tag..'')
ass:append(ass_opacity(math.min(options.timeline_opacity + 0.1, 1)))
ass:pos(math.min(math.max(cursor.x, box_half_width_guesstimate), display.width - box_half_width_guesstimate), fay)
ass:pos(math.min(math.max(cursor.x, box_half_width_estimate), display.width - box_half_width_estimate), fay)
ass:an(2)
ass:append(mp.format_time(hovered_seconds))
ass:append(chapter_title .. '\\N')
ass:append(time_formatted)

-- Cursor line
ass:new_event()
Expand Down

0 comments on commit 2790c04

Please sign in to comment.