From 7e43178e04533042d6f095b3e08c34158133abe0 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Oct 2026 11:36:21 +0000 Subject: [PATCH] ui: every kind of spacer channel, and its text wherever a channel is named Only [cspacerN] was recognized, so [spacer], [rspacer] and [*spacer]--- rows showed their raw names, and so did chat tabs, search results, notifications and the other screens that name a channel. parse_spacer (in voelin-model, so the Android voice notification uses it too) reads them all, with any suffix (it only keeps names unique); a line repeats its text across the row and is cut at its end. The tree search, Ctrl+K and the event form leave out lines and empty spacers. Names that go to the server (the invite link, joining a friend's channel) stay raw; the toast after copying an invite shows the text. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ --- CHANGELOG.md | 4 + crates/voelin-android/src/foreground.rs | 13 +- crates/voelin-model/src/lib.rs | 2 +- crates/voelin-model/src/tree.rs | 78 +++++++++- crates/voelin-ui/src/app.rs | 2 +- crates/voelin-ui/src/chat.rs | 2 +- crates/voelin-ui/src/dev.rs | 8 +- crates/voelin-ui/src/events.rs | 8 +- crates/voelin-ui/src/home.rs | 2 +- crates/voelin-ui/src/inbox.rs | 3 +- crates/voelin-ui/src/messages.rs | 13 +- crates/voelin-ui/src/servers.rs | 12 +- crates/voelin-ui/src/social.rs | 42 +++--- crates/voelin-ui/src/streams.rs | 3 +- crates/voelin-ui/src/studio.rs | 10 +- crates/voelin-ui/src/vm/social.rs | 38 +++++ crates/voelin-ui/src/vm/tree.rs | 159 ++++++++++++++++----- crates/voelin-ui/ui/bridge.slint | 6 +- crates/voelin-ui/ui/screens/channels.slint | 24 ++-- docs/ui.md | 14 +- 20 files changed, 347 insertions(+), 96 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c9e8ef..98306eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,10 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows - Hover help in the Stream Studio (a source's error, the status details) shows each time and closes when the pointer leaves; it showed only once, and stayed open until a click. +- Spacer channels: `[spacer]`, `[lspacer]`, `[rspacer]` and `[*spacer]` lines + are drawn as TeamSpeak draws them, like `[cspacer]` was, and chats, search + results, notifications and the other screens show a spacer's text instead + of its raw name. ## [0.0.1-alpha] - 2026-10-04 diff --git a/crates/voelin-android/src/foreground.rs b/crates/voelin-android/src/foreground.rs index e48434e..afe59c4 100644 --- a/crates/voelin-android/src/foreground.rs +++ b/crates/voelin-android/src/foreground.rs @@ -13,7 +13,7 @@ use std::sync::Arc; use voelin_core::stream::{StreamState, ViewerInfo, ViewerState}; use voelin_core::{Event, SessionId, VoiceState}; -use voelin_model::Presence; +use voelin_model::{Presence, channel_title}; /// What the voice notification shows. #[derive(Clone, Debug, PartialEq, Eq)] @@ -72,13 +72,13 @@ impl Session { self.name.as_deref().unwrap_or("a server") } - /// Our channel's name and how many are in it. + /// Our channel's name (a spacer's text) and how many are in it. fn channel(&self) -> Option<(&str, usize)> { let id = self.own_channel?; let channel = self.presence.channels.get(&id)?; let people = self.presence.clients.values().filter(|c| c.channel == id && !c.is_query).count(); - Some((channel.name.as_str(), people)) + Some((channel_title(channel).0, people)) } } @@ -222,8 +222,11 @@ mod tests { fn presence(people: u16) -> Event { let mut p = Presence::default(); - p.channels - .insert(2, ChannelInfo { id: 2, name: "Chill Zone".into(), ..Default::default() }); + // A spacer shows its text. + p.channels.insert( + 2, + ChannelInfo { id: 2, name: "[cspacer1]Chill Zone".into(), ..Default::default() }, + ); for id in 1..=people { p.clients.insert(id, ClientInfo { id, channel: 2, ..Default::default() }); } diff --git a/crates/voelin-model/src/lib.rs b/crates/voelin-model/src/lib.rs index 95acfa9..44dd2f8 100644 --- a/crates/voelin-model/src/lib.rs +++ b/crates/voelin-model/src/lib.rs @@ -16,4 +16,4 @@ pub use presence::{ pub use server::{ BannerMode, Capabilities, HostMessageMode, ServerDetails, ServerFlavor, ServerVersion, }; -pub use tree::{TreeRow, order_siblings, tree_rows}; +pub use tree::{Spacer, TreeRow, channel_title, order_siblings, parse_spacer, tree_rows}; diff --git a/crates/voelin-model/src/tree.rs b/crates/voelin-model/src/tree.rs index e13fe2d..fe97c6e 100644 --- a/crates/voelin-model/src/tree.rs +++ b/crates/voelin-model/src/tree.rs @@ -1,4 +1,5 @@ -//! Flatten presence into display rows in TeamSpeak's channel order. +//! Flatten presence into display rows in TeamSpeak's channel order, and +//! read the names of spacer channels. use std::collections::HashMap; @@ -64,6 +65,51 @@ fn add_level<'a>( } } +/// How a TeamSpeak spacer channel draws its text. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Spacer { + Left, + Center, + Right, + /// The text repeated across the row: a line such as `---`. + Fill, +} + +impl Spacer { + /// Whether a spacer with this text only separates the rows around it + /// (a line, or no text): nothing to search for or pick. + pub fn separates(self, text: &str) -> bool { + self == Spacer::Fill || text.trim().is_empty() + } +} + +/// A spacer name split into its kind and its text: `[cspacer]Games` is a +/// centred "Games", `[*spacer1]-=` repeats "-=", plain `[spacer3]` is an +/// empty row. The part between `spacer` and `]` only keeps the names +/// unique, so anything goes there. Anything else is not a spacer. +pub fn parse_spacer(name: &str) -> Option<(Spacer, &str)> { + let (inside, text) = name.strip_prefix('[')?.split_once(']')?; + let (kind, _suffix) = inside.split_once("spacer")?; + let kind = match kind { + "" | "l" => Spacer::Left, + "c" => Spacer::Center, + "r" => Spacer::Right, + "*" => Spacer::Fill, + _ => return None, + }; + Some((kind, text)) +} + +/// A channel's name as shown, and its spacer kind. Only top-level channels +/// are spacers, as in TeamSpeak: a sub-channel keeps its name as it is. +/// Names sent to the server (joining by name, invite links) stay raw. +pub fn channel_title(channel: &ChannelInfo) -> (&str, Option) { + match parse_spacer(&channel.name).filter(|_| channel.parent == 0) { + Some((kind, text)) => (text, Some(kind)), + None => (&channel.name, None), + } +} + #[cfg(test)] mod tests { use super::*; @@ -113,4 +159,34 @@ mod tests { ["0#Lobby", "1-Alice", "1-zed", "0#Games"] ); } + + #[test] + fn spacer_names() { + use Spacer::*; + for (name, spacer) in [ + ("[spacer0]", Some((Left, ""))), + ("[spacer3]Hi", Some((Left, "Hi"))), + ("[lspacer]Hi", Some((Left, "Hi"))), + ("[rspacer9]Hi", Some((Right, "Hi"))), + ("[cspacer]Hi", Some((Center, "Hi"))), + ("[cspacerx]Hi", Some((Center, "Hi"))), + ("[cspacer12]Гамесы [1]", Some((Center, "Гамесы [1]"))), + ("[*spacer1]-=", Some((Fill, "-="))), + ("[*spacer]", Some((Fill, ""))), + ("[cspacer2Games", None), + ("Games", None), + ("[Spacer]x", None), + ("[xspacer]x", None), + ("[spacr]x", None), + ("x[spacer]", None), + ] { + assert_eq!(parse_spacer(name), spacer, "{name}"); + } + assert!(Fill.separates("-=") && Left.separates("") && Center.separates(" ")); + assert!(!Left.separates("Hi")); + // Only top-level channels are spacers: a sub-channel keeps its name. + assert_eq!(channel_title(&ch(1, 0, 0, "[rspacer]Staff")), ("Staff", Some(Right))); + assert_eq!(channel_title(&ch(2, 1, 0, "[rspacer]Staff")), ("[rspacer]Staff", None)); + assert_eq!(channel_title(&ch(3, 0, 0, "Lobby")), ("Lobby", None)); + } } diff --git a/crates/voelin-ui/src/app.rs b/crates/voelin-ui/src/app.rs index 1985241..ea654fa 100644 --- a/crates/voelin-ui/src/app.rs +++ b/crates/voelin-ui/src/app.rs @@ -290,7 +290,7 @@ impl SessionView { self.channel_of(client) .filter(|c| Some(*c) != self.state.own_channel) .and_then(|c| self.presence.channels.get(&c)) - .map_or_else(String::new, |c| c.name.clone()) + .map_or_else(String::new, |c| crate::vm::tree::channel_title(c).0.to_owned()) } /// A client's nickname, or its id. diff --git a/crates/voelin-ui/src/chat.rs b/crates/voelin-ui/src/chat.rs index ca7e3dc..b4e29fe 100644 --- a/crates/voelin-ui/src/chat.rs +++ b/crates/voelin-ui/src/chat.rs @@ -145,7 +145,7 @@ impl App { view.presence .channels .get(cid) - .map(|c| c.name.clone()) + .map(|c| vm::tree::channel_title(c).0.to_owned()) .unwrap_or_else(|| cid.to_string()) ), ChatTarget::Private(_) => format!("@{author}"), diff --git a/crates/voelin-ui/src/dev.rs b/crates/voelin-ui/src/dev.rs index aec945b..f85fac5 100644 --- a/crates/voelin-ui/src/dev.rs +++ b/crates/voelin-ui/src/dev.rs @@ -444,16 +444,20 @@ fn demo_ui(app: &mut App) { music.icon = DEMO_MUSIC_ICON; music.banner_gfx_url = Some(DEMO_MUSIC_BANNER.into()); music.banner_mode = BannerMode::NoAdjust; - let mut locked = channel(7, 0, 6, "Officers"); + let mut locked = channel(7, 0, 9, "Officers"); locked.has_password = true; + // Spacers as servers name them: a centred heading, one on the right and + // a line. for c in [ channel(1, 0, 0, "Lobby"), chill, channel(3, 0, 2, "[cspacer0]Gaming"), raid, music, - channel(6, 0, 5, "AFK"), + channel(9, 0, 5, "[rspacer2]Staff"), locked, + channel(8, 0, 7, "[*spacer1]---"), + channel(6, 0, 8, "AFK"), ] { p.channels.insert(c.id, c); } diff --git a/crates/voelin-ui/src/events.rs b/crates/voelin-ui/src/events.rs index db634d2..d3ca4e0 100644 --- a/crates/voelin-ui/src/events.rs +++ b/crates/voelin-ui/src/events.rs @@ -126,12 +126,16 @@ impl App { self.refresh_events(); } - /// Channels an event can be in: server-wide first. + /// Channels an event can be in: server-wide first; no lines or empty + /// spacers. fn event_channels(&self) -> Vec<(Option, String)> { let mut out = vec![(None, "Server-wide".to_owned())]; if let Some(view) = self.view() { out.extend( - view.presence.channels.values().map(|c| (Some(c.id), format!("#{}", c.name))), + view.presence + .channels + .values() + .filter_map(|c| Some((Some(c.id), format!("#{}", vm::tree::listed_title(c)?)))), ); } out diff --git a/crates/voelin-ui/src/home.rs b/crates/voelin-ui/src/home.rs index 6f4a9e9..57ddab4 100644 --- a/crates/voelin-ui/src/home.rs +++ b/crates/voelin-ui/src/home.rs @@ -35,7 +35,7 @@ impl App { let Some(view) = self.sessions.get(&b.id) else { continue }; let channel_of = |cid: Option| { cid.and_then(|c| view.presence.channels.get(&c)) - .map(|c| c.name.clone()) + .map(|c| vm::tree::channel_title(c).0.to_owned()) .unwrap_or_default() }; let backdrop = vm::avatar::tint(&b.name); diff --git a/crates/voelin-ui/src/inbox.rs b/crates/voelin-ui/src/inbox.rs index 0bb05c1..494cdfd 100644 --- a/crates/voelin-ui/src/inbox.rs +++ b/crates/voelin-ui/src/inbox.rs @@ -67,7 +67,8 @@ impl App { _ => view.state.own_channel, } .map(|c| { - let name = view.presence.channels.get(&c).map(|c| c.name.as_str()); + let name = + view.presence.channels.get(&c).map(|c| crate::vm::tree::channel_title(c).0); (c, name.map_or_else(|| "the channel".to_owned(), |n| format!("#{n}"))) }); Some((id, tab.title.clone(), channel)) diff --git a/crates/voelin-ui/src/messages.rs b/crates/voelin-ui/src/messages.rs index 877d2f6..52994c8 100644 --- a/crates/voelin-ui/src/messages.rs +++ b/crates/voelin-ui/src/messages.rs @@ -195,7 +195,10 @@ impl App { let name = session .and_then(|s| self.sessions.get(&s)) .and_then(|v| v.presence.channels.get(cid)) - .map_or_else(|| format!("#channel {cid}"), |c| format!("#{}", c.name)); + .map_or_else( + || format!("#channel {cid}"), + |c| format!("#{}", vm::tree::channel_title(c).0), + ); (name, slint::Image::default(), false, 1) } ChatTarget::Server => (server.clone(), slint::Image::default(), false, 0), @@ -463,8 +466,8 @@ impl App { Some(s) => match &s.away { Some(m) if !m.is_empty() => format!("Away: {m} · {}", s.server), Some(_) => format!("Away · {}", s.server), - None if s.channel_name.is_empty() => format!("Online · {}", s.server), - None => format!("Online · {} · #{}", s.server, s.channel_name), + None if s.channel_title.is_empty() => format!("Online · {}", s.server), + None => format!("Online · {} · #{}", s.server, s.channel_title), }, None => match contact.filter(|c| c.last_seen_ms > 0) { Some(c) => format!("Offline · last seen {}", ago(c.last_seen_ms)), @@ -494,10 +497,10 @@ impl App { spots .iter() .map(|s| { - if s.channel_name.is_empty() { + if s.channel_title.is_empty() { s.server.clone().into() } else { - format!("{} · #{}", s.server, s.channel_name).into() + format!("{} · #{}", s.server, s.channel_title).into() } }) .collect() diff --git a/crates/voelin-ui/src/servers.rs b/crates/voelin-ui/src/servers.rs index b4737f8..54b2d63 100644 --- a/crates/voelin-ui/src/servers.rs +++ b/crates/voelin-ui/src/servers.rs @@ -509,7 +509,8 @@ impl App { let bookmark = self.current.and_then(|id| self.bookmark(id)).map(|b| b.address.clone()); let path = self.view().and_then(|v| { let mut names = Vec::new(); - let mut channel = v.presence.channels.get(&v.state.own_channel?)?; + let own = v.presence.channels.get(&v.state.own_channel?)?; + let mut channel = own; loop { names.push(channel.name.clone()); match v.presence.channels.get(&channel.parent) { @@ -518,16 +519,17 @@ impl App { } } names.reverse(); - Some(names) + // The link names the channels as the server has them; the + // toast as the tree shows them. + Some((names, vm::tree::channel_title(own).0.to_owned())) }); - let (Some(address), Some(path)) = (bookmark, path) else { + let (Some(address), Some((path, title))) = (bookmark, path) else { self.set_status("Join a voice channel to invite others to it"); return String::new(); }; let path: Vec<&str> = path.iter().map(String::as_str).collect(); let link = vm::servers::invite_link(&address, &path); - self.copy_note = - Some(format!("Copied an invite to {}: {link}", path.last().unwrap_or(&""))); + self.copy_note = Some(format!("Copied an invite to {title}: {link}")); link } diff --git a/crates/voelin-ui/src/social.rs b/crates/voelin-ui/src/social.rs index 28957e3..85a9446 100644 --- a/crates/voelin-ui/src/social.rs +++ b/crates/voelin-ui/src/social.rs @@ -130,7 +130,10 @@ pub(crate) struct Spot { pub server: String, pub client: u16, pub channel: u64, + /// The channel's name as the server has it (to join it by name). pub channel_name: String, + /// The channel's name as shown (a spacer's text). + pub channel_title: String, pub away: Option, pub streaming: bool, /// We are connected with voice there (messages, pokes, moving). @@ -275,16 +278,15 @@ impl App { else { continue; }; + let channel = view.presence.channels.get(&c.channel); spots.push(Spot { session: id, server: self.server_name(id), client: c.id, channel: c.channel, - channel_name: view - .presence - .channels - .get(&c.channel) - .map(|ch| ch.name.clone()) + channel_name: channel.map(|ch| ch.name.clone()).unwrap_or_default(), + channel_title: channel + .map(|ch| vm::tree::channel_title(ch).0.to_owned()) .unwrap_or_default(), away: c.away.clone(), streaming: c.streaming == Some(true), @@ -328,8 +330,8 @@ impl App { (Some(s), None) => match &s.away { Some(m) if !m.is_empty() => format!("Away: {m}"), Some(_) => "Away".into(), - None if s.channel_name.is_empty() => "Online".into(), - None => format!("In {}", s.channel_name), + None if s.channel_title.is_empty() => "Online".into(), + None => format!("In {}", s.channel_title), }, (None, None) => "Offline".into(), }; @@ -356,10 +358,10 @@ impl App { let spot_texts: Vec = spots .iter() .map(|s| { - if s.channel_name.is_empty() { + if s.channel_title.is_empty() { s.server.clone().into() } else { - format!("{} · #{}", s.server, s.channel_name).into() + format!("{} · #{}", s.server, s.channel_title).into() } }) .collect(); @@ -742,7 +744,7 @@ impl App { .sessions .get(&session) .and_then(|v| v.presence.channels.get(cid)) - .map(|c| format!("#{} · {server}", c.name)) + .map(|c| format!("#{} · {server}", vm::tree::channel_title(c).0)) .unwrap_or(server), _ => server, }; @@ -906,10 +908,15 @@ impl App { }); if new { let s = &sessions[0]; - let place = if s.channel_name.is_empty() { + let channel = self + .sessions + .get(&(s.session as i64)) + .and_then(|v| v.presence.channels.get(&s.channel)) + .map_or(s.channel_name.as_str(), |c| vm::tree::channel_title(c).0); + let place = if channel.is_empty() { format!("on {}", self.server_name(s.session as i64)) } else { - format!("on {} · #{}", self.server_name(s.session as i64), s.channel_name) + format!("on {} · #{channel}", self.server_name(s.session as i64)) }; self.notify( NoticeKind::Friend, @@ -971,15 +978,17 @@ impl App { let mut channels = Vec::new(); for b in &self.bookmarks { let Some(view) = self.sessions.get(&b.id) else { continue }; - for c in view.presence.channels.values().filter(|c| matches(&query, &[&c.name])) { + for (channel, title) in + vm::social::found_channels(view.presence.channels.values(), &query) + { channels.push(( SearchItem { kind: "channel".into(), - title: c.name.clone().into(), + title: title.into(), subtitle: b.name.clone().into(), ..Default::default() }, - Found::Channel(b.id, c.id), + Found::Channel(b.id, channel), )); } } @@ -1004,8 +1013,7 @@ impl App { .presence .channels .get(&c.channel) - .map(|ch| ch.name.as_str()) - .unwrap_or(""); + .map_or("", |ch| vm::tree::channel_title(ch).0); people.push(( SearchItem { kind: "person".into(), diff --git a/crates/voelin-ui/src/streams.rs b/crates/voelin-ui/src/streams.rs index cd1a4de..2eb6416 100644 --- a/crates/voelin-ui/src/streams.rs +++ b/crates/voelin-ui/src/streams.rs @@ -436,7 +436,8 @@ impl App { ); let channel = u16::try_from(streamer).ok().and_then(|id| { let view = self.view()?; - view.presence.channels.get(&view.channel_of(id)?).map(|c| c.name.clone()) + let channel = view.presence.channels.get(&view.channel_of(id)?)?; + Some(crate::vm::tree::channel_title(channel).0.to_owned()) }); bridge.set_viewer_channel(channel.unwrap_or_default().into()); bridge.set_viewer_elapsed(watch.elapsed().into()); diff --git a/crates/voelin-ui/src/studio.rs b/crates/voelin-ui/src/studio.rs index 38a2a5c..0c9e12f 100644 --- a/crates/voelin-ui/src/studio.rs +++ b/crates/voelin-ui/src/studio.rs @@ -874,7 +874,7 @@ impl App { .state .own_channel .and_then(|c| view.presence.channels.get(&c)) - .map(|c| c.name.clone()) + .map(|c| vm::tree::channel_title(c).0.to_owned()) .unwrap_or_default(); let server = if view.presence.server_name.is_empty() { self.bookmark(id).map(|b| b.name.clone()).unwrap_or_default() @@ -929,8 +929,12 @@ impl App { let target = ChatTarget::Channel(channel); let demo = self.demo_ui; let view = self.sessions.entry(id).or_default(); - let name = view.presence.channels.get(&channel).map(|c| c.name.clone()); - let name = name.unwrap_or_default(); + let name = view + .presence + .channels + .get(&channel) + .map(|c| vm::tree::channel_title(c).0.to_owned()) + .unwrap_or_default(); if !view.tabs.iter().any(|t| t.target == target) { view.tabs.push(Tab::new(target.clone(), format!("#{name}"))); if !demo { diff --git a/crates/voelin-ui/src/vm/social.rs b/crates/voelin-ui/src/vm/social.rs index 79023de..ac51cdb 100644 --- a/crates/voelin-ui/src/vm/social.rs +++ b/crates/voelin-ui/src/vm/social.rs @@ -120,6 +120,19 @@ pub fn matches(query: &str, fields: &[&str]) -> bool { q.is_empty() || fields.iter().any(|f| f.to_lowercase().contains(&q)) } +/// The channels the search (Ctrl+K) finds for `query`, with their titles: +/// a spacer by its text, never a line or an empty spacer. +pub fn found_channels<'a>( + channels: impl IntoIterator, + query: &str, +) -> Vec<(u64, &'a str)> { + channels + .into_iter() + .filter_map(|c| Some((c.id, crate::vm::tree::listed_title(c)?))) + .filter(|(_, title)| matches(query, &[*title])) + .collect() +} + /// The date block of an event: "SAT", "26", "APR". pub fn date_block(ts_ms: i64) -> (String, String, String) { local(ts_ms) @@ -224,6 +237,31 @@ mod tests { assert!(!matches("zz", &["Kairo"])); } + /// The search shows spacers by their text and leaves out lines. + #[test] + fn search_channels() { + let channel = |id, parent, name: &str| voelin_model::ChannelInfo { + id, + parent, + name: name.into(), + ..Default::default() + }; + let channels = [ + channel(1, 0, "[cspacer0]Gaming"), + channel(2, 0, "[*spacer]---"), + channel(3, 0, "[spacer1]"), + // Only top-level channels are spacers. + channel(4, 1, "[cspacer]Game Night"), + channel(5, 0, "Lobby"), + ]; + assert_eq!(found_channels(&channels, "gam"), [(1, "Gaming"), (4, "[cspacer]Game Night")]); + assert!(found_channels(&channels, "-").is_empty()); + // A spacer is not found by its prefix; a sub-channel's name is all + // its own. + assert_eq!(found_channels(&channels, "spacer"), [(4, "[cspacer]Game Night")]); + assert_eq!(found_channels(&channels, "").len(), 3); + } + #[test] fn event_dates() { let start = parse_local("2026-04-25 19:00").unwrap(); diff --git a/crates/voelin-ui/src/vm/tree.rs b/crates/voelin-ui/src/vm/tree.rs index b97c97a..41d05b4 100644 --- a/crates/voelin-ui/src/vm/tree.rs +++ b/crates/voelin-ui/src/vm/tree.rs @@ -4,8 +4,9 @@ use std::collections::{HashMap, HashSet}; use std::path::PathBuf; +pub use voelin_model::channel_title; use voelin_model::{ - BannerMode, ChannelId, ChannelInfo, ClientInfo, GroupInfo, Presence, TreeRow, tree_rows, + BannerMode, ChannelId, ChannelInfo, ClientInfo, GroupInfo, Presence, Spacer, TreeRow, tree_rows, }; use crate::app::{MemberItem, TreeItem}; @@ -104,22 +105,40 @@ fn talking(input: &TreeInput, client: &ClientInfo) -> bool { input.talking.contains(&client.id) || client.talking == Some(true) } -/// Centered spacer prefixes are presentation metadata, not part of the title. -/// Leave other names untouched rather than guessing at the full spacer syntax. -fn channel_label(name: &str) -> (&str, bool) { - if let Some((suffix, label)) = name.strip_prefix("[cspacer").and_then(|s| s.split_once(']')) - && suffix.bytes().all(|b| b.is_ascii_digit()) - { - return (label, true); +/// A spacer kind as the UI takes it (`TreeItem.spacer`, 0: no spacer). +fn spacer_index(kind: Spacer) -> i32 { + match kind { + Spacer::Left => 1, + Spacer::Center => 2, + Spacer::Right => 3, + Spacer::Fill => 4, } - (name, false) } -/// A channel's name as shown, and whether it is a centred spacer. Only -/// top-level channels are spacers, as in TeamSpeak: a sub-channel keeps its -/// name as it is. -pub fn channel_title(channel: &ChannelInfo) -> (&str, bool) { - if channel.parent == 0 { channel_label(&channel.name) } else { (&channel.name, false) } +/// A channel's title for lists and pickers (the search, the event form); +/// none for a spacer that only separates. +pub fn listed_title(channel: &ChannelInfo) -> Option<&str> { + match channel_title(channel) { + (text, Some(kind)) if kind.separates(text) => None, + (text, _) => Some(text), + } +} + +/// About as many characters as a fill spacer's row holds: more than the +/// widest tree shows. +const FILL_CHARS: usize = 200; + +/// A spacer's text as its row shows it: a fill pattern repeated across the +/// row, a blank text empty. +fn spacer_text(kind: Spacer, text: &str) -> String { + match kind { + Spacer::Fill => match text.chars().count() { + 0 => String::new(), + n => text.repeat((FILL_CHARS / n).max(1)), + }, + _ if text.trim().is_empty() => String::new(), + _ => text.to_owned(), + } } /// The rows of the tree, channels with their clients below. @@ -129,9 +148,12 @@ pub fn rows(input: &TreeInput) -> Vec { .into_iter() .map(|row| match row { TreeRow::Channel { depth, channel } => { - let (name, centered_spacer) = channel_title(channel); + let (name, spacer) = match channel_title(channel) { + (text, Some(kind)) => (spacer_text(kind, text), spacer_index(kind)), + (name, None) => (name.to_owned(), 0), + }; TreeItem { - centered_spacer, + spacer, is_channel: true, depth: depth as i32, id: channel.id as i32, @@ -183,14 +205,24 @@ pub fn rows(input: &TreeInput) -> Vec { filter(rows, input.filter) } -/// Rows that match `query`, and the channels above them. +/// A spacer row that only separates: a line, or no text. +fn separator(row: &TreeItem) -> bool { + row.is_channel + && (row.spacer == spacer_index(Spacer::Fill) || (row.spacer != 0 && row.name.is_empty())) +} + +/// Rows that match `query`, and the channels above them. A separator +/// never matches (`---` is no channel to look for), but stays above what +/// does. fn filter(rows: Vec, query: &str) -> Vec { let query = query.trim().to_lowercase(); if query.is_empty() { return rows; } - let matches: Vec = - rows.iter().map(|r| r.name.to_lowercase().contains(query.as_str())).collect(); + let matches: Vec = rows + .iter() + .map(|r| !separator(r) && r.name.to_lowercase().contains(query.as_str())) + .collect(); let mut keep = matches.clone(); // A channel stays if anything below it matches. for i in 0..rows.len() { @@ -505,28 +537,85 @@ mod tests { } #[test] - fn centered_spacer_titles_keep_tree_identity_and_search() { + fn spacer_rows_keep_tree_identity() { let mut p = presence(); p.channels.get_mut(&2).unwrap().name = "[cspacer12]Гамесы".into(); + let more = |id, order, name: &str| ChannelInfo { + id, + order, + name: name.into(), + has_password: id == 5, + ..Default::default() + }; + for c in + [more(4, 2, "[*spacer1]-="), more(5, 4, "[rspacer2]Staff"), more(6, 5, "[spacer3]")] + { + p.channels.insert(c.id, c); + } let (t, c, pb) = (HashSet::new(), HashSet::from([2]), ClientPlaybackMap::new()); let e = Extras::default(); - let rows = rows(&input(&p, &t, &c, &pb, "Гамесы", &e)); - assert_eq!(rows.len(), 1); - assert_eq!(rows[0].name, "Гамесы"); - assert!(rows[0].centered_spacer && rows[0].collapsed); - assert_eq!(rows[0].id, 2); - assert_eq!(channel_label("[cspacer]Games"), ("Games", true)); - for name in ["[cspacerx]Games", "[cspacer2Games", "Games", "[spacer0]Games"] { - assert_eq!(channel_label(name), (name, false)); - } + let rows = rows(&input(&p, &t, &c, &pb, "", &e)); + let channels: Vec<_> = rows + .iter() + .filter(|r| r.is_channel) + .map(|r| (r.id, r.spacer, r.name.chars().take(6).collect::())) + .collect(); + let row = |id, spacer, name: &str| (id, spacer, name.to_owned()); + assert_eq!( + channels, + [ + row(1, 0, "Lobby"), + row(2, 2, "Гамесы"), + row(4, 4, "-=-=-="), + row(5, 3, "Staff"), + row(6, 1, ""), + ] + ); + // A fill line repeats its pattern across the row. + let fill = &rows.iter().find(|r| r.id == 4 && r.is_channel).unwrap().name; + assert_eq!(fill.chars().count(), FILL_CHARS); + assert_eq!(spacer_text(Spacer::Fill, ""), ""); + assert_eq!(spacer_text(Spacer::Fill, "x".repeat(300).as_str()).len(), 300); + let games = rows.iter().find(|r| r.id == 2 && r.is_channel).unwrap(); + assert!(games.collapsed && games.members == 1); + assert!(rows.iter().any(|r| r.id == 5 && r.is_channel && r.locked)); // Only top-level channels are spacers: a sub-channel keeps its name. p.channels.get_mut(&3).unwrap().name = "[cspacer1]Chess".into(); - let (t, c) = (HashSet::new(), HashSet::new()); - let found = super::rows(&input(&p, &t, &c, &pb, "Chess", &e)); - let chess = found.iter().find(|r| r.is_channel && r.id == 3).unwrap(); - assert_eq!((chess.name.as_str(), chess.centered_spacer), ("[cspacer1]Chess", false)); - assert_eq!(channel_title(&p.channels[&2]), ("Гамесы", true)); - assert_eq!(channel_title(&p.channels[&3]), ("[cspacer1]Chess", false)); + let c = HashSet::new(); + let rows = super::rows(&input(&p, &t, &c, &pb, "", &e)); + let chess = rows.iter().find(|r| r.is_channel && r.id == 3).unwrap(); + assert_eq!((chess.name.as_str(), chess.spacer), ("[cspacer1]Chess", 0)); + assert_eq!(channel_title(&p.channels[&2]), ("Гамесы", Some(Spacer::Center))); + assert_eq!(channel_title(&p.channels[&3]), ("[cspacer1]Chess", None)); + // Lists and pickers leave out what only separates. + let listed: Vec<_> = p.channels.values().filter_map(listed_title).collect(); + assert_eq!(listed, ["Lobby", "Гамесы", "[cspacer1]Chess", "Staff"]); + } + + /// The search finds a spacer by its text, never a separator, but keeps + /// separators above what it finds. + #[test] + fn search_skips_separators() { + let mut p = presence(); + p.channels.get_mut(&2).unwrap().name = "[*spacer1]---".into(); + p.channels.get_mut(&1).unwrap().name = "[cspacer]Lobby".into(); + p.channels.insert( + 4, + ChannelInfo { id: 4, order: 2, name: "[spacer4]".into(), ..Default::default() }, + ); + let (t, c, pb) = (HashSet::new(), HashSet::new(), ClientPlaybackMap::new()); + let e = Extras::default(); + let names = |filter| { + super::rows(&input(&p, &t, &c, &pb, filter, &e)) + .iter() + .map(|r| r.name.chars().take(3).collect::()) + .collect::>() + }; + assert!(names("-").is_empty()); + assert!(names("spacer").is_empty()); + assert_eq!(names("lob"), ["Lob"]); + // The line stays as the parent of Chess. + assert_eq!(names("chess"), ["---", "Che"]); } #[test] diff --git a/crates/voelin-ui/ui/bridge.slint b/crates/voelin-ui/ui/bridge.slint index a23ce53..e5a0000 100644 --- a/crates/voelin-ui/ui/bridge.slint +++ b/crates/voelin-ui/ui/bridge.slint @@ -27,8 +27,10 @@ export struct ServerItem { export struct TreeItem { is-channel: bool, - // Recognized centred TeamSpeak spacer; name excludes its wire prefix. - centered-spacer: bool, + // A TeamSpeak spacer channel, its name without the `[cspacer1]` part: + // 0 none, 1 left, 2 centred, 3 right, 4 a line (the name repeats its + // pattern across the row). + spacer: int, depth: int, id: int, name: string, diff --git a/crates/voelin-ui/ui/screens/channels.slint b/crates/voelin-ui/ui/screens/channels.slint index 0a1e206..f4a9541 100644 --- a/crates/voelin-ui/ui/screens/channels.slint +++ b/crates/voelin-ui/ui/screens/channels.slint @@ -126,6 +126,8 @@ component TreeRow inherits Rectangle { in property item; callback client-clicked(int); property indent: item.depth * 14px; + // A spacer that only separates: a line, or no text. + property separator: item.is-channel && (item.spacer == 4 || (item.spacer != 0 && item.name == "")); height: item.is-channel ? 34px * Theme.font-scale : 30px * Theme.font-scale; clip: true; border-radius: Theme.radius-md; @@ -133,7 +135,7 @@ component TreeRow inherits Rectangle { border-width: item.is-channel && item.own ? 1px : 0px; border-color: Theme.accent; accessible-role: AccessibleRole.list-item; - accessible-label: item.is-channel ? @tr("Channel {}", item.name) : item.name; + accessible-label: !item.is-channel ? item.name : root.separator ? @tr("Separator") : @tr("Channel {}", item.name); accessible-description: (item.talking ? @tr("talking") + " " : "") + (item.streaming ? @tr("streaming") + " " : "") + (item.muted ? @tr("microphone off") + " " : "") + (item.local-muted ? @tr("muted for you") : ""); accessible-action-default => { if item.is-channel { @@ -177,11 +179,13 @@ component TreeRow inherits Rectangle { padding-left: Theme.space-2 + root.indent; padding-right: Theme.space-3; spacing: Theme.space-2; - if item.centered-spacer: Rectangle { width: 18px; } - if !item.centered-spacer && item.icon.width > 0: RowIcon { + // Spacers have no icon; a centred one is balanced against the + // chevron. + if item.spacer == 2: Rectangle { width: 18px; } + if item.spacer == 0 && item.icon.width > 0: RowIcon { source: item.icon; } - if !item.centered-spacer && item.icon.width == 0: Icon { + if item.spacer == 0 && item.icon.width == 0: Icon { source: item.locked ? Icons.lock : Icons.volume-2; size: 18px; tint: item.banner.width > 0 || item.own ? Theme.text : Theme.icon; @@ -189,23 +193,25 @@ component TreeRow inherits Rectangle { } Text { text: item.name; - horizontal-alignment: item.centered-spacer ? center : left; + horizontal-alignment: item.spacer == 2 ? center : item.spacer == 3 ? right : left; // Full contrast over a banner. color: item.own || item.banner.width > 0 ? Theme.text : Theme.text-secondary; font-weight: item.own || item.banner.width > 0 ? Theme.weight-semibold : Theme.weight-medium; vertical-alignment: center; horizontal-stretch: 1; - overflow: elide; + // A line is cut where the row ends; it must not widen the list. + overflow: item.spacer == 4 ? clip : elide; + min-width: 0px; } // At the end where the start shows the channel's icon, or nothing - // (a centred spacer). - if item.locked && (item.icon.width > 0 || item.centered-spacer): Icon { + // (a spacer). + if item.locked && (item.icon.width > 0 || item.spacer != 0): Icon { source: Icons.lock; size: 14px; tint: item.banner.width > 0 ? Theme.text : Theme.icon; y: (parent.height - self.height) / 2; } - if !item.centered-spacer && (item.members > 0 || item.max-members >= 0): HorizontalLayout { + if item.spacer == 0 && (item.members > 0 || item.max-members >= 0): HorizontalLayout { spacing: 3px; if item.own: Icon { source: Icons.users; diff --git a/docs/ui.md b/docs/ui.md index 79f7739..baba270 100644 --- a/docs/ui.md +++ b/docs/ui.md @@ -463,10 +463,16 @@ The compact server card shows its icon over the host banner. TeamSpeak 6 channel banners sit behind their titles in fixed-height tree rows (34 pixels), and behind desktop and phone chat/voice headers. Artwork uses centred cover cropping without distortion; it never adds height to navigation. Custom channel -icons lead the title, and recognized `[cspacerN]` labels are centred without -showing the prefix. A theme-aware surface gradient (74% to 66% opacity) keeps -primary text above 4.5:1 contrast even on all-white or all-black artwork, while -leaving the image visible. Missing pictures retain the normal background. +icons lead the title. Top-level spacer channels show their text without the +prefix and without an icon or a member count: `[spacerN]` and `[lspacerN]` on +the left, `[cspacerN]` centred, `[rspacerN]` on the right, and `[*spacerN]---` +repeats its text across the row as a line (any text may follow `spacer`, as +it only keeps names unique). Every screen that names a channel, and the +Android voice notification, shows a spacer's text; the tree search, Ctrl+K and +the event form leave out lines and empty spacers. A theme-aware surface +gradient (74% to 66% opacity) keeps primary text above 4.5:1 contrast even on +all-white or all-black artwork, while leaving the image visible. Missing +pictures retain the normal background. Bookmarks remember the server icon ID and the address that supplied it. The server list, search results and server header load its cached bytes before