Skip to content

Commit 1595bb5

Browse files
authored
Merge pull request #310 from Samillion/dev_cache_info_function_feat
feat: add click function to cache_info and improve its display
2 parents f724ca2 + 32ea384 commit 1595bb5

File tree

3 files changed

+13
-30
lines changed

3 files changed

+13
-30
lines changed

docs/USER_OPTS.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ Useful when adjusting font size or type, this will help you change the affected
195195
| time_codes_height | 35 | time codes height position |
196196
| time_codes_centered_height | 57 | time codes height position with portrait window |
197197
| tooltip_height_offset | 2 | tooltip height position offset |
198-
| tooltip_left_offset | 3 | if tooltip contains many characters, it is moved to the left by offset |
199-
| tooltip_cache_speed_offset | 5 | if cache speed is enabled, adjust the main tooltip for cache |
198+
| tooltip_left_offset | 5 | if tooltip contains many characters, it is moved to the left by offset |
200199
| portrait_window_trigger | 930 | portrait window width trigger to move some elements |
201200
| hide_volume_bar_trigger | 1150 | hide volume bar trigger window width |
202201
| notitle_osc_h_offset | 25 | osc height offset if title above seekbar is disabled |

modernz.conf

+1-3
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,7 @@ time_codes_centered_height=57
284284
# tooltip height position offset
285285
tooltip_height_offset=2
286286
# if tooltip contains many characters, it is moved to the left by offset
287-
tooltip_left_offset=3
288-
# if cache speed is enabled, adjust the main tooltip for cache
289-
tooltip_cache_speed_offset=5
287+
tooltip_left_offset=5
290288
# portrait window width trigger to move some elements
291289
portrait_window_trigger=930
292290
# hide volume bar trigger window width

modernz.lua

