diff --git a/crates/voelin-ui/src/studio.rs b/crates/voelin-ui/src/studio.rs index b80a82b..d550fc2 100644 --- a/crates/voelin-ui/src/studio.rs +++ b/crates/voelin-ui/src/studio.rs @@ -19,9 +19,7 @@ use std::sync::{Arc, Weak}; use std::time::Duration; use serde::{Deserialize, Serialize}; -use slint::{ - ComponentHandle, Model, ModelRc, Rgba8Pixel, SharedPixelBuffer, SharedString, VecModel, -}; +use slint::{ComponentHandle, Model, ModelRc, Rgba8Pixel, SharedPixelBuffer, VecModel}; use tokio::sync::broadcast::error::RecvError; use tokio::sync::{broadcast, mpsc}; use tracing::warn; @@ -110,7 +108,7 @@ struct Models { audio: Rc>, layers: Rc>, viewers: Rc>, - destinations: Rc>, + destinations: Rc>, picks: Rc>, /// The chat while there is no destination. no_chat: Rc>, @@ -796,9 +794,9 @@ impl App { ids.into_iter().map(|id| (id, self.studio_destination_name(id))).collect() } - /// "Chill Zone • Nightfall Guild". - fn studio_destination_name(&self, id: i64) -> String { - let Some(view) = self.sessions.get(&id) else { return String::new() }; + /// The channel and the server of a destination. + fn studio_destination_parts(&self, id: i64) -> (String, String) { + let Some(view) = self.sessions.get(&id) else { return Default::default() }; let channel = view .state .own_channel @@ -810,6 +808,12 @@ impl App { } else { view.presence.server_name.clone() }; + (channel, server) + } + + /// "Chill Zone • Nightfall Guild". + fn studio_destination_name(&self, id: i64) -> String { + let (channel, server) = self.studio_destination_parts(id); format!("{channel} • {server}") } @@ -821,8 +825,14 @@ impl App { keep.filter(|id| list.iter().any(|(d, _)| d == id)).or_else(|| { self.studio.stream.as_ref().map(|s| s.session).or(list.first().map(|(id, _)| *id)) }); - let names: Vec = list.iter().map(|(_, n)| n.clone().into()).collect(); - vm::list::sync(&self.studio.models.destinations, &names); + let rows: Vec = list + .iter() + .map(|(id, _)| { + let (channel, server) = self.studio_destination_parts(*id); + StudioPick { name: channel.into(), detail: server.into(), kind: "server".into() } + }) + .collect(); + vm::list::sync(&self.studio.models.destinations, &rows); self.studio_bind_chat(); self.studio_refresh_form(); } diff --git a/crates/voelin-ui/src/vm/studio.rs b/crates/voelin-ui/src/vm/studio.rs index d73c8fc..1530bf0 100644 --- a/crates/voelin-ui/src/vm/studio.rs +++ b/crates/voelin-ui/src/vm/studio.rs @@ -29,10 +29,10 @@ pub fn scenes(scenes: &Scenes) -> Vec { .collect() } -/// "Camera + Screen": the names of the visible sources, front first. +/// "Screen + Camera": the names of the visible sources, back first (the +/// main picture, then what is over it). fn summary(scene: &Scene) -> String { - let names: Vec<&str> = - scene.sources.iter().rev().filter(|s| s.visible).map(Source::label).collect(); + let names: Vec<&str> = scene.sources.iter().filter(|s| s.visible).map(Source::label).collect(); if names.is_empty() { "Empty".into() } else { names.join(" + ") } } @@ -517,15 +517,22 @@ fn overlay_kind(name: &str, text: &str) -> SourceKind { } } -fn overlay_place(name: &str, (w, h): (u32, u32)) -> Transform { +/// Where an overlay starts (people can move it): the viewer count at the +/// top right (by an estimate of its width), the chat at the left, what is +/// on above the bottom left. Clear of the corners the studio's own badges +/// cover in the preview. +fn overlay_place(name: &str, text: &str, (w, h): (u32, u32)) -> Transform { let (w, h) = (w as f32, h as f32); - let x = (w * 0.025).round(); - let y = match name { - OVERLAY_VIEWERS => h * 0.11, - OVERLAY_CHAT => h * 0.3, - _ => h * 0.84, + let margin = (w * 0.025).round(); + let (x, y) = match name { + OVERLAY_VIEWERS => { + let wide = text.chars().count() as f32 * 34.0 * 0.58 + 28.0; + (w - margin - wide, h * 0.14) + } + OVERLAY_CHAT => (margin, h * 0.3), + _ => (margin, h * 0.7), }; - Transform { x, y: y.round(), ..Transform::default() } + Transform { x: x.max(0.0).round(), y: y.round(), ..Transform::default() } } /// Make the scenes hold `wanted`: an overlay that is on is added to the live @@ -561,7 +568,7 @@ pub fn apply_overlays(scenes: &mut Scenes, wanted: &[Overlay]) -> bool { let id = scene.next_source_id(); scene.sources.push(Source { name: overlay.name.into(), - transform: overlay_place(overlay.name, size), + transform: overlay_place(overlay.name, text, size), ..Source::new(id, overlay_kind(overlay.name, text)) }); changed = true; @@ -591,7 +598,7 @@ mod tests { let rows = super::scenes(&scenes); assert_eq!(rows.len(), 2); assert!(rows[0].live && !rows[1].live); - assert_eq!(rows[0].detail, "Camera + Screen"); + assert_eq!(rows[0].detail, "Screen + Camera"); assert_eq!(rows[1].detail, "Empty"); let sources = super::sources(scenes.active(), &[]); assert_eq!( diff --git a/crates/voelin-ui/ui/screens/studio-parts.slint b/crates/voelin-ui/ui/screens/studio-parts.slint index fff23ed..c59548e 100644 --- a/crates/voelin-ui/ui/screens/studio-parts.slint +++ b/crates/voelin-ui/ui/screens/studio-parts.slint @@ -62,6 +62,7 @@ export component PanelTitle inherits HorizontalLayout { font-weight: Theme.weight-semibold; vertical-alignment: center; overflow: elide; + horizontal-stretch: 0; accessible-role: AccessibleRole.text; } if root.note != "": Text { @@ -70,6 +71,10 @@ export component PanelTitle inherits HorizontalLayout { font-size: root.compact ? Theme.font-sm : Theme.font-body; vertical-alignment: center; overflow: elide; + horizontal-stretch: 0; + } + Rectangle { + horizontal-stretch: 1; } } @children @@ -511,6 +516,7 @@ export component StudioPreview inherits Rectangle { HorizontalLayout { x: root.large ? Theme.space-4 : Theme.space-3; y: root.large ? Theme.space-4 : Theme.space-3; + width: self.preferred-width; height: root.large ? 30px : 24px; spacing: Theme.space-3; if StudioBridge.status.live: LiveBadge { @@ -541,6 +547,7 @@ export component StudioPreview inherits Rectangle { if StudioBridge.status.live && !root.controls: HorizontalLayout { x: parent.width - self.width - (root.large ? Theme.space-4 : Theme.space-3); y: root.large ? Theme.space-4 : Theme.space-3; + width: self.preferred-width; height: root.large ? 30px : 24px; spacing: Theme.space-2; PreviewChip { @@ -560,6 +567,7 @@ export component StudioPreview inherits Rectangle { if root.controls: HorizontalLayout { x: parent.width - self.width - Theme.space-3; y: Theme.space-3; + width: self.preferred-width; height: 30px; spacing: 0px; Rectangle { @@ -957,6 +965,32 @@ component ChatRow inherits Rectangle { // The chat of the channel the stream goes to. export component StudioChat inherits StudioPanel { + // New lines (and another chat) scroll to the end once the rows are laid + // out (a few tries). + property lines: StudioBridge.chat.length; + property tries; + property passes; + changed lines => { + tries = 0; + passes = 0; + to-end.running = true; + } + init => { to-end.running = true; } + to-end := Timer { + interval: 50ms; + running: false; + // Twice: the rows at the end are measured after the first scroll. + triggered => { + root.tries += 1; + if chat-list.content-height > 0 { + chat-list.content-y = min(0px, chat-list.visible-height - chat-list.content-height); + root.passes += 1; + } + if root.passes >= 2 || root.tries > 20 { + self.running = false; + } + } + } VerticalLayout { padding-top: Theme.space-3; padding-bottom: Theme.space-3; @@ -980,20 +1014,23 @@ export component StudioChat inherits StudioPanel { } } Divider { } - if StudioBridge.chat-name == "": Text { + Rectangle { vertical-stretch: 1; - text: @tr("Join a voice channel on a TeamSpeak 6 server: its chat shows here."); - color: Theme.text-muted; - font-size: Theme.font-sm; - horizontal-alignment: center; - vertical-alignment: center; - wrap: word-wrap; - } - if StudioBridge.chat-name != "": ListView { - vertical-stretch: 1; - accessible-label: @tr("Stream chat"); - for line in StudioBridge.chat: ChatRow { - line: line; + chat-list := ListView { + width: parent.width; + height: parent.height; + accessible-label: @tr("Stream chat"); + for line in StudioBridge.chat: ChatRow { + line: line; + } + } + if StudioBridge.chat-name == "": Text { + width: parent.width - 2 * Theme.space-5; + text: @tr("Join a voice channel on a TeamSpeak 6 server: its chat shows here."); + color: Theme.text-muted; + font-size: Theme.font-sm; + horizontal-alignment: center; + wrap: word-wrap; } } HorizontalLayout { @@ -1045,7 +1082,9 @@ export component StudioChat inherits StudioPanel { // The destination drop-down: channel and server of each choice. export component DestinationSelect inherits Rectangle { in property compact; - property current: StudioBridge.form.destination >= 0 && StudioBridge.form.destination < StudioBridge.destinations.length ? StudioBridge.destinations[StudioBridge.form.destination] : ""; + property chosen: StudioBridge.form.destination >= 0 && StudioBridge.form.destination < StudioBridge.destinations.length; + property current: chosen ? StudioBridge.destinations[StudioBridge.form.destination].name : ""; + property server: chosen ? StudioBridge.destinations[StudioBridge.form.destination].detail : ""; height: compact ? 40px : 52px; border-radius: Theme.radius-md; background: touch.has-hover ? Theme.surface-3 : Theme.surface-2; @@ -1077,6 +1116,13 @@ export component DestinationSelect inherits Rectangle { text: root.current == "" ? @tr("No TeamSpeak 6 voice connection") : root.current; color: root.current == "" ? Theme.text-muted : Theme.text; font-size: root.compact ? Theme.font-sm : Theme.font-md; + font-weight: Theme.weight-medium; + overflow: elide; + } + if root.server != "" && !root.compact: Text { + text: root.server; + color: Theme.text-muted; + font-size: Theme.font-xs; overflow: elide; } } @@ -1113,7 +1159,7 @@ export component DestinationSelect inherits Rectangle { HorizontalLayout { padding-left: Theme.space-3; Text { - text: item; + text: item.detail != "" ? item.name + " • " + item.detail : item.name; color: Theme.text; vertical-alignment: center; overflow: elide; @@ -1247,6 +1293,7 @@ component LayerRow inherits HorizontalLayout { export component StreamSettings inherits VerticalLayout { // The detached window: destination, quality and title only. in property compact; + alignment: start; padding: root.compact ? Theme.space-3 : Theme.space-5; spacing: root.compact ? Theme.space-2 : Theme.space-4; PanelTitle { @@ -1583,7 +1630,7 @@ export component StudioActions inherits HorizontalLayout { y: (parent.height - self.height) / 2; } Rectangle { - min-width: root.compact ? 170px : 210px; + min-width: root.compact ? 160px : 180px; height: root.h; y: (parent.height - self.height) / 2; Rectangle { @@ -1601,13 +1648,14 @@ export component StudioActions inherits HorizontalLayout { kind: ButtonKind.primary; icon: Icons.radio; text: StudioBridge.status.live ? @tr("Live") : StudioBridge.status.starting ? @tr("Starting…") : @tr("Go Live"); - enabled: StudioBridge.status.can-go-live; + enabled: StudioBridge.status.can-go-live || StudioBridge.status.live; + checked: StudioBridge.status.live; accessible-description: StudioBridge.status.hint; clicked => { StudioBridge.go-live(); } } } Button { - min-width: root.compact ? 170px : 210px; + min-width: root.compact ? 160px : 180px; min-height: root.h; kind: ButtonKind.danger; icon: Icons.square; diff --git a/crates/voelin-ui/ui/screens/studio.slint b/crates/voelin-ui/ui/screens/studio.slint index d79b33b..e039020 100644 --- a/crates/voelin-ui/ui/screens/studio.slint +++ b/crates/voelin-ui/ui/screens/studio.slint @@ -68,8 +68,12 @@ export component StudioPage inherits Rectangle { VerticalLayout { horizontal-stretch: 1; spacing: Theme.space-3; + // As tall as a 16:9 picture across the column needs; the + // mixer and the chat get the rest. StudioPanel { - vertical-stretch: 1.7; + vertical-stretch: 0; + preferred-height: (self.width - 2 * Theme.space-4) * 9 / 16 + 96px + (StudioBridge.viewers.length > 0 ? 40px : 0px); + min-height: 260px; VerticalLayout { padding: Theme.space-4; padding-top: Theme.space-3; @@ -84,7 +88,7 @@ export component StudioPage inherits Rectangle { } HorizontalLayout { vertical-stretch: 1; - min-height: 250px; + min-height: 240px; spacing: Theme.space-3; MixerCard { horizontal-stretch: 1.35; @@ -105,8 +109,8 @@ export component StudioPage inherits Rectangle { height: 64px; spacing: Theme.space-3; StudioUser { - width: 250px * max(1.0, Theme.font-scale); padding-left: Theme.space-3; + horizontal-stretch: 0; } StudioActions { horizontal-stretch: 1; @@ -340,6 +344,7 @@ export component MobileStudio inherits Rectangle { sv := ScrollView { VerticalLayout { width: sv.visible-width; + alignment: start; padding: Theme.space-4; padding-top: Theme.space-2; spacing: Theme.space-4; @@ -401,6 +406,47 @@ export component MobileStudio inherits Rectangle { font-weight: Theme.weight-bold; } } + if StudioBridge.sources.length > 0: Rectangle { + x: Theme.space-3; + y: parent.height - self.height - Theme.space-3; + width: min(parent.width - 2 * Theme.space-3, caption.preferred-width); + height: 46px; + border-radius: Theme.radius-md; + background: #060a18b0; + caption := HorizontalLayout { + padding-left: Theme.space-2; + padding-right: Theme.space-4; + spacing: Theme.space-3; + Rectangle { + width: 34px; + height: 34px; + y: (parent.height - self.height) / 2; + border-radius: Theme.radius-sm; + background: #ffffff18; + Icon { + source: StudioKinds.icon(StudioBridge.sources[StudioBridge.sources.length - 1].kind); + size: 20px; + tint: #ffffff; + } + } + VerticalLayout { + alignment: center; + Text { + text: StudioBridge.form.title != "" ? StudioBridge.form.title : StudioBridge.sources[StudioBridge.sources.length - 1].name; + color: #ffffff; + font-size: Theme.font-body; + font-weight: Theme.weight-medium; + overflow: elide; + } + Text { + text: StudioBridge.sources[StudioBridge.sources.length - 1].name + " • " + (StudioBridge.status.output-height * 16 == StudioBridge.status.output-width * 9 ? "16:9" : StudioBridge.status.output-width + "×" + StudioBridge.status.output-height); + color: #ffffffb0; + font-size: Theme.font-xs; + overflow: elide; + } + } + } + } Rectangle { x: parent.width - self.width - Theme.space-3; y: Theme.space-3; diff --git a/crates/voelin-ui/ui/studio-bridge.slint b/crates/voelin-ui/ui/studio-bridge.slint index a9e85f7..bc7bcbd 100644 --- a/crates/voelin-ui/ui/studio-bridge.slint +++ b/crates/voelin-ui/ui/studio-bridge.slint @@ -187,8 +187,8 @@ export global StudioBridge { in property <[StudioSource]> sources; in property <[StudioAudio]> audio; in property <[StudioLayer]> layers; - // "Chill Zone • Starfall Community", one per server the stream can go to. - in property <[string]> destinations; + // Where the stream can go: the channel (name) on each server (detail). + in property <[StudioPick]> destinations; in property <[StudioViewer]> viewers; // The chat of the channel the stream goes to, and its name. in property <[ChatLine]> chat; diff --git a/crates/voelin-ui/ui/studio-window.slint b/crates/voelin-ui/ui/studio-window.slint index 658837b..b70319e 100644 --- a/crates/voelin-ui/ui/studio-window.slint +++ b/crates/voelin-ui/ui/studio-window.slint @@ -6,7 +6,7 @@ import { Theme } from "theme.slint"; import { Icons } from "icons.slint"; import { StudioBridge, StudioNav } from "studio-bridge.slint"; -import { IconButton } from "components/index.slint"; +import { IconButton, ScrollView } from "components/index.slint"; import { ScenesCard, SourcesCard, StudioPanel, PanelTitle, StudioPreview, MixerCard, StreamSettings, StudioActions, ViewerRequests, StudioDialogs } from "screens/studio-parts.slint"; export component StudioWindow inherits Window { @@ -77,7 +77,8 @@ export component StudioWindow inherits Window { horizontal-stretch: 1; spacing: Theme.space-3; StudioPanel { - vertical-stretch: 1.25; + vertical-stretch: 1.2; + min-height: 200px; VerticalLayout { padding: Theme.space-3; spacing: Theme.space-2; @@ -96,7 +97,7 @@ export component StudioWindow inherits Window { } HorizontalLayout { vertical-stretch: 1; - min-height: 220px; + min-height: 200px; spacing: Theme.space-3; MixerCard { compact: true; @@ -104,8 +105,10 @@ export component StudioWindow inherits Window { } StudioPanel { horizontal-stretch: 1; - StreamSettings { - compact: true; + ScrollView { + StreamSettings { + compact: true; + } } } }