feat: implement flash-ui binding and flash-elements message

This commit is contained in:
tomasklaen
2022-10-03 17:01:04 +02:00
parent 2347334bf7
commit e8b8a69c25
2 changed files with 35 additions and 25 deletions

View File

@@ -107,21 +107,33 @@ Available commands:
Makes the whole UI visible until you call this command again. Useful for peeking remaining time and such while watching.
There's also a `toggle-elements <elements>` message you can send to toggle one or more specific elements by specifying their names separated by comma:
There's also a `toggle-elements <ids>` message you can send to toggle one or more specific elements by specifying their names separated by comma:
```
script-message-to uosc toggle-elements timeline,speed
```
Available element names: `timeline`, `controls`, `volume`, `top-bar`, `speed`
Available element IDs: `timeline`, `controls`, `volume`, `top_bar`, `speed`
#### `toggle-progress`
Toggles the always visible portion of the timeline. You can look at it as switching `timeline_size_min` option between it's configured value and 0.
#### `flash-{element}`
#### `flash-ui`
Commands to briefly flash a specified element. Available: `flash-timeline`, `flash-top-bar`, `flash-volume`, `flash-speed`, `flash-pause-indicator`, `decide-pause-indicator`
Command(s) to briefly flash the whole UI. Elements are revealed for a second and then fade away.
To flash individual elements, you can use: `flash-timeline`, `flash-top-bar`, `flash-volume`, `flash-speed`, `flash-pause-indicator`, `decide-pause-indicator`
There's also a `flash-elements <ids>` message you can use to flash one or more specific elements. Example:
```
script-message-to uosc flash-elements timeline,speed
```
Available element IDs: `timeline`, `controls`, `volume`, `top_bar`, `speed`, `pause_indicator`
This is useful in combination with other commands that modify values represented by flashed elements, for example: flashing volume element when changing the volume.
You can use it in your bindings like so:
@@ -137,11 +149,11 @@ down add volume -10; script-binding uosc/flash-volume
[ add speed -0.25; script-binding uosc/flash-speed
] add speed 0.25; script-binding uosc/flash-speed
\ set speed 1; script-binding uosc/flash-speed
> script-binding uosc/next; script-binding uosc/flash-top-bar; script-binding uosc/flash-timeline
< script-binding uosc/prev; script-binding uosc/flash-top-bar; script-binding uosc/flash-timeline
> script-binding uosc/next; script-message-to uosc flash-elements top_bar,timeline
< script-binding uosc/prev; script-message-to uosc flash-elements top_bar,timeline
```
Case for `(flash/decide)-pause-indicator`: mpv handles frame stepping forward by briefly resuming the video, which causes pause indicator to flash, and none likes that when they are trying to compare frames. The solution is to enable manual pause indicator (`pause_indicator=manual`) and use `flash-pause-indicator` (for a brief flash) or `decide-pause-indicator` (for a static indicator) as a secondary command to all bindings you wish would display it (see space binding example above).
Case for `(flash/decide)-pause-indicator`: mpv handles frame stepping forward by briefly resuming the video, which causes pause indicator to flash, and none likes that when they are trying to compare frames. The solution is to enable manual pause indicator (`pause_indicator=manual`) and use `flash-pause-indicator` (for a brief flash) or `decide-pause-indicator` (for a static indicator) as a secondary command to appropriate bindings.
#### `menu`

View File

@@ -1223,6 +1223,13 @@ function Elements:toggle(ids)
for _, element in ipairs(elements) do element:tween_property('min_visibility', element.min_visibility, to) end
end
-- Flash passed elements.
---@param ids string[] IDs of elements to peek.
function Elements:flash(ids)
local elements = itable_filter(self.itable, function(element) return itable_index_of(ids, element.id) ~= nil end)
for _, element in ipairs(elements) do element:flash() end
end
---@param name string Event name.
function Elements:trigger(name, ...)
for _, element in self:ipairs() do element:trigger(name, ...) end
@@ -1528,6 +1535,7 @@ function Element:flash()
if options.flash_duration > 0 and (self.proximity < 1 or self._flash_out_timer:is_enabled()) then
self:tween_stop()
self.forced_visibility = 1
request_render()
self._flash_out_timer:kill()
self._flash_out_timer:resume()
end
@@ -4369,6 +4377,12 @@ mp.observe_property('estimated-display-fps', 'native', update_render_delay)
-- KEY BINDABLE FEATURES
mp.add_key_binding(nil, 'toggle-ui', function() Elements:toggle({'timeline', 'controls', 'volume', 'top_bar'}) end)
mp.add_key_binding(nil, 'flash-ui', function() Elements:flash({'timeline', 'controls', 'volume', 'top_bar'}) end)
mp.add_key_binding(nil, 'flash-timeline', function() Elements:flash({'timeline'}) end)
mp.add_key_binding(nil, 'flash-top-bar', function() Elements:flash({'top_bar'}) end)
mp.add_key_binding(nil, 'flash-volume', function() Elements:flash({'volume'}) end)
mp.add_key_binding(nil, 'flash-speed', function() Elements:flash({'speed'}) end)
mp.add_key_binding(nil, 'flash-pause-indicator', function() Elements:flash({'pause_indicator'}) end)
mp.add_key_binding(nil, 'toggle-progress', function()
local timeline = Elements.timeline
if timeline.size_min_override then
@@ -4379,24 +4393,7 @@ mp.add_key_binding(nil, 'toggle-progress', function()
timeline:tween_property('size_min_override', timeline.size_min, 0)
end
end)
mp.add_key_binding(nil, 'flash-timeline', function()
Elements.timeline:flash()
end)
mp.add_key_binding(nil, 'flash-top-bar', function()
Elements.top_bar:flash()
end)
mp.add_key_binding(nil, 'flash-volume', function()
if Elements.volume then Elements.volume:flash() end
end)
mp.add_key_binding(nil, 'flash-speed', function()
if Elements.speed then Elements.speed:flash() end
end)
mp.add_key_binding(nil, 'flash-pause-indicator', function()
Elements.pause_indicator:flash()
end)
mp.add_key_binding(nil, 'decide-pause-indicator', function()
Elements.pause_indicator:decide()
end)
mp.add_key_binding(nil, 'decide-pause-indicator', function() Elements.pause_indicator:decide() end)
mp.add_key_binding(nil, 'menu', function() toggle_menu_with_items() end)
mp.add_key_binding(nil, 'menu-blurred', function() toggle_menu_with_items({mouse_nav = true}) end)
local track_loaders = {
@@ -4738,3 +4735,4 @@ mp.register_script_message('set', function(name, value)
Elements:trigger('external_prop_' .. name, utils.parse_json(value))
end)
mp.register_script_message('toggle-elements', function(elements) Elements:toggle(split(elements, ' *, *')) end)
mp.register_script_message('flash-elements', function(elements) Elements:flash(split(elements, ' *, *')) end)