+11-25
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ local user_opts = {
184184
time_codes_height = 35, -- time codes height position
185185
time_codes_centered_height = 57, -- time codes height position with portrait window
186186
tooltip_height_offset = 2, -- tooltip height position offset
187-
tooltip_left_offset = 3, -- if tooltip contains many characters, it is moved to the left by offset
188-
tooltip_cache_speed_offset = 5, -- if cache speed is enabled, adjust the main tooltip for cache
187+
tooltip_left_offset = 5, -- if tooltip contains many characters, it is moved to the left by offset
189188
portrait_window_trigger = 930, -- portrait window width trigger to move some elements
190189
hide_volume_bar_trigger = 1150, -- hide volume bar trigger window width
191190
notitle_osc_h_offset = 25, -- osc height offset if title above seekbar is disabled
@@ -1283,7 +1282,7 @@ local function render_elements(master_ass)
12831282
local hoverstyle = button_lo.hoverstyle
12841283
if hovered and (contains(user_opts.hover_effect, "size") or contains(user_opts.hover_effect, "color")) then
12851284
-- remove font scale tags for these elements, it looks out of place
1286-
if element.name == "title" or element.name == "time_codes" or element.name == "chapter_title" then
1285+
if element.name == "title" or element.name == "time_codes" or element.name == "chapter_title" or element.name == "cache_info" then
12871286
hoverstyle = hoverstyle:gsub("\\fscx%d+\\fscy%d+", "")
12881287
end
12891288
elem_ass:append(hoverstyle .. buttontext)
@@ -1301,15 +1300,14 @@ local function render_elements(master_ass)
13011300

13021301
-- add tooltip for button elements
13031302
if element.tooltipF ~= nil and (user_opts.tooltips_for_disabled_elements or element.enabled) then
1304-
local cache_info_offset = (element.name == "cache_info" and user_opts.cache_info_speed) and user_opts.tooltip_cache_speed_offset or 0
13051303
if mouse_hit(element) then
13061304
local tooltiplabel = element.tooltipF
13071305
local an = 1
1308-
local ty = element.hitbox.y1 - user_opts.tooltip_height_offset + cache_info_offset
1306+
local ty = element.hitbox.y1 - user_opts.tooltip_height_offset
13091307
local tx = get_virt_mouse_pos()
13101308

13111309
if ty < osc_param.playresy / 2 then
1312-
ty = element.hitbox.y2 - user_opts.tooltip_height_offset + cache_info_offset
1310+
ty = element.hitbox.y2 - user_opts.tooltip_height_offset
13131311
an = 7
13141312
end
13151313

@@ -1757,7 +1755,6 @@ layouts["modern"] = function ()
17571755
local loop_button = user_opts.loop_button
17581756
local speed_button = user_opts.speed_button
17591757
local download_button = user_opts.download_button and state.is_URL
1760-
local cache_speed = user_opts.cache_info_speed
17611758
local playlist_button = user_opts.playlist_button and (not user_opts.hide_empty_playlist_button or mp.get_property_number("playlist-count", 0) > 1)
17621759

17631760
local offset = jump_buttons and 60 or 0
@@ -1941,14 +1938,8 @@ layouts["modern"] = function ()
19411938
local cache_x_offset = (download_button and 0 or 45) + (speed_button and 0 or 45) + (loop_button and 0 or 45) + (screenshot_button and 0 or 45) + (ontop_button and 0 or 45) + (info_button and 0 or 45) + (fullscreen_button and 0 or 45)
19421939

19431940
lo = add_layout("cache_info")
1944-
lo.geometry = {x = osc_geo.w - (cache_speed and 345 or 340) + cache_x_offset, y = refY - (cache_speed and 41 or 35), an = 6, w = 35, h = 24}
1941+
lo.geometry = {x = osc_geo.w - 345 + cache_x_offset, y = refY - 35, an = 6, w = (user_opts.cache_info_speed and 70 or 45), h = 24}
19451942
lo.style = osc_styles.cache
1946-
1947-
if user_opts.cache_info_speed then
1948-
lo = add_layout("cache_info_speed")
1949-
lo.geometry = {x = osc_geo.w - 345 + cache_x_offset, y = refY - 27, an = 6, w = 35, h = 24}
1950-
lo.style = osc_styles.cache
1951-
end
19521943
end
19531944
end
19541945

@@ -2606,22 +2597,17 @@ local function osc_init()
26062597
local sec = math.floor(dmx_cache % 60) -- don't round e.g. 59.9 to 60
26072598
local cache_time = (min > 0 and string.format("%sm%02.0fs", min, sec) or string.format("%3.0fs", sec))
26082599

2609-
return state.buffering and locale.buffering .. ": " .. mp.get_property("cache-buffering-state") .. "%" or cache_time
2610-
end
2611-
ne.tooltip_style = osc_styles.tooltip
2612-
ne.tooltipF = (user_opts.tooltip_hints and cache_enabled()) and locale.cache or ""
2613-
2614-
-- cache info speed
2615-
ne = new_element("cache_info_speed", "button")
2616-
ne.visible = (osc_param.playresx >= 1250 - outeroffset - (user_opts.speed_button and 0 or 100) - (user_opts.loop_button and 0 or 100) - (user_opts.screenshot_button and 0 or 100) - (user_opts.ontop_button and 0 or 100) - (user_opts.info_button and 0 or 100) - (user_opts.fullscreen_button and 0 or 100))
2617-
ne.content = function ()
2618-
if not cache_enabled() then return "" end
26192600
local dmx_speed = state.cache_state["raw-input-rate"] or 0
26202601
local cache_speed = utils.format_bytes_humanized(dmx_speed)
26212602
local number, unit = cache_speed:match("([%d%.]+)%s*(%S+)")
2603+
local cache_info = state.buffering and locale.buffering .. ": " .. mp.get_property("cache-buffering-state") .. "%" or cache_time
2604+
local cache_info_speed = string.format("%8s %4s/s", number, unit)
26222605

2623-
return string.format("%8s %4s/s", number, unit)
2606+
return user_opts.cache_info_speed and cache_info .. "\\N" .. cache_info_speed or cache_info
26242607
end
2608+
ne.tooltip_style = osc_styles.tooltip
2609+
ne.tooltipF = (user_opts.tooltip_hints and cache_enabled()) and locale.cache or ""
2610+
ne.eventresponder["mbtn_left_up"] = function() mp.command("script-binding stats/display-page-3") end
26252611

26262612
--seekbar
26272613
ne = new_element("seekbar", "slider")

0 commit comments

Comments
 (0)