Add a player widget, and let a slider be drawn as a fader

The player is the one tile that both reads and publishes, so it has two
bindings: it shows a `record` describing what is playing — title, artist,
album, status, and position and duration in seconds — and publishes transport
words back to one `str` message (`toggle`, `next`, `prev`, `seek:<seconds>`).
Those are a streamer's own vocabulary rather than this app's, which is what
lets one tile drive whatever is on the other end.

The position counts forward in the browser between readings, so the bar moves
at one second while the device behind it is polled at whatever rate suits it;
every reading that arrives is taken as the truth and the count restarts there.
That is also why this is one record rather than five messages — a tile drawn
from five would redraw itself five times, and show a new title against the old
duration in between.

Being both is why `INPUT_WIDGETS` does not gain it: what that set means is "the
message this widget publishes is its only binding", which is exactly what a
player is not. Its reading is checked the usual way and its `target` separately.

The fader beside it needed nothing new. `ui/core` has had `orientation` on the
slider all along and all three looks draw it; only the widget never passed it,
so a volume control — the one thing reached for without looking, where up is
louder — could not be a column. Now it can, and the tile's height is the track.
This commit is contained in:
2026-08-30 14:17:16 +02:00
parent dd34b59b2d
commit d2464d4d28
9 changed files with 302 additions and 27 deletions
+54 -23
View File
@@ -15,6 +15,7 @@ import "./dashboard.css"
import { ForecastWidget } from "./ForecastWidget"
import { IconWidget } from "./IconWidget"
import { MediaWidget } from "./MediaWidget"
import { PlayerWidget } from "./PlayerWidget"
import { usePublish } from "./publish"
import { useUi } from "./ui"
import { COLOR_DTYPES, colorFormatOf } from "./ui/core/color"
@@ -58,6 +59,10 @@ export const WIDGET_DTYPES: Partial<Record<WidgetKind, string[]>> = {
// bound to; a plain artifact is taken as well, since the media type on the
// reference is what says what the bytes are.
media: ["image", "audio", "video", "artifact"],
// What a streamer says it is playing: title, artist, status, position and
// duration in one reading, because they are one thing and a player drawn
// from five separate messages would redraw itself five times.
player: ["record"],
// An icon maps weather strings, bool hints and numbers alike, and a clock
// binds nothing at all, so neither has a row to be held to.
}
@@ -80,6 +85,7 @@ export const WIDGET_LABELS: Record<WidgetKind, string> = {
forecast: "Forecast",
clock: "Clock",
media: "Media",
player: "Player",
button: "Button",
switch: "Switch",
slider: "Slider",
@@ -101,6 +107,7 @@ export const WIDGET_SIZES: Record<WidgetKind, { w: number; h: number }> = {
forecast: { w: 6, h: 2 },
clock: { w: 3, h: 2 },
media: { w: 4, h: 4 },
player: { w: 4, h: 3 },
button: { w: 3, h: 2 },
switch: { w: 3, h: 2 },
slider: { w: 4, h: 2 },
@@ -191,6 +198,12 @@ export function widgetIssue(widget: WidgetDef): string | null {
return null
}
// A player is the one widget that both reads and publishes, so it is the one
// whose wiring is only half done when a single picker is filled in.
if (widget.type === "player" && text(cfg.message) && !text(cfg.target)) {
return "This player does not publish to a message yet."
}
const input = INPUT_WIDGETS.has(widget.type)
const bound = text(cfg[input ? "target" : "message"])
if (!bound) {
@@ -494,37 +507,54 @@ function SliderWidget({ widget, dashboard }: WidgetProps) {
if (!target) return <Unbound />
const unit = cfg.unit ? text(cfg.unit) : undefined
const vertical = cfg.orientation === "vertical"
const reading = typeof value === "number" ? value : min
const control = (
<Slider
value={reading}
min={min}
max={num(cfg.max, 100)}
step={num(cfg.step, 1)}
unit={unit}
orientation={vertical ? "vertical" : "horizontal"}
// On by default, because a slider without them says how far along it
// is and not what that means. Off is for a short tile: they are the
// last row of a control that has three, and on a seven-inch panel
// that row is the difference between fitting and being cut off. A
// column has no room for them at all.
ticks={cfg.ticks !== false}
label={widget.title || target}
disabled={locked}
onCommit={send}
/>
)
const readout = (
<Readout value={reading} precision={null} unit={unit} size="inline" />
)
// A column takes the tile's height and puts the reading under it, which is
// what a fader looks like. A volume control is the case it exists for: it is
// reached for without looking, and up is louder.
if (vertical) {
return (
<div className="flex h-full min-h-0 flex-col items-center gap-2">
{pulse}
{control}
<div className="shrink-0">{readout}</div>
</div>
)
}
return (
// Value beside the track rather than above it, the way a bar row reads —
// one row instead of two, and the tile keeps the height for the control.
<div className="flex items-start gap-3">
{pulse}
<div className="min-w-0 flex-1">
<Slider
value={typeof value === "number" ? value : min}
min={min}
max={num(cfg.max, 100)}
step={num(cfg.step, 1)}
unit={unit}
// On by default, because a slider without them says how far along it
// is and not what that means. Off is for a short tile: they are the
// last row of a control that has three, and on a seven-inch panel
// that row is the difference between fitting and being cut off.
ticks={cfg.ticks !== false}
label={widget.title || target}
disabled={locked}
onCommit={send}
/>
</div>
<div className="min-w-0 flex-1">{control}</div>
{/* Held to the control's own height, so the value sits on the track's
midline whether or not there is a row of ticks under it. */}
<div className="flex h-[var(--dui-control)] shrink-0 items-center">
<Readout
value={typeof value === "number" ? value : min}
precision={null}
unit={unit}
size="inline"
/>
{readout}
</div>
</div>
)
@@ -622,6 +652,7 @@ const RENDERERS: Partial<
forecast: ForecastWidget,
clock: ClockWidget,
media: MediaWidget,
player: PlayerWidget,
button: ButtonWidget,
switch: SwitchWidget,
slider: SliderWidget,