mpv-osc-tethys icon indicating copy to clipboard operation
mpv-osc-tethys copied to clipboard

Track buttons/numbers don't have enough padding with double digit track numbers

Open xmopi opened this issue 3 years ago • 3 comments

The track numbers padding is insufficient when you have a double digit amount of subtitle tracks or audio tracks

image

xmopi avatar May 31 '22 17:05 xmopi

Ah thanks. I kinda knew the fit might be tight, but I never really tested a video with that many subs. Ended up downloading DBZA Ep 1 which has 25 different languages (--embed-sub --sub-lang all).

Current State:

  • Tethys uses buttons 90x36 wide, while regular buttons are 42x42 wide. So 2.5 width:height ratio.
  • https://github.com/mpv-player/mpv/blob/b4c73ed10590ac7b7186f887ab1e24eeb68b35ce/player/lua/osc.lua#L1303
    The default osc.lua box layout uses 70x18 wide buttons while other buttons are 40x40 or 25x25. So 3.8 width:height ratio.
  • https://github.com/mpv-player/mpv/blob/b4c73ed10590ac7b7186f887ab1e24eeb68b35ce/player/lua/osc.lua#L1481
    The default osc.lua bottombar` layout uses 90x30 buttons, while other buttons are 27x30. So 3.0 width/height ratio.

Issue:

The OSC is drawn with LibASS, which has no TextMetrics so we can't calculate the width of the rendered text. We have to guess it.

Solutions:

  • I could use {clip(x1, y1, x2, y2)} to clip the text so that 10 or 100 will not overflow.
    • https://github.com/mpv-player/mpv/blob/b4c73ed10590ac7b7186f887ab1e24eeb68b35ce/player/lua/osc.lua#L1572
    • https://github.com/libass/libass/blob/cba045a65d7dfe08e86fedc509002f84bd39b760/libass/ass_parse.c#L685
  • I've been tempted to make the 1/15 text even smaller though, as we don't really need it that big. We could probably get away with 27px tall, which is the same size as the timestamp. 90 / 27 = 3.3 width:height ratio.
  • I could dynamically change the button width based on the number of subtitles.
    • https://math.stackexchange.com/questions/469606/how-to-get-count-of-digits-of-a-number
    • Math.log(1)/Math.log(10) + 1 = 1
    • Math.log(10)/Math.log(10) + 1 = 2
    • Math.log(100)/Math.log(10) + 1 = 3
    • https://www.lua.org/manual/5.3/manual.html#pdf-math.log supports an optional base=10 parameter unlike javascript.

Zren avatar May 31 '22 18:05 Zren

With:

    local trackButtonSize = tethys.trackButtonSize
    local trackIconWidth = trackButtonSize * (32/23.273)
    local trackDigitWidth = trackButtonSize * 0.4
    -- "ICON -/0"
    -- "ICON 1/1"
    -- "ICON 1/10"
    local numTrackDigits = 1
    if tracks_osc.audio ~= nil then
        numTrackDigits = math.floor(math.log(#tracks_osc.sub, 10)) + 1
    end
    local trackButtonWidth = trackIconWidth + trackDigitWidth * (1 + numTrackDigits + 1 + numTrackDigits)

With OSC scaled to 1080p, the buttons are:

  • Track 1/1 is a 143x47 button
  • Track 25/25 is a 180x47 button

The internal mpv osc units are:

[osc_tethys] trackButtonSize 32 
[osc_tethys] trackIconWidth 43.999484381042 
[osc_tethys] trackDigitWidth 12.8 
[osc_tethys] sub.numTrackDigits 2 
[osc_tethys] sub.trackButtonWidth 120.79948438104 
[osc_tethys] audio.numTrackDigits 1 
[osc_tethys] audio.trackButtonWidth 95.199484381042 

Ah, I need to add a few math.ceil().

Zren avatar May 31 '22 19:05 Zren

Hmm, it's already using osc_styles.smallButtonsLlabel.

local osc_styles = {
    smallButtonsLlabel = "{\\fscx105\\fscy105\\fn" .. mp.get_property("options/osd-font") .. "}",
}

    --cy_sub
    ne = new_element("cy_sub", "button")
    ne.enabled = (#tracks_osc.sub > 0)
    ne.content = function ()
        local sid = "–"
        if not (get_track("sub") == 0) then
            sid = get_track("sub")
        end
        return ("\238\132\135" .. osc_styles.smallButtonsLlabel
            .. " " .. sid .. "/" .. #tracks_osc.sub)
    end

Seems that \\fscx105\\fscy105 is 105% text scale, making it slightly taller than the icon.

https://aegi.vmoe.info/docs/3.0/ASS_Tags/#index16h3

Zren avatar May 31 '22 19:05 Zren