Files
VoelinClient/crates/voelin-ui/src/bind/studio.rs
T
faumarayandClaude Sonnet 5.5 ce7ec3afb7 Move the view models into voelin-ui-vm; the Slint models take plain rows
vm/{avatar,tree,servers,streams,home,chat,social,studio} and the UI
settings (settings.rs: keys, UiSettings, LastVoice, ClientPlaybackMap,
the audio form) move into voelin-ui-vm with their tests (102 there now;
the 86 view-model tests of voelin-ui all survive, the old list::sync test
became the list::diff tests). They produce the plain bridge structs, with
Rgb for colours and ImageRef for pictures:

- a file picture is ImageSource::File { path, stamp }: the engine writes
  a picture that arrives again into the same file, so the length and
  write time are part of the reference and a changed file redraws its
  row; size() reads the header once per stamp (no toolkit decoder);
- pictures held in memory (chat previews) are ImageSource::Memory;
- the line cache of the chat no longer keeps Slint models alive for
  pointer equality: plain lines compare by value, so an unchanged
  message makes the same line with or without the cache.

voelin-ui keeps every model as bind::rows::Rows<T>: the plain rows last
shown plus the VecModel, synced with list::diff, converting only the rows
that changed (bind/convert has the From impls). The controllers hand the
view-model rows to Rows::sync and convert forms at the bridge
(`.into()`); crate::vm is now `voelin_ui_vm as vm`, so paths stay.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-20 10:20:55 +03:00

139 lines
3.9 KiB
Rust

//! The Stream Studio's callbacks, for the main window and for the studio's
//! own window (each has its own StudioBridge global).
use voelin_core::studio::Command;
use crate::app::{StudioBridge, with_app};
/// Slint ids are ints; the studio's are u64.
fn id(value: i32) -> u64 {
u64::try_from(value).unwrap_or(u64::MAX)
}
fn index(value: i32) -> usize {
usize::try_from(value).unwrap_or(usize::MAX)
}
pub(crate) fn wire(bridge: &StudioBridge) {
// From a page's init: run it after the page is built, outside of Slint's
// update.
bridge.on_open(|| {
let _ = slint::invoke_from_event_loop(|| {
with_app(|app| app.studio_open());
});
});
bridge.on_detach(|| {
with_app(|app| app.studio_detach());
});
bridge.on_dock(|| {
with_app(|app| app.studio_dock());
});
bridge.on_select_scene(|scene| {
with_app(|app| app.studio_scene_command(Command::SetActiveScene { scene: id(scene) }));
});
bridge.on_add_scene(|| {
with_app(|app| app.studio_add_scene());
});
bridge.on_rename_scene(|scene, name| {
let name = name.trim().to_owned();
if !name.is_empty() {
with_app(|app| {
app.studio_scene_command(Command::RenameScene { scene: id(scene), name })
});
}
});
bridge.on_remove_scene(|scene| {
with_app(|app| app.studio_scene_command(Command::RemoveScene { scene: id(scene) }));
});
bridge.on_list_sources(|kind| with_app(|app| app.studio_list_sources(&kind)).unwrap_or(false));
bridge.on_add_picked(|_, i| {
with_app(|app| app.studio_add_picked(index(i)));
});
bridge.on_add_source(|form| {
with_app(|app| app.studio_add_source(&form.into()));
});
bridge.on_source_form(|source| {
with_app(|app| app.studio_source_form(id(source))).unwrap_or_default().into()
});
bridge.on_apply_source(|form| {
with_app(|app| app.studio_apply_source(&form.into()));
});
bridge.on_toggle_source(|source| {
with_app(|app| app.studio_toggle_source(id(source)));
});
bridge.on_source_action(|source, action| {
with_app(|app| app.studio_source_action(id(source), &action));
});
bridge.on_main_source(|kind| {
with_app(|app| app.studio_main_source(&kind));
});
bridge.on_list_audio(|| {
with_app(|app| app.studio_list_audio());
});
bridge.on_toggle_audio(|i| {
with_app(|app| app.studio_toggle_audio(index(i)));
});
bridge.on_set_gain(|i, db, done| {
with_app(|app| app.studio_set_gain(index(i), db, done));
});
bridge.on_toggle_mute(|i| {
with_app(|app| app.studio_toggle_mute(index(i)));
});
bridge.on_remove_audio(|i| {
with_app(|app| app.studio_remove_audio(index(i)));
});
bridge.on_edit_form(|key, value| {
with_app(|app| app.studio_edit(&key, &value));
});
bridge.on_set_output(|w, h, fps| {
with_app(|app| app.studio_set_output(&w, &h, &fps));
});
bridge.on_set_layer(|i, layer| {
with_app(|app| app.studio_set_layer(index(i), &layer.into()));
});
bridge.on_add_layer(|| {
with_app(|app| app.studio_add_layer());
});
bridge.on_remove_layer(|i| {
with_app(|app| app.studio_remove_layer(index(i)));
});
bridge.on_advanced_settings(|| {
with_app(|app| app.studio_advanced());
});
bridge.on_save_clip(|| {
with_app(|app| app.studio_save_clip());
});
bridge.on_toggle_recording(|| {
with_app(|app| app.studio_toggle_recording());
});
bridge.on_open_recordings(|| {
with_app(|app| app.studio_open_recordings());
});
bridge.on_go_live(|| {
with_app(|app| app.studio_go_live());
});
bridge.on_end_stream(|| {
with_app(|app| app.studio_end());
});
bridge
.on_settings_form(|| with_app(|app| app.studio_settings_form()).unwrap_or_default().into());
bridge.on_apply_settings(|form| {
with_app(|app| app.studio_apply_settings(&form.into()));
});
bridge.on_respond_viewer(|client, accept| {
with_app(|app| app.studio_respond_viewer(u16::try_from(client).unwrap_or(0), accept));
});
bridge.on_send_chat(|text| {
with_app(|app| app.studio_send_chat(text.to_string()));
});
bridge.on_open_chat(|| {
with_app(|app| app.studio_open_chat());
});
}