Goal: a slider in your window drives something live (a video filter, the volume, a preview), the effect follows the pointer while the user drags, and nothing lags behind or queues up.
A slider reports every pointer movement, often more than 60 times a second. Each report is a callback in your plugin. The plugin stays responsive if every callback only records the newest value and hands it to something that keeps only the newest value. It stutters when every callback starts its own slow request and the requests queue up behind each other.
in-out propertyIn the Slint file, declare the value in-out and bind the slider's value with <=>, and report moves and the release through two callbacks:
in-out property <float> brightness;
callback brightness-changed(float); // every pointer move
callback brightness-released(float); // once, when the button is released
Slider {
value <=> root.brightness; // two-way: never `value: root.brightness`
changed(value) => { root.brightness-changed(value); }
released(value) => { root.brightness-released(value); }
}
In the changed callback, store the value in your model and return; do not await anything there. Do one-off work (the on-screen message, saving, logging) in the released callback instead, which fires once per drag.
Pass the value on with a call that has latest-value semantics, such as filter.set(), player.setOutput() or Scrub.seek. Do not call one-request-per-call methods (player.seek, player.setRate, osd.show) on every move: use player.scrub() for a seek slider.
Send the slider's value and its label with brightnessWindow.bind(() => …), not set, so an unchanged value is never written back under the user's pointer; a Reset that changes the model still moves the thumb.
If a move triggers your own asynchronous work (a preview rendered with plugin.tools.run, a network request), run it through a helper that keeps one run at a time and only the newest value, and call plugin.update() when a result arrives after an await:
import type { Plugin } from "@vestra-player/sdk";
/** Run `work` for the newest value only: one run at a time; values that arrive meanwhile replace each other. */
export function latest<T>(work: (value: T) => Promise<void>) {
let running = false;
let next: { value: T } | undefined;
return async (value: T) => {
next = { value };
if (running) return; // the running loop picks it up
running = true;
try {
while (next) {
const current = next.value;
next = undefined;
await work(current);
}
} finally {
running = false;
}
};
}
declare function renderPreview(strength: number): Promise<string>; // your own slow work
export default async function activate(plugin: Plugin) {
let preview = "";
const previewWindow = plugin.windows.create("ui/preview.slint");
previewWindow.bind(() => ({ preview }));
const refresh = latest(async (strength: number) => {
preview = await renderPreview(strength);
plugin.update(); // changed after an await: send it now
});
previewWindow.on("strengthChanged", (strength: number) => refresh(strength));
}
A Brightness window with a slider from −1 to 1, a value label and a Reset button. The video follows the slider while it moves; an on-screen message reports the value when the user lets go.
manifest.json:
{
"id": "examples.brightness",
"version": "1.0.0",
"apiVersion": "vestra/1",
"entry": "main.ts",
"minPlayerVersion": "0.9.0"
}
ui/brightness.slint:
import { Theme } from "@vestra/theme.slint";
import { Button, Slider } from "@vestra/widgets.slint";
export component BrightnessWindow inherits Window {
title: "Brightness";
width: 300px;
background: Theme.bg-panel;
// Written by the plugin and by the slider: in-out, bound two-way below.
in-out property <float> brightness;
in property <string> label;
callback brightness-changed(float); // every pointer move
callback brightness-released(float); // once, when the button is released
callback reset();
HorizontalLayout {
padding: Theme.dialog-padding;
spacing: 8px;
Slider {
minimum: -1;
maximum: 1;
value <=> root.brightness;
changed(value) => { root.brightness-changed(value); }
released(value) => { root.brightness-released(value); }
}
Text {
width: 36px;
text: root.label;
color: Theme.text;
font-size: Theme.font-body;
horizontal-alignment: right;
vertical-alignment: center;
}
Button {
text: "Reset";
small: true;
clicked => { root.reset(); }
}
}
}
main.ts:
import type { Plugin, VideoFilter } from "@vestra-player/sdk";
export default function activate(plugin: Plugin) {
let brightness = 0; // the model: −1–1, 0 = unchanged
// A filter keeps one request in flight and sends only the newest value.
// Made on first use: a chain keeps the plugin running from then on.
let filter: VideoFilter | undefined;
const apply = () =>
(filter ??= plugin.video.filter("brightness")).set([
{ kind: "eq", brightness, contrast: 1, saturation: 1, gamma: 1 },
]);
const brightnessWindow = plugin.windows.create("ui/brightness.slint");
// Derived from the model: sent only when it changes.
brightnessWindow.bind(() => ({ brightness, label: brightness.toFixed(2) }));
brightnessWindow.on("brightnessChanged", (value: number) => {
brightness = Math.min(1, Math.max(-1, value)); // record the newest value…
apply(); // …and hand it on; no await
});
brightnessWindow.on("brightnessReleased", () => {
void plugin.osd.show("Brightness {}", [brightness.toFixed(2)]); // once per drag
});
brightnessWindow.on("reset", () => {
brightness = 0; // the bound value moves the slider back
apply();
});
plugin.commands.add({
id: "brightness",
path: ["@video", "Brightness…"],
run: () => brightnessWindow.show(),
});
}
A slider reports every pointer move, and the SDK runs each callback as soon as it arrives. The callback only records the value and returns, so callbacks never queue. filter.set() keeps one request in flight and replaces waiting values with newer ones, so a fast drag costs one request per round trip to the player, not one per move, and the video ends exactly where the slider stopped. bind sends a value only when it differs from the last one sent, and the player skips a write the slider already shows, so the plugin never fights the pointer. A one-way binding in Slint (value: root.brightness) is broken the first time the user drags, after which Reset no longer moves the thumb. Work you start yourself has no such semantics: overlapping runs can finish out of order and leave an older result on screen, and a value changed after an await shows only when the handler ends unless you call plugin.update() (Open a tool window and remember its state).
Calls that keep only the newest value (safe on every move): VideoFilter.set, AudioFilter.set, Player.setOutput, Scrub.seek (about one seek per display frame), view properties (bind, set), OsdPanel.set, and JsonStore.save (debounced, 300 ms). One request per call (not on every move): Player.seek (use Player.scrub), player.setRate and the other player controls, Osd.show.
Open a tool window and remember its state: set, bind and the update pass.
The blur example (a strength slider on a video filter).