summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2025-05-13 01:50:29 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2025-05-13 01:50:29 -0700
commitd5b6d72a8a9375a32378033c4883a933355b63f5 (patch)
tree4f7115f4f1bbfe0ffc71e2d680ad6e18748bb850 /main.lua
parentd8a57993b184e378742947adeef382572775ef80 (diff)
downloadmpv-iptv-menu-d5b6d72a8a9375a32378033c4883a933355b63f5.tar.gz
mpv-iptv-menu-d5b6d72a8a9375a32378033c4883a933355b63f5.tar.xz
centre menu options when using go-to shortcut
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua40
1 files changed, 27 insertions, 13 deletions
diff --git a/main.lua b/main.lua
index 681f7bb..086dd4b 100644
--- a/main.lua
+++ b/main.lua
@@ -318,13 +318,15 @@ local function update_osd()
osd_bg:update()
end
-local function set_cursor(pos, move_view)
+local function set_cursor(pos, opts)
local menu = menus[depth]
local lines = osd_menu_lines()
local pos = math.max(1, math.min(pos, #menu.options))
local top = menu.view_top
- if move_view then
+ if opts and opts.centre then
+ top = pos - math.floor((osd_menu_lines() - 1) / 2)
+ elseif opts and opts.keep_offset then
top = top + pos - menu.cursor
end
@@ -359,11 +361,20 @@ local function cursor_end()
end
local function cursor_page_up()
- set_cursor(menus[depth].cursor - osd_menu_lines(), true)
+ set_cursor(menus[depth].cursor - osd_menu_lines(), {keep_offset=true})
end
local function cursor_page_down()
- set_cursor(menus[depth].cursor + osd_menu_lines(), true)
+ set_cursor(menus[depth].cursor + osd_menu_lines(), {keep_offset=true})
+end
+
+local function cursor_to_object(id)
+ for i, v in ipairs(menus[depth].options) do
+ if v.id == id then
+ set_cursor(i, {centre=true})
+ return
+ end
+ end
end
local function prev_menu()
@@ -475,6 +486,8 @@ local function push_group_menu(group)
push_menu({
options=group_menu_options(group),
title=group.name,
+ type='group',
+ group_id=group.id,
})
update_osd()
end
@@ -530,21 +543,22 @@ end
local function goto_option()
local menu = menus[depth]
local opt = menu.options[menu.cursor]
- if not opt or not opt.path then
+ if not opt then
return
end
- for i = 1, #opt.path do
- push_group_menu(opt.path[i])
+ if menu.type == 'search' or menu.group_id == 'favourites' then
+ depth = depth - 1
+ end
- local target = i == #opt.path and opt or opt.path[i+1]
- for i, v in ipairs(menus[depth].options) do
- if v.id == target.id then
- set_cursor(i, true)
- break
- end
+ if opt.path then
+ for i = 1, #opt.path do
+ cursor_to_object(opt.path[i].id)
+ push_group_menu(opt.path[i])
end
end
+ cursor_to_object(opt.id)
+ update_osd()
end
local function search_menu_options_build(options, t, path)