refactor!: element system, menu implementation, ...
With this, the codebase is mostly typed (as much as sumneko's type checking allows), and finally go-to-definition-able. This refactor changed or touched more than 90% of the codebase, so here's just the most notable changes I can recall: Menu implementation is now way more robust, and supports: - live menu updates - opening submenus allows navigating to parent menus - items icons and bold & italic styling - keeping menu open after selecting the item - peeking submenus - and a lot of other small tweaks The menu input data structure changed. It no longer accepts `active_index` and `selected_index`, instead, each item can now have `active` or `selected` property. And I'm sure there's a lot I'm forgetting to mention, but it's midnight here T.T closes #144, ref #171, closes #176
This commit is contained in:
33
README.md
33
README.md
@@ -367,45 +367,50 @@ Parameters
|
|||||||
|
|
||||||
ID (title) of the submenu, including `>` subsections as defined in `input.conf`. It has to be match the title exactly.
|
ID (title) of the submenu, including `>` subsections as defined in `input.conf`. It has to be match the title exactly.
|
||||||
|
|
||||||
### `show-menu <menu_json>`
|
### `open-menu <menu_json> [submenu_id]`
|
||||||
|
|
||||||
A message other scripts can send to display a uosc menu serialized as JSON.
|
A message other scripts can send to open a uosc menu serialized as JSON. You can optionally pass a `submenu_id` to pre-open a submenu. The ID is the submenu title chain leading to the submenu concatenated with `>`, for example `Tools > Aspect ratio`.
|
||||||
|
|
||||||
Menu data structure:
|
Menu data structure:
|
||||||
|
|
||||||
```
|
```
|
||||||
Menu {
|
Menu {
|
||||||
type?: string;
|
type?: string;
|
||||||
title?: string;
|
|
||||||
selected_index?: number;
|
|
||||||
active_index?: number;
|
|
||||||
items: Item[];
|
|
||||||
}
|
|
||||||
|
|
||||||
Submenu {
|
|
||||||
title?: string;
|
title?: string;
|
||||||
items: Item[];
|
items: Item[];
|
||||||
|
keep_open?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item = Command | Submenu;
|
Item = Command | Submenu;
|
||||||
|
|
||||||
|
Submenu {
|
||||||
|
title?: string;
|
||||||
|
hint?: string;
|
||||||
|
items: Item[];
|
||||||
|
keep_open?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
Command {
|
Command {
|
||||||
title?: string;
|
title?: string;
|
||||||
hint?: string;
|
hint?: string;
|
||||||
|
icon?: string;
|
||||||
value: string | string[];
|
value: string | string[];
|
||||||
bold?: boolean;
|
bold?: boolean;
|
||||||
italic?: boolean;
|
italic?: boolean;
|
||||||
muted?: boolean;
|
muted?: boolean;
|
||||||
|
selected?: number;
|
||||||
|
active?: number;
|
||||||
|
keep_open?: boolean;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
When command value is a string, it'll be passed to `mp.command(value)`. If it's a table (array) of strings, it'll be used as `mp.commandv(table.unpack(value))`.
|
When command value is a string, it'll be passed to `mp.command(value)`. If it's a table (array) of strings, it'll be used as `mp.commandv(table.unpack(value))`.
|
||||||
|
|
||||||
Menu `type` controls what happens when opening a menu when some other menu is already open. When the new menu type is different, it'll replace the currently opened menu. When it's the same, the currently open menu will simply be closed. This is used to implement toggling (open->close) of menus with the same key.
|
Menu `type` controls what happens when opening a menu when some other menu is already open. When the new menu type is different, it'll replace the currently opened menu. When it's the same, the currently open menu will simply be closed. This is used to implement toggling of menus with the same type.
|
||||||
|
|
||||||
`active_index` displays the item at that index as active. For example, in subtitles menu, the currently displayed subtitles are considered _active_.
|
When `keep_open` is `true`, activating the item will not close the menu. This property can be defined on both menus and items, and is inherited from parent to child. Set to `false` to override the parent.
|
||||||
|
|
||||||
`selected_index` marks item at that index as selected - the starting position for all keyboard based navigation in the menu. It defaults to `active_index` if any, or `1` otherwise, which means in most cases you can just ignore this prop.
|
It's usually not necessary to define `selected` as it'll default to `active` item, or 1st item in the list.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@@ -414,11 +419,9 @@ local utils = require('mp.utils')
|
|||||||
local menu = {
|
local menu = {
|
||||||
type = 'menu_type',
|
type = 'menu_type',
|
||||||
title = 'Custom menu',
|
title = 'Custom menu',
|
||||||
active_index = 1,
|
|
||||||
selected_index = 1,
|
|
||||||
items = {
|
items = {
|
||||||
{title = 'Foo', hint = 'foo', value = 'quit'},
|
{title = 'Foo', hint = 'foo', value = 'quit'},
|
||||||
{title = 'Bar', hint = 'bar', value = 'quit'},
|
{title = 'Bar', hint = 'bar', value = 'quit', active = true},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
local json = utils.format_json(menu)
|
local json = utils.format_json(menu)
|
||||||
|
@@ -107,7 +107,7 @@ menu_min_width=260
|
|||||||
menu_min_width_fullscreen=360
|
menu_min_width_fullscreen=360
|
||||||
menu_wasd_navigation=no
|
menu_wasd_navigation=no
|
||||||
menu_hjkl_navigation=no
|
menu_hjkl_navigation=no
|
||||||
menu_opacity=0.8
|
menu_opacity=1
|
||||||
menu_parent_opacity=0.4
|
menu_parent_opacity=0.4
|
||||||
menu_font_scale=1
|
menu_font_scale=1
|
||||||
|
|
||||||
|
5826
scripts/uosc.lua
5826
scripts/uosc.lua
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user