Add voelin-ui-vm: toolkit-free view-model types and the Slint adapter
New crate voelin-ui-vm with no UI toolkit in its tree: ImageRef (Arc<ImageSource>: File, Rgba, Svg, Memory, None, with size()), Rgb for colours, list::diff(old, new) -> Changes (updates, removals and insertions by index) and the bridge structs as plain Clone + PartialEq values (the 51 of bridge.slint without the account's two, and the 10 of studio-bridge.slint). Strings are Arc<str>, lists Vec. voelin-ui keeps the temporary seam: From impls between every bridge struct and its Slint twin (bind/convert), and bind/rows.rs, which applies Changes to a VecModel and converts only the rows that changed. The viewer's quality list is the first model on it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7c6d149f78
commit
4dc8272c64
16 files changed
+3900
-6
No files matched your search
Generated
+10
@@ -9753,6 +9753,16 @@ dependencies = [
|
||||
"voelin-platform",
|
||||
"voelin-query",
|
||||
"voelin-store",
|
||||
"voelin-ui-vm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "voelin-ui-vm"
|
||||
version = "0.0.1-alpha"
|
||||
dependencies = [
|
||||
"image",
|
||||
"png",
|
||||
"voelin-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -23,6 +23,7 @@ members = [
|
||||
"crates/voelin-store",
|
||||
"crates/voelin-stream",
|
||||
"crates/voelin-ui",
|
||||
"crates/voelin-ui-vm",
|
||||
"tools/voelinctl",
|
||||
]
|
||||
default-members = [
|
||||
@@ -43,6 +44,7 @@ default-members = [
|
||||
"crates/voelin-store",
|
||||
"crates/voelin-stream",
|
||||
"crates/voelin-ui",
|
||||
"crates/voelin-ui-vm",
|
||||
"tools/voelinctl",
|
||||
]
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
[package]
|
||||
name = "voelin-ui-vm"
|
||||
version = "0.0.1-alpha"
|
||||
description = "Toolkit-free view models of the desktop client: engine state turned into plain rows, shared by the Slint and GPUI front ends."
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[lib]
|
||||
name = "voelin_ui_vm"
|
||||
path = "src/lib.rs"
|
||||
|
||||
# No UI toolkit here (no slint, no gpui): `cargo tree -p voelin-ui-vm -e normal`
|
||||
# must show neither. The front ends convert these types (docs/ui.md).
|
||||
[dependencies]
|
||||
# Picture sizes (the header of a file); PNG and JPEG are listed as the
|
||||
# front end's toolkit used to bring them.
|
||||
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "gif", "webp", "bmp", "ico"] }
|
||||
voelin-core = { path = "../voelin-core", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
png = "0.18"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -0,0 +1,934 @@
|
||||
//! The bridge structs: the rows and forms the screens show, as plain
|
||||
//! values. They mirror the Slint structs of `crates/voelin-ui/ui/bridge.slint`
|
||||
//! field by field (strings are shared `Arc<str>`, pictures [`ImageRef`],
|
||||
//! colours [`Rgb`], lists `Vec`); the Slint crate converts them
|
||||
//! (`bind/convert.rs`), the GPUI client will render them as they are.
|
||||
//! `MytsBadge` and `MytsForm` (account screens without a data source in this
|
||||
//! build) stay in Slint.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::color::Rgb;
|
||||
use crate::image::ImageRef;
|
||||
|
||||
/// A row or form of the bridge (the plain counterpart of the Slint struct `ServerItem`).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct ServerItem {
|
||||
pub id: i32,
|
||||
pub name: Arc<str>,
|
||||
pub address: Arc<str>,
|
||||
/// "offline", "connecting", "observing" or "connected"
|
||||
pub status: Arc<str>,
|
||||
/// Avatar of a server without an icon.
|
||||
pub initials: Arc<str>,
|
||||
pub tint: Rgb,
|
||||
/// The server's icon, empty without one.
|
||||
pub icon: ImageRef,
|
||||
/// Unread messages in its chats.
|
||||
pub unread: i32,
|
||||
/// Someone streams in our channel there.
|
||||
pub live: bool,
|
||||
/// "9 online · 7 channels" while its presence is known, else the address.
|
||||
pub detail: Arc<str>,
|
||||
/// "TeamSpeak 6", "TeamSpeak 3", "" before it was reached.
|
||||
pub product: Arc<str>,
|
||||
/// Gateway or query credentials: presence without joining.
|
||||
pub gateway: bool,
|
||||
}
|
||||
|
||||
/// A row or form of the bridge (the plain counterpart of the Slint struct `TreeItem`).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct TreeItem {
|
||||
pub is_channel: 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).
|
||||
pub spacer: i32,
|
||||
pub depth: i32,
|
||||
pub id: i32,
|
||||
pub name: Arc<str>,
|
||||
pub own: bool,
|
||||
pub talking: bool,
|
||||
pub muted: bool,
|
||||
pub sound_off: bool,
|
||||
pub away: bool,
|
||||
pub streaming: bool,
|
||||
pub locked: bool,
|
||||
pub collapsed: bool,
|
||||
/// Local playback of this client: muted, or its volume in percent
|
||||
/// (100 = unchanged).
|
||||
pub local_muted: bool,
|
||||
pub local_volume: i32,
|
||||
/// Our own client.
|
||||
pub myself: bool,
|
||||
/// Avatar of a client.
|
||||
pub initials: Arc<str>,
|
||||
pub tint: Rgb,
|
||||
/// The client's avatar picture, empty without one.
|
||||
pub avatar: ImageRef,
|
||||
/// Channels: clients inside, and the limit (-1: none).
|
||||
pub members: i32,
|
||||
pub max_members: i32,
|
||||
/// Leading channel icon or trailing client icons, empty where absent: a channel's
|
||||
/// icon; a client's server group icons, its channel group's and its own,
|
||||
/// in that order (the first three).
|
||||
pub icon: ImageRef,
|
||||
pub icon_2: ImageRef,
|
||||
pub icon_3: ImageRef,
|
||||
/// A client's badges (myTeamSpeak), the first three in its order, empty
|
||||
/// where absent; shown after the name.
|
||||
pub badge: ImageRef,
|
||||
pub badge_2: ImageRef,
|
||||
pub badge_3: ImageRef,
|
||||
/// A channel's banner picture (TeamSpeak 6), drawn behind the row;
|
||||
/// Wire sizing metadata; compact decorative backgrounds always cover.
|
||||
pub banner: ImageRef,
|
||||
pub banner_mode: i32,
|
||||
}
|
||||
|
||||
/// A client for the members panel (everyone on the server) and the voice
|
||||
/// channel view (our channel).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct MemberItem {
|
||||
pub id: i32,
|
||||
pub name: Arc<str>,
|
||||
pub initials: Arc<str>,
|
||||
pub tint: Rgb,
|
||||
pub avatar: ImageRef,
|
||||
pub talking: bool,
|
||||
pub muted: bool,
|
||||
pub sound_off: bool,
|
||||
pub away: bool,
|
||||
pub streaming: bool,
|
||||
pub myself: bool,
|
||||
/// "Speaking", "Streaming", "Away", ...
|
||||
pub status: Arc<str>,
|
||||
/// The away message, empty without one.
|
||||
pub away_message: Arc<str>,
|
||||
/// The section the row is in (a server group, "In Voice",
|
||||
/// "Streaming"), and the group's icon.
|
||||
pub group: Arc<str>,
|
||||
pub group_icon: ImageRef,
|
||||
/// The first row of its section draws the heading, with the number of
|
||||
/// rows in the section.
|
||||
pub first_in_group: bool,
|
||||
pub group_count: i32,
|
||||
/// Badges: a crown for the server's admin groups.
|
||||
pub admin: bool,
|
||||
/// A moderator group's name, shown as a role next to the name.
|
||||
pub role: Arc<str>,
|
||||
pub priority: bool,
|
||||
pub commander: bool,
|
||||
pub recording: bool,
|
||||
/// Its channel needs more talk power than it has (and it is no
|
||||
/// talker): it cannot speak.
|
||||
pub cannot_talk: bool,
|
||||
/// myTeamSpeak badges, as in `TreeItem`.
|
||||
pub badge: ImageRef,
|
||||
pub badge_2: ImageRef,
|
||||
pub badge_3: ImageRef,
|
||||
}
|
||||
|
||||
/// A myTeamSpeak badge on the member card: "Badge" and its GUID for one
|
||||
/// the app does not know; its picture is empty until it is downloaded.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct BadgeItem {
|
||||
pub name: Arc<str>,
|
||||
pub description: Arc<str>,
|
||||
pub icon: ImageRef,
|
||||
}
|
||||
|
||||
/// The member card over a member row: everything about one client and what
|
||||
/// can be done with them.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct MemberCard {
|
||||
pub open: bool,
|
||||
pub id: i32,
|
||||
pub name: Arc<str>,
|
||||
pub initials: Arc<str>,
|
||||
pub tint: Rgb,
|
||||
pub avatar: ImageRef,
|
||||
pub status: Arc<str>,
|
||||
pub description: Arc<str>,
|
||||
/// Server groups, one per line.
|
||||
pub groups: Vec<Arc<str>>,
|
||||
/// The badges the client shows (at most three, in its order).
|
||||
pub badges: Vec<BadgeItem>,
|
||||
pub country: Arc<str>,
|
||||
pub talk_power: i32,
|
||||
pub friend: bool,
|
||||
pub blocked: bool,
|
||||
/// Local playback, in percent.
|
||||
pub volume: f32,
|
||||
pub muted: bool,
|
||||
/// The client has a unique id, so contacts and private chats work.
|
||||
pub known: bool,
|
||||
/// The client streams: the card offers to watch it.
|
||||
pub streaming: bool,
|
||||
}
|
||||
|
||||
/// A row or form of the bridge (the plain counterpart of the Slint struct `ChatTab`).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct ChatTab {
|
||||
/// "Lobby", "@alice", "Server"
|
||||
pub title: Arc<str>,
|
||||
/// The name alone ("Lobby").
|
||||
pub name: Arc<str>,
|
||||
/// 0 = server chat, 1 = channel chat, 2 = private chat
|
||||
pub kind: i32,
|
||||
pub id: i32,
|
||||
pub unread: i32,
|
||||
/// The channel's topic (channel chats).
|
||||
pub topic: Arc<str>,
|
||||
/// The last message ("Mira: the banner I promised") and its time.
|
||||
pub last: Arc<str>,
|
||||
pub time: Arc<str>,
|
||||
/// The channel's banner picture behind the chat's header (as TreeItem).
|
||||
pub banner: ImageRef,
|
||||
pub banner_mode: i32,
|
||||
}
|
||||
|
||||
/// A piece of a chat line: a word in its style, or an emoji shown as an
|
||||
/// image (`emoji` is its Twemoji key, e.g. "1f600"; `text` then holds the
|
||||
/// characters).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct TextRun {
|
||||
pub text: Arc<str>,
|
||||
pub emoji: Arc<str>,
|
||||
pub bold: bool,
|
||||
pub italic: bool,
|
||||
pub underline: bool,
|
||||
pub strike: bool,
|
||||
/// Code: on a background.
|
||||
pub code: bool,
|
||||
/// The author's colour, made readable on each theme; transparent: the
|
||||
/// text's own.
|
||||
pub ink_dark: Option<Rgb>,
|
||||
pub ink_light: Option<Rgb>,
|
||||
/// Where it links to ("": nowhere), and whether its text shows something
|
||||
/// else (a page's name, another address): asked about before it opens.
|
||||
pub link: Arc<str>,
|
||||
pub masked: bool,
|
||||
}
|
||||
|
||||
/// A block of a chat line (`vm::bbcode`): its runs, and what it is.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct TextBlock {
|
||||
pub runs: Vec<TextRun>,
|
||||
/// 0 = a line, 1 = a quote's line, 2 = a line of code, 3 = a list item,
|
||||
/// 4 = a rule (no runs)
|
||||
pub kind: i32,
|
||||
/// Who a quote quotes, on its first line.
|
||||
pub caption: Arc<str>,
|
||||
}
|
||||
|
||||
/// One emoji under a message, with how many put it there.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct ReactionItem {
|
||||
/// The Twemoji key of the first emoji in `text` ("1f389"), for the image.
|
||||
pub key: Arc<str>,
|
||||
pub text: Arc<str>,
|
||||
pub count: i32,
|
||||
/// We reacted with it.
|
||||
pub me: bool,
|
||||
}
|
||||
|
||||
/// A file linked in a message (`ChatMessage::file_refs`).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct FileItem {
|
||||
pub name: Arc<str>,
|
||||
/// "2.4 MB", or what the transfer is doing.
|
||||
pub detail: Arc<str>,
|
||||
/// Index of the link in the message (what `download-file` takes).
|
||||
pub index: i32,
|
||||
/// "", "running", "done", "failed"
|
||||
pub state: Arc<str>,
|
||||
/// 0 … 1 while it downloads.
|
||||
pub progress: f32,
|
||||
/// A picture, so the icon differs.
|
||||
pub picture: bool,
|
||||
/// The picture itself, once downloaded: shown inline instead of the card.
|
||||
pub preview: ImageRef,
|
||||
}
|
||||
|
||||
/// A row or form of the bridge (the plain counterpart of the Slint struct `ChatLine`).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct ChatLine {
|
||||
/// A handle for this message in its chat, stable while the chat is open
|
||||
/// (the engine's ids do not fit a Slint int).
|
||||
pub key: i32,
|
||||
pub author: Arc<str>,
|
||||
/// The text without formatting, a line per block (shown as it is when
|
||||
/// the message has neither formatting nor emoji, and read out).
|
||||
pub text: Arc<str>,
|
||||
pub time: Arc<str>,
|
||||
/// The text in blocks of styled runs; only filled when it has
|
||||
/// formatting or emoji (`rich`).
|
||||
pub blocks: Vec<TextBlock>,
|
||||
pub rich: bool,
|
||||
/// Only one to three emoji: shown large.
|
||||
pub jumbo: bool,
|
||||
/// Same author as the line before, shortly after: no header.
|
||||
pub continued: bool,
|
||||
pub initials: Arc<str>,
|
||||
pub tint: Rgb,
|
||||
pub avatar: ImageRef,
|
||||
/// From a blocked contact.
|
||||
pub blocked: bool,
|
||||
pub pinned: bool,
|
||||
pub reactions: Vec<ReactionItem>,
|
||||
pub files: Vec<FileItem>,
|
||||
/// The gateway knows this message: it can be pinned, reacted to and
|
||||
/// made into a topic.
|
||||
pub remote: bool,
|
||||
/// The topic it belongs to, "" outside a topic.
|
||||
pub topic: Arc<str>,
|
||||
/// Highlighted after jumping to it from the pins.
|
||||
pub marked: bool,
|
||||
/// The first web address it links to, "" if none.
|
||||
pub link: Arc<str>,
|
||||
/// The first new message: the "New" divider is above it (never
|
||||
/// `continued`).
|
||||
pub unread_start: bool,
|
||||
}
|
||||
|
||||
/// A pinned message in the pins drawer.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct PinItem {
|
||||
pub line: ChatLine,
|
||||
/// "pinned by Nova · 12:04"
|
||||
pub by: Arc<str>,
|
||||
}
|
||||
|
||||
/// A gateway topic (thread).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct TopicItem {
|
||||
pub id: i32,
|
||||
pub title: Arc<str>,
|
||||
pub creator: Arc<str>,
|
||||
/// "12 messages · by Nova"
|
||||
pub detail: Arc<str>,
|
||||
/// "Last active 3 min ago", and whether that was within the hour.
|
||||
pub activity: Arc<str>,
|
||||
pub recent: bool,
|
||||
pub archived: bool,
|
||||
}
|
||||
|
||||
/// The server dialog: a bookmark (id -1: a new one) and, from a link, where
|
||||
/// Connect goes.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct BookmarkForm {
|
||||
pub id: i32,
|
||||
pub name: Arc<str>,
|
||||
pub address: Arc<str>,
|
||||
pub nickname: Arc<str>,
|
||||
pub server_password: Arc<str>,
|
||||
/// The server has voice: no Connect.
|
||||
pub connected: bool,
|
||||
/// From a link, not stored with the server: the channel to join (a
|
||||
/// path, or /<id>), its password and a privilege key.
|
||||
pub channel: Arc<str>,
|
||||
pub channel_password: Arc<str>,
|
||||
pub token: Arc<str>,
|
||||
}
|
||||
|
||||
/// A stream on the server, ours first: a stream can be watched from any
|
||||
/// channel. An empty id: a client that streams, but whose stream is still
|
||||
/// being looked up (it started before we joined, or in another channel).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct StreamItem {
|
||||
pub id: Arc<str>,
|
||||
pub name: Arc<str>,
|
||||
pub streamer: Arc<str>,
|
||||
/// The streamer's channel when it is not ours; empty in ours.
|
||||
pub channel: Arc<str>,
|
||||
/// The streamer's client id (their avatar in the members).
|
||||
pub streamer_id: i32,
|
||||
/// The streamer's avatar, as the members show it: their picture, or
|
||||
/// their initials on their colour (also the card's picture's colour).
|
||||
pub initials: Arc<str>,
|
||||
pub tint: Rgb,
|
||||
pub avatar: ImageRef,
|
||||
/// How many watch it (the gateway's directory; 0 unknown).
|
||||
pub viewers: i32,
|
||||
pub audio: bool,
|
||||
/// "Screen", "Window", "Camera"; and the announced bitrate ("8 Mbit/s").
|
||||
pub kind: Arc<str>,
|
||||
pub bitrate: Arc<str>,
|
||||
/// Shown in the viewer.
|
||||
pub watching: bool,
|
||||
/// Our own stream.
|
||||
pub own: bool,
|
||||
/// Ours from the Stream Studio: its preview is the card's picture.
|
||||
pub studio: bool,
|
||||
}
|
||||
|
||||
/// A viewer of our stream. state: "requested", "connecting" or "connected".
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct ViewerItem {
|
||||
pub client: i32,
|
||||
pub name: Arc<str>,
|
||||
pub state: Arc<str>,
|
||||
pub message: Arc<str>,
|
||||
/// Their avatar picture, empty without one.
|
||||
pub avatar: ImageRef,
|
||||
}
|
||||
|
||||
/// A capture source for the share dialog.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct SourceItem {
|
||||
pub name: Arc<str>,
|
||||
pub detail: Arc<str>,
|
||||
}
|
||||
|
||||
/// A row or form of the bridge (the plain counterpart of the Slint struct `ShareForm`).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct ShareForm {
|
||||
pub source: i32,
|
||||
pub name: Arc<str>,
|
||||
/// Index into the frame rate choices (15, 30, 60, 120, 144, 240, 320).
|
||||
pub fps_index: i32,
|
||||
/// Frames per second as typed; a choice fills it in. Any number above 0.
|
||||
pub fps: Arc<str>,
|
||||
/// Index into the bitrate choices (Auto, 2.5, 4.6, 8, 10, 20, 40, 60
|
||||
/// Mbit/s).
|
||||
pub bitrate_index: i32,
|
||||
/// Video bitrate in kbit/s as typed; a choice fills it in. Empty with
|
||||
/// Auto: from the size and frame rate shared, up to 60 Mbit/s.
|
||||
pub bitrate: Arc<str>,
|
||||
pub audio: bool,
|
||||
pub auto_accept: bool,
|
||||
}
|
||||
|
||||
/// A row or form of the bridge (the plain counterpart of the Slint struct `AudioForm`).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct AudioForm {
|
||||
/// 0 = system default, then the devices.
|
||||
pub input_index: i32,
|
||||
pub output_index: i32,
|
||||
/// 0 = push-to-talk, 1 = voice activation, 2 = continuous.
|
||||
pub transmit: i32,
|
||||
/// dBFS.
|
||||
pub vad_threshold: f32,
|
||||
pub echo_cancellation: bool,
|
||||
pub noise_suppression: bool,
|
||||
/// 0 = low ... 3 = very high.
|
||||
pub noise_level: i32,
|
||||
pub auto_gain: bool,
|
||||
/// dB.
|
||||
pub input_gain: f32,
|
||||
/// Percent.
|
||||
pub output_volume: f32,
|
||||
/// Milliseconds.
|
||||
pub playback_buffer: f32,
|
||||
}
|
||||
|
||||
/// Local playback settings of one client. volume in percent.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct ClientAudio {
|
||||
pub id: i32,
|
||||
pub name: Arc<str>,
|
||||
pub volume: f32,
|
||||
pub muted: bool,
|
||||
/// The client streams: the dialog offers to watch it.
|
||||
pub streaming: bool,
|
||||
}
|
||||
|
||||
/// The appearance settings (`ui.*` keys).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct AppearanceForm {
|
||||
/// "dark", "light" or "system"
|
||||
pub theme: Arc<str>,
|
||||
pub font_scale: f32,
|
||||
/// Pixels.
|
||||
pub narrow_breakpoint: f32,
|
||||
pub image_cache_mb: f32,
|
||||
}
|
||||
|
||||
/// A contact (friend, blocked or neutral) and where they are now.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct ContactItem {
|
||||
pub uid: Arc<str>,
|
||||
pub name: Arc<str>,
|
||||
pub initials: Arc<str>,
|
||||
pub tint: Rgb,
|
||||
pub avatar: ImageRef,
|
||||
/// "friend", "blocked" or "neutral"
|
||||
pub relation: Arc<str>,
|
||||
pub online: bool,
|
||||
pub away: bool,
|
||||
pub streaming: bool,
|
||||
/// What they do: "In Chill Zone", "Streaming", "Away: brb", "Offline".
|
||||
pub status: Arc<str>,
|
||||
/// Where: the server of the first session that sees them, or "Last seen
|
||||
/// 2 h ago on Nightfall Guild".
|
||||
pub place: Arc<str>,
|
||||
/// "12m ago": online since (this run), else when last seen.
|
||||
pub when: Arc<str>,
|
||||
pub note: Arc<str>,
|
||||
/// Local playback in percent.
|
||||
pub volume: f32,
|
||||
pub muted: bool,
|
||||
/// "Contact since 14 Jan 2022".
|
||||
pub since: Arc<str>,
|
||||
/// Every session that sees them: "Nightfall Guild · Chill Zone".
|
||||
pub spots: Vec<Arc<str>>,
|
||||
/// A voice connection sees them: they can be messaged, poked, joined.
|
||||
pub reachable: bool,
|
||||
pub selected: bool,
|
||||
}
|
||||
|
||||
/// A live stream on one of our servers (home page).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct LiveItem {
|
||||
/// The session (bookmark id) and the stream (directory or stream id).
|
||||
pub session: i32,
|
||||
pub id: Arc<str>,
|
||||
pub title: Arc<str>,
|
||||
pub streamer: Arc<str>,
|
||||
pub initials: Arc<str>,
|
||||
pub tint: Rgb,
|
||||
pub avatar: ImageRef,
|
||||
pub server: Arc<str>,
|
||||
pub channel: Arc<str>,
|
||||
/// 0: unknown.
|
||||
pub viewers: i32,
|
||||
/// "Screen", "Camera", ...
|
||||
pub kind: Arc<str>,
|
||||
/// The server's colour, for the card's picture.
|
||||
pub backdrop: Rgb,
|
||||
/// In our voice channel: it can be watched at once.
|
||||
pub watchable: bool,
|
||||
}
|
||||
|
||||
/// A chat in the recent chats and in the direct messages list.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct ConversationItem {
|
||||
/// Index in Rust's list (what `open-conversation` takes).
|
||||
pub key: i32,
|
||||
/// 0 server chat, 1 channel chat, 2 private chat, 3 offline message.
|
||||
pub kind: i32,
|
||||
pub title: Arc<str>,
|
||||
/// The server's name.
|
||||
pub server: Arc<str>,
|
||||
/// "You: That works!", "Sent a file".
|
||||
pub preview: Arc<str>,
|
||||
/// "11:42", "Yesterday", "Mon", "12 Mar".
|
||||
pub time: Arc<str>,
|
||||
/// "10m ago".
|
||||
pub ago: Arc<str>,
|
||||
pub unread: i32,
|
||||
pub initials: Arc<str>,
|
||||
pub tint: Rgb,
|
||||
pub avatar: ImageRef,
|
||||
pub online: bool,
|
||||
pub selected: bool,
|
||||
}
|
||||
|
||||
/// A notification of the bell.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct NoticeItem {
|
||||
pub key: i32,
|
||||
/// "mention", "poke", "message", "event", "friend"
|
||||
pub kind: Arc<str>,
|
||||
pub title: Arc<str>,
|
||||
pub body: Arc<str>,
|
||||
/// "3 min ago"
|
||||
pub time: Arc<str>,
|
||||
pub unread: bool,
|
||||
pub initials: Arc<str>,
|
||||
pub tint: Rgb,
|
||||
pub avatar: ImageRef,
|
||||
}
|
||||
|
||||
/// A result of the search (Ctrl+K).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct SearchItem {
|
||||
/// "server", "channel", "person", "contact", "setting"
|
||||
pub kind: Arc<str>,
|
||||
pub title: Arc<str>,
|
||||
pub subtitle: Arc<str>,
|
||||
pub initials: Arc<str>,
|
||||
pub tint: Rgb,
|
||||
pub avatar: ImageRef,
|
||||
/// The first result of a group names it ("Servers", "People", ...).
|
||||
pub header: Arc<str>,
|
||||
}
|
||||
|
||||
/// Something on our servers: an event, a scheduled stream or server news.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct HappeningItem {
|
||||
/// "event", "stream", "news"
|
||||
pub kind: Arc<str>,
|
||||
pub title: Arc<str>,
|
||||
pub subtitle: Arc<str>,
|
||||
/// "Sat 26 Apr · 19:00"
|
||||
pub when: Arc<str>,
|
||||
pub session: i32,
|
||||
pub id: i32,
|
||||
pub live: bool,
|
||||
}
|
||||
|
||||
/// Home's "Continue where you left off": the voice channel we were in last.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct ResumeItem {
|
||||
/// There is one: its server is still a bookmark at the same address.
|
||||
pub shown: bool,
|
||||
pub server_id: i32,
|
||||
pub server: Arc<str>,
|
||||
pub initials: Arc<str>,
|
||||
pub tint: Rgb,
|
||||
pub icon: ImageRef,
|
||||
/// The channel's name as the tree shows it.
|
||||
pub channel: Arc<str>,
|
||||
/// Voice is connected there: the button shows the server; else it
|
||||
/// connects into the channel.
|
||||
pub open: bool,
|
||||
pub connecting: bool,
|
||||
}
|
||||
|
||||
/// A scheduled event of a server's gateway.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct EventItem {
|
||||
pub id: i32,
|
||||
pub title: Arc<str>,
|
||||
pub description: Arc<str>,
|
||||
/// The date block: "SAT", "26", "APR".
|
||||
pub weekday: Arc<str>,
|
||||
pub day: Arc<str>,
|
||||
pub month: Arc<str>,
|
||||
/// "Sat 26 Apr, 19:00 – 21:00"
|
||||
pub when: Arc<str>,
|
||||
/// "Raid Night" or "Server-wide".
|
||||
pub place: Arc<str>,
|
||||
/// A scheduled stream: "Exploring the Lands Between · Elden Ring".
|
||||
pub stream: Arc<str>,
|
||||
pub live: bool,
|
||||
pub going: i32,
|
||||
pub maybe: i32,
|
||||
pub not_going: i32,
|
||||
/// "going", "maybe", "not_going" or "".
|
||||
pub rsvp: Arc<str>,
|
||||
pub creator: Arc<str>,
|
||||
/// We may edit and delete it (ours, or we moderate).
|
||||
pub editable: bool,
|
||||
/// "Starts in 15 min", "Started 5 min ago", "".
|
||||
pub soon: Arc<str>,
|
||||
/// "Nova (going)", ...; filled once the event was opened.
|
||||
pub attendees: Vec<Arc<str>>,
|
||||
pub expanded: bool,
|
||||
}
|
||||
|
||||
/// The event form (create or edit).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct EventForm {
|
||||
/// -1: a new event.
|
||||
pub id: i32,
|
||||
pub title: Arc<str>,
|
||||
pub description: Arc<str>,
|
||||
/// "2026-10-04 19:00", local time.
|
||||
pub start: Arc<str>,
|
||||
/// Empty: no end.
|
||||
pub end: Arc<str>,
|
||||
/// Index into `event-channels` (0: server-wide).
|
||||
pub channel: i32,
|
||||
pub stream: bool,
|
||||
pub stream_title: Arc<str>,
|
||||
pub game: Arc<str>,
|
||||
}
|
||||
|
||||
/// An offline message to write (mail the server keeps).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct OfflineForm {
|
||||
/// The peer's unique id and name.
|
||||
pub uid: Arc<str>,
|
||||
pub to: Arc<str>,
|
||||
pub subject: Arc<str>,
|
||||
pub text: Arc<str>,
|
||||
}
|
||||
|
||||
/// The open direct message: who, and what can be done.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct DmPeer {
|
||||
pub open: bool,
|
||||
pub uid: Arc<str>,
|
||||
pub name: Arc<str>,
|
||||
pub initials: Arc<str>,
|
||||
pub tint: Rgb,
|
||||
pub avatar: ImageRef,
|
||||
pub online: bool,
|
||||
/// "Online · Nightfall Guild · Chill Zone", "Offline · last seen 2 h ago".
|
||||
pub status: Arc<str>,
|
||||
pub description: Arc<str>,
|
||||
pub groups: Vec<Arc<str>>,
|
||||
pub note: Arc<str>,
|
||||
pub since: Arc<str>,
|
||||
/// Where they are now, or where they were last seen.
|
||||
pub servers: Vec<Arc<str>>,
|
||||
/// Pictures linked in the conversation that are downloaded, newest
|
||||
/// first (at most six; `media-more` counts the others), and the other
|
||||
/// files: name, "2.4 MB · Today at 11:36", picture.
|
||||
pub media: Vec<ImageRef>,
|
||||
pub media_more: i32,
|
||||
pub files: Vec<FileItem>,
|
||||
pub friend: bool,
|
||||
pub blocked: bool,
|
||||
pub volume: f32,
|
||||
pub muted: bool,
|
||||
/// Messages can be sent now (a voice connection that sees them).
|
||||
pub can_send: bool,
|
||||
/// Why not: "Kairo is offline.", "Connect to Nightfall Guild to send."
|
||||
pub notice: Arc<str>,
|
||||
/// The server keeps offline messages: offer one.
|
||||
pub offline: bool,
|
||||
/// Connect with voice to the server of this conversation.
|
||||
pub can_connect: bool,
|
||||
/// The messages come from the store, without a session: read-only.
|
||||
pub stored: bool,
|
||||
/// An offline message is shown instead of the conversation.
|
||||
pub mail: bool,
|
||||
pub mail_subject: Arc<str>,
|
||||
pub mail_text: Arc<str>,
|
||||
pub mail_time: Arc<str>,
|
||||
}
|
||||
|
||||
/// An identity (Profiles page); never its key.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct IdentityItem {
|
||||
pub id: i32,
|
||||
pub name: Arc<str>,
|
||||
/// Unique ids on TeamSpeak 3 and TeamSpeak 6 servers.
|
||||
pub uid: Arc<str>,
|
||||
pub uid6: Arc<str>,
|
||||
pub level: i32,
|
||||
/// The store's default: servers see us as this one unless a bookmark
|
||||
/// names another.
|
||||
pub default: bool,
|
||||
/// Where it came from: "Made in Voelin", "Imported", "Chosen by you".
|
||||
pub origin: Arc<str>,
|
||||
/// Raising its level: the level aimed at and the best one reached (0: no).
|
||||
pub improving: i32,
|
||||
pub reached: i32,
|
||||
/// The bookmarks that use it.
|
||||
pub used_by: Arc<str>,
|
||||
}
|
||||
|
||||
/// An identity found in another client's files (import).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct FoundIdentity {
|
||||
pub name: Arc<str>,
|
||||
pub uid: Arc<str>,
|
||||
pub level: i32,
|
||||
pub source: Arc<str>,
|
||||
/// Already in our identities.
|
||||
pub known: bool,
|
||||
pub picked: bool,
|
||||
}
|
||||
|
||||
/// A bookmark and the identity it connects with (Profiles page).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct BookmarkIdentity {
|
||||
pub id: i32,
|
||||
pub name: Arc<str>,
|
||||
/// Index into `identity-names` (0: the default identity).
|
||||
pub identity: i32,
|
||||
}
|
||||
|
||||
/// Camera, video and stream quality (Voice & Video page).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct VideoForm {
|
||||
/// Index into `cameras`.
|
||||
pub camera: i32,
|
||||
/// 0 none, 1 blur.
|
||||
pub background: i32,
|
||||
/// "auto", "1280x720", ...
|
||||
pub resolution: Arc<str>,
|
||||
/// `stream.fps` as typed.
|
||||
pub fps: Arc<str>,
|
||||
/// auto, vp8, vp9, h264, av1.
|
||||
pub codec: i32,
|
||||
pub hardware: bool,
|
||||
pub mirror: bool,
|
||||
/// everyone, friends, channel, nobody.
|
||||
pub permissions: i32,
|
||||
/// 0 auto, 1 720p, 2 1080p, 3 1440p, -1 other layers.
|
||||
pub quality: i32,
|
||||
/// kbit/s.
|
||||
pub bitrate: f32,
|
||||
/// The camera preview runs.
|
||||
pub preview: bool,
|
||||
}
|
||||
|
||||
/// A simulcast layer of our stream (Streaming page); numbers as typed.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct LayerItem {
|
||||
/// "1920x1080", or a scale like "0.5".
|
||||
pub size: Arc<str>,
|
||||
/// Frames per second; "" no cap.
|
||||
pub fps: Arc<str>,
|
||||
/// kbit/s.
|
||||
pub bitrate: Arc<str>,
|
||||
pub min_bitrate: Arc<str>,
|
||||
pub max_bitrate: Arc<str>,
|
||||
}
|
||||
|
||||
/// An audio source mixed into our stream.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct AudioSourceItem {
|
||||
/// "desktop", "app", "window", "microphone", "synthetic"
|
||||
pub kind: Arc<str>,
|
||||
pub name: Arc<str>,
|
||||
pub detail: Arc<str>,
|
||||
/// Percent.
|
||||
pub gain: f32,
|
||||
pub muted: bool,
|
||||
}
|
||||
|
||||
/// Stream defaults (Streaming page).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct StreamingForm {
|
||||
pub fps: Arc<str>,
|
||||
pub bitrate: Arc<str>,
|
||||
/// auto, vp8, vp9, h264, av1.
|
||||
pub codec: i32,
|
||||
/// auto, portal, wlroots, x11.
|
||||
pub capture: i32,
|
||||
pub replay_seconds: Arc<str>,
|
||||
pub replay_memory: Arc<str>,
|
||||
pub recording_dir: Arc<str>,
|
||||
}
|
||||
|
||||
/// Notification kinds: 0 off, 1 in the app, 2 also on the desktop.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct NotifyForm {
|
||||
pub mentions: i32,
|
||||
pub pokes: i32,
|
||||
pub messages: i32,
|
||||
pub events: i32,
|
||||
pub friends: i32,
|
||||
}
|
||||
|
||||
/// Privacy & Safety.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct PrivacyForm {
|
||||
/// 0 hide, 1 show flagged.
|
||||
pub block_mode: i32,
|
||||
/// everyone, friends, nobody.
|
||||
pub messages: i32,
|
||||
pub pokes: i32,
|
||||
}
|
||||
|
||||
/// A server's gateway (Integrations page).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct GatewayItem {
|
||||
pub session: i32,
|
||||
pub server: Arc<str>,
|
||||
pub url: Arc<str>,
|
||||
/// "connected", "connecting", "off"
|
||||
pub status: Arc<str>,
|
||||
pub features: Vec<Arc<str>>,
|
||||
pub admin: bool,
|
||||
}
|
||||
|
||||
/// A gateway configuration key (gateway administration).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct ConfigItem {
|
||||
pub key: Arc<str>,
|
||||
/// JSON.
|
||||
pub value: Arc<str>,
|
||||
pub source: Arc<str>,
|
||||
pub description: Arc<str>,
|
||||
pub kind: Arc<str>,
|
||||
pub bootstrap: bool,
|
||||
}
|
||||
|
||||
/// A gateway permission rule.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct PermItem {
|
||||
pub action: Arc<str>,
|
||||
/// "Everyone", "Server groups 6, 7", "Default: server admins".
|
||||
pub rule: Arc<str>,
|
||||
pub source: Arc<str>,
|
||||
pub everyone: bool,
|
||||
pub server_groups: Arc<str>,
|
||||
pub channel_groups: Arc<str>,
|
||||
}
|
||||
|
||||
/// A video encoder backend (Integrations page).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct EncoderItem {
|
||||
pub name: Arc<str>,
|
||||
pub api: Arc<str>,
|
||||
pub codec: Arc<str>,
|
||||
pub hardware: bool,
|
||||
pub ok: bool,
|
||||
/// Why it does not work, or "used first".
|
||||
pub status: Arc<str>,
|
||||
}
|
||||
|
||||
/// Any registered setting (Advanced page).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct SettingItem {
|
||||
pub key: Arc<str>,
|
||||
pub doc: Arc<str>,
|
||||
/// JSON.
|
||||
pub value: Arc<str>,
|
||||
/// "set here", "command line", "config file", "default".
|
||||
pub source: Arc<str>,
|
||||
}
|
||||
|
||||
/// A recording or clip of the Stream Studio (Library).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct RecordingItem {
|
||||
pub name: Arc<str>,
|
||||
/// "12.3 MB · 3 Oct 18:04".
|
||||
pub detail: Arc<str>,
|
||||
pub clip: bool,
|
||||
pub path: Arc<str>,
|
||||
}
|
||||
|
||||
/// Encoders, chat history, cache and logs (Advanced page); numbers as typed.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct AdvancedForm {
|
||||
pub encoder: Arc<str>,
|
||||
pub hardware: bool,
|
||||
/// `stream.decoder_backend`, `stream.hardware_decoding`.
|
||||
pub decoder: Arc<str>,
|
||||
pub hardware_decoding: bool,
|
||||
pub store_history: bool,
|
||||
pub history_page: Arc<str>,
|
||||
pub dedupe_ms: Arc<str>,
|
||||
pub retention_days: Arc<str>,
|
||||
pub cache_mb: Arc<str>,
|
||||
pub fetch_images: bool,
|
||||
pub progress_ms: Arc<str>,
|
||||
/// `ui.image_preview_kb`.
|
||||
pub preview_kb: Arc<str>,
|
||||
pub logs: Arc<str>,
|
||||
pub crash_dir: Arc<str>,
|
||||
}
|
||||
|
||||
/// A row or form of the bridge (the plain counterpart of the Slint struct `AccountForm`).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct AccountForm {
|
||||
pub nickname: Arc<str>,
|
||||
pub identity: Arc<str>,
|
||||
pub uid: Arc<str>,
|
||||
pub uid6: Arc<str>,
|
||||
pub level: i32,
|
||||
pub server: Arc<str>,
|
||||
}
|
||||
|
||||
/// One emoji of the picker. `text` is what picking it inserts.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct EmojiCell {
|
||||
pub key: Arc<str>,
|
||||
pub name: Arc<str>,
|
||||
pub text: Arc<str>,
|
||||
}
|
||||
|
||||
/// A row or form of the bridge (the plain counterpart of the Slint struct `EmojiRow`).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct EmojiRow {
|
||||
pub cells: Vec<EmojiCell>,
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
//! Colours without a toolkit.
|
||||
|
||||
/// An opaque colour as `0xrrggbb`. Where "no colour" means something (a
|
||||
/// text's own colour), the field is an `Option<Rgb>`.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
pub struct Rgb(pub u32);
|
||||
|
||||
impl Rgb {
|
||||
/// The colour with these channels.
|
||||
pub const fn new(r: u8, g: u8, b: u8) -> Self {
|
||||
Self((r as u32) << 16 | (g as u32) << 8 | b as u32)
|
||||
}
|
||||
|
||||
/// The red channel.
|
||||
pub const fn r(self) -> u8 {
|
||||
(self.0 >> 16) as u8
|
||||
}
|
||||
|
||||
/// The green channel.
|
||||
pub const fn g(self) -> u8 {
|
||||
(self.0 >> 8) as u8
|
||||
}
|
||||
|
||||
/// The blue channel.
|
||||
pub const fn b(self) -> u8 {
|
||||
self.0 as u8
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for Rgb {
|
||||
/// `0xrrggbb`; the top byte is ignored.
|
||||
fn from(rgb: u32) -> Self {
|
||||
Self(rgb & 0x00ff_ffff)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[u8; 3]> for Rgb {
|
||||
fn from([r, g, b]: [u8; 3]) -> Self {
|
||||
Self::new(r, g, b)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn channels() {
|
||||
let c = Rgb::from(0x2d6bff);
|
||||
assert_eq!((c.r(), c.g(), c.b()), (0x2d, 0x6b, 0xff));
|
||||
assert_eq!(Rgb::new(0x2d, 0x6b, 0xff), c);
|
||||
assert_eq!(Rgb::from([1, 2, 3]), Rgb(0x010203));
|
||||
assert_eq!(Rgb::from(0xff12_3456), Rgb(0x123456));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
//! Pictures without a toolkit: where a picture comes from, and how large it
|
||||
//! is. A front end turns an [`ImageRef`] into its own image type (Slint's
|
||||
//! `Image` through its decoded-picture cache, GPUI's `img()`).
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::SystemTime;
|
||||
|
||||
/// A picture: shared, cheap to clone, compared by what it is made of.
|
||||
pub type ImageRef = Arc<ImageSource>;
|
||||
|
||||
/// Where a picture comes from.
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub enum ImageSource {
|
||||
/// No picture.
|
||||
#[default]
|
||||
None,
|
||||
/// A file of the engine's picture cache (`avatars/<md5>`, `icons/<id>`,
|
||||
/// banners): PNG, JPEG, GIF, WebP, BMP, ICO or SVG, told by content, not
|
||||
/// by name.
|
||||
File(PathBuf),
|
||||
/// Decoded pixels, 4 bytes per pixel in the order red, green, blue, alpha.
|
||||
Rgba {
|
||||
/// Width in pixels.
|
||||
w: u32,
|
||||
/// Height in pixels.
|
||||
h: u32,
|
||||
/// `w * h * 4` bytes.
|
||||
bytes: Arc<[u8]>,
|
||||
},
|
||||
/// An SVG document.
|
||||
Svg(Arc<[u8]>),
|
||||
/// A picture file held in memory (a chat picture downloaded for its
|
||||
/// preview): the file's bytes, and a key the front end may keep its
|
||||
/// decoded picture under.
|
||||
Memory {
|
||||
/// Names the picture, for caches.
|
||||
key: Arc<str>,
|
||||
/// The file's bytes.
|
||||
bytes: Arc<[u8]>,
|
||||
},
|
||||
}
|
||||
|
||||
impl fmt::Debug for ImageSource {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::None => f.write_str("None"),
|
||||
Self::File(path) => f.debug_tuple("File").field(path).finish(),
|
||||
Self::Rgba { w, h, .. } => write!(f, "Rgba({w}x{h})"),
|
||||
Self::Svg(bytes) => write!(f, "Svg({} bytes)", bytes.len()),
|
||||
Self::Memory { key, bytes } => write!(f, "Memory({key}, {} bytes)", bytes.len()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A picture's size in pixels.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub struct Size {
|
||||
/// Width, 0 for no picture.
|
||||
pub width: u32,
|
||||
/// Height, 0 for no picture.
|
||||
pub height: u32,
|
||||
}
|
||||
|
||||
impl ImageSource {
|
||||
/// A reference to no picture.
|
||||
pub fn none() -> ImageRef {
|
||||
ImageRef::default()
|
||||
}
|
||||
|
||||
/// A reference to a file of the picture cache.
|
||||
pub fn file(path: impl Into<PathBuf>) -> ImageRef {
|
||||
Arc::new(Self::File(path.into()))
|
||||
}
|
||||
|
||||
/// A reference to decoded pixels (`bytes`: `w * h * 4`, red, green, blue,
|
||||
/// alpha); no picture if the length does not fit.
|
||||
pub fn rgba(w: u32, h: u32, bytes: impl Into<Arc<[u8]>>) -> ImageRef {
|
||||
let bytes = bytes.into();
|
||||
if bytes.len() as u64 == u64::from(w) * u64::from(h) * 4 {
|
||||
Arc::new(Self::Rgba { w, h, bytes })
|
||||
} else {
|
||||
Self::none()
|
||||
}
|
||||
}
|
||||
|
||||
/// The size the picture shows with; 0 by 0 when there is none or it can
|
||||
/// not be shown: a file that is missing, is not a picture, or is too
|
||||
/// large to decode (a front end drops those, as it would show nothing).
|
||||
/// A file's size is read from its header, once while it stays as it is;
|
||||
/// a vector picture has none of its own: its stated width and height,
|
||||
/// else 1 by 1.
|
||||
pub fn size(&self) -> Size {
|
||||
match self {
|
||||
Self::None => Size::default(),
|
||||
Self::File(path) => file_size(path),
|
||||
Self::Rgba { w, h, .. } => Size { width: *w, height: *h },
|
||||
Self::Svg(bytes) => svg_size(bytes),
|
||||
Self::Memory { bytes, .. } => bytes_size(bytes),
|
||||
}
|
||||
}
|
||||
|
||||
/// There is no picture, or it can not be shown ([`Self::size`]).
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.size().width == 0
|
||||
}
|
||||
}
|
||||
|
||||
/// A picture with more pixels than this (as RGBA bytes) is not decoded.
|
||||
const MAX_DECODED_BYTES: u64 = 128 << 20;
|
||||
|
||||
fn checked(width: u32, height: u32) -> Size {
|
||||
if width == 0 || height == 0 || u64::from(width) * u64::from(height) * 4 > MAX_DECODED_BYTES {
|
||||
Size::default()
|
||||
} else {
|
||||
Size { width, height }
|
||||
}
|
||||
}
|
||||
|
||||
/// The size of a picture file's bytes, told by content.
|
||||
fn bytes_size(bytes: &[u8]) -> Size {
|
||||
let bytes = bytes.strip_prefix(b"\xef\xbb\xbf").unwrap_or(bytes);
|
||||
let Ok(reader) = image::ImageReader::new(std::io::Cursor::new(bytes)).with_guessed_format()
|
||||
else {
|
||||
return Size::default();
|
||||
};
|
||||
if reader.format().is_none() {
|
||||
return if voelin_core::is_svg(bytes) { svg_size(bytes) } else { Size::default() };
|
||||
}
|
||||
reader.into_dimensions().map_or_else(|_| Size::default(), |(w, h)| checked(w, h))
|
||||
}
|
||||
|
||||
/// The number at the start of an attribute's value ("48", "48px", "4.5em").
|
||||
fn number(value: &str) -> Option<u32> {
|
||||
let end = value.find(|c: char| !c.is_ascii_digit() && c != '.').unwrap_or(value.len());
|
||||
value[..end].parse::<f32>().ok().filter(|v| *v >= 1.0).map(|v| v as u32)
|
||||
}
|
||||
|
||||
/// The value of `name="…"` in the root tag of an SVG.
|
||||
fn attribute<'a>(tag: &'a str, name: &str) -> Option<&'a str> {
|
||||
let mut rest = tag;
|
||||
while let Some(at) = rest.find(name) {
|
||||
let before = rest[..at].chars().next_back();
|
||||
let after = &rest[at + name.len()..];
|
||||
let after = after.trim_start();
|
||||
if before.is_none_or(char::is_whitespace)
|
||||
&& let Some(value) = after.strip_prefix('=')
|
||||
{
|
||||
let value = value.trim_start();
|
||||
let quote = value.chars().next().filter(|q| matches!(q, '"' | '\''))?;
|
||||
return value[1..].split(quote).next();
|
||||
}
|
||||
rest = &rest[at + name.len()..];
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn svg_size(bytes: &[u8]) -> Size {
|
||||
let text = String::from_utf8_lossy(bytes);
|
||||
let Some(start) = text.find("<svg") else { return Size { width: 1, height: 1 } };
|
||||
let tag = &text[start..];
|
||||
let tag = &tag[..tag.find('>').unwrap_or(tag.len())];
|
||||
let stated =
|
||||
attribute(tag, "width").and_then(number).zip(attribute(tag, "height").and_then(number));
|
||||
let boxed = || {
|
||||
let mut parts = attribute(tag, "viewBox")?.split([' ', ',']).filter(|p| !p.is_empty());
|
||||
let (_, _, w, h) = (parts.next()?, parts.next()?, parts.next()?, parts.next()?);
|
||||
number(w).zip(number(h))
|
||||
};
|
||||
let (width, height) = stated.or_else(boxed).unwrap_or((1, 1));
|
||||
checked(width, height)
|
||||
}
|
||||
|
||||
/// What a probe of a file found, and what the file was then.
|
||||
type Probe = ((u64, Option<SystemTime>), Size);
|
||||
|
||||
/// Probed files, so a picture shown in many rows is read once; entries are
|
||||
/// checked against the file's length and time before use.
|
||||
static PROBES: Mutex<Option<HashMap<PathBuf, Probe>>> = Mutex::new(None);
|
||||
|
||||
/// Probes kept at most; the picture cache is far smaller than this.
|
||||
const MAX_PROBES: usize = 4096;
|
||||
|
||||
fn file_size(path: &Path) -> Size {
|
||||
let Ok(meta) = std::fs::metadata(path) else { return Size::default() };
|
||||
let stamp = (meta.len(), meta.modified().ok());
|
||||
let mut guard = PROBES.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let probes = guard.get_or_insert_with(HashMap::new);
|
||||
if let Some((was, size)) = probes.get(path)
|
||||
&& *was == stamp
|
||||
{
|
||||
return *size;
|
||||
}
|
||||
// The file is read with the lock held; probes are short and rare.
|
||||
let size = std::fs::read(path).map_or_else(|_| Size::default(), |bytes| bytes_size(&bytes));
|
||||
if probes.len() >= MAX_PROBES {
|
||||
probes.clear();
|
||||
}
|
||||
probes.insert(path.to_owned(), (stamp, size));
|
||||
size
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// A PNG of `width` by `height` pixels.
|
||||
pub(crate) fn png(width: u32, height: u32) -> Vec<u8> {
|
||||
let mut bytes = Vec::new();
|
||||
let mut encoder = ::png::Encoder::new(&mut bytes, width, height);
|
||||
encoder.set_color(::png::ColorType::Rgba);
|
||||
encoder.set_depth(::png::BitDepth::Eight);
|
||||
let pixels = vec![200; width as usize * height as usize * 4];
|
||||
encoder.write_header().unwrap().write_image_data(&pixels).unwrap();
|
||||
bytes
|
||||
}
|
||||
|
||||
fn temp(name: &str) -> PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!("voelin-ui-vm-{name}-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
dir
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pixels_and_nothing() {
|
||||
assert_eq!(ImageSource::none().size(), Size::default());
|
||||
assert!(ImageSource::none().is_empty());
|
||||
let pixels = ImageSource::rgba(2, 3, vec![0u8; 24]);
|
||||
assert_eq!(pixels.size(), Size { width: 2, height: 3 });
|
||||
assert!(!pixels.is_empty());
|
||||
// The wrong length is no picture.
|
||||
assert!(ImageSource::rgba(2, 3, vec![0u8; 23]).is_empty());
|
||||
assert_eq!(format!("{pixels:?}"), "Rgba(2x3)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn files_by_content() {
|
||||
let dir = temp("files");
|
||||
// No extension: the cache's files have none.
|
||||
let path = dir.join("1234");
|
||||
std::fs::write(&path, png(4, 2)).unwrap();
|
||||
assert_eq!(ImageSource::file(&path).size(), Size { width: 4, height: 2 });
|
||||
// A changed file is read again.
|
||||
std::fs::write(&path, png(5, 3)).unwrap();
|
||||
assert_eq!(ImageSource::file(&path).size(), Size { width: 5, height: 3 });
|
||||
let junk = dir.join("junk");
|
||||
std::fs::write(&junk, b"not a picture").unwrap();
|
||||
assert!(ImageSource::file(&junk).is_empty());
|
||||
assert!(ImageSource::file(dir.join("missing")).is_empty());
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vector_pictures() {
|
||||
let size = |svg: &str| ImageSource::Svg(svg.as_bytes().into()).size();
|
||||
assert_eq!(size("<svg width=\"32\" height=\"16\"/>"), Size { width: 32, height: 16 });
|
||||
assert_eq!(size("<svg viewBox='0 0 24 12'/>"), Size { width: 24, height: 12 });
|
||||
assert_eq!(size("<svg xmlns='http://www.w3.org/2000/svg'/>"), Size { width: 1, height: 1 });
|
||||
assert_eq!(size("<svg width=\"4096px\" height=\"4096px\"/>").width, 4096);
|
||||
// Too large to decode.
|
||||
assert!(
|
||||
ImageSource::Svg(b"<svg width=\"99999\" height=\"99999\"/>".as_slice().into())
|
||||
.is_empty()
|
||||
);
|
||||
// An SVG file with a byte order mark and a prolog, and in memory.
|
||||
let svg: &[u8] = b"\xef\xbb\xbf<?xml version=\"1.0\"?><svg width=\"8\" height=\"8\"/>";
|
||||
let dir = temp("svg");
|
||||
std::fs::write(dir.join("icon"), svg).unwrap();
|
||||
assert_eq!(ImageSource::file(dir.join("icon")).size().width, 8);
|
||||
let memory = ImageSource::Memory { key: "k".into(), bytes: png(3, 3).into() };
|
||||
assert_eq!(memory.size(), Size { width: 3, height: 3 });
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
//! Toolkit-free view models of the desktop client: engine state turned into
|
||||
//! plain rows and forms, with the logic that decides what the screens show.
|
||||
//! Neither Slint nor GPUI is a dependency; each front end converts these
|
||||
//! types (docs/ui.md, "Two crates").
|
||||
|
||||
pub mod bridge;
|
||||
pub mod color;
|
||||
pub mod image;
|
||||
pub mod list;
|
||||
pub mod studio_bridge;
|
||||
|
||||
pub use color::Rgb;
|
||||
pub use image::{ImageRef, ImageSource, Size};
|
||||
@@ -0,0 +1,138 @@
|
||||
//! Incremental list updates: what changed between two versions of a list,
|
||||
//! as row operations. A front end that keeps a list model (Slint's
|
||||
//! `VecModel`) applies them row by row, so a client that starts talking
|
||||
//! redraws one row of the tree; one that rebuilds from the list (GPUI) just
|
||||
//! re-renders and has no use for them.
|
||||
|
||||
/// One row operation of a [`Changes`].
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Change {
|
||||
/// Row `i` holds another value: `new[i]`.
|
||||
Update(usize),
|
||||
/// Row `i` is gone.
|
||||
Remove(usize),
|
||||
/// `new[i]` is a new row, at `i`.
|
||||
Insert(usize),
|
||||
}
|
||||
|
||||
/// Row operations that turn the old list into the new one, in the order to
|
||||
/// apply them: updates, then removals (each at the index it has when its
|
||||
/// turn comes), then insertions (in ascending order).
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct Changes(pub Vec<Change>);
|
||||
|
||||
impl Changes {
|
||||
/// Nothing changed.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
|
||||
/// How many rows are updated in place.
|
||||
pub fn updated(&self) -> usize {
|
||||
self.0.iter().filter(|c| matches!(c, Change::Update(_))).count()
|
||||
}
|
||||
|
||||
/// How many rows are removed.
|
||||
pub fn removed(&self) -> usize {
|
||||
self.0.iter().filter(|c| matches!(c, Change::Remove(_))).count()
|
||||
}
|
||||
|
||||
/// How many rows are inserted.
|
||||
pub fn inserted(&self) -> usize {
|
||||
self.0.iter().filter(|c| matches!(c, Change::Insert(_))).count()
|
||||
}
|
||||
|
||||
/// Apply the changes to `rows` (the old list), which then equals `new`.
|
||||
/// Also the reference for front ends: their models do the same
|
||||
/// operations in the same order.
|
||||
pub fn apply<T: Clone>(&self, rows: &mut Vec<T>, new: &[T]) {
|
||||
for change in &self.0 {
|
||||
match *change {
|
||||
Change::Update(i) => rows[i] = new[i].clone(),
|
||||
Change::Remove(i) => {
|
||||
rows.remove(i);
|
||||
}
|
||||
Change::Insert(i) => rows.insert(i, new[i].clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What changes `old` into `new` with few row operations: the rows both
|
||||
/// share at the start and the end stay, rows in between are changed in
|
||||
/// place where they differ, and the rest inserted or removed.
|
||||
pub fn diff<T: PartialEq>(old: &[T], new: &[T]) -> Changes {
|
||||
let min = old.len().min(new.len());
|
||||
let prefix = old.iter().zip(new).take_while(|(a, b)| a == b).count();
|
||||
let suffix = old[prefix..]
|
||||
.iter()
|
||||
.rev()
|
||||
.zip(new[prefix..].iter().rev())
|
||||
.take(min - prefix)
|
||||
.take_while(|(a, b)| a == b)
|
||||
.count();
|
||||
let old_mid = old.len() - prefix - suffix;
|
||||
let new_mid = new.len() - prefix - suffix;
|
||||
let common = old_mid.min(new_mid);
|
||||
let mut changes = Vec::new();
|
||||
for i in prefix..prefix + common {
|
||||
if old[i] != new[i] {
|
||||
changes.push(Change::Update(i));
|
||||
}
|
||||
}
|
||||
let at = prefix + common;
|
||||
changes.extend((new_mid..old_mid).map(|_| Change::Remove(at)));
|
||||
changes.extend((at..at + new_mid.saturating_sub(old_mid)).map(Change::Insert));
|
||||
Changes(changes)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// The changes from `old` to `new`; applying them gives `new`.
|
||||
fn run(old: &[i32], new: &[i32]) -> Changes {
|
||||
let changes = diff(old, new);
|
||||
let mut rows = old.to_vec();
|
||||
changes.apply(&mut rows, new);
|
||||
assert_eq!(rows, new, "{old:?} -> {new:?}");
|
||||
changes
|
||||
}
|
||||
|
||||
fn counts(changes: &Changes) -> (usize, usize, usize) {
|
||||
(changes.updated(), changes.inserted(), changes.removed())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn minimal_changes() {
|
||||
assert!(run(&[1, 2, 3], &[1, 2, 3]).is_empty());
|
||||
assert_eq!(run(&[1, 2, 3], &[1, 9, 3]), Changes(vec![Change::Update(1)]));
|
||||
assert_eq!(run(&[1, 2, 3], &[1, 2, 7, 3]), Changes(vec![Change::Insert(2)]));
|
||||
assert_eq!(run(&[1, 2, 3], &[1, 3]), Changes(vec![Change::Remove(1)]));
|
||||
assert_eq!(counts(&run(&[], &[1, 2])), (0, 2, 0));
|
||||
assert_eq!(counts(&run(&[1, 2], &[])), (0, 0, 2));
|
||||
assert_eq!(run(&[1, 2, 3, 4], &[5, 6]).updated(), 2);
|
||||
run(&[1, 1, 1], &[1, 1]);
|
||||
run(&[1, 2, 1], &[1, 1, 2, 1]);
|
||||
run(&[4, 5, 6], &[1, 2, 3, 4, 5, 6, 7]);
|
||||
}
|
||||
|
||||
/// Whatever the lists, applying the changes gives the new list, and
|
||||
/// rows that stay at the ends are not touched.
|
||||
#[test]
|
||||
fn every_small_pair() {
|
||||
let lists: Vec<Vec<i32>> = (0..4usize)
|
||||
.flat_map(|n| (0..3i32.pow(n as u32)).map(move |k| (n, k)))
|
||||
.map(|(n, k)| (0..n as u32).map(|i| (k / 3i32.pow(i)) % 3).collect())
|
||||
.collect();
|
||||
for old in &lists {
|
||||
for new in &lists {
|
||||
let changes = run(old, new);
|
||||
let kept = old.iter().zip(new).take_while(|(a, b)| a == b).count();
|
||||
assert!(changes.0.iter().all(|c| match *c {
|
||||
Change::Update(i) | Change::Remove(i) | Change::Insert(i) => i >= kept,
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
//! The Stream Studio's structs: the plain counterparts of
|
||||
//! `crates/voelin-ui/ui/studio-bridge.slint`, as [`crate::bridge`] has those of
|
||||
//! `bridge.slint`.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::image::ImageRef;
|
||||
|
||||
/// A scene of the studio.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct StudioScene {
|
||||
pub id: i32,
|
||||
pub name: Arc<str>,
|
||||
/// Its sources, front first: "Screen + Camera + Text".
|
||||
pub detail: Arc<str>,
|
||||
/// Composited now (the live scene).
|
||||
pub live: bool,
|
||||
/// The kind of its front-most source (for the icon).
|
||||
pub kind: Arc<str>,
|
||||
}
|
||||
|
||||
/// A source of the live scene, front first.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct StudioSource {
|
||||
pub id: i32,
|
||||
pub name: Arc<str>,
|
||||
/// screen, window, portal, camera, image, text, colour, pattern
|
||||
pub kind: Arc<str>,
|
||||
pub visible: bool,
|
||||
pub locked: bool,
|
||||
/// keep, blur, image, colour
|
||||
pub background: Arc<str>,
|
||||
/// Why it shows nothing ("" while it works).
|
||||
pub error: Arc<str>,
|
||||
/// "1920×1080 · 60 fps"
|
||||
pub info: Arc<str>,
|
||||
/// At the front or the back (cannot move further).
|
||||
pub front: bool,
|
||||
pub back: bool,
|
||||
}
|
||||
|
||||
/// An audio source of the stream (`stream.audio_sources`).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct StudioAudio {
|
||||
pub name: Arc<str>,
|
||||
/// "Elgato Wave:3", the application...
|
||||
pub detail: Arc<str>,
|
||||
/// microphone, desktop, app, window, tone
|
||||
pub kind: Arc<str>,
|
||||
pub gain_db: f32,
|
||||
pub muted: bool,
|
||||
/// The meter in dBFS, after the gain.
|
||||
pub level: f32,
|
||||
/// Why it captures nothing.
|
||||
pub error: Arc<str>,
|
||||
}
|
||||
|
||||
/// A simulcast layer (`stream.layers`) as typed: any numbers.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct StudioLayer {
|
||||
/// "1280x720"; empty: `scale` of the output.
|
||||
pub size: Arc<str>,
|
||||
pub scale: Arc<str>,
|
||||
/// Frame-rate cap; empty: the output's.
|
||||
pub fps: Arc<str>,
|
||||
/// kbit/s.
|
||||
pub bitrate: Arc<str>,
|
||||
/// kbit/s a viewer needs for this layer.
|
||||
pub min_bitrate: Arc<str>,
|
||||
}
|
||||
|
||||
/// A viewer of the studio's stream.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct StudioViewer {
|
||||
pub client: i32,
|
||||
pub name: Arc<str>,
|
||||
/// requested, connecting, connected
|
||||
pub state: Arc<str>,
|
||||
}
|
||||
|
||||
/// An entry of a picker (screens, windows, cameras, audio sources).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct StudioPick {
|
||||
pub name: Arc<str>,
|
||||
pub detail: Arc<str>,
|
||||
/// For the icon: monitor, window, portal, camera, microphone, desktop, app, tone
|
||||
pub kind: Arc<str>,
|
||||
/// The application's own icon (audio), if it has one.
|
||||
pub icon: ImageRef,
|
||||
/// Already mixed in (audio): picking it again takes it out.
|
||||
pub selected: bool,
|
||||
}
|
||||
|
||||
/// The header, the preview's badges and the bottom bar.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct StudioStatus {
|
||||
/// The engine runs (preview, mixer, replay buffer).
|
||||
pub running: bool,
|
||||
/// "Chill Zone • Starfall Community"; empty without a destination.
|
||||
pub destination: Arc<str>,
|
||||
/// 0: not live, 1: poor, 2: fair, 3: good, 4: excellent.
|
||||
pub quality: i32,
|
||||
pub quality_text: Arc<str>,
|
||||
/// "1080p • 60 FPS • 8,250 kbps"
|
||||
pub format: Arc<str>,
|
||||
/// The numbers behind it, for the info button.
|
||||
pub details: Arc<str>,
|
||||
pub live: bool,
|
||||
/// Going live: waiting for the server.
|
||||
pub starting: bool,
|
||||
/// "00:12:34"
|
||||
pub elapsed: Arc<str>,
|
||||
pub viewers: i32,
|
||||
pub participants: i32,
|
||||
pub can_go_live: bool,
|
||||
/// Why Go Live is off, or what goes wrong.
|
||||
pub hint: Arc<str>,
|
||||
pub recording: bool,
|
||||
pub recorded: Arc<str>,
|
||||
/// The replay buffer's window (0: off) and what it holds now.
|
||||
pub replay_seconds: i32,
|
||||
pub replay_held: Arc<str>,
|
||||
pub output_width: i32,
|
||||
pub output_height: i32,
|
||||
pub fps: i32,
|
||||
pub detached: bool,
|
||||
/// A window of its own is possible (not on Android).
|
||||
pub can_detach: bool,
|
||||
/// The live scene shows a screen, a camera, a window (the phone's cards).
|
||||
pub screen_shown: bool,
|
||||
pub camera_shown: bool,
|
||||
pub window_shown: bool,
|
||||
}
|
||||
|
||||
/// The stream settings panel (`studio.stream`, `stream.bitrate_kbps`).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct StudioForm {
|
||||
pub destination: i32,
|
||||
pub title: Arc<str>,
|
||||
pub game: Arc<str>,
|
||||
pub message: Arc<str>,
|
||||
pub show_viewers: bool,
|
||||
pub show_chat: bool,
|
||||
pub show_now_playing: bool,
|
||||
pub audio: bool,
|
||||
/// kbit/s of the stream without layers, as typed.
|
||||
pub bitrate: Arc<str>,
|
||||
}
|
||||
|
||||
/// The source properties dialog (also for adding text, colour and image
|
||||
/// sources: `id` -1). Numbers as typed.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct StudioSourceForm {
|
||||
pub id: i32,
|
||||
pub name: Arc<str>,
|
||||
pub kind: Arc<str>,
|
||||
pub x: Arc<str>,
|
||||
pub y: Arc<str>,
|
||||
/// Empty: the source's own size times `scale`.
|
||||
pub width: Arc<str>,
|
||||
pub height: Arc<str>,
|
||||
pub scale: Arc<str>,
|
||||
/// contain, cover, stretch
|
||||
pub fit: Arc<str>,
|
||||
pub crop_left: Arc<str>,
|
||||
pub crop_top: Arc<str>,
|
||||
pub crop_right: Arc<str>,
|
||||
pub crop_bottom: Arc<str>,
|
||||
/// Percent.
|
||||
pub opacity: f32,
|
||||
pub locked: bool,
|
||||
pub visible: bool,
|
||||
/// keep, blur, image, colour
|
||||
pub background: Arc<str>,
|
||||
/// Blur radius in percent of the picture's height.
|
||||
pub blur: Arc<str>,
|
||||
pub background_path: Arc<str>,
|
||||
pub background_colour: Arc<str>,
|
||||
/// Text, colour ("#rrggbb" or "#rrggbbaa") and image sources.
|
||||
pub text: Arc<str>,
|
||||
pub text_size: Arc<str>,
|
||||
pub colour: Arc<str>,
|
||||
pub path: Arc<str>,
|
||||
pub mirror: bool,
|
||||
}
|
||||
|
||||
/// The studio settings dialog (`studio.*` keys and the preview).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct StudioSettingsForm {
|
||||
pub replay_seconds: Arc<str>,
|
||||
pub replay_memory: Arc<str>,
|
||||
pub recording_dir: Arc<str>,
|
||||
pub preview_width: Arc<str>,
|
||||
pub preview_fps: Arc<str>,
|
||||
}
|
||||
@@ -44,6 +44,7 @@ voelin-model = { path = "../voelin-model" }
|
||||
voelin-platform = { path = "../voelin-platform", default-features = false }
|
||||
voelin-query = { path = "../voelin-query" }
|
||||
voelin-store = { path = "../voelin-store" }
|
||||
voelin-ui-vm = { path = "../voelin-ui-vm" }
|
||||
tsclientlib = { path = "../proto/tsclientlib" }
|
||||
|
||||
# Desktop: the keyring for passwords, stream media with libvpx, OpenH264, X11
|
||||
|
||||
@@ -31,6 +31,7 @@ use voelin_model::{Capabilities, ChannelId, ChatMessage, ChatTarget, GroupInfo,
|
||||
use voelin_platform::crash;
|
||||
use voelin_store::{Bookmark, MemorySecrets, Secrets, Store};
|
||||
|
||||
use crate::bind::rows::Rows;
|
||||
use crate::hotkey::GlobalPtt;
|
||||
use crate::settings::{
|
||||
CLIENT_PLAYBACK, ClientPlaybackMap, DeviceChoices, UI, UiSettings, appearance_keys,
|
||||
@@ -495,7 +496,7 @@ pub(crate) struct Models {
|
||||
pub topics: Rc<VecModel<TopicItem>>,
|
||||
pub topic_messages: Rc<VecModel<ChatLine>>,
|
||||
/// The quality choices of the watched stream.
|
||||
pub qualities: Rc<VecModel<slint::SharedString>>,
|
||||
pub qualities: Rows<Arc<str>>,
|
||||
/// Shown when there is no chat.
|
||||
pub no_chat: Rc<VecModel<ChatLine>>,
|
||||
/// Home, friends, messages, the bell, the search, events.
|
||||
@@ -523,7 +524,7 @@ impl Models {
|
||||
pins: Rc::default(),
|
||||
topics: Rc::default(),
|
||||
topic_messages: Rc::default(),
|
||||
qualities: Rc::default(),
|
||||
qualities: Rows::default(),
|
||||
no_chat: Rc::default(),
|
||||
social: crate::social::SocialModels::new(bridge),
|
||||
layers: Rc::default(),
|
||||
@@ -550,7 +551,7 @@ impl Models {
|
||||
bridge.set_pins(ModelRc::from(self.pins.clone()));
|
||||
bridge.set_topics(ModelRc::from(self.topics.clone()));
|
||||
bridge.set_topic_messages(ModelRc::from(self.topic_messages.clone()));
|
||||
bridge.set_viewer_qualities(ModelRc::from(self.qualities.clone()));
|
||||
bridge.set_viewer_qualities(self.qualities.model());
|
||||
bridge.set_messages(ModelRc::from(self.no_chat.clone()));
|
||||
bridge.set_layers(ModelRc::from(self.layers.clone()));
|
||||
bridge.set_audio_sources(ModelRc::from(self.audio_sources.clone()));
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
//! Plain view-model values (`voelin-ui-vm`) to Slint values, and back where
|
||||
//! that can be done. Temporary, like the Slint front end itself: the rows
|
||||
//! (`items`) are converted when [`super::rows::Rows`] applies a change, so
|
||||
//! only changed rows pay for it.
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use slint::{Color, Image, ModelRc, Rgba8Pixel, SharedPixelBuffer, SharedString, VecModel};
|
||||
use voelin_ui_vm::{ImageRef, ImageSource, Rgb};
|
||||
|
||||
mod items;
|
||||
|
||||
/// An opaque colour.
|
||||
pub(crate) fn color(c: Rgb) -> Color {
|
||||
Color::from_rgb_u8(c.r(), c.g(), c.b())
|
||||
}
|
||||
|
||||
/// A colour that may be absent: transparent is the text's own colour.
|
||||
pub(crate) fn ink(c: Option<Rgb>) -> Color {
|
||||
c.map(color).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The opaque colour of a Slint colour (its transparency is dropped).
|
||||
pub(crate) fn unrgb(c: Color) -> Rgb {
|
||||
Rgb::new(c.red(), c.green(), c.blue())
|
||||
}
|
||||
|
||||
/// The colour of a Slint colour, none for a transparent one.
|
||||
pub(crate) fn unink(c: Color) -> Option<Rgb> {
|
||||
(c.alpha() > 0).then(|| unrgb(c))
|
||||
}
|
||||
|
||||
/// A picture as Slint shows it: files and downloaded pictures through the
|
||||
/// decoded-picture cache (`images.rs`), pixels as they are.
|
||||
pub(crate) fn image(picture: &ImageRef) -> Image {
|
||||
match &**picture {
|
||||
ImageSource::None => Image::default(),
|
||||
ImageSource::File(path) => crate::images::file(path),
|
||||
ImageSource::Rgba { w, h, bytes } => {
|
||||
Image::from_rgba8(SharedPixelBuffer::<Rgba8Pixel>::clone_from_slice(bytes, *w, *h))
|
||||
}
|
||||
ImageSource::Svg(data) => Image::load_from_svg_data(data).unwrap_or_default(),
|
||||
ImageSource::Memory { key, bytes } => crate::images::picture(key, bytes),
|
||||
}
|
||||
}
|
||||
|
||||
/// A model of pictures.
|
||||
pub(crate) fn images(pictures: &[ImageRef]) -> ModelRc<Image> {
|
||||
ModelRc::from(Rc::new(VecModel::from(pictures.iter().map(image).collect::<Vec<_>>())))
|
||||
}
|
||||
|
||||
/// A model of strings.
|
||||
pub(crate) fn strings(texts: &[Arc<str>]) -> ModelRc<SharedString> {
|
||||
ModelRc::from(Rc::new(VecModel::from(
|
||||
texts.iter().map(|t| SharedString::from(&**t)).collect::<Vec<_>>(),
|
||||
)))
|
||||
}
|
||||
|
||||
/// The strings of a model.
|
||||
pub(crate) fn unstrings(model: &ModelRc<SharedString>) -> Vec<Arc<str>> {
|
||||
slint::Model::iter(model).map(|t| Arc::from(t.as_str())).collect()
|
||||
}
|
||||
|
||||
/// A model of the Slint rows the plain rows convert to.
|
||||
pub(crate) fn model<V, S: for<'a> From<&'a V> + Clone + 'static>(rows: &[V]) -> ModelRc<S> {
|
||||
ModelRc::from(Rc::new(VecModel::from(rows.iter().map(S::from).collect::<Vec<_>>())))
|
||||
}
|
||||
|
||||
/// The plain rows of a model.
|
||||
pub(crate) fn rows<S: Clone + 'static, V: From<S>>(model: &ModelRc<S>) -> Vec<V> {
|
||||
slint::Model::iter(model).map(V::from).collect()
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -2,8 +2,10 @@
|
||||
//! area; each has a `wire` that the window calls once.
|
||||
|
||||
mod chat;
|
||||
pub(crate) mod convert;
|
||||
mod emoji;
|
||||
mod pages;
|
||||
pub(crate) mod rows;
|
||||
mod servers;
|
||||
mod settings;
|
||||
mod social;
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
//! A Slint list model kept in step with plain rows: the view-model code
|
||||
//! produces the new list, [`list::diff`](voelin_ui_vm::list::diff) finds
|
||||
//! the row operations, and only those rows are converted and handed to the
|
||||
//! `VecModel` (views redraw only the rows that changed: a client that
|
||||
//! starts talking is one `set_row_data`).
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use slint::{Model, ModelRc, SharedString, VecModel};
|
||||
use voelin_ui_vm::list::{Change, Changes, diff};
|
||||
|
||||
/// A plain row that a Slint model shows as another type. Implemented for
|
||||
/// the bridge structs (`convert/items.rs`).
|
||||
pub(crate) trait Row: Clone + PartialEq {
|
||||
/// The Slint type of the row.
|
||||
type Shown: Clone + 'static;
|
||||
|
||||
/// The row as the window shows it.
|
||||
fn show(&self) -> Self::Shown;
|
||||
}
|
||||
|
||||
impl Row for Arc<str> {
|
||||
type Shown = SharedString;
|
||||
|
||||
fn show(&self) -> SharedString {
|
||||
SharedString::from(&**self)
|
||||
}
|
||||
}
|
||||
|
||||
/// The rows of a list as the view model made them (`T`), and the model the
|
||||
/// window shows.
|
||||
pub(crate) struct Rows<T: Row> {
|
||||
model: Rc<VecModel<T::Shown>>,
|
||||
rows: RefCell<Vec<T>>,
|
||||
}
|
||||
|
||||
impl<T: Row> Default for Rows<T> {
|
||||
fn default() -> Self {
|
||||
Self { model: Rc::default(), rows: RefCell::default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Row> Rows<T> {
|
||||
/// The model, for a window property.
|
||||
pub fn model(&self) -> ModelRc<T::Shown> {
|
||||
ModelRc::from(self.model.clone())
|
||||
}
|
||||
|
||||
/// Make the list `new`, with the fewest row operations.
|
||||
pub fn sync(&self, new: &[T]) -> Changes {
|
||||
let mut rows = self.rows.borrow_mut();
|
||||
let changes = diff(&rows, new);
|
||||
for change in &changes.0 {
|
||||
match *change {
|
||||
Change::Update(i) => self.model.set_row_data(i, new[i].show()),
|
||||
Change::Remove(i) => {
|
||||
self.model.remove(i);
|
||||
}
|
||||
Change::Insert(i) => self.model.insert(i, new[i].show()),
|
||||
}
|
||||
}
|
||||
changes.apply(&mut rows, new);
|
||||
changes
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct Plain(i32);
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct Shown(i32);
|
||||
impl Row for Plain {
|
||||
type Shown = Shown;
|
||||
|
||||
fn show(&self) -> Shown {
|
||||
Shown(self.0 * 10)
|
||||
}
|
||||
}
|
||||
|
||||
fn run(old: &[i32], new: &[i32]) -> Changes {
|
||||
let rows: Rows<Plain> = Rows::default();
|
||||
rows.sync(&old.iter().map(|&n| Plain(n)).collect::<Vec<_>>());
|
||||
let changes = rows.sync(&new.iter().map(|&n| Plain(n)).collect::<Vec<_>>());
|
||||
let shown: Vec<i32> = rows.model.iter().map(|s| s.0).collect();
|
||||
assert_eq!(shown, new.iter().map(|n| n * 10).collect::<Vec<_>>(), "{old:?} -> {new:?}");
|
||||
assert_eq!(rows.rows.borrow().len(), new.len());
|
||||
changes
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_model_follows_the_rows() {
|
||||
assert!(run(&[1, 2, 3], &[1, 2, 3]).is_empty());
|
||||
assert_eq!(run(&[1, 2, 3], &[1, 9, 3]).updated(), 1);
|
||||
assert_eq!(run(&[1, 2, 3], &[1, 2, 7, 3]).inserted(), 1);
|
||||
assert_eq!(run(&[1, 2, 3], &[1, 3]).removed(), 1);
|
||||
run(&[], &[1, 2]);
|
||||
run(&[1, 2], &[]);
|
||||
run(&[1, 2, 1], &[1, 1, 2, 1]);
|
||||
run(&[4, 5, 6], &[1, 2, 3, 4, 5, 6, 7]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strings_are_rows() {
|
||||
let rows: Rows<Arc<str>> = Rows::default();
|
||||
rows.sync(&["720p".into(), "1080p".into()]);
|
||||
assert_eq!(rows.model().row_data(1).as_deref(), Some("1080p"));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
//! viewer. The engine runs the stream sessions; `video.rs` captures,
|
||||
//! encodes and decodes.
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use slint::{ComponentHandle, Model};
|
||||
@@ -111,11 +112,11 @@ impl Watch {
|
||||
}
|
||||
|
||||
/// "Auto" and one entry per layer the streamer offers.
|
||||
fn qualities(&self) -> Vec<slint::SharedString> {
|
||||
fn qualities(&self) -> Vec<Arc<str>> {
|
||||
if self.layers.len() < 2 {
|
||||
return Vec::new();
|
||||
}
|
||||
let mut names = vec![slint::SharedString::from("Auto")];
|
||||
let mut names: Vec<Arc<str>> = vec!["Auto".into()];
|
||||
names.extend(self.layers.iter().map(|l| layer_name(l).into()));
|
||||
names
|
||||
}
|
||||
@@ -472,7 +473,7 @@ impl App {
|
||||
.layer
|
||||
.and_then(|id| watch.layers.iter().position(|l| l.id == id))
|
||||
.map_or(0, |i| i as i32 + 1);
|
||||
crate::vm::list::sync(&self.models.qualities, &qualities);
|
||||
self.models.qualities.sync(&qualities);
|
||||
self.viewer_each(|bridge| {
|
||||
bridge.set_viewer_popped(popped);
|
||||
bridge.set_viewer_title(watch.title.as_str().into());
|
||||
|
||||
Reference in new issue
Block a user