feat: move @ in control badge props from prefix to suffix for consistency

The old `@prop` syntax will still work, but consider it deprecated.
This commit is contained in:
tomasklaen
2022-10-10 10:20:46 +02:00
parent 75ab13f2e3
commit 30a3ec195d
2 changed files with 11 additions and 15 deletions

View File

@@ -519,26 +519,14 @@ In your script, set the value of `foo` to `1`.
mp.commandv('script-message-to', 'uosc', 'set', 'foo', 1)
```
This property can now be used as a control button badge by prefixing it with `@`.
```
controls=command:icon_name:command_name#@foo?My foo button
```
It can also be used as a `toggle` or `cycle` property name by specifying its owner with a `@{script_name}` suffix:
`foo` can now be used as a `toggle` or `cycle` property by specifying its owner with a `@{script_name}` suffix:
```
toggle:icon_name:foo@script_name
cycle:icon_name:foo@script_name:no/yes!
```
If user clicks this `toggle` or `cycle` button, uosc will send this `set` message back to the script owner:
```lua
mp.commandv('script-message-to', 'script_name', 'set', 'foo', new_value)
```
You can then listen to this message, do what you need with the new value, and update uosc state accordingly:
If user clicks this `toggle` or `cycle` button, uosc will send a `set` message back to the script owner. You can then listen to this message, do what you need with the new value, and update uosc state accordingly:
```lua
-- Send initial value so that the button has a correct active state
@@ -551,6 +539,12 @@ mp.register_script_message('set', function(prop, value)
end)
```
External properties can also be used as control button badges:
```
controls=command:icon_name:command_name#foo@script_name?My foo button
```
## Why _uosc_?
It stood for micro osc as it used to render just a couple rectangles before it grew to what it is today. And now it means a minimalist UI design direction where everything is out of your way until needed.

View File

@@ -3438,7 +3438,9 @@ function Controls:register_badge_updater(badge, element)
return count
end
else
if prop:sub(1, 1) == '@' then prop, is_external_prop = prop:sub(2), true end
local parts = split(prop, '@')
-- Support both new `prop@owner` and old `@prop` syntaxes
if #parts > 1 then prop, is_external_prop = parts[1] ~= '' and parts[1] or parts[2], true end
serializer = function(value) return value and (type(value) == 'table' and #value or tostring(value)) or nil end
end