stats.lua: allow keybindings to toggle the display of a specific page

This lets you define bindings like h script-binding
stats/display-page-4-toggle. Requested in #14966.
This commit is contained in:
Guido Cella
2024-10-01 21:47:48 +02:00
committed by Avi Halachmi
parent be814e3753
commit 493cab7efc
3 changed files with 15 additions and 8 deletions

View File

@@ -1750,14 +1750,20 @@ mp.add_key_binding(nil, "display-stats", function() process_key_binding(true) en
mp.add_key_binding(nil, "display-stats-toggle", function() process_key_binding(false) end,
{repeatable=false})
-- Single invocation bindings without key, can be used in input.conf to create
-- bindings for a specific page: "e script-binding stats/display-page-2"
for k, _ in pairs(pages) do
mp.add_key_binding(nil, "display-page-" .. k,
function()
curr_page = k
process_key_binding(true)
end, {repeatable=true})
-- Single invocation key bindings for specific pages, e.g.:
-- "e script-binding stats/display-page-2"
mp.add_key_binding(nil, "display-page-" .. k, function()
curr_page = k
process_key_binding(true)
end, {repeatable=true})
-- Key bindings to toggle a specific page, e.g.:
-- "h script-binding stats/display-page-4-toggle".
mp.add_key_binding(nil, "display-page-" .. k .. "-toggle", function()
curr_page = k
process_key_binding(false)
end, {repeatable=true})
end
-- Reprint stats immediately when VO was reconfigured, only when toggled