voelin-ui: design system, shells and view models for the new design
The single 1700-line app.slint becomes a design system and screens that later waves can compose: - theme.slint: colour, radius, spacing and type tokens (dark and light, a runtime font scale); icons.slint: Lucide icons as tintable images. - components/: Button, IconButton, TextField, SearchBox, Select, Toggle, Slider, SegmentedTabs, Avatar, badges, Card, Meter, NavItem, ListItem, PopupMenu, Tooltip, Modal, Toast, ResizeHandle, Spinner, RichText and the EmojiPicker. - shells/: the desktop frame (server rail, top bar, sidebar with the user card) and the phone frame with a bottom navigation, switched at a breakpoint from the settings. - screens/: today's screens re-skinned (channels, chat, streams panel and viewer, settings page, home, dialogs, phone pages); all callbacks and properties keep their behaviour. Navigation state is the Nav global. On the Rust side app.rs keeps setup and event glue; servers.rs, chat.rs, settings_page.rs and appearance.rs hold the logic, vm/ the pure view models, bind/ the callbacks, dev.rs the development switches. Models are created once and updated row by row (vm::list::sync); each chat tab owns its lines model, so a message appends one row. Emoji come from the bundled Twemoji archive through a size-bounded image cache, split into runs that wrap with the text. New settings ui.theme, ui.font_scale, ui.narrow_breakpoint and ui.image_cache_mb apply live. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
1 parent
529211bfc6
commit
c854053090
58 files changed
+8849
-2628
No files matched your search
Generated
+2
@@ -9267,6 +9267,7 @@ dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
"dirs",
|
||||
"miniz_oxide 0.8.9",
|
||||
"png",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -9276,6 +9277,7 @@ dependencies = [
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"tsclientlib",
|
||||
"unicode-segmentation",
|
||||
"voelin-audio",
|
||||
"voelin-core",
|
||||
"voelin-model",
|
||||
|
||||
@@ -20,11 +20,15 @@ path = "src/main.rs"
|
||||
anyhow = "1.0.104"
|
||||
chrono = { version = "0.4.45", default-features = false, features = ["clock"] }
|
||||
dirs = "6"
|
||||
# Twemoji archive blocks (raw deflate); already used by png.
|
||||
miniz_oxide = "0.8"
|
||||
png = "0.18"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
tokio = { version = "1.53.1", features = ["rt-multi-thread", "macros", "time", "sync"] }
|
||||
tracing = "0.1.44"
|
||||
tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
|
||||
# Grapheme clusters for emoji in chat text.
|
||||
unicode-segmentation = "1.13"
|
||||
voelin-audio = { path = "../voelin-audio" }
|
||||
voelin-core = { path = "../voelin-core", default-features = false, features = ["audio-device"] }
|
||||
voelin-model = { path = "../voelin-model" }
|
||||
|
||||
Binary file not shown.
@@ -1,7 +1,7 @@
|
||||
fn main() {
|
||||
slint_build::compile_with_config(
|
||||
"ui/app.slint",
|
||||
slint_build::CompilerConfiguration::new().with_style("fluent-dark".into()),
|
||||
slint_build::CompilerConfiguration::new().with_style("fluent".into()),
|
||||
)
|
||||
.expect("slint compile");
|
||||
}
|
||||
+130
-937
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,56 @@
|
||||
//! Appearance settings (`ui.theme`, `ui.font_scale`, `ui.narrow_breakpoint`,
|
||||
//! `ui.image_cache_mb`): applied to the Theme and Nav globals and the image
|
||||
//! cache whenever they change, from the settings page or elsewhere.
|
||||
|
||||
use slint::ComponentHandle;
|
||||
use tracing::warn;
|
||||
|
||||
use crate::app::{App, AppearanceForm, Bridge, Nav, Theme};
|
||||
use crate::images;
|
||||
use crate::settings::{
|
||||
ThemeChoice, UI_FONT_SCALE, UI_IMAGE_CACHE_MB, UI_NARROW_BREAKPOINT, UI_THEME,
|
||||
};
|
||||
|
||||
impl App {
|
||||
/// Show the current values of the appearance keys.
|
||||
pub(crate) fn apply_appearance(&self) {
|
||||
let theme = self.prefs.get(&UI_THEME);
|
||||
let scale = self.prefs.get(&UI_FONT_SCALE);
|
||||
let breakpoint = self.prefs.get(&UI_NARROW_BREAKPOINT);
|
||||
let cache_mb = self.prefs.get(&UI_IMAGE_CACHE_MB);
|
||||
images::set_budget_mb(cache_mb);
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let t = ui.global::<Theme>();
|
||||
t.set_mode(theme.as_str().into());
|
||||
t.set_font_scale(scale);
|
||||
ui.global::<Nav>().set_narrow_breakpoint(breakpoint as f32);
|
||||
let bridge = ui.global::<Bridge>();
|
||||
bridge.set_appearance(AppearanceForm {
|
||||
theme: theme.as_str().into(),
|
||||
font_scale: scale,
|
||||
narrow_breakpoint: breakpoint as f32,
|
||||
image_cache_mb: cache_mb as f32,
|
||||
});
|
||||
bridge.set_image_cache_usage(images::usage_text().into());
|
||||
}
|
||||
|
||||
/// The settings page changed the form: store the keys (they apply
|
||||
/// through the change events).
|
||||
pub(crate) fn appearance_changed(&mut self, form: &AppearanceForm) {
|
||||
let results = [
|
||||
self.prefs.set(&UI_THEME, ThemeChoice::parse(&form.theme)),
|
||||
self.prefs.set(&UI_FONT_SCALE, form.font_scale),
|
||||
self.prefs.set(&UI_NARROW_BREAKPOINT, form.narrow_breakpoint.max(0.0).round() as u32),
|
||||
self.prefs.set(&UI_IMAGE_CACHE_MB, form.image_cache_mb.max(0.0).round() as u32),
|
||||
];
|
||||
for result in results {
|
||||
if let Err(e) = result {
|
||||
warn!(%e, "appearance setting rejected");
|
||||
self.set_status(e.to_string());
|
||||
}
|
||||
}
|
||||
// Applied now too: change events come through the engine, which
|
||||
// may not run the settings service (tests, a hosted engine).
|
||||
self.apply_appearance();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
//! The chat view.
|
||||
|
||||
use slint::ComponentHandle;
|
||||
use voelin_model::{ChannelId, ChatTarget};
|
||||
|
||||
use crate::app::{Bridge, MainWindow, with_app};
|
||||
|
||||
pub(super) fn wire(ui: &MainWindow) {
|
||||
let bridge = ui.global::<Bridge>();
|
||||
bridge.on_open_channel_chat(|cid| {
|
||||
with_app(|app| app.open_chat(ChatTarget::Channel(cid as ChannelId), true));
|
||||
});
|
||||
bridge.on_select_tab(|i| {
|
||||
with_app(|app| app.select_tab(i as usize));
|
||||
});
|
||||
bridge.on_close_tab(|i| {
|
||||
with_app(|app| app.close_tab(i as usize));
|
||||
});
|
||||
bridge.on_send_message(|text| {
|
||||
with_app(|app| app.send_message(text.to_string()));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
//! Emoji: images for the `Images` global, and the picker's rows.
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
use slint::{ComponentHandle, Model, ModelRc, VecModel};
|
||||
|
||||
use crate::app::{Emoji, EmojiCell, EmojiRow, Images, MainWindow};
|
||||
use crate::emoji::{self, PickerEmoji};
|
||||
use crate::images;
|
||||
|
||||
/// Rows of `columns` cells.
|
||||
fn rows(emoji: Vec<PickerEmoji>, columns: usize) -> Vec<EmojiRow> {
|
||||
emoji
|
||||
.chunks(columns.max(1))
|
||||
.map(|chunk| EmojiRow {
|
||||
cells: ModelRc::from(Rc::new(VecModel::from(
|
||||
chunk
|
||||
.iter()
|
||||
.map(|e| EmojiCell {
|
||||
key: e.key.into(),
|
||||
name: e.name.into(),
|
||||
text: e.text.clone().into(),
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
))),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn show(ui: &MainWindow, category: i32, list: Vec<PickerEmoji>) {
|
||||
let global = ui.global::<Emoji>();
|
||||
let columns = usize::try_from(global.get_columns()).unwrap_or(8);
|
||||
global.set_category(category);
|
||||
global.set_rows(ModelRc::from(Rc::new(VecModel::from(rows(list, columns)))));
|
||||
}
|
||||
|
||||
pub(super) fn wire(ui: &MainWindow) {
|
||||
ui.global::<Images>().on_emoji(|key| images::emoji(&key));
|
||||
let global = ui.global::<Emoji>();
|
||||
let weak = ui.as_weak();
|
||||
global.on_load(move || {
|
||||
if let Some(ui) = weak.upgrade()
|
||||
&& ui.global::<Emoji>().get_rows().row_count() == 0
|
||||
{
|
||||
let category = ui.global::<Emoji>().get_category().max(0);
|
||||
show(&ui, category, emoji::archive().category(category as usize));
|
||||
}
|
||||
});
|
||||
let weak = ui.as_weak();
|
||||
global.on_show_category(move |category| {
|
||||
if let Some(ui) = weak.upgrade() {
|
||||
show(&ui, category, emoji::archive().category(category.max(0) as usize));
|
||||
}
|
||||
});
|
||||
let weak = ui.as_weak();
|
||||
global.on_search(move |text| {
|
||||
let Some(ui) = weak.upgrade() else { return };
|
||||
if text.trim().is_empty() {
|
||||
let category = ui.global::<Emoji>().get_category().max(0);
|
||||
show(&ui, category, emoji::archive().category(category as usize));
|
||||
} else {
|
||||
show(&ui, -1, emoji::archive().search(&text));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn rows_of_cells() {
|
||||
let list = emoji::archive().category(0);
|
||||
let n = list.len();
|
||||
let rows = rows(list, 8);
|
||||
assert_eq!(rows.len(), n.div_ceil(8));
|
||||
assert_eq!(rows[0].cells.row_count(), 8);
|
||||
assert_eq!(rows[0].cells.row_data(0).unwrap().key, "1f600");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//! Callbacks of the screens, wired to the app. One module per screen or
|
||||
//! area; each has a `wire` that the window calls once.
|
||||
|
||||
mod chat;
|
||||
mod emoji;
|
||||
mod servers;
|
||||
mod settings;
|
||||
mod streams;
|
||||
|
||||
use crate::app::MainWindow;
|
||||
|
||||
/// Connect every callback of the window.
|
||||
pub(crate) fn wire(ui: &MainWindow) {
|
||||
servers::wire(ui);
|
||||
chat::wire(ui);
|
||||
streams::wire(ui);
|
||||
settings::wire(ui);
|
||||
emoji::wire(ui);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
//! The rail, the server card, the channel tree and the voice controls.
|
||||
|
||||
use slint::ComponentHandle;
|
||||
use voelin_core::Command;
|
||||
use voelin_model::ChannelId;
|
||||
|
||||
use crate::app::{Bridge, MainWindow, with_app};
|
||||
|
||||
pub(super) fn wire(ui: &MainWindow) {
|
||||
let bridge = ui.global::<Bridge>();
|
||||
bridge.on_select_server(|id| {
|
||||
with_app(|app| app.select_server(id as i64));
|
||||
});
|
||||
bridge.on_search(|text| {
|
||||
with_app(|app| app.search(text.to_string()));
|
||||
});
|
||||
bridge.on_connect_voice(|| {
|
||||
with_app(|app| app.connect_voice());
|
||||
});
|
||||
bridge.on_disconnect_voice(|| {
|
||||
with_app(|app| app.command(|session| Command::DisconnectVoice { session }));
|
||||
});
|
||||
bridge.on_toggle_observe(|| {
|
||||
with_app(|app| app.toggle_observe());
|
||||
});
|
||||
bridge.on_join_channel(|cid| {
|
||||
with_app(|app| {
|
||||
app.command(|session| Command::MoveToChannel {
|
||||
session,
|
||||
channel: cid as ChannelId,
|
||||
password: None,
|
||||
})
|
||||
});
|
||||
});
|
||||
bridge.on_toggle_collapse(|cid| {
|
||||
with_app(|app| app.toggle_collapse(cid as ChannelId));
|
||||
});
|
||||
bridge.on_set_input_muted(|muted| {
|
||||
with_app(|app| app.command(|session| Command::SetInputMuted { session, muted }));
|
||||
});
|
||||
bridge.on_set_output_muted(|muted| {
|
||||
with_app(|app| app.command(|session| Command::SetOutputMuted { session, muted }));
|
||||
});
|
||||
bridge.on_push_to_talk(|on| {
|
||||
with_app(|app| app.command(|session| Command::SetTransmitting { session, on }));
|
||||
});
|
||||
bridge.on_edit_bookmark(|id| with_app(|app| app.bookmark_form(id as i64)).unwrap_or_default());
|
||||
bridge.on_save_bookmark(|form| {
|
||||
with_app(|app| app.save_bookmark(form));
|
||||
});
|
||||
bridge.on_delete_bookmark(|id| {
|
||||
with_app(|app| app.delete_bookmark(id as i64));
|
||||
});
|
||||
bridge.on_open_client(|id| with_app(|app| app.open_client(id as u16)).unwrap_or(false));
|
||||
bridge.on_client_audio_changed(|form| {
|
||||
with_app(|app| app.client_playback_changed(&form));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
//! The settings page, crash reports and About.
|
||||
|
||||
use slint::{ComponentHandle, SharedString};
|
||||
|
||||
use crate::app::{Bridge, MainWindow, with_app};
|
||||
|
||||
pub(super) fn wire(ui: &MainWindow) {
|
||||
let bridge = ui.global::<Bridge>();
|
||||
bridge.on_open_settings(|| {
|
||||
with_app(|app| app.open_settings());
|
||||
});
|
||||
bridge.on_close_settings(|| {
|
||||
with_app(|app| app.close_settings());
|
||||
});
|
||||
bridge.on_audio_changed(|form| {
|
||||
with_app(|app| app.audio_changed(&form));
|
||||
});
|
||||
bridge.on_toggle_mic_test(|| {
|
||||
with_app(|app| app.set_mic_test(!app.mic_test));
|
||||
});
|
||||
bridge.on_apply_ptt(|enabled, key| {
|
||||
with_app(|app| app.apply_ptt(enabled, key.to_string()));
|
||||
});
|
||||
bridge.on_set_h264(|enabled| {
|
||||
with_app(|app| app.set_h264(enabled));
|
||||
});
|
||||
bridge.on_download_h264(|| {
|
||||
with_app(|app| app.download_h264());
|
||||
});
|
||||
bridge.on_appearance_changed(|form| {
|
||||
with_app(|app| app.appearance_changed(&form));
|
||||
});
|
||||
bridge.on_set_crash_reports(|enabled| {
|
||||
with_app(|app| app.set_crash_reports(enabled));
|
||||
});
|
||||
bridge.on_open_crash_folder(|| {
|
||||
with_app(|app| app.open_crash_folder());
|
||||
});
|
||||
bridge.on_delete_crash_reports(|| {
|
||||
with_app(|app| app.delete_crash_reports());
|
||||
});
|
||||
bridge.on_dismiss_crash_notice(|| {
|
||||
with_app(|app| {
|
||||
if let Some(ui) = app.ui.upgrade() {
|
||||
ui.global::<Bridge>().set_crash_notice(SharedString::new());
|
||||
}
|
||||
});
|
||||
});
|
||||
bridge.on_open_about(|| {
|
||||
with_app(|app| app.load_notices());
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
//! The streams panel, the share dialog and the viewer.
|
||||
|
||||
use slint::ComponentHandle;
|
||||
|
||||
use crate::app::{Bridge, MainWindow, with_app};
|
||||
|
||||
pub(super) fn wire(ui: &MainWindow) {
|
||||
let bridge = ui.global::<Bridge>();
|
||||
bridge.on_open_share(|| with_app(|app| app.open_share()).unwrap_or_default());
|
||||
bridge.on_start_share(|form| {
|
||||
with_app(|app| app.start_share(form));
|
||||
});
|
||||
bridge.on_stop_share(|| {
|
||||
with_app(|app| app.stop_share());
|
||||
});
|
||||
bridge.on_respond_viewer(|viewer, accept| {
|
||||
with_app(|app| app.respond_viewer(viewer as u16, accept));
|
||||
});
|
||||
bridge.on_kick_viewer(|viewer| {
|
||||
with_app(|app| app.kick_viewer(viewer as u16));
|
||||
});
|
||||
bridge.on_watch_stream(|id| {
|
||||
with_app(|app| app.watch_stream(id.to_string()));
|
||||
});
|
||||
bridge.on_show_viewer(|| {
|
||||
with_app(|app| app.show_viewer(true));
|
||||
});
|
||||
bridge.on_hide_viewer(|| {
|
||||
with_app(|app| app.show_viewer(false));
|
||||
});
|
||||
bridge.on_leave_stream(|| {
|
||||
with_app(|app| app.leave_stream());
|
||||
});
|
||||
bridge.on_set_stream_volume(|volume| {
|
||||
with_app(|app| app.set_stream_volume(volume));
|
||||
});
|
||||
bridge.on_toggle_fullscreen(|| {
|
||||
with_app(|app| app.toggle_fullscreen());
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
//! Chat: tabs per session (server, channels, private chats) and their
|
||||
//! messages. Each tab keeps its lines as a model; the chat view shows the
|
||||
//! selected tab's model, so a new message appends one row.
|
||||
|
||||
use slint::{ComponentHandle, ModelRc};
|
||||
use voelin_core::Command;
|
||||
use voelin_model::{ChatMessage, ChatTarget};
|
||||
|
||||
use crate::app::{App, Bridge, ChatTab, Tab};
|
||||
use crate::vm;
|
||||
|
||||
impl App {
|
||||
pub(crate) fn open_chat(&mut self, target: ChatTarget, focus: bool) {
|
||||
let Some(id) = self.current else { return };
|
||||
let title = match &target {
|
||||
ChatTarget::Channel(cid) => {
|
||||
let name = self
|
||||
.sessions
|
||||
.get(&id)
|
||||
.and_then(|v| v.presence.channels.get(cid).map(|c| c.name.clone()));
|
||||
format!("#{}", name.unwrap_or_else(|| cid.to_string()))
|
||||
}
|
||||
ChatTarget::Server => "Server".into(),
|
||||
ChatTarget::Private(uid) => format!("@{uid}"),
|
||||
};
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let index = match view.tabs.iter().position(|t| t.target == target) {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
view.tabs.push(Tab::new(target.clone(), title));
|
||||
if !self.demo_ui {
|
||||
self.engine.send(Command::OpenChat { session: id as u64, target });
|
||||
}
|
||||
view.tabs.len() - 1
|
||||
}
|
||||
};
|
||||
if focus {
|
||||
view.current_tab = index;
|
||||
view.tabs[index].unread = 0;
|
||||
}
|
||||
self.refresh_chat();
|
||||
self.refresh_servers();
|
||||
}
|
||||
|
||||
pub(crate) fn select_tab(&mut self, index: usize) {
|
||||
if let Some(view) = self.view_mut()
|
||||
&& index < view.tabs.len()
|
||||
{
|
||||
view.current_tab = index;
|
||||
view.tabs[index].unread = 0;
|
||||
}
|
||||
self.refresh_chat();
|
||||
self.refresh_servers();
|
||||
}
|
||||
|
||||
pub(crate) fn close_tab(&mut self, index: usize) {
|
||||
let Some(id) = self.current else { return };
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
if index == 0 || index >= view.tabs.len() {
|
||||
return;
|
||||
}
|
||||
let tab = view.tabs.remove(index);
|
||||
view.current_tab = view.current_tab.min(view.tabs.len() - 1);
|
||||
self.engine.send(Command::CloseChat { session: id as u64, target: tab.target });
|
||||
self.refresh_chat();
|
||||
}
|
||||
|
||||
pub(crate) fn send_message(&mut self, text: String) {
|
||||
let Some(id) = self.current else { return };
|
||||
let Some(view) = self.sessions.get(&id) else { return };
|
||||
let target = view.tabs[view.current_tab].target.clone();
|
||||
self.engine.send(Command::SendChat { session: id as u64, target, text });
|
||||
}
|
||||
|
||||
pub(crate) fn add_message(&mut self, id: i64, message: ChatMessage) {
|
||||
let current = self.current == Some(id);
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let index = match view.tabs.iter().position(|t| t.target == message.target) {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
let title = match &message.target {
|
||||
ChatTarget::Channel(cid) => format!(
|
||||
"#{}",
|
||||
view.presence
|
||||
.channels
|
||||
.get(cid)
|
||||
.map(|c| c.name.clone())
|
||||
.unwrap_or_else(|| cid.to_string())
|
||||
),
|
||||
ChatTarget::Private(_) => format!("@{}", message.author_name),
|
||||
ChatTarget::Server => "Server".into(),
|
||||
};
|
||||
view.tabs.push(Tab::new(message.target.clone(), title));
|
||||
view.tabs.len() - 1
|
||||
}
|
||||
};
|
||||
let shown = current && view.current_tab == index;
|
||||
let tab = &mut view.tabs[index];
|
||||
let line = vm::chat::line(&message, tab.last.as_ref());
|
||||
tab.last = Some(vm::chat::Previous::of(&message));
|
||||
tab.lines.push(line);
|
||||
if !shown {
|
||||
tab.unread += 1;
|
||||
}
|
||||
if current {
|
||||
self.refresh_chat();
|
||||
}
|
||||
if !shown {
|
||||
self.refresh_servers();
|
||||
}
|
||||
}
|
||||
|
||||
/// Tabs and the shown tab's messages.
|
||||
pub(crate) fn refresh_chat(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let (tabs, lines) = match self.view() {
|
||||
None => (
|
||||
vec![ChatTab { title: "Server".into(), ..Default::default() }],
|
||||
ModelRc::from(self.models.no_chat.clone()),
|
||||
),
|
||||
Some(view) => {
|
||||
let tabs: Vec<ChatTab> = view
|
||||
.tabs
|
||||
.iter()
|
||||
.map(|t| ChatTab {
|
||||
title: t.title.clone().into(),
|
||||
kind: match t.target {
|
||||
ChatTarget::Server => 0,
|
||||
ChatTarget::Channel(_) => 1,
|
||||
ChatTarget::Private(_) => 2,
|
||||
},
|
||||
id: match t.target {
|
||||
ChatTarget::Channel(cid) => cid as i32,
|
||||
_ => 0,
|
||||
},
|
||||
unread: t.unread,
|
||||
topic: match t.target {
|
||||
ChatTarget::Channel(cid) => view
|
||||
.presence
|
||||
.channels
|
||||
.get(&cid)
|
||||
.and_then(|c| c.topic.clone())
|
||||
.unwrap_or_default()
|
||||
.into(),
|
||||
_ => Default::default(),
|
||||
},
|
||||
})
|
||||
.collect();
|
||||
(tabs, ModelRc::from(view.tabs[view.current_tab].lines.clone()))
|
||||
}
|
||||
};
|
||||
vm::list::sync(&self.models.tabs, &tabs);
|
||||
let current = self.view().map_or(0, |v| v.current_tab as i32);
|
||||
if bridge.get_current_tab() != current {
|
||||
bridge.set_current_tab(current);
|
||||
}
|
||||
// Swap the model only when another tab is shown.
|
||||
if bridge.get_messages() != lines {
|
||||
bridge.set_messages(lines);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,339 @@
|
||||
//! Development switches (environment variables), for trying screens and
|
||||
//! taking screenshots without a server:
|
||||
//!
|
||||
//! - `VOELIN_DATA_DIR=<dir>`: the database (app.rs).
|
||||
//! - `VOELIN_AUTOCONNECT=voice|observe`: connect the first bookmark on start.
|
||||
//! - `VOELIN_SCREENSHOT=<png>`: save the window after
|
||||
//! `VOELIN_SCREENSHOT_DELAY` seconds (default 4) and exit.
|
||||
//! - `VOELIN_WINDOW_SIZE=<w>x<h>`: the window's size (e.g. `390x844` for the
|
||||
//! phone layout).
|
||||
//! - `VOELIN_DEMO_UI=1`: sample servers, channels, chat and streams, no
|
||||
//! server needed (nothing is stored).
|
||||
//! - `VOELIN_DEMO_STREAM=1`: a local test stream in the viewer.
|
||||
//! - `VOELIN_OPEN=<what>[,<what>...]`: open screens on start: `home`,
|
||||
//! `server`, `settings[:<section>]` (voice, keybinds, streaming, privacy,
|
||||
//! appearance, or 0-4), `about`, `share`, `bookmark` (add a server),
|
||||
//! `emoji` (the picker), `client` (the volume dialog of the first other
|
||||
//! client once connected), `panel` / `no-panel` (the right panel),
|
||||
//! `tab:<home|servers|chat|activity|you>` (phone layout).
|
||||
//! - `VOELIN_AUTOWATCH=1`: watch the first stream that shows up.
|
||||
//! - `VOELIN_AUTOSHARE=test-pattern`: share the test pattern (accepting
|
||||
//! everyone) once connected to a TeamSpeak 6 server.
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Result;
|
||||
use slint::ComponentHandle;
|
||||
use voelin_core::stream::{StreamInfo, StreamKind};
|
||||
use voelin_core::{Event, ObserveState, SessionState, Source, VoiceState};
|
||||
use voelin_model::{ChannelInfo, ChatMessage, ChatTarget, ClientInfo, Presence, ServerFlavor};
|
||||
use voelin_store::Bookmark;
|
||||
|
||||
use crate::app::{App, MainWindow, MobileTab, Nav, Page, SettingsSection, with_app};
|
||||
|
||||
/// The switches read at start.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub(crate) struct Switches {
|
||||
pub demo_stream: bool,
|
||||
pub demo_ui: bool,
|
||||
pub autoshare: bool,
|
||||
pub open_client: bool,
|
||||
open: Vec<String>,
|
||||
autoconnect: Option<String>,
|
||||
screenshot: Option<std::path::PathBuf>,
|
||||
screenshot_delay: u64,
|
||||
window_size: Option<(f32, f32)>,
|
||||
}
|
||||
|
||||
fn flag(name: &str) -> bool {
|
||||
std::env::var(name).is_ok_and(|v| v == "1")
|
||||
}
|
||||
|
||||
/// `390x844` → (390, 844).
|
||||
fn parse_size(text: &str) -> Option<(f32, f32)> {
|
||||
let (w, h) = text.split_once(['x', 'X'])?;
|
||||
Some((w.trim().parse().ok()?, h.trim().parse().ok()?))
|
||||
}
|
||||
|
||||
impl Switches {
|
||||
pub fn from_env() -> Self {
|
||||
let open: Vec<String> = std::env::var("VOELIN_OPEN")
|
||||
.unwrap_or_default()
|
||||
.split(',')
|
||||
.map(|s| s.trim().to_owned())
|
||||
.filter(|s| !s.is_empty())
|
||||
.collect();
|
||||
Self {
|
||||
demo_stream: flag("VOELIN_DEMO_STREAM"),
|
||||
demo_ui: flag("VOELIN_DEMO_UI"),
|
||||
autoshare: std::env::var("VOELIN_AUTOSHARE").is_ok_and(|v| v == "test-pattern"),
|
||||
open_client: open.iter().any(|o| o == "client"),
|
||||
open,
|
||||
autoconnect: std::env::var("VOELIN_AUTOCONNECT").ok(),
|
||||
screenshot: std::env::var_os("VOELIN_SCREENSHOT").map(Into::into),
|
||||
screenshot_delay: std::env::var("VOELIN_SCREENSHOT_DELAY")
|
||||
.ok()
|
||||
.and_then(|d| d.parse().ok())
|
||||
.unwrap_or(4),
|
||||
window_size: std::env::var("VOELIN_WINDOW_SIZE").ok().as_deref().and_then(parse_size),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn section(name: &str) -> SettingsSection {
|
||||
match name {
|
||||
"1" | "keybinds" | "ptt" => SettingsSection::Keybinds,
|
||||
"2" | "streaming" => SettingsSection::Streaming,
|
||||
"3" | "privacy" => SettingsSection::Privacy,
|
||||
"4" | "appearance" => SettingsSection::Appearance,
|
||||
_ => SettingsSection::Voice,
|
||||
}
|
||||
}
|
||||
|
||||
fn mobile_tab(name: &str) -> MobileTab {
|
||||
match name {
|
||||
"home" => MobileTab::Home,
|
||||
"servers" => MobileTab::Servers,
|
||||
"activity" => MobileTab::Activity,
|
||||
"you" => MobileTab::You,
|
||||
_ => MobileTab::Chat,
|
||||
}
|
||||
}
|
||||
|
||||
/// Timers that must live while the window runs.
|
||||
pub(crate) struct Running {
|
||||
_screenshot: Option<slint::Timer>,
|
||||
}
|
||||
|
||||
/// Apply the switches once the app is set up.
|
||||
pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
||||
if let Some((w, h)) = switches.window_size {
|
||||
ui.window().set_size(slint::LogicalSize::new(w, h));
|
||||
}
|
||||
if switches.demo_ui {
|
||||
with_app(demo_ui);
|
||||
}
|
||||
match switches.autoconnect.as_deref() {
|
||||
Some("voice") => {
|
||||
with_app(|app| app.connect_voice());
|
||||
}
|
||||
Some("observe") => {
|
||||
with_app(|app| app.toggle_observe());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
let nav = ui.global::<Nav>();
|
||||
for open in &switches.open {
|
||||
let (what, arg) = open.split_once(':').unwrap_or((open.as_str(), ""));
|
||||
match what {
|
||||
"home" => nav.invoke_show(Page::Home),
|
||||
"server" => nav.invoke_show(Page::Server),
|
||||
"settings" => nav.invoke_open_settings(section(arg)),
|
||||
"about" => nav.invoke_open_about(),
|
||||
"share" => nav.invoke_open_share(),
|
||||
"bookmark" => nav.invoke_add_server(),
|
||||
"emoji" => nav.set_emoji_open(true),
|
||||
"panel" => nav.set_right_panel_open(true),
|
||||
"no-panel" => nav.set_right_panel_open(false),
|
||||
"tab" => nav.set_mobile_tab(mobile_tab(arg)),
|
||||
// Opened once connected (settings_page.rs).
|
||||
"client" => {}
|
||||
other => eprintln!("VOELIN_OPEN: unknown screen {other:?}"),
|
||||
}
|
||||
}
|
||||
let screenshot = switches.screenshot.clone().map(|path| {
|
||||
let weak = ui.as_weak();
|
||||
let timer = slint::Timer::default();
|
||||
timer.start(
|
||||
slint::TimerMode::SingleShot,
|
||||
Duration::from_secs(switches.screenshot_delay),
|
||||
move || {
|
||||
if let Some(ui) = weak.upgrade() {
|
||||
if let Err(e) = save_screenshot(&ui, &path) {
|
||||
eprintln!("screenshot failed: {e}");
|
||||
}
|
||||
let _ = ui.hide();
|
||||
}
|
||||
},
|
||||
);
|
||||
timer
|
||||
});
|
||||
Running { _screenshot: screenshot }
|
||||
}
|
||||
|
||||
fn save_screenshot(ui: &MainWindow, path: &std::path::Path) -> Result<()> {
|
||||
let image = ui.window().take_snapshot()?;
|
||||
let file = std::io::BufWriter::new(std::fs::File::create(path)?);
|
||||
let mut encoder = png::Encoder::new(file, image.width(), image.height());
|
||||
encoder.set_color(png::ColorType::Rgba);
|
||||
encoder.set_depth(png::BitDepth::Eight);
|
||||
encoder.write_header()?.write_image_data(image.as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
const DEMO: i64 = 9001;
|
||||
|
||||
fn channel(id: u64, parent: u64, order: u64, name: &str) -> ChannelInfo {
|
||||
ChannelInfo { id, parent, order, name: name.into(), ..Default::default() }
|
||||
}
|
||||
|
||||
fn client(id: u16, channel: u64, name: &str) -> ClientInfo {
|
||||
ClientInfo {
|
||||
id,
|
||||
channel,
|
||||
nickname: name.into(),
|
||||
uid: Some(format!("demo-{id}")),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Sample data through the same events a server would send.
|
||||
fn demo_ui(app: &mut App) {
|
||||
let bookmark = |id: i64, name: &str, address: &str| Bookmark {
|
||||
id,
|
||||
name: name.into(),
|
||||
address: address.into(),
|
||||
nickname: "Nova".into(),
|
||||
identity: None,
|
||||
default_channel: None,
|
||||
gateway_url: None,
|
||||
query: None,
|
||||
client_version: None,
|
||||
};
|
||||
app.bookmarks = vec![
|
||||
bookmark(DEMO, "Nightfall Guild", "ts.nightfall.example:9987"),
|
||||
bookmark(DEMO + 1, "Pixel Lounge", "pixel.example"),
|
||||
bookmark(DEMO + 2, "Dev TS3", "127.0.0.1:9987"),
|
||||
];
|
||||
app.current = Some(DEMO);
|
||||
let session = DEMO as u64;
|
||||
|
||||
let mut p = Presence { server_name: "Nightfall Guild".into(), ..Default::default() };
|
||||
let mut chill = channel(2, 0, 1, "Chill Zone");
|
||||
chill.max_clients = Some(50);
|
||||
chill.topic = Some("Hang out, chat, and explore the worlds beyond.".into());
|
||||
let mut locked = channel(7, 0, 6, "Officers");
|
||||
locked.has_password = true;
|
||||
for c in [
|
||||
channel(1, 0, 0, "Lobby"),
|
||||
chill,
|
||||
channel(3, 0, 2, "Gaming"),
|
||||
channel(4, 3, 0, "Raid Night"),
|
||||
channel(5, 0, 3, "Music"),
|
||||
channel(6, 0, 5, "AFK"),
|
||||
locked,
|
||||
] {
|
||||
p.channels.insert(c.id, c);
|
||||
}
|
||||
let mut clients = vec![
|
||||
client(1, 2, "Nova"),
|
||||
client(2, 2, "Lumen"),
|
||||
client(3, 2, "Kairo"),
|
||||
client(4, 2, "Mira"),
|
||||
client(5, 2, "dex"),
|
||||
client(6, 3, "Talon"),
|
||||
client(7, 4, "Zeph"),
|
||||
client(8, 6, "Blaze"),
|
||||
client(9, 1, "Rin"),
|
||||
];
|
||||
clients[1].streaming = Some(true);
|
||||
clients[4].input_muted = true;
|
||||
clients[7].away = Some("brb".into());
|
||||
clients[8].output_muted = true;
|
||||
for c in clients {
|
||||
p.clients.insert(c.id, c);
|
||||
}
|
||||
|
||||
let flavor = ServerFlavor::from_version_string("6.0.0-beta13.1 [Build: 1]");
|
||||
let capabilities = flavor.capabilities();
|
||||
let events = [
|
||||
Event::ServerInfo { session, name: "Nightfall Guild".into(), flavor, capabilities },
|
||||
Event::Presence { session, presence: Arc::new(p) },
|
||||
Event::State {
|
||||
session,
|
||||
state: SessionState {
|
||||
voice: VoiceState::Connected,
|
||||
presence_source: Some(Source::Voice),
|
||||
own_channel: Some(2),
|
||||
own_client: Some(1),
|
||||
..Default::default()
|
||||
},
|
||||
},
|
||||
Event::Talking { session, client: 3, talking: true },
|
||||
Event::StreamsChanged {
|
||||
session,
|
||||
streams: vec![StreamInfo {
|
||||
id: "demo-stream".into(),
|
||||
streamer: tsclientlib::ClientId(2),
|
||||
name: "Exploring the Lands Between".into(),
|
||||
kind: StreamKind::Screen,
|
||||
bitrate: 8000,
|
||||
viewer_limit: 0,
|
||||
audio: true,
|
||||
}],
|
||||
},
|
||||
Event::State {
|
||||
session: session + 1,
|
||||
state: SessionState { observe: ObserveState::Observing, ..Default::default() },
|
||||
},
|
||||
];
|
||||
for event in events {
|
||||
app.handle_event(event);
|
||||
}
|
||||
let now = chrono::Utc::now().timestamp_millis();
|
||||
let lines = [
|
||||
(
|
||||
DEMO,
|
||||
ChatTarget::Channel(2),
|
||||
"Nova",
|
||||
"Beautiful morning for a game. Who's up for a session later? ☀️",
|
||||
0,
|
||||
false,
|
||||
),
|
||||
(DEMO, ChatTarget::Channel(2), "Kairo", "Definitely! I'll be on after lunch.", 4, false),
|
||||
(DEMO, ChatTarget::Channel(2), "Kairo", "Bringing snacks 🍕🍩", 4, false),
|
||||
(
|
||||
DEMO,
|
||||
ChatTarget::Channel(2),
|
||||
"Mira",
|
||||
"Working on a new video today — here's a sneak peek soon! 🎬",
|
||||
7,
|
||||
false,
|
||||
),
|
||||
(
|
||||
DEMO,
|
||||
ChatTarget::Channel(2),
|
||||
"Lumen",
|
||||
"Going live in Chill Zone — exploring the Lands Between. Come hang! 🔥🗡️",
|
||||
48,
|
||||
false,
|
||||
),
|
||||
(DEMO, ChatTarget::Channel(2), "dex", "🎉🎉", 50, false),
|
||||
(
|
||||
DEMO,
|
||||
ChatTarget::Channel(2),
|
||||
"Ari",
|
||||
"Anyone want to run some co-op later? 👀 Posting from the web.",
|
||||
55,
|
||||
true,
|
||||
),
|
||||
(DEMO, ChatTarget::Server, "Talon", "Server restart tonight at 23:00.", 20, false),
|
||||
(DEMO + 1, ChatTarget::Server, "Ivy", "Welcome to the lounge!", 30, false),
|
||||
(DEMO + 1, ChatTarget::Server, "Ivy", "New channel for artists 🎨", 31, false),
|
||||
];
|
||||
for (id, target, author, text, minute, relay) in lines {
|
||||
let message = ChatMessage {
|
||||
target,
|
||||
author_name: author.into(),
|
||||
author_uid: None,
|
||||
author_id: None,
|
||||
text: text.into(),
|
||||
ts_ms: now - (60 - minute) * 60_000,
|
||||
via_relay: relay,
|
||||
};
|
||||
app.add_message(id, message);
|
||||
}
|
||||
app.set_status("Connected to Nightfall Guild (TeamSpeak 6 6.0.0-beta13.1)");
|
||||
app.refresh_all();
|
||||
}
|
||||
@@ -0,0 +1,411 @@
|
||||
//! Twemoji as images. The software renderer draws no colour glyphs, so the
|
||||
//! UI shows emoji as pictures: this module reads the packed archive
|
||||
//! (`assets/twemoji.bin`, made by `scripts/pack-twemoji.py`), finds the
|
||||
//! picture of a grapheme cluster, splits text into runs of text and emoji,
|
||||
//! and lists emoji for the picker. Decoding the SVGs into images is
|
||||
//! `images.rs`' job.
|
||||
|
||||
use std::sync::{Arc, Mutex, OnceLock};
|
||||
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
static DATA: &[u8] = include_bytes!("../assets/twemoji.bin");
|
||||
|
||||
const MAGIC: &[u8; 8] = b"VTWEMOJ1";
|
||||
const ENTRY_SIZE: usize = 28;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct Block {
|
||||
offset: u32,
|
||||
len: u32,
|
||||
raw_len: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct Entry {
|
||||
key: (u32, u16),
|
||||
category: u16,
|
||||
block: u32,
|
||||
offset: u32,
|
||||
len: u32,
|
||||
name: (u32, u16),
|
||||
picker: bool,
|
||||
}
|
||||
|
||||
/// An emoji of the picker.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct PickerEmoji {
|
||||
/// The archive key (`1f600`).
|
||||
pub key: &'static str,
|
||||
/// Lower-case name for search and screen readers.
|
||||
pub name: &'static str,
|
||||
/// The characters picking it inserts.
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
/// The packed Twemoji: an index sorted by key and deflate blocks.
|
||||
pub struct Archive {
|
||||
entries: Vec<Entry>,
|
||||
blocks: Vec<Block>,
|
||||
strings: &'static [u8],
|
||||
data: &'static [u8],
|
||||
/// Picker entries (indices into `entries`) in picker order.
|
||||
picker: Vec<u32>,
|
||||
/// The last decompressed block: neighbours are often wanted together.
|
||||
last: Mutex<Option<(u32, Arc<[u8]>)>>,
|
||||
}
|
||||
|
||||
fn u32_at(b: &[u8], at: usize) -> Option<u32> {
|
||||
Some(u32::from_le_bytes(b.get(at..at + 4)?.try_into().ok()?))
|
||||
}
|
||||
|
||||
fn u16_at(b: &[u8], at: usize) -> Option<u16> {
|
||||
Some(u16::from_le_bytes(b.get(at..at + 2)?.try_into().ok()?))
|
||||
}
|
||||
|
||||
impl Archive {
|
||||
/// Parse the index of an archive; `None` if it is malformed.
|
||||
pub fn parse(bytes: &'static [u8]) -> Option<Self> {
|
||||
if bytes.get(..8)? != MAGIC {
|
||||
return None;
|
||||
}
|
||||
let count = u32_at(bytes, 8)? as usize;
|
||||
let block_count = u32_at(bytes, 12)? as usize;
|
||||
let strings_len = u32_at(bytes, 16)? as usize;
|
||||
let mut at = 20;
|
||||
let mut blocks = Vec::with_capacity(block_count);
|
||||
for _ in 0..block_count {
|
||||
blocks.push(Block {
|
||||
offset: u32_at(bytes, at)?,
|
||||
len: u32_at(bytes, at + 4)?,
|
||||
raw_len: u32_at(bytes, at + 8)?,
|
||||
});
|
||||
at += 12;
|
||||
}
|
||||
let mut entries = Vec::with_capacity(count);
|
||||
for _ in 0..count {
|
||||
entries.push(Entry {
|
||||
key: (u32_at(bytes, at)?, u16_at(bytes, at + 4)?),
|
||||
category: u16_at(bytes, at + 6)?,
|
||||
block: u32_at(bytes, at + 8)?,
|
||||
offset: u32_at(bytes, at + 12)?,
|
||||
len: u32_at(bytes, at + 16)?,
|
||||
name: (u32_at(bytes, at + 20)?, u16_at(bytes, at + 24)?),
|
||||
picker: u16_at(bytes, at + 26)? & 1 == 1,
|
||||
});
|
||||
at += ENTRY_SIZE;
|
||||
}
|
||||
let strings = bytes.get(at..at + strings_len)?;
|
||||
let data = bytes.get(at + strings_len..)?;
|
||||
let mut picker: Vec<u32> =
|
||||
(0..entries.len() as u32).filter(|&i| entries[i as usize].picker).collect();
|
||||
picker.sort_by_key(|&i| {
|
||||
let e = &entries[i as usize];
|
||||
(e.category, e.block, e.offset)
|
||||
});
|
||||
Some(Self { entries, blocks, strings, data, picker, last: Mutex::new(None) })
|
||||
}
|
||||
|
||||
fn string(&self, (offset, len): (u32, u16)) -> &'static str {
|
||||
let (offset, len) = (offset as usize, len as usize);
|
||||
let strings: &'static [u8] = self.strings;
|
||||
strings.get(offset..offset + len).and_then(|b| std::str::from_utf8(b).ok()).unwrap_or("")
|
||||
}
|
||||
|
||||
fn find(&self, key: &str) -> Option<&Entry> {
|
||||
self.entries
|
||||
.binary_search_by(|e| self.string(e.key).cmp(key))
|
||||
.ok()
|
||||
.map(|i| &self.entries[i])
|
||||
}
|
||||
|
||||
/// Number of emoji in the archive.
|
||||
#[cfg(test)]
|
||||
pub fn len(&self) -> usize {
|
||||
self.entries.len()
|
||||
}
|
||||
|
||||
pub fn contains(&self, key: &str) -> bool {
|
||||
self.find(key).is_some()
|
||||
}
|
||||
|
||||
/// The name of an emoji (lower case), if the archive has it.
|
||||
#[allow(dead_code, reason = "for screens that label emoji (reactions)")]
|
||||
pub fn name(&self, key: &str) -> Option<&'static str> {
|
||||
self.find(key).map(|e| self.string(e.name))
|
||||
}
|
||||
|
||||
/// The SVG of an emoji.
|
||||
pub fn svg(&self, key: &str) -> Option<Vec<u8>> {
|
||||
let entry = *self.find(key)?;
|
||||
let block = self.block(entry.block)?;
|
||||
let (start, len) = (entry.offset as usize, entry.len as usize);
|
||||
block.get(start..start + len).map(<[u8]>::to_vec)
|
||||
}
|
||||
|
||||
fn block(&self, index: u32) -> Option<Arc<[u8]>> {
|
||||
let mut last = self.last.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if let Some((i, block)) = last.as_ref()
|
||||
&& *i == index
|
||||
{
|
||||
return Some(block.clone());
|
||||
}
|
||||
let b = self.blocks.get(index as usize)?;
|
||||
let compressed = self.data.get(b.offset as usize..(b.offset + b.len) as usize)?;
|
||||
let raw =
|
||||
miniz_oxide::inflate::decompress_to_vec_with_limit(compressed, b.raw_len as usize)
|
||||
.ok()?;
|
||||
let raw: Arc<[u8]> = raw.into();
|
||||
*last = Some((index, raw.clone()));
|
||||
Some(raw)
|
||||
}
|
||||
|
||||
fn picker_emoji(&self, entry: &Entry) -> PickerEmoji {
|
||||
let key = self.string(entry.key);
|
||||
PickerEmoji { key, name: self.string(entry.name), text: text_of(key) }
|
||||
}
|
||||
|
||||
/// The picker's emoji of a category: smileys, people, nature, food,
|
||||
/// activities, travel, objects, symbols, flags (0-8).
|
||||
pub fn category(&self, category: usize) -> Vec<PickerEmoji> {
|
||||
self.picker
|
||||
.iter()
|
||||
.map(|&i| &self.entries[i as usize])
|
||||
.filter(|e| e.category as usize == category)
|
||||
.map(|e| self.picker_emoji(e))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Picker emoji whose name has every word of `query` (case-insensitive).
|
||||
pub fn search(&self, query: &str) -> Vec<PickerEmoji> {
|
||||
let words: Vec<String> = query.split_whitespace().map(str::to_lowercase).collect();
|
||||
if words.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
self.picker
|
||||
.iter()
|
||||
.map(|&i| &self.entries[i as usize])
|
||||
.filter(|e| {
|
||||
let name = self.string(e.name);
|
||||
words.iter().all(|w| name.contains(w.as_str()))
|
||||
})
|
||||
.map(|e| self.picker_emoji(e))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// The archive in the binary.
|
||||
pub fn archive() -> &'static Archive {
|
||||
static ARCHIVE: OnceLock<Archive> = OnceLock::new();
|
||||
ARCHIVE.get_or_init(|| Archive::parse(DATA).expect("the bundled emoji archive is valid"))
|
||||
}
|
||||
|
||||
/// Characters shown as emoji even without U+FE0F: Emoji_Presentation=Yes
|
||||
/// below U+1F000 (above it nearly everything is).
|
||||
const PRESENTATION_BMP: &[(u32, u32)] = &[
|
||||
(0x231A, 0x231B),
|
||||
(0x23E9, 0x23EC),
|
||||
(0x23F0, 0x23F0),
|
||||
(0x23F3, 0x23F3),
|
||||
(0x25FD, 0x25FE),
|
||||
(0x2614, 0x2615),
|
||||
(0x2648, 0x2653),
|
||||
(0x267F, 0x267F),
|
||||
(0x2693, 0x2693),
|
||||
(0x26A1, 0x26A1),
|
||||
(0x26AA, 0x26AB),
|
||||
(0x26BD, 0x26BE),
|
||||
(0x26C4, 0x26C5),
|
||||
(0x26CE, 0x26CE),
|
||||
(0x26D4, 0x26D4),
|
||||
(0x26EA, 0x26EA),
|
||||
(0x26F2, 0x26F3),
|
||||
(0x26F5, 0x26F5),
|
||||
(0x26FA, 0x26FA),
|
||||
(0x26FD, 0x26FD),
|
||||
(0x2705, 0x2705),
|
||||
(0x270A, 0x270B),
|
||||
(0x2728, 0x2728),
|
||||
(0x274C, 0x274C),
|
||||
(0x274E, 0x274E),
|
||||
(0x2753, 0x2755),
|
||||
(0x2757, 0x2757),
|
||||
(0x2795, 0x2797),
|
||||
(0x27B0, 0x27B0),
|
||||
(0x27BF, 0x27BF),
|
||||
(0x2B1B, 0x2B1C),
|
||||
(0x2B50, 0x2B50),
|
||||
(0x2B55, 0x2B55),
|
||||
];
|
||||
|
||||
fn emoji_presentation(cp: u32) -> bool {
|
||||
cp >= 0x1F000 || PRESENTATION_BMP.iter().any(|&(lo, hi)| (lo..=hi).contains(&cp))
|
||||
}
|
||||
|
||||
/// Whether a character can start an emoji; text without any is plain.
|
||||
fn may_be_emoji(c: char) -> bool {
|
||||
c as u32 >= 0x2000 || c == '\u{FE0F}' || c == '\u{20E3}' || c == '\u{a9}' || c == '\u{ae}'
|
||||
}
|
||||
|
||||
fn key_of(cps: &[u32]) -> String {
|
||||
cps.iter().map(|cp| format!("{cp:x}")).collect::<Vec<_>>().join("-")
|
||||
}
|
||||
|
||||
/// The characters of an archive key, with U+FE0F after a lone character
|
||||
/// that is text by default, so other clients show an emoji too.
|
||||
fn text_of(key: &str) -> String {
|
||||
let cps: Vec<u32> = key.split('-').filter_map(|p| u32::from_str_radix(p, 16).ok()).collect();
|
||||
let mut text: String = cps.iter().filter_map(|&cp| char::from_u32(cp)).collect();
|
||||
if cps.len() == 1 && !emoji_presentation(cps[0]) {
|
||||
text.push('\u{FE0F}');
|
||||
}
|
||||
text
|
||||
}
|
||||
|
||||
/// The archive key of a grapheme cluster that is an emoji: code points in
|
||||
/// hex joined by `-`, without U+FE0F unless the sequence has a ZWJ (as
|
||||
/// Twemoji names its files).
|
||||
pub fn key_for(grapheme: &str) -> Option<String> {
|
||||
let cps: Vec<u32> = grapheme.chars().map(|c| c as u32).collect();
|
||||
let first = *cps.first()?;
|
||||
let has_vs = cps.contains(&0xFE0F);
|
||||
let has_keycap = cps.contains(&0x20E3);
|
||||
// Text characters (digits, ©, ↔) are emoji only with U+FE0F or a keycap.
|
||||
if cps.len() == 1 && !emoji_presentation(first) {
|
||||
return None;
|
||||
}
|
||||
if first < 0x2000 && !has_vs && !has_keycap && first != 0xA9 && first != 0xAE {
|
||||
return None;
|
||||
}
|
||||
if (first == 0xA9 || first == 0xAE) && !has_vs {
|
||||
return None;
|
||||
}
|
||||
let archive = archive();
|
||||
let key = if cps.contains(&0x200D) {
|
||||
key_of(&cps)
|
||||
} else {
|
||||
key_of(&cps.iter().copied().filter(|&cp| cp != 0xFE0F).collect::<Vec<_>>())
|
||||
};
|
||||
if archive.contains(&key) {
|
||||
return Some(key);
|
||||
}
|
||||
// Some ZWJ sequences are named without their U+FE0F.
|
||||
let bare = key_of(&cps.iter().copied().filter(|&cp| cp != 0xFE0F).collect::<Vec<_>>());
|
||||
archive.contains(&bare).then_some(bare)
|
||||
}
|
||||
|
||||
/// A piece of text: plain, or one emoji (`emoji` is its key).
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Run {
|
||||
pub text: String,
|
||||
pub emoji: Option<String>,
|
||||
}
|
||||
|
||||
/// Text split into runs for a wrapping layout: a run per word (with the
|
||||
/// space after it) and per emoji. `None` if the text has no emoji (show it
|
||||
/// as one text). Line breaks become spaces.
|
||||
pub fn runs(text: &str) -> Option<Vec<Run>> {
|
||||
if !text.chars().any(may_be_emoji) {
|
||||
return None;
|
||||
}
|
||||
let mut out: Vec<Run> = Vec::new();
|
||||
let mut word = String::new();
|
||||
let mut any = false;
|
||||
for g in text.graphemes(true) {
|
||||
if let Some(key) = key_for(g) {
|
||||
if !word.is_empty() {
|
||||
out.push(Run { text: std::mem::take(&mut word), emoji: None });
|
||||
}
|
||||
out.push(Run { text: g.to_owned(), emoji: Some(key) });
|
||||
any = true;
|
||||
continue;
|
||||
}
|
||||
let space = g.chars().all(char::is_whitespace);
|
||||
if space {
|
||||
// Spaces stay with the word before them (or stand alone after
|
||||
// an emoji).
|
||||
word.push(' ');
|
||||
out.push(Run { text: std::mem::take(&mut word), emoji: None });
|
||||
} else {
|
||||
word.push_str(g);
|
||||
}
|
||||
}
|
||||
if !word.is_empty() {
|
||||
out.push(Run { text: word, emoji: None });
|
||||
}
|
||||
any.then_some(out)
|
||||
}
|
||||
|
||||
/// One to three emoji and nothing else but spaces: shown large.
|
||||
pub fn is_jumbo(runs: &[Run]) -> bool {
|
||||
let emoji = runs.iter().filter(|r| r.emoji.is_some()).count();
|
||||
(1..=3).contains(&emoji) && runs.iter().all(|r| r.emoji.is_some() || r.text.trim().is_empty())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn archive_opens() {
|
||||
let a = archive();
|
||||
assert!(a.len() > 3000);
|
||||
assert!(a.contains("1f600"));
|
||||
assert!(!a.contains("zzz"));
|
||||
assert_eq!(a.name("1f600"), Some("grinning face"));
|
||||
let svg = a.svg("1f600").unwrap();
|
||||
assert!(svg.starts_with(b"<svg"), "{:?}", String::from_utf8_lossy(&svg[..20]));
|
||||
assert!(svg.ends_with(b"</svg>"));
|
||||
// Twice (the cached block).
|
||||
assert_eq!(a.svg("1f600").unwrap(), svg);
|
||||
let zwj = a.svg("1f468-200d-1f4bb").unwrap();
|
||||
assert!(zwj.starts_with(b"<svg"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keys_of_graphemes() {
|
||||
assert_eq!(key_for("😀").as_deref(), Some("1f600"));
|
||||
// U+FE0F dropped outside ZWJ sequences.
|
||||
assert_eq!(key_for("❤\u{FE0F}").as_deref(), Some("2764"));
|
||||
// Keycap.
|
||||
assert_eq!(key_for("1\u{FE0F}\u{20E3}").as_deref(), Some("31-20e3"));
|
||||
// Skin tone.
|
||||
assert_eq!(key_for("👍🏽").as_deref(), Some("1f44d-1f3fd"));
|
||||
// ZWJ sequence.
|
||||
assert_eq!(key_for("👨\u{200D}💻").as_deref(), Some("1f468-200d-1f4bb"));
|
||||
// Flag.
|
||||
assert_eq!(key_for("🇩🇪").as_deref(), Some("1f1e9-1f1ea"));
|
||||
// Text stays text.
|
||||
assert_eq!(key_for("a"), None);
|
||||
assert_eq!(key_for("1"), None);
|
||||
assert_eq!(key_for("©"), None);
|
||||
assert_eq!(key_for("❤"), None);
|
||||
assert_eq!(key_for("—"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_runs() {
|
||||
assert_eq!(runs("plain text, no emoji"), None);
|
||||
assert_eq!(runs("em — dash"), None);
|
||||
let r = runs("hi 👋 there").unwrap();
|
||||
let texts: Vec<_> = r.iter().map(|r| (r.text.as_str(), r.emoji.as_deref())).collect();
|
||||
assert_eq!(texts, [("hi ", None), ("👋", Some("1f44b")), (" ", None), ("there", None)]);
|
||||
assert!(!is_jumbo(&r));
|
||||
let r = runs("🔥🔥 ").unwrap();
|
||||
assert!(is_jumbo(&r));
|
||||
assert!(!is_jumbo(&runs("🔥🔥🔥🔥").unwrap()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn picker() {
|
||||
let a = archive();
|
||||
let smileys = a.category(0);
|
||||
assert!(smileys.len() > 50);
|
||||
assert_eq!(smileys[0].key, "1f600");
|
||||
assert_eq!(smileys[0].text, "😀");
|
||||
assert!(a.category(1).iter().all(|e| !e.key.contains("1f3fb")), "no skin tone variants");
|
||||
let hearts = a.search("red heart");
|
||||
assert!(hearts.iter().any(|e| e.key == "2764" && e.text == "❤\u{FE0F}"));
|
||||
assert!(a.search(" ").is_empty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
//! Decoded images by key (emoji now; avatars and server icons later): each
|
||||
//! is decoded once and kept while it fits the budget (setting
|
||||
//! `ui.image_cache_mb`); the least recently used go first.
|
||||
//!
|
||||
//! The cache lives on the UI thread apart from the app state, because Slint
|
||||
//! asks for images (`Images.emoji`) while it evaluates bindings, which may
|
||||
//! happen while the app state is borrowed.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
use slint::Image;
|
||||
|
||||
use crate::emoji;
|
||||
|
||||
/// An LRU map with a byte budget. Generic over the value for tests.
|
||||
pub struct Lru<V> {
|
||||
budget: usize,
|
||||
used: usize,
|
||||
tick: u64,
|
||||
entries: HashMap<String, (V, usize, u64)>,
|
||||
/// Keys by last use.
|
||||
order: BTreeMap<u64, String>,
|
||||
}
|
||||
|
||||
impl<V: Clone> Lru<V> {
|
||||
pub fn new(budget: usize) -> Self {
|
||||
Self { budget, used: 0, tick: 0, entries: HashMap::new(), order: BTreeMap::new() }
|
||||
}
|
||||
|
||||
/// Bytes in use and the budget.
|
||||
pub fn usage(&self) -> (usize, usize) {
|
||||
(self.used, self.budget)
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.entries.len()
|
||||
}
|
||||
|
||||
pub fn set_budget(&mut self, budget: usize) {
|
||||
self.budget = budget;
|
||||
self.evict();
|
||||
}
|
||||
|
||||
/// The value of `key`, or the loaded one (`load` gives it with its cost
|
||||
/// in bytes). A value larger than the budget is returned but not kept.
|
||||
pub fn get_or_load(
|
||||
&mut self,
|
||||
key: &str,
|
||||
load: impl FnOnce() -> Option<(V, usize)>,
|
||||
) -> Option<V> {
|
||||
self.tick += 1;
|
||||
let tick = self.tick;
|
||||
if let Some((value, _, last)) = self.entries.get_mut(key) {
|
||||
self.order.remove(last);
|
||||
*last = tick;
|
||||
self.order.insert(tick, key.to_owned());
|
||||
return Some(value.clone());
|
||||
}
|
||||
let (value, cost) = load()?;
|
||||
if cost <= self.budget {
|
||||
self.entries.insert(key.to_owned(), (value.clone(), cost, tick));
|
||||
self.order.insert(tick, key.to_owned());
|
||||
self.used += cost;
|
||||
self.evict();
|
||||
}
|
||||
Some(value)
|
||||
}
|
||||
|
||||
fn evict(&mut self) {
|
||||
while self.used > self.budget {
|
||||
let Some((_, key)) = self.order.pop_first() else { break };
|
||||
if let Some((_, cost, _)) = self.entries.remove(&key) {
|
||||
self.used -= cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What an SVG costs in the cache: the renderer keeps rasterized copies at
|
||||
/// the sizes shown, so count a 64×64 RGBA picture besides the source.
|
||||
fn svg_cost(svg_len: usize) -> usize {
|
||||
svg_len + 64 * 64 * 4
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static CACHE: RefCell<Lru<Image>> = RefCell::new(Lru::new(64 << 20));
|
||||
}
|
||||
|
||||
/// Set the budget in megabytes.
|
||||
pub fn set_budget_mb(mb: u32) {
|
||||
CACHE.with(|c| c.borrow_mut().set_budget(mb as usize * (1 << 20)));
|
||||
}
|
||||
|
||||
/// "3.2 of 64 MB (120 images)"
|
||||
pub fn usage_text() -> String {
|
||||
CACHE.with(|c| {
|
||||
let c = c.borrow();
|
||||
let (used, budget) = c.usage();
|
||||
format!("{:.1} of {} MB ({} images)", used as f64 / (1 << 20) as f64, budget >> 20, c.len())
|
||||
})
|
||||
}
|
||||
|
||||
/// A Twemoji by key; an empty image if there is none.
|
||||
pub fn emoji(key: &str) -> Image {
|
||||
if key.is_empty() {
|
||||
return Image::default();
|
||||
}
|
||||
let cache_key = format!("emoji:{key}");
|
||||
CACHE
|
||||
.with(|c| {
|
||||
c.borrow_mut().get_or_load(&cache_key, || {
|
||||
let svg = emoji::archive().svg(key)?;
|
||||
let image = Image::load_from_svg_data(&svg).ok()?;
|
||||
Some((image, svg_cost(svg.len())))
|
||||
})
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn lru_budget() {
|
||||
let mut lru: Lru<u32> = Lru::new(10);
|
||||
let loads = std::cell::Cell::new(0);
|
||||
let get = |lru: &mut Lru<u32>, k: &str, cost: usize| {
|
||||
lru.get_or_load(k, || {
|
||||
loads.set(loads.get() + 1);
|
||||
Some((k.len() as u32, cost))
|
||||
})
|
||||
};
|
||||
get(&mut lru, "a", 4);
|
||||
get(&mut lru, "b", 4);
|
||||
get(&mut lru, "a", 4); // a is now newer than b
|
||||
get(&mut lru, "c", 4); // evicts b
|
||||
assert_eq!(lru.usage(), (8, 10));
|
||||
assert_eq!(lru.len(), 2);
|
||||
get(&mut lru, "a", 4);
|
||||
get(&mut lru, "b", 4); // loaded again
|
||||
// Too large to keep, still returned.
|
||||
assert_eq!(get(&mut lru, "huge", 100), Some(4));
|
||||
assert!(lru.len() <= 2);
|
||||
assert_eq!(loads.get(), 5);
|
||||
lru.set_budget(0);
|
||||
assert_eq!(lru.usage(), (0, 0));
|
||||
// Unknown keys are not cached.
|
||||
assert_eq!(lru.get_or_load("none", || None), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn emoji_images_decode() {
|
||||
let image = emoji("1f600");
|
||||
assert!(image.size().width > 0);
|
||||
assert_eq!(emoji("nope").size().width, 0);
|
||||
assert!(usage_text().contains("of 64 MB"));
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,18 @@
|
||||
//! Slint user interface shared by the desktop binary and the mobile apps.
|
||||
|
||||
mod app;
|
||||
mod appearance;
|
||||
mod bind;
|
||||
mod chat;
|
||||
mod dev;
|
||||
mod emoji;
|
||||
mod hotkey;
|
||||
mod images;
|
||||
mod servers;
|
||||
mod settings;
|
||||
mod settings_page;
|
||||
mod streams;
|
||||
mod video;
|
||||
mod vm;
|
||||
|
||||
pub use app::{HostedEngine, RunOptions, run};
|
||||
@@ -0,0 +1,299 @@
|
||||
//! Servers: bookmarks, connecting and observing, the rail, the sidebar's
|
||||
//! server card and the channel tree.
|
||||
|
||||
use slint::{ComponentHandle, SharedString};
|
||||
use tracing::warn;
|
||||
use voelin_core::{Command, ObserveState, Source, VoiceOptions, VoiceState};
|
||||
use voelin_store::{Bookmark, QueryConfig, QueryTransport};
|
||||
|
||||
use crate::app::{App, BookmarkForm, Bridge};
|
||||
use crate::vm;
|
||||
|
||||
impl App {
|
||||
pub(crate) fn connect_voice(&mut self) {
|
||||
let Some(b) = self.current.and_then(|id| self.bookmark(id)).cloned() else { return };
|
||||
let mut options = VoiceOptions::new(&b.address, &b.nickname);
|
||||
options.identity = Some(self.identity.clone());
|
||||
options.server_password = self.secrets.get(&b.server_password_key()).ok().flatten();
|
||||
options.channel = b.default_channel.clone();
|
||||
options.audio = true;
|
||||
options.stream_peer = self.video.peer_config(options.stream_peer);
|
||||
self.engine
|
||||
.send(Command::ConnectVoice { session: b.id as u64, options: Box::new(options) });
|
||||
self.set_status(format!("Connecting to {}…", b.address));
|
||||
}
|
||||
|
||||
pub(crate) fn toggle_observe(&mut self) {
|
||||
let Some(b) = self.current.and_then(|id| self.bookmark(id)).cloned() else { return };
|
||||
let session = b.id as u64;
|
||||
let observing =
|
||||
self.sessions.get(&b.id).is_some_and(|v| v.state.observe != ObserveState::Off);
|
||||
if observing {
|
||||
self.engine.send(Command::StopObserving { session });
|
||||
return;
|
||||
}
|
||||
if let Some(url) = &b.gateway_url {
|
||||
self.engine.send(Command::ObserveGateway {
|
||||
session,
|
||||
url: url.clone(),
|
||||
identity: Box::new(self.identity.clone()),
|
||||
});
|
||||
} else if let Some(q) = &b.query {
|
||||
let secret = self.secrets.get(&b.query_password_key()).ok().flatten();
|
||||
let transport = match q.transport {
|
||||
QueryTransport::Raw => voelin_query::Transport::Raw,
|
||||
QueryTransport::Ssh => voelin_query::Transport::Ssh,
|
||||
QueryTransport::Http => voelin_query::Transport::Http,
|
||||
};
|
||||
let connect = voelin_query::Connect {
|
||||
transport,
|
||||
addr: format!("{}:{}", q.host, q.port),
|
||||
user: q.user.clone(),
|
||||
secret,
|
||||
server_port: q.server_port,
|
||||
server_id: None,
|
||||
line: Default::default(),
|
||||
};
|
||||
self.engine.send(Command::ObserveQuery { session, connect: Box::new(connect) });
|
||||
}
|
||||
self.set_status("Observing invisibly…");
|
||||
}
|
||||
|
||||
pub(crate) fn select_server(&mut self, id: i64) {
|
||||
self.current = Some(id);
|
||||
self.refresh_all();
|
||||
}
|
||||
|
||||
pub(crate) fn bookmark_form(&self, id: i64) -> BookmarkForm {
|
||||
let Some(b) = self.bookmark(id) else {
|
||||
return BookmarkForm {
|
||||
id: -1,
|
||||
nickname: std::env::var("USER").unwrap_or_default().into(),
|
||||
query_transport: "none".into(),
|
||||
query_user: "serveradmin".into(),
|
||||
..Default::default()
|
||||
};
|
||||
};
|
||||
let secret = |key: String| -> SharedString {
|
||||
self.secrets.get(&key).ok().flatten().unwrap_or_default().into()
|
||||
};
|
||||
let (transport, addr, user) = match &b.query {
|
||||
Some(q) => (
|
||||
match q.transport {
|
||||
QueryTransport::Raw => "raw",
|
||||
QueryTransport::Ssh => "ssh",
|
||||
QueryTransport::Http => "http",
|
||||
},
|
||||
format!("{}:{}", q.host, q.port),
|
||||
q.user.clone(),
|
||||
),
|
||||
None => ("none", String::new(), "serveradmin".to_string()),
|
||||
};
|
||||
BookmarkForm {
|
||||
id: b.id as i32,
|
||||
name: b.name.clone().into(),
|
||||
address: b.address.clone().into(),
|
||||
nickname: b.nickname.clone().into(),
|
||||
server_password: secret(b.server_password_key()),
|
||||
gateway_url: b.gateway_url.clone().unwrap_or_default().into(),
|
||||
query_transport: transport.into(),
|
||||
query_addr: addr.into(),
|
||||
query_user: user.into(),
|
||||
query_password: secret(b.query_password_key()),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn save_bookmark(&mut self, form: BookmarkForm) {
|
||||
let query = match form.query_transport.as_str() {
|
||||
"none" | "" => None,
|
||||
t => {
|
||||
let (host, port) = form
|
||||
.query_addr
|
||||
.rsplit_once(':')
|
||||
.map_or((form.query_addr.to_string(), None), |(h, p)| {
|
||||
(h.to_string(), p.parse().ok())
|
||||
});
|
||||
let transport = match t {
|
||||
"raw" => QueryTransport::Raw,
|
||||
"http" => QueryTransport::Http,
|
||||
_ => QueryTransport::Ssh,
|
||||
};
|
||||
let default_port = match transport {
|
||||
QueryTransport::Raw => 10011,
|
||||
QueryTransport::Ssh => 10022,
|
||||
QueryTransport::Http => 10080,
|
||||
};
|
||||
Some(QueryConfig {
|
||||
transport,
|
||||
host,
|
||||
port: port.unwrap_or(default_port),
|
||||
user: form.query_user.to_string(),
|
||||
server_port: None,
|
||||
})
|
||||
}
|
||||
};
|
||||
let mut bookmark = Bookmark {
|
||||
id: form.id as i64,
|
||||
name: if form.name.is_empty() {
|
||||
form.address.to_string()
|
||||
} else {
|
||||
form.name.to_string()
|
||||
},
|
||||
address: form.address.to_string(),
|
||||
nickname: form.nickname.to_string(),
|
||||
identity: None,
|
||||
default_channel: None,
|
||||
gateway_url: Some(form.gateway_url.to_string()).filter(|u| !u.is_empty()),
|
||||
query,
|
||||
client_version: None,
|
||||
};
|
||||
let result = if bookmark.id < 0 {
|
||||
self.store.add_bookmark(&bookmark).map(|id| bookmark.id = id)
|
||||
} else {
|
||||
self.store.update_bookmark(&bookmark)
|
||||
};
|
||||
if let Err(e) = result {
|
||||
self.set_status(format!("Could not save: {e}"));
|
||||
return;
|
||||
}
|
||||
for (key, value) in [
|
||||
(bookmark.server_password_key(), &form.server_password),
|
||||
(bookmark.query_password_key(), &form.query_password),
|
||||
] {
|
||||
let result = if value.is_empty() {
|
||||
self.secrets.delete(&key)
|
||||
} else {
|
||||
self.secrets.set(&key, value)
|
||||
};
|
||||
if let Err(e) = result {
|
||||
warn!(%e, "could not store secret");
|
||||
}
|
||||
}
|
||||
self.current = Some(bookmark.id);
|
||||
self.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.refresh_all();
|
||||
}
|
||||
|
||||
pub(crate) fn delete_bookmark(&mut self, id: i64) {
|
||||
self.engine.send(Command::CloseSession { session: id as u64 });
|
||||
if let Some(b) = self.bookmark(id).cloned() {
|
||||
let _ = self.secrets.delete(&b.server_password_key());
|
||||
let _ = self.secrets.delete(&b.query_password_key());
|
||||
}
|
||||
let _ = self.store.delete_bookmark(id);
|
||||
self.sessions.remove(&id);
|
||||
self.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.current = self.bookmarks.first().map(|b| b.id);
|
||||
self.refresh_all();
|
||||
}
|
||||
|
||||
/// The rail: servers with their state, unread count and streams.
|
||||
pub(crate) fn refresh_servers(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let items: Vec<_> = self
|
||||
.bookmarks
|
||||
.iter()
|
||||
.map(|b| {
|
||||
let view = self.sessions.get(&b.id);
|
||||
let state = view.map(|v| v.state.clone()).unwrap_or_default();
|
||||
let unread = view.map_or(0, |v| v.unread());
|
||||
let live = view.is_some_and(|v| v.streams_available() && !v.streams.is_empty());
|
||||
vm::servers::item(b, &state, unread, live)
|
||||
})
|
||||
.collect();
|
||||
vm::list::sync(&self.models.servers, &items);
|
||||
bridge.set_current_server(self.current.map_or(-1, |id| id as i32));
|
||||
bridge.set_unread_total(self.view().map_or(0, |v| v.unread()));
|
||||
}
|
||||
|
||||
/// The server card, the voice controls and who we are.
|
||||
pub(crate) fn refresh_toolbar(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let bookmark = self.current.and_then(|id| self.bookmark(id));
|
||||
let view = self.view();
|
||||
let state = view.map(|v| v.state.clone()).unwrap_or_default();
|
||||
bridge.set_server_title(
|
||||
bookmark.map_or("No server selected".into(), |b| b.name.clone()).into(),
|
||||
);
|
||||
let has_presence = view.is_some_and(|v| !v.presence.channels.is_empty())
|
||||
&& (state.voice == VoiceState::Connected || state.observe == ObserveState::Observing);
|
||||
bridge.set_server_stats(
|
||||
view.filter(|_| has_presence)
|
||||
.map(|v| vm::tree::stats(&v.presence))
|
||||
.unwrap_or_default()
|
||||
.into(),
|
||||
);
|
||||
bridge.set_nickname(bookmark.map(|b| b.nickname.clone()).unwrap_or_default().into());
|
||||
let own_channel = view
|
||||
.and_then(|v| state.own_channel.and_then(|c| v.presence.channels.get(&c)))
|
||||
.map(|c| c.name.clone())
|
||||
.unwrap_or_default();
|
||||
bridge.set_own_channel(own_channel.into());
|
||||
bridge.set_voice_connected(state.voice == VoiceState::Connected);
|
||||
bridge.set_voice_connecting(state.voice == VoiceState::Connecting);
|
||||
bridge.set_observing(state.observe != ObserveState::Off);
|
||||
bridge.set_can_observe(
|
||||
bookmark.is_some_and(|b| b.gateway_url.is_some() || b.query.is_some()),
|
||||
);
|
||||
bridge.set_input_muted(state.input_muted);
|
||||
bridge.set_output_muted(state.output_muted);
|
||||
bridge.set_transmitting(state.transmitting);
|
||||
bridge.set_presence_source(
|
||||
match state.presence_source {
|
||||
Some(Source::Voice) => "live (voice)",
|
||||
Some(Source::Gateway) => "invisible (gateway)",
|
||||
Some(Source::Query) => "invisible (query)",
|
||||
None => "",
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
if state.voice != VoiceState::Connected {
|
||||
bridge.set_input_level(-100.0);
|
||||
bridge.set_input_sending(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// The channel tree and the members of our channel.
|
||||
pub(crate) fn refresh_tree(&self) {
|
||||
let Some(view) = self.view() else {
|
||||
vm::list::sync(&self.models.tree, &[]);
|
||||
vm::list::sync(&self.models.members, &[]);
|
||||
return;
|
||||
};
|
||||
let input = vm::tree::TreeInput {
|
||||
presence: &view.presence,
|
||||
collapsed: &view.collapsed,
|
||||
talking: &view.talking,
|
||||
playback: &self.playback,
|
||||
own_channel: view.state.own_channel,
|
||||
own_client: view.state.own_client,
|
||||
filter: &self.tree_filter,
|
||||
};
|
||||
vm::list::sync(&self.models.tree, &vm::tree::rows(&input));
|
||||
let members = if view.state.voice == VoiceState::Connected {
|
||||
vm::tree::members(&input)
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
vm::list::sync(&self.models.members, &members);
|
||||
}
|
||||
|
||||
pub(crate) fn toggle_collapse(&mut self, channel: u64) {
|
||||
if let Some(view) = self.view_mut()
|
||||
&& !view.collapsed.remove(&channel)
|
||||
{
|
||||
view.collapsed.insert(channel);
|
||||
}
|
||||
self.refresh_tree();
|
||||
}
|
||||
|
||||
/// The top bar's search.
|
||||
pub(crate) fn search(&mut self, text: String) {
|
||||
if self.tree_filter != text {
|
||||
self.tree_filter = text;
|
||||
self.refresh_tree();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,75 @@ pub static CLIENT_PLAYBACK: Key<ClientPlaybackMap> = Key::new(
|
||||
ClientPlaybackMap::new,
|
||||
);
|
||||
|
||||
/// Colours of the window.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ThemeChoice {
|
||||
#[default]
|
||||
Dark,
|
||||
Light,
|
||||
/// The system's light or dark scheme.
|
||||
System,
|
||||
}
|
||||
|
||||
impl ThemeChoice {
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Dark => "dark",
|
||||
Self::Light => "light",
|
||||
Self::System => "system",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse(text: &str) -> Self {
|
||||
match text {
|
||||
"light" => Self::Light,
|
||||
"system" => Self::System,
|
||||
_ => Self::Dark,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `ui.theme`. (In a config file write `"ui.theme" = "light"` at the top:
|
||||
/// a `[ui]` table would be read as the `ui` blob.)
|
||||
pub static UI_THEME: Key<ThemeChoice> = Key::new(
|
||||
"ui.theme",
|
||||
Kind::Choice(&["dark", "light", "system"]),
|
||||
"Colours of the window: dark, light, or the system's scheme.",
|
||||
ThemeChoice::default,
|
||||
);
|
||||
|
||||
fn positive_scale(v: &f32) -> Result<(), String> {
|
||||
if v.is_finite() && *v > 0.0 { Ok(()) } else { Err("must be a number above 0".into()) }
|
||||
}
|
||||
|
||||
/// `ui.font_scale`: text size, 1 = normal (no upper limit).
|
||||
pub static UI_FONT_SCALE: Key<f32> =
|
||||
Key::new("ui.font_scale", Kind::Json, "Text size as a factor (a number; 1 = normal).", || 1.0)
|
||||
.validated(positive_scale);
|
||||
|
||||
/// `ui.narrow_breakpoint`: below this window width (logical pixels) the
|
||||
/// phone layout is used.
|
||||
pub static UI_NARROW_BREAKPOINT: Key<u32> = Key::new(
|
||||
"ui.narrow_breakpoint",
|
||||
Kind::UInt { min: 0 },
|
||||
"Window width in pixels below which the phone layout is used.",
|
||||
|| 800,
|
||||
);
|
||||
|
||||
/// `ui.image_cache_mb`: memory for decoded images (avatars, icons, emoji).
|
||||
pub static UI_IMAGE_CACHE_MB: Key<u32> = Key::new(
|
||||
"ui.image_cache_mb",
|
||||
Kind::UInt { min: 0 },
|
||||
"Memory in MB for decoded images (avatars, icons, emoji); 0 keeps none.",
|
||||
|| 64,
|
||||
);
|
||||
|
||||
/// The UI's keys besides [`UI`] and [`CLIENT_PLAYBACK`], for registering.
|
||||
pub fn appearance_keys() -> [&'static dyn voelin_core::settings::Setting; 4] {
|
||||
[&UI_THEME, &UI_FONT_SCALE, &UI_NARROW_BREAKPOINT, &UI_IMAGE_CACHE_MB]
|
||||
}
|
||||
|
||||
/// Frame rates and bitrates (kbit/s) the share dialog offers; any other
|
||||
/// value can be typed in.
|
||||
pub const FPS_CHOICES: [u32; 3] = [15, 30, 60];
|
||||
@@ -293,6 +362,11 @@ mod tests {
|
||||
assert!(!parsed.crash_reports, "crash reports are opt-in");
|
||||
assert_eq!(parsed.ptt_key, "Ctrl+Shift+T");
|
||||
assert_eq!(parsed.share, ShareDefaults::default());
|
||||
assert_eq!(serde_json::to_value(ThemeChoice::System).unwrap(), "system");
|
||||
assert_eq!(ThemeChoice::parse("light"), ThemeChoice::Light);
|
||||
assert_eq!(ThemeChoice::parse("??"), ThemeChoice::Dark);
|
||||
assert!(UI_FONT_SCALE.validate(&0.0).is_err());
|
||||
assert!(UI_FONT_SCALE.validate(&3.5).is_ok());
|
||||
let map: ClientPlaybackMap =
|
||||
serde_json::from_str(r#"{"uid=":{"volume":0.5,"muted":false}}"#).unwrap();
|
||||
assert_eq!(map["uid="].volume, 0.5);
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
//! The settings page (audio, push-to-talk, H.264, crash reports), the
|
||||
//! About page's notices, and the local volume of clients.
|
||||
|
||||
use slint::{ComponentHandle, SharedString};
|
||||
use tracing::warn;
|
||||
use voelin_core::settings::{AUDIO, CRASH_REPORTS};
|
||||
use voelin_core::{Command, Source, VoiceState};
|
||||
use voelin_platform::{crash, notices};
|
||||
|
||||
use crate::app::{App, AudioForm, Bridge, ClientAudio, later, model};
|
||||
use crate::settings::{self, CLIENT_PLAYBACK, ClientPlayback, DeviceChoices};
|
||||
|
||||
impl App {
|
||||
pub(crate) fn open_settings(&mut self) {
|
||||
let list = |devices: voelin_audio::Result<Vec<voelin_audio::device::DeviceInfo>>,
|
||||
input: bool| {
|
||||
let devices = devices.unwrap_or_else(|e| {
|
||||
warn!("cannot list audio devices: {e}");
|
||||
Vec::new()
|
||||
});
|
||||
devices
|
||||
.into_iter()
|
||||
.map(|d| {
|
||||
let default = if input { d.default_input } else { d.default_output };
|
||||
(d.id, d.name, default)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
let inputs = list(voelin_audio::device::input_devices(), true);
|
||||
let outputs = list(voelin_audio::device::output_devices(), false);
|
||||
self.inputs = DeviceChoices::new(&inputs, self.audio.input_device.as_deref());
|
||||
self.outputs = DeviceChoices::new(&outputs, self.audio.output_device.as_deref());
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let names = |c: &DeviceChoices| model(c.names.iter().map(SharedString::from).collect());
|
||||
bridge.set_input_devices(names(&self.inputs));
|
||||
bridge.set_output_devices(names(&self.outputs));
|
||||
bridge.set_audio(settings::audio_form(&self.audio, &self.inputs, &self.outputs));
|
||||
bridge.set_global_ptt(self.settings.global_ptt);
|
||||
bridge.set_ptt_key(self.settings.ptt_key.clone().into());
|
||||
bridge.set_h264_enabled(self.settings.openh264);
|
||||
bridge.set_image_cache_usage(crate::images::usage_text().into());
|
||||
self.refresh_h264();
|
||||
}
|
||||
|
||||
pub(crate) fn close_settings(&mut self) {
|
||||
self.set_mic_test(false);
|
||||
self.save_audio();
|
||||
}
|
||||
|
||||
pub(crate) fn audio_changed(&mut self, form: &AudioForm) {
|
||||
let audio = settings::apply_audio_form(form, &self.audio, &self.inputs, &self.outputs);
|
||||
if audio == self.audio {
|
||||
return;
|
||||
}
|
||||
self.audio = audio;
|
||||
self.audio_dirty = true;
|
||||
self.engine.send(Command::SetAudioSettings(Box::new(self.audio.clone())));
|
||||
}
|
||||
|
||||
pub(crate) fn save_audio(&mut self) {
|
||||
if !self.audio_dirty {
|
||||
return;
|
||||
}
|
||||
self.audio_dirty = false;
|
||||
if let Err(e) = self.prefs.set(&AUDIO, self.audio.clone()) {
|
||||
warn!(%e, "could not store audio settings");
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn set_mic_test(&mut self, on: bool) {
|
||||
if self.mic_test == on {
|
||||
return;
|
||||
}
|
||||
self.mic_test = on;
|
||||
self.engine.send(Command::TestMicrophone { on });
|
||||
if let Some(ui) = self.ui.upgrade() {
|
||||
let bridge = ui.global::<Bridge>();
|
||||
bridge.set_mic_test(on);
|
||||
if !on {
|
||||
bridge.set_input_level(-100.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn apply_ptt(&mut self, enabled: bool, key: String) {
|
||||
let key = key.trim().to_owned();
|
||||
self.settings.global_ptt = enabled;
|
||||
if !key.is_empty() {
|
||||
self.settings.ptt_key = key.clone();
|
||||
}
|
||||
self.store_settings();
|
||||
self.ptt.set((enabled && !key.is_empty()).then_some(key));
|
||||
}
|
||||
|
||||
pub(crate) fn set_ptt_status(&mut self, status: String) {
|
||||
if let Some(ui) = self.ui.upgrade() {
|
||||
ui.global::<Bridge>().set_ptt_status(status.into());
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn set_h264(&mut self, enabled: bool) {
|
||||
self.settings.openh264 = enabled;
|
||||
self.store_settings();
|
||||
self.video.set_h264(enabled);
|
||||
self.refresh_h264();
|
||||
}
|
||||
|
||||
pub(crate) fn download_h264(&mut self) {
|
||||
let runtime = self.engine.runtime().clone();
|
||||
self.video.download_h264(&runtime, |download| {
|
||||
later(move |app| {
|
||||
app.video.downloaded(download, app.settings.openh264);
|
||||
app.refresh_h264();
|
||||
});
|
||||
});
|
||||
self.refresh_h264();
|
||||
}
|
||||
|
||||
fn refresh_h264(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let (loaded, status) = self.video.h264_status();
|
||||
bridge.set_h264_loaded(loaded);
|
||||
bridge.set_h264_busy(status.starts_with("Downloading"));
|
||||
bridge.set_h264_status(status.into());
|
||||
}
|
||||
|
||||
/// Switches the About page and the settings show.
|
||||
pub(crate) fn refresh_settings_flags(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
bridge.set_h264_enabled(self.settings.openh264);
|
||||
bridge.set_h264_attribution(notices::OPENH264_ATTRIBUTION.into());
|
||||
bridge.set_crash_reports(self.settings.crash_reports);
|
||||
}
|
||||
|
||||
pub(crate) fn set_crash_reports(&mut self, enabled: bool) {
|
||||
self.settings.crash_reports = enabled;
|
||||
// Also in the blob, for older versions.
|
||||
self.store_settings();
|
||||
if let Err(e) = self.prefs.set(&CRASH_REPORTS, enabled) {
|
||||
warn!(%e, "could not store the crash report setting");
|
||||
}
|
||||
crash::set_enabled(enabled);
|
||||
}
|
||||
|
||||
/// A notice while crash reports are on disk.
|
||||
pub(crate) fn refresh_crash_notice(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let text = match crash::pending_reports() {
|
||||
Ok(reports) if !reports.is_empty() => {
|
||||
let newest = &reports[reports.len() - 1];
|
||||
let saved = match reports.len() {
|
||||
1 => "1 crash report is saved".to_owned(),
|
||||
n => format!("{n} crash reports are saved"),
|
||||
};
|
||||
format!("The app crashed earlier ({}). {saved} on this device.", newest.summary)
|
||||
}
|
||||
_ => String::new(),
|
||||
};
|
||||
ui.global::<Bridge>().set_crash_notice(text.into());
|
||||
}
|
||||
|
||||
pub(crate) fn open_crash_folder(&mut self) {
|
||||
let result = crash::dir().ok_or_else(|| "no crash report folder".to_owned());
|
||||
if let Err(e) =
|
||||
result.and_then(|dir| crate::app::open_path(&dir).map_err(|e| e.to_string()))
|
||||
{
|
||||
self.set_status(format!("Cannot open the crash report folder: {e}"));
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn delete_crash_reports(&mut self) {
|
||||
match crash::clear() {
|
||||
Ok(n) => self.set_status(format!("Deleted {n} crash reports")),
|
||||
Err(e) => self.set_status(format!("Cannot delete the crash reports: {e}")),
|
||||
}
|
||||
self.refresh_crash_notice();
|
||||
}
|
||||
|
||||
/// The third-party notices, one model entry per line.
|
||||
pub(crate) fn load_notices(&mut self) {
|
||||
if self.notices_loaded {
|
||||
return;
|
||||
}
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let lines: Vec<SharedString> = notices::text().lines().map(SharedString::from).collect();
|
||||
ui.global::<Bridge>().set_notices(model(lines));
|
||||
self.notices_loaded = true;
|
||||
}
|
||||
|
||||
// Local volume and mute of clients.
|
||||
|
||||
/// Fill the volume dialog for `client` of the current session.
|
||||
pub(crate) fn open_client(&mut self, client: u16) -> bool {
|
||||
let Some(id) = self.current else { return false };
|
||||
let Some(info) = self.view().and_then(|v| v.presence.clients.get(&client)).cloned() else {
|
||||
return false;
|
||||
};
|
||||
let playback =
|
||||
info.uid.as_ref().and_then(|uid| self.playback.get(uid)).copied().unwrap_or_default();
|
||||
self.playback_dialog = Some((id, client, info.uid.clone()));
|
||||
if let Some(ui) = self.ui.upgrade() {
|
||||
ui.global::<Bridge>().set_client_audio(ClientAudio {
|
||||
id: client as i32,
|
||||
name: info.nickname.into(),
|
||||
volume: playback.volume * 100.0,
|
||||
muted: playback.muted,
|
||||
});
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub(crate) fn client_playback_changed(&mut self, form: &ClientAudio) {
|
||||
let Some((session, client, uid)) = self.playback_dialog.clone() else { return };
|
||||
let playback =
|
||||
ClientPlayback { volume: (form.volume / 100.0).clamp(0.0, 4.0), muted: form.muted };
|
||||
let session = session as u64;
|
||||
self.engine.send(Command::SetClientVolume { session, client, volume: playback.volume });
|
||||
self.engine.send(Command::SetClientMuted { session, client, muted: playback.muted });
|
||||
// Kept by unique id; clients without one only for this connection.
|
||||
if let Some(uid) = uid {
|
||||
if playback.is_default() {
|
||||
self.playback.remove(&uid);
|
||||
} else {
|
||||
self.playback.insert(uid, playback);
|
||||
}
|
||||
if let Err(e) = self.prefs.set(&CLIENT_PLAYBACK, self.playback.clone()) {
|
||||
warn!(%e, "could not store client volumes");
|
||||
}
|
||||
}
|
||||
self.refresh_tree();
|
||||
}
|
||||
|
||||
/// `VOELIN_OPEN=client`: the volume dialog of the first client that is not us.
|
||||
pub(crate) fn open_first_client(&mut self) {
|
||||
let Some(view) = self.view().filter(|v| v.state.own_client.is_some()) else { return };
|
||||
let own = view.state.own_client;
|
||||
let mut others: Vec<_> =
|
||||
view.presence.clients.values().filter(|c| Some(c.id) != own && !c.is_query).collect();
|
||||
others.sort_by_key(|c| c.id);
|
||||
let Some(id) = others.first().map(|c| c.id) else { return };
|
||||
self.open_client_pending = false;
|
||||
if self.open_client(id)
|
||||
&& let Some(ui) = self.ui.upgrade()
|
||||
{
|
||||
ui.global::<crate::app::Nav>().set_client_open(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// Send the stored volumes of clients that appeared in a voice session.
|
||||
pub(crate) fn apply_client_playback(&mut self, session: i64) {
|
||||
let Some(view) = self.sessions.get_mut(&session) else { return };
|
||||
if view.state.voice != VoiceState::Connected
|
||||
|| view.state.presence_source != Some(Source::Voice)
|
||||
{
|
||||
return;
|
||||
}
|
||||
let presence = view.presence.clone();
|
||||
view.applied_playback.retain(|id| presence.clients.contains_key(id));
|
||||
for client in presence.clients.values() {
|
||||
if !view.applied_playback.insert(client.id) {
|
||||
continue;
|
||||
}
|
||||
let stored = client.uid.as_ref().and_then(|uid| self.playback.get(uid));
|
||||
let Some(playback) = stored else { continue };
|
||||
let (s, c) = (session as u64, client.id);
|
||||
self.engine.send(Command::SetClientVolume {
|
||||
session: s,
|
||||
client: c,
|
||||
volume: playback.volume,
|
||||
});
|
||||
if playback.muted {
|
||||
self.engine.send(Command::SetClientMuted { session: s, client: c, muted: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,7 @@ impl App {
|
||||
.map(|s| s.id.clone());
|
||||
view.streams = streams;
|
||||
self.refresh_streams();
|
||||
self.refresh_servers();
|
||||
if autowatch && let Some(id) = first {
|
||||
self.watch_stream(id);
|
||||
}
|
||||
@@ -208,7 +209,7 @@ impl App {
|
||||
});
|
||||
}
|
||||
bridge.set_streams_available(self.demo || view.is_some_and(|v| v.streams_available()));
|
||||
bridge.set_streams(model(items));
|
||||
crate::vm::list::sync(&self.models.streams, &items);
|
||||
bridge.set_can_share(video::AVAILABLE);
|
||||
|
||||
let share = self.share.as_ref().filter(|s| Some(s.session) == current);
|
||||
@@ -243,7 +244,7 @@ impl App {
|
||||
.unwrap_or_default();
|
||||
let requests = viewers.iter().filter(|v| v.state == "requested").count();
|
||||
bridge.set_share_requests(requests as i32);
|
||||
bridge.set_share_viewers(model(viewers));
|
||||
crate::vm::list::sync(&self.models.viewers, &viewers);
|
||||
let status = match share {
|
||||
Some(s) if s.live => s.capture.status(),
|
||||
Some(s) => format!("Starting the stream of {}…", s.capture.source_name()),
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
//! Avatars without pictures: initials on a colour from the name.
|
||||
|
||||
use slint::Color;
|
||||
|
||||
/// Background colours for initials; white text reads on all of them.
|
||||
const TINTS: [u32; 10] = [
|
||||
0x2d6bff, 0x7c4dff, 0xc2379a, 0xe0572e, 0xd08a00, 0x1f9d6b, 0x0c93b8, 0x5865f2, 0xa0439e,
|
||||
0x3a7d44,
|
||||
];
|
||||
|
||||
/// Up to two letters: the first letters of the first two words, or the
|
||||
/// first two of a single word ("Nova Star" → "NS", "dex" → "DE").
|
||||
pub fn initials(name: &str) -> String {
|
||||
let words: Vec<&str> = name
|
||||
.split(|c: char| c.is_whitespace() || c == '_' || c == '-' || c == '.')
|
||||
.filter(|w| w.chars().any(char::is_alphanumeric))
|
||||
.collect();
|
||||
let first = |w: &str| w.chars().find(|c| c.is_alphanumeric());
|
||||
let letters: String = match words.as_slice() {
|
||||
[] => String::new(),
|
||||
[one] => one.chars().filter(|c| c.is_alphanumeric()).take(2).collect(),
|
||||
[a, b, ..] => first(a).into_iter().chain(first(b)).collect(),
|
||||
};
|
||||
letters.to_uppercase()
|
||||
}
|
||||
|
||||
/// A stable colour for a name (FNV-1a).
|
||||
pub fn tint(name: &str) -> Color {
|
||||
let mut hash: u32 = 0x811c_9dc5;
|
||||
for b in name.to_lowercase().bytes() {
|
||||
hash ^= u32::from(b);
|
||||
hash = hash.wrapping_mul(0x0100_0193);
|
||||
}
|
||||
let rgb = TINTS[(hash % TINTS.len() as u32) as usize];
|
||||
Color::from_rgb_u8((rgb >> 16) as u8, (rgb >> 8) as u8, rgb as u8)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn initials_of_names() {
|
||||
assert_eq!(initials("Nova Star"), "NS");
|
||||
assert_eq!(initials("dex"), "DE");
|
||||
assert_eq!(initials("x"), "X");
|
||||
assert_eq!(initials("dark_knight"), "DK");
|
||||
assert_eq!(initials(" "), "");
|
||||
assert_eq!(initials("[Bot] Relay"), "BR");
|
||||
assert_eq!(initials("Ärger über"), "ÄÜ");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tints_are_stable() {
|
||||
assert_eq!(tint("Alice"), tint("alice"));
|
||||
let distinct: std::collections::HashSet<_> =
|
||||
["Alice", "Bob", "Carol", "Dave", "Eve", "Mallory"]
|
||||
.iter()
|
||||
.map(|n| tint(n).as_argb_encoded())
|
||||
.collect();
|
||||
assert!(distinct.len() > 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
//! Chat lines.
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
use slint::{ModelRc, VecModel};
|
||||
use voelin_model::ChatMessage;
|
||||
|
||||
use crate::app::{ChatLine, TextRun};
|
||||
use crate::emoji;
|
||||
use crate::vm::avatar;
|
||||
|
||||
/// Lines of the same author within this time are grouped (no header).
|
||||
const GROUP_MS: i64 = 5 * 60 * 1000;
|
||||
|
||||
/// The author and time of the line before, for grouping.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct Previous {
|
||||
pub author: String,
|
||||
pub relayed: bool,
|
||||
pub ts_ms: i64,
|
||||
}
|
||||
|
||||
impl Previous {
|
||||
pub fn of(message: &ChatMessage) -> Self {
|
||||
Self {
|
||||
author: message.author_name.clone(),
|
||||
relayed: message.via_relay,
|
||||
ts_ms: message.ts_ms,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn time_of(ts_ms: i64) -> String {
|
||||
chrono::DateTime::from_timestamp_millis(ts_ms)
|
||||
.map(|t| t.with_timezone(&chrono::Local).format("%H:%M").to_string())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The line of a message; `previous` is the line before it in the chat.
|
||||
pub fn line(message: &ChatMessage, previous: Option<&Previous>) -> ChatLine {
|
||||
let continued = previous.is_some_and(|p| {
|
||||
p.author == message.author_name
|
||||
&& p.relayed == message.via_relay
|
||||
&& (0..GROUP_MS).contains(&(message.ts_ms - p.ts_ms))
|
||||
});
|
||||
let runs = emoji::runs(&message.text);
|
||||
let jumbo = runs.as_deref().is_some_and(emoji::is_jumbo);
|
||||
let runs_model = match &runs {
|
||||
Some(runs) => ModelRc::from(Rc::new(VecModel::from(
|
||||
runs.iter()
|
||||
.map(|r| TextRun {
|
||||
text: r.text.clone().into(),
|
||||
emoji: r.emoji.clone().unwrap_or_default().into(),
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
))),
|
||||
None => ModelRc::default(),
|
||||
};
|
||||
ChatLine {
|
||||
author: message.author_name.clone().into(),
|
||||
text: message.text.clone().into(),
|
||||
time: time_of(message.ts_ms).into(),
|
||||
relayed: message.via_relay,
|
||||
runs: runs_model,
|
||||
rich: runs.is_some(),
|
||||
jumbo,
|
||||
continued,
|
||||
initials: avatar::initials(&message.author_name).into(),
|
||||
tint: avatar::tint(&message.author_name),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use slint::Model;
|
||||
use voelin_model::ChatTarget;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn message(author: &str, text: &str, ts_ms: i64) -> ChatMessage {
|
||||
ChatMessage {
|
||||
target: ChatTarget::Server,
|
||||
author_name: author.into(),
|
||||
author_uid: None,
|
||||
author_id: None,
|
||||
text: text.into(),
|
||||
ts_ms,
|
||||
via_relay: false,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn grouping() {
|
||||
let first = message("Alice", "hi", 1_000_000);
|
||||
let a = line(&first, None);
|
||||
assert!(!a.continued);
|
||||
assert_eq!(a.initials, "AL");
|
||||
let prev = Previous::of(&first);
|
||||
assert!(line(&message("Alice", "again", 1_060_000), Some(&prev)).continued);
|
||||
assert!(!line(&message("Bob", "me", 1_060_000), Some(&prev)).continued);
|
||||
assert!(!line(&message("Alice", "later", 1_000_000 + GROUP_MS), Some(&prev)).continued);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn emoji_runs() {
|
||||
let plain = line(&message("A", "no emoji here", 0), None);
|
||||
assert!(!plain.rich && plain.runs.row_count() == 0);
|
||||
let rich = line(&message("A", "gg 🎉", 0), None);
|
||||
assert!(rich.rich && !rich.jumbo);
|
||||
assert_eq!(rich.runs.row_count(), 2);
|
||||
assert_eq!(rich.runs.row_data(1).unwrap().emoji, "1f389");
|
||||
assert!(line(&message("A", "🎉", 0), None).jumbo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
//! Incremental model updates.
|
||||
|
||||
use slint::{Model, VecModel};
|
||||
|
||||
/// Row operations [`sync`] applied (for tests and tracing).
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub struct Changes {
|
||||
pub set: usize,
|
||||
pub inserted: usize,
|
||||
pub removed: usize,
|
||||
}
|
||||
|
||||
/// Make `model` hold `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. Views redraw only the
|
||||
/// rows that changed (a client that starts talking is one `set_row_data`).
|
||||
pub fn sync<T: Clone + PartialEq + 'static>(model: &VecModel<T>, new: &[T]) -> Changes {
|
||||
let old_len = model.row_count();
|
||||
let new_len = new.len();
|
||||
let min = old_len.min(new_len);
|
||||
let mut prefix = 0;
|
||||
while prefix < min && model.row_data(prefix).as_ref() == Some(&new[prefix]) {
|
||||
prefix += 1;
|
||||
}
|
||||
let mut suffix = 0;
|
||||
while suffix < min - prefix
|
||||
&& model.row_data(old_len - 1 - suffix).as_ref() == Some(&new[new_len - 1 - suffix])
|
||||
{
|
||||
suffix += 1;
|
||||
}
|
||||
let old_mid = old_len - prefix - suffix;
|
||||
let new_mid = new_len - prefix - suffix;
|
||||
let common = old_mid.min(new_mid);
|
||||
let mut changes = Changes::default();
|
||||
for (i, row) in new.iter().enumerate().skip(prefix).take(common) {
|
||||
if model.row_data(i).as_ref() != Some(row) {
|
||||
model.set_row_data(i, row.clone());
|
||||
changes.set += 1;
|
||||
}
|
||||
}
|
||||
let at = prefix + common;
|
||||
for _ in new_mid..old_mid {
|
||||
model.remove(at);
|
||||
changes.removed += 1;
|
||||
}
|
||||
for (k, row) in new[at..at + new_mid.saturating_sub(old_mid)].iter().enumerate() {
|
||||
model.insert(at + k, row.clone());
|
||||
changes.inserted += 1;
|
||||
}
|
||||
changes
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn run(old: &[i32], new: &[i32]) -> Changes {
|
||||
let model = VecModel::from(old.to_vec());
|
||||
let changes = sync(&model, new);
|
||||
assert_eq!(model.iter().collect::<Vec<_>>(), new, "{old:?} -> {new:?}");
|
||||
changes
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn minimal_changes() {
|
||||
assert_eq!(run(&[1, 2, 3], &[1, 2, 3]), Changes::default());
|
||||
assert_eq!(run(&[1, 2, 3], &[1, 9, 3]), Changes { set: 1, ..Default::default() });
|
||||
assert_eq!(run(&[1, 2, 3], &[1, 2, 7, 3]), Changes { inserted: 1, ..Default::default() });
|
||||
assert_eq!(run(&[1, 2, 3], &[1, 3]), Changes { removed: 1, ..Default::default() });
|
||||
assert_eq!(run(&[], &[1, 2]), Changes { inserted: 2, ..Default::default() });
|
||||
assert_eq!(run(&[1, 2], &[]), Changes { removed: 2, ..Default::default() });
|
||||
assert_eq!(run(&[1, 2, 3, 4], &[5, 6]).set, 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]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
//! View models: engine state turned into the Slint structs the screens
|
||||
//! show. Pure functions (no window, no engine), unit-tested here; the
|
||||
//! models live in `crate::models` and are updated row by row with
|
||||
//! [`list::sync`], so a small change redraws only what changed.
|
||||
|
||||
pub mod avatar;
|
||||
pub mod chat;
|
||||
pub mod list;
|
||||
pub mod servers;
|
||||
pub mod tree;
|
||||
@@ -0,0 +1,49 @@
|
||||
//! The server rail.
|
||||
|
||||
use voelin_core::{ObserveState, SessionState, VoiceState};
|
||||
use voelin_store::Bookmark;
|
||||
|
||||
use crate::app::ServerItem;
|
||||
use crate::vm::avatar;
|
||||
|
||||
/// "offline", "connecting", "observing" or "connected".
|
||||
pub fn status(state: &SessionState) -> &'static str {
|
||||
match (state.voice, state.observe) {
|
||||
(VoiceState::Connected, _) => "connected",
|
||||
(VoiceState::Connecting, _) | (_, ObserveState::Connecting) => "connecting",
|
||||
(_, ObserveState::Observing) => "observing",
|
||||
_ => "offline",
|
||||
}
|
||||
}
|
||||
|
||||
/// A server of the rail. `unread`: messages in its chats; `live`:
|
||||
/// streams in our channel there.
|
||||
pub fn item(bookmark: &Bookmark, state: &SessionState, unread: i32, live: bool) -> ServerItem {
|
||||
ServerItem {
|
||||
id: bookmark.id as i32,
|
||||
name: bookmark.name.clone().into(),
|
||||
address: bookmark.address.clone().into(),
|
||||
status: status(state).into(),
|
||||
initials: avatar::initials(&bookmark.name).into(),
|
||||
tint: avatar::tint(&bookmark.name),
|
||||
unread,
|
||||
live,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn states() {
|
||||
let mut s = SessionState::default();
|
||||
assert_eq!(status(&s), "offline");
|
||||
s.observe = ObserveState::Observing;
|
||||
assert_eq!(status(&s), "observing");
|
||||
s.voice = VoiceState::Connecting;
|
||||
assert_eq!(status(&s), "connecting");
|
||||
s.voice = VoiceState::Connected;
|
||||
assert_eq!(status(&s), "connected");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
//! The channel tree and the members of our channel.
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use voelin_model::{ChannelId, ClientInfo, Presence, TreeRow, tree_rows};
|
||||
|
||||
use crate::app::{MemberItem, TreeItem};
|
||||
use crate::settings::ClientPlaybackMap;
|
||||
use crate::vm::avatar;
|
||||
|
||||
/// What the tree shows besides the presence.
|
||||
pub struct TreeInput<'a> {
|
||||
pub presence: &'a Presence,
|
||||
pub collapsed: &'a HashSet<ChannelId>,
|
||||
pub talking: &'a HashSet<u16>,
|
||||
pub playback: &'a ClientPlaybackMap,
|
||||
pub own_channel: Option<ChannelId>,
|
||||
pub own_client: Option<u16>,
|
||||
/// Search text: only matching channels and clients (and the channels
|
||||
/// above them) are shown. Empty: everything.
|
||||
pub filter: &'a str,
|
||||
}
|
||||
|
||||
fn talking(input: &TreeInput, client: &ClientInfo) -> bool {
|
||||
input.talking.contains(&client.id) || client.talking == Some(true)
|
||||
}
|
||||
|
||||
/// The rows of the tree, channels with their clients below.
|
||||
pub fn rows(input: &TreeInput) -> Vec<TreeItem> {
|
||||
let p = input.presence;
|
||||
let rows: Vec<TreeItem> = tree_rows(p, &|cid| input.collapsed.contains(&cid))
|
||||
.into_iter()
|
||||
.map(|row| match row {
|
||||
TreeRow::Channel { depth, channel } => TreeItem {
|
||||
is_channel: true,
|
||||
depth: depth as i32,
|
||||
id: channel.id as i32,
|
||||
name: channel.name.clone().into(),
|
||||
own: input.own_channel == Some(channel.id),
|
||||
locked: channel.has_password,
|
||||
collapsed: input.collapsed.contains(&channel.id),
|
||||
local_volume: 100,
|
||||
members: p.members(channel.id).count() as i32,
|
||||
max_members: channel.max_clients.filter(|m| *m >= 0).unwrap_or(-1),
|
||||
..Default::default()
|
||||
},
|
||||
TreeRow::Client { depth, client } => {
|
||||
let playback = client
|
||||
.uid
|
||||
.as_ref()
|
||||
.and_then(|uid| input.playback.get(uid))
|
||||
.copied()
|
||||
.unwrap_or_default();
|
||||
TreeItem {
|
||||
is_channel: false,
|
||||
depth: depth as i32,
|
||||
id: client.id as i32,
|
||||
name: client.nickname.clone().into(),
|
||||
talking: talking(input, client),
|
||||
muted: client.input_muted,
|
||||
sound_off: client.output_muted,
|
||||
away: client.away.is_some(),
|
||||
streaming: client.streaming == Some(true),
|
||||
local_muted: playback.muted,
|
||||
local_volume: (playback.volume * 100.0).round() as i32,
|
||||
myself: input.own_client == Some(client.id),
|
||||
initials: avatar::initials(&client.nickname).into(),
|
||||
tint: avatar::tint(&client.nickname),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
filter(rows, input.filter)
|
||||
}
|
||||
|
||||
/// Rows that match `query`, and the channels above them.
|
||||
fn filter(rows: Vec<TreeItem>, query: &str) -> Vec<TreeItem> {
|
||||
let query = query.trim().to_lowercase();
|
||||
if query.is_empty() {
|
||||
return rows;
|
||||
}
|
||||
let matches: Vec<bool> =
|
||||
rows.iter().map(|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() {
|
||||
if !rows[i].is_channel || keep[i] {
|
||||
continue;
|
||||
}
|
||||
let depth = rows[i].depth;
|
||||
keep[i] = rows[i + 1..]
|
||||
.iter()
|
||||
.zip(&matches[i + 1..])
|
||||
.take_while(|(r, _)| r.depth > depth)
|
||||
.any(|(_, m)| *m);
|
||||
}
|
||||
rows.into_iter().zip(keep).filter_map(|(r, k)| k.then_some(r)).collect()
|
||||
}
|
||||
|
||||
/// "12 online · 8 channels"
|
||||
pub fn stats(p: &Presence) -> String {
|
||||
let online = p.clients.values().filter(|c| !c.is_query).count();
|
||||
let channels = p.channels.len();
|
||||
format!("{online} online · {channels} {}", if channels == 1 { "channel" } else { "channels" })
|
||||
}
|
||||
|
||||
/// The clients in our channel, for the members panel, by name.
|
||||
pub fn members(input: &TreeInput) -> Vec<MemberItem> {
|
||||
let Some(channel) = input.own_channel else { return Vec::new() };
|
||||
let mut clients: Vec<&ClientInfo> = input.presence.members(channel).collect();
|
||||
clients.sort_by_key(|c| c.nickname.to_lowercase());
|
||||
clients
|
||||
.into_iter()
|
||||
.map(|c| {
|
||||
let talking = talking(input, c);
|
||||
let status = if talking {
|
||||
"Speaking".to_owned()
|
||||
} else if c.streaming == Some(true) {
|
||||
"Streaming".to_owned()
|
||||
} else if let Some(message) = &c.away {
|
||||
if message.is_empty() { "Away".to_owned() } else { format!("Away: {message}") }
|
||||
} else if c.output_muted {
|
||||
"Sound off".to_owned()
|
||||
} else if c.input_muted {
|
||||
"Muted".to_owned()
|
||||
} else {
|
||||
"Listening".to_owned()
|
||||
};
|
||||
MemberItem {
|
||||
id: c.id as i32,
|
||||
name: c.nickname.clone().into(),
|
||||
initials: avatar::initials(&c.nickname).into(),
|
||||
tint: avatar::tint(&c.nickname),
|
||||
talking,
|
||||
muted: c.input_muted,
|
||||
sound_off: c.output_muted,
|
||||
away: c.away.is_some(),
|
||||
streaming: c.streaming == Some(true),
|
||||
myself: input.own_client == Some(c.id),
|
||||
status: status.into(),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use voelin_model::ChannelInfo;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn presence() -> Presence {
|
||||
let channel = |id, parent, order, name: &str| ChannelInfo {
|
||||
id,
|
||||
parent,
|
||||
order,
|
||||
name: name.into(),
|
||||
max_clients: if id == 2 { Some(5) } else { None },
|
||||
..Default::default()
|
||||
};
|
||||
let client = |id, channel, name: &str| ClientInfo {
|
||||
id,
|
||||
channel,
|
||||
nickname: name.into(),
|
||||
..Default::default()
|
||||
};
|
||||
let mut p = Presence::default();
|
||||
for c in [channel(1, 0, 0, "Lobby"), channel(2, 0, 1, "Games"), channel(3, 2, 0, "Chess")] {
|
||||
p.channels.insert(c.id, c);
|
||||
}
|
||||
for c in [client(10, 1, "Alice"), client(11, 2, "bob"), client(12, 3, "Carol")] {
|
||||
p.clients.insert(c.id, c);
|
||||
}
|
||||
let mut query = client(13, 1, "serveradmin");
|
||||
query.is_query = true;
|
||||
p.clients.insert(13, query);
|
||||
p
|
||||
}
|
||||
|
||||
fn input<'a>(
|
||||
p: &'a Presence,
|
||||
talking: &'a HashSet<u16>,
|
||||
collapsed: &'a HashSet<ChannelId>,
|
||||
playback: &'a ClientPlaybackMap,
|
||||
filter: &'a str,
|
||||
) -> TreeInput<'a> {
|
||||
TreeInput {
|
||||
presence: p,
|
||||
collapsed,
|
||||
talking,
|
||||
playback,
|
||||
own_channel: Some(2),
|
||||
own_client: Some(11),
|
||||
filter,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tree_rows_and_counts() {
|
||||
let p = presence();
|
||||
let (t, c, pb) = (HashSet::from([11]), HashSet::new(), ClientPlaybackMap::new());
|
||||
let rows = rows(&input(&p, &t, &c, &pb, ""));
|
||||
let names: Vec<_> = rows.iter().map(|r| r.name.as_str()).collect();
|
||||
assert_eq!(names, ["Lobby", "Alice", "Games", "bob", "Chess", "Carol"]);
|
||||
assert_eq!((rows[0].members, rows[0].max_members), (1, -1));
|
||||
assert_eq!((rows[2].members, rows[2].max_members, rows[2].own), (1, 5, true));
|
||||
assert!(rows[3].talking && rows[3].myself);
|
||||
assert_eq!(rows[3].initials, "BO");
|
||||
assert_eq!(stats(&p), "3 online · 3 channels");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn search_keeps_parents() {
|
||||
let p = presence();
|
||||
let (t, c, pb) = (HashSet::new(), HashSet::new(), ClientPlaybackMap::new());
|
||||
let rows = rows(&input(&p, &t, &c, &pb, "car"));
|
||||
let names: Vec<_> = rows.iter().map(|r| r.name.as_str()).collect();
|
||||
assert_eq!(names, ["Games", "Chess", "Carol"]);
|
||||
let rows = super::rows(&input(&p, &t, &c, &pb, "LOBBY"));
|
||||
assert_eq!(rows.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn members_of_our_channel() {
|
||||
let mut p = presence();
|
||||
p.clients.get_mut(&12).unwrap().channel = 2;
|
||||
p.clients.get_mut(&12).unwrap().away = Some(String::new());
|
||||
let (t, c, pb) = (HashSet::new(), HashSet::new(), ClientPlaybackMap::new());
|
||||
let members = members(&input(&p, &t, &c, &pb, ""));
|
||||
let names: Vec<_> = members.iter().map(|m| (m.name.as_str(), m.status.as_str())).collect();
|
||||
assert_eq!(names, [("bob", "Listening"), ("Carol", "Away")]);
|
||||
}
|
||||
}
|
||||
+144
-1679
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,350 @@
|
||||
// The data Rust gives the UI and the callbacks it handles. Models are
|
||||
// VecModels that Rust updates row by row (src/vm/), so screens can bind to
|
||||
// them freely.
|
||||
|
||||
export struct ServerItem {
|
||||
id: int,
|
||||
name: string,
|
||||
address: string,
|
||||
// "offline", "connecting", "observing" or "connected"
|
||||
status: string,
|
||||
// Avatar of a server without an icon.
|
||||
initials: string,
|
||||
tint: color,
|
||||
// Unread messages in its chats.
|
||||
unread: int,
|
||||
// Someone streams in our channel there.
|
||||
live: bool,
|
||||
}
|
||||
|
||||
export struct TreeItem {
|
||||
is-channel: bool,
|
||||
depth: int,
|
||||
id: int,
|
||||
name: string,
|
||||
own: bool,
|
||||
talking: bool,
|
||||
muted: bool,
|
||||
sound-off: bool,
|
||||
away: bool,
|
||||
streaming: bool,
|
||||
locked: bool,
|
||||
collapsed: bool,
|
||||
// Local playback of this client: muted, or its volume in percent
|
||||
// (100 = unchanged).
|
||||
local-muted: bool,
|
||||
local-volume: int,
|
||||
// Our own client.
|
||||
myself: bool,
|
||||
// Avatar of a client.
|
||||
initials: string,
|
||||
tint: color,
|
||||
// Channels: clients inside, and the limit (-1: none).
|
||||
members: int,
|
||||
max-members: int,
|
||||
}
|
||||
|
||||
// A client in our channel, for the members panel.
|
||||
export struct MemberItem {
|
||||
id: int,
|
||||
name: string,
|
||||
initials: string,
|
||||
tint: color,
|
||||
talking: bool,
|
||||
muted: bool,
|
||||
sound-off: bool,
|
||||
away: bool,
|
||||
streaming: bool,
|
||||
myself: bool,
|
||||
// "Speaking", "Streaming", "Away", ...
|
||||
status: string,
|
||||
}
|
||||
|
||||
export struct ChatTab {
|
||||
title: string,
|
||||
// 0 = server chat, 1 = channel chat, 2 = private chat
|
||||
kind: int,
|
||||
id: int,
|
||||
unread: int,
|
||||
// The channel's topic (channel chats).
|
||||
topic: string,
|
||||
}
|
||||
|
||||
// A piece of a chat line: text, or an emoji shown as an image (`emoji` is
|
||||
// its Twemoji key, e.g. "1f600"; `text` then holds the characters).
|
||||
export struct TextRun {
|
||||
text: string,
|
||||
emoji: string,
|
||||
}
|
||||
|
||||
export struct ChatLine {
|
||||
author: string,
|
||||
text: string,
|
||||
time: string,
|
||||
relayed: bool,
|
||||
// The text split into runs; only filled when it has emoji (`rich`).
|
||||
runs: [TextRun],
|
||||
rich: bool,
|
||||
// Only one to three emoji: shown large.
|
||||
jumbo: bool,
|
||||
// Same author as the line before, shortly after: no header.
|
||||
continued: bool,
|
||||
initials: string,
|
||||
tint: color,
|
||||
}
|
||||
|
||||
export struct BookmarkForm {
|
||||
id: int,
|
||||
name: string,
|
||||
address: string,
|
||||
nickname: string,
|
||||
server-password: string,
|
||||
gateway-url: string,
|
||||
query-transport: string,
|
||||
query-addr: string,
|
||||
query-user: string,
|
||||
query-password: string,
|
||||
}
|
||||
|
||||
// A stream in our channel. An empty id: a client that streams, but whose
|
||||
// stream is still being looked up (it started before we joined).
|
||||
export struct StreamItem {
|
||||
id: string,
|
||||
name: string,
|
||||
streamer: string,
|
||||
audio: bool,
|
||||
// Shown in the viewer.
|
||||
watching: bool,
|
||||
// Our own stream.
|
||||
own: bool,
|
||||
}
|
||||
|
||||
// A viewer of our stream. state: "requested", "connecting" or "connected".
|
||||
export struct ViewerItem {
|
||||
client: int,
|
||||
name: string,
|
||||
state: string,
|
||||
message: string,
|
||||
}
|
||||
|
||||
// A capture source for the share dialog.
|
||||
export struct SourceItem {
|
||||
name: string,
|
||||
detail: string,
|
||||
}
|
||||
|
||||
export struct ShareForm {
|
||||
source: int,
|
||||
name: string,
|
||||
// Index into the frame rate choices (15, 30, 60).
|
||||
fps-index: int,
|
||||
// Frames per second as typed; a choice fills it in. Any number above 0.
|
||||
fps: string,
|
||||
// Index into the bitrate choices (2.5, 4.6, 8, 10 Mbit/s).
|
||||
bitrate-index: int,
|
||||
// Video bitrate in kbit/s as typed; a choice fills it in.
|
||||
bitrate: string,
|
||||
audio: bool,
|
||||
auto-accept: bool,
|
||||
}
|
||||
|
||||
export struct AudioForm {
|
||||
// 0 = system default, then the devices.
|
||||
input-index: int,
|
||||
output-index: int,
|
||||
// 0 = push-to-talk, 1 = voice activation, 2 = continuous.
|
||||
transmit: int,
|
||||
// dBFS.
|
||||
vad-threshold: float,
|
||||
echo-cancellation: bool,
|
||||
noise-suppression: bool,
|
||||
// 0 = low ... 3 = very high.
|
||||
noise-level: int,
|
||||
auto-gain: bool,
|
||||
// dB.
|
||||
input-gain: float,
|
||||
// Percent.
|
||||
output-volume: float,
|
||||
// Milliseconds.
|
||||
playback-buffer: float,
|
||||
}
|
||||
|
||||
// Local playback settings of one client. volume in percent.
|
||||
export struct ClientAudio {
|
||||
id: int,
|
||||
name: string,
|
||||
volume: float,
|
||||
muted: bool,
|
||||
}
|
||||
|
||||
// The appearance settings (`ui.*` keys).
|
||||
export struct AppearanceForm {
|
||||
// "dark", "light" or "system"
|
||||
theme: string,
|
||||
font-scale: float,
|
||||
// Pixels.
|
||||
narrow-breakpoint: float,
|
||||
image-cache-mb: float,
|
||||
}
|
||||
|
||||
export global Bridge {
|
||||
in property <[ServerItem]> servers;
|
||||
in-out property <int> current-server: -1;
|
||||
in property <[TreeItem]> tree;
|
||||
// Clients in our channel.
|
||||
in property <[MemberItem]> members;
|
||||
in property <[ChatTab]> tabs;
|
||||
in-out property <int> current-tab: 0;
|
||||
in property <[ChatLine]> messages;
|
||||
in property <string> status-text;
|
||||
// Unread messages in all chats of the current server.
|
||||
in property <int> unread-total;
|
||||
in property <string> server-title: @tr("No server selected");
|
||||
// "12 online · 8 channels"
|
||||
in property <string> server-stats;
|
||||
// Our nickname on the current server, and the channel we are in.
|
||||
in property <string> nickname;
|
||||
in property <string> own-channel;
|
||||
in property <bool> voice-connected;
|
||||
in property <bool> voice-connecting;
|
||||
in property <bool> observing;
|
||||
in property <bool> can-observe;
|
||||
in property <bool> input-muted;
|
||||
in property <bool> output-muted;
|
||||
in property <bool> transmitting;
|
||||
in property <string> presence-source;
|
||||
|
||||
// Streams (TeamSpeak 6 while connected with voice).
|
||||
in property <bool> streams-available;
|
||||
in property <[StreamItem]> streams;
|
||||
// Our stream: "", "starting", "live" or "ended".
|
||||
in property <string> share-state;
|
||||
in property <string> share-status;
|
||||
in property <[ViewerItem]> share-viewers;
|
||||
in property <int> share-requests;
|
||||
in property <[SourceItem]> share-sources;
|
||||
in property <string> share-error;
|
||||
in property <bool> share-busy;
|
||||
// Whether capture and encoding are built in.
|
||||
in property <bool> can-share: true;
|
||||
|
||||
// The stream shown in the viewer.
|
||||
in property <bool> viewer-open;
|
||||
in property <image> viewer-frame;
|
||||
in property <bool> viewer-has-frame;
|
||||
in property <string> viewer-title;
|
||||
// Shown instead of (or over) the picture: waiting, ended, errors.
|
||||
in property <string> viewer-status;
|
||||
in property <string> viewer-info;
|
||||
in property <bool> viewer-ended;
|
||||
in-out property <float> viewer-volume: 100;
|
||||
in property <bool> viewer-fullscreen;
|
||||
|
||||
// Settings.
|
||||
in property <[string]> input-devices;
|
||||
in property <[string]> output-devices;
|
||||
in-out property <AudioForm> audio;
|
||||
// Microphone level in dBFS and whether voice is sent.
|
||||
in property <float> input-level: -100;
|
||||
in property <bool> input-sending;
|
||||
in property <bool> mic-test;
|
||||
in-out property <bool> global-ptt;
|
||||
in-out property <string> ptt-key;
|
||||
in property <string> ptt-status;
|
||||
in-out property <bool> h264-enabled;
|
||||
in property <bool> h264-loaded;
|
||||
in property <bool> h264-busy;
|
||||
in property <string> h264-status;
|
||||
in property <string> h264-attribution;
|
||||
in-out property <AppearanceForm> appearance;
|
||||
// "3.2 of 64 MB"
|
||||
in property <string> image-cache-usage;
|
||||
// The product name (voelin_platform::APP_NAME, not translated) and version.
|
||||
in property <string> app-name: "Voelin";
|
||||
in property <string> app-version;
|
||||
in-out property <ClientAudio> client-audio;
|
||||
// Opt-in local crash reports, and a notice about reports on disk.
|
||||
in-out property <bool> crash-reports;
|
||||
in property <string> crash-notice;
|
||||
// Third-party notices, one entry per line, for the About page.
|
||||
in property <[string]> notices;
|
||||
|
||||
callback select-server(int);
|
||||
// The search field of the top bar: filters the channel tree.
|
||||
callback search(string);
|
||||
callback connect-voice();
|
||||
callback disconnect-voice();
|
||||
callback toggle-observe();
|
||||
callback join-channel(int);
|
||||
callback open-channel-chat(int);
|
||||
callback toggle-collapse(int);
|
||||
callback select-tab(int);
|
||||
callback close-tab(int);
|
||||
callback send-message(string);
|
||||
callback set-input-muted(bool);
|
||||
callback set-output-muted(bool);
|
||||
callback push-to-talk(bool);
|
||||
callback edit-bookmark(int) -> BookmarkForm;
|
||||
callback save-bookmark(BookmarkForm);
|
||||
callback delete-bookmark(int);
|
||||
|
||||
callback open-share() -> ShareForm;
|
||||
callback start-share(ShareForm);
|
||||
callback stop-share();
|
||||
callback respond-viewer(int, bool);
|
||||
callback kick-viewer(int);
|
||||
callback watch-stream(string);
|
||||
callback show-viewer();
|
||||
callback hide-viewer();
|
||||
callback leave-stream();
|
||||
callback set-stream-volume(float);
|
||||
callback toggle-fullscreen();
|
||||
|
||||
callback open-settings();
|
||||
callback close-settings();
|
||||
callback audio-changed(AudioForm);
|
||||
callback toggle-mic-test();
|
||||
callback apply-ptt(bool, string);
|
||||
callback set-h264(bool);
|
||||
callback download-h264();
|
||||
callback appearance-changed(AppearanceForm);
|
||||
callback open-client(int) -> bool;
|
||||
callback client-audio-changed(ClientAudio);
|
||||
callback set-crash-reports(bool);
|
||||
callback open-crash-folder();
|
||||
callback delete-crash-reports();
|
||||
callback dismiss-crash-notice();
|
||||
callback open-about();
|
||||
}
|
||||
|
||||
// Decoded images by key, from Rust's image cache (src/images.rs): each is
|
||||
// decoded once and kept while the cache (setting `ui.image_cache_mb`) has
|
||||
// room.
|
||||
export global Images {
|
||||
// A Twemoji by key ("1f600", "1f468-200d-1f4bb"); empty if unknown.
|
||||
pure callback emoji(string) -> image;
|
||||
}
|
||||
|
||||
// One emoji of the picker. `text` is what picking it inserts.
|
||||
export struct EmojiCell {
|
||||
key: string,
|
||||
name: string,
|
||||
text: string,
|
||||
}
|
||||
|
||||
export struct EmojiRow {
|
||||
cells: [EmojiCell],
|
||||
}
|
||||
|
||||
// The emoji picker's data (src/bind/emoji.rs).
|
||||
export global Emoji {
|
||||
// The shown category as rows of `columns` cells.
|
||||
in property <[EmojiRow]> rows;
|
||||
// The category shown (see EmojiPicker), -1 while searching.
|
||||
in-out property <int> category: 0;
|
||||
in property <int> columns: 8;
|
||||
// Filled once the picker is first opened.
|
||||
callback load();
|
||||
callback show-category(int);
|
||||
callback search(string);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Icon } from "icon.slint";
|
||||
|
||||
// Presence shown in the avatar's status dot.
|
||||
export enum Status {
|
||||
none,
|
||||
online,
|
||||
idle,
|
||||
dnd,
|
||||
offline,
|
||||
// A blue dot: observed invisibly, streaming...
|
||||
info,
|
||||
}
|
||||
|
||||
// A round avatar: a picture, or initials on a colour; a status dot, a crown
|
||||
// badge, and a green ring while speaking.
|
||||
export component Avatar inherits Rectangle {
|
||||
in property <image> image;
|
||||
in property <string> initials;
|
||||
in property <color> tint: Theme.accent-soft;
|
||||
in property <length> size: 36px;
|
||||
in property <Status> status: Status.none;
|
||||
in property <bool> speaking;
|
||||
in property <bool> crown;
|
||||
// Squircle instead of a circle (server icons).
|
||||
in property <bool> square;
|
||||
in property <string> label;
|
||||
|
||||
width: size;
|
||||
height: size;
|
||||
accessible-role: AccessibleRole.image;
|
||||
accessible-label: label;
|
||||
|
||||
// Speaking ring (outside the picture).
|
||||
if speaking: Rectangle {
|
||||
x: -3px;
|
||||
y: -3px;
|
||||
width: root.size + 6px;
|
||||
height: root.size + 6px;
|
||||
border-radius: root.square ? Theme.radius-lg + 3px : self.width / 2;
|
||||
border-width: 2px;
|
||||
border-color: Theme.success;
|
||||
}
|
||||
face := Rectangle {
|
||||
border-radius: root.square ? Theme.radius-lg : root.size / 2;
|
||||
background: root.image.width > 0 ? Theme.surface-3 : root.tint;
|
||||
clip: true;
|
||||
if root.image.width > 0: Image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
source: root.image;
|
||||
image-fit: cover;
|
||||
}
|
||||
if root.image.width == 0: Text {
|
||||
text: root.initials;
|
||||
color: #ffffff;
|
||||
font-size: root.size * 0.38;
|
||||
font-weight: Theme.weight-semibold;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
if root.status != Status.none: Rectangle {
|
||||
property <length> dot: max(10px, root.size * 0.3);
|
||||
x: root.size - dot + 1px;
|
||||
y: root.size - dot + 1px;
|
||||
width: dot;
|
||||
height: dot;
|
||||
border-radius: dot / 2;
|
||||
background: root.status == Status.online ? Theme.success
|
||||
: root.status == Status.idle ? Theme.idle
|
||||
: root.status == Status.dnd ? Theme.dnd
|
||||
: root.status == Status.info ? Theme.info
|
||||
: Theme.offline;
|
||||
border-width: 2px;
|
||||
border-color: Theme.surface;
|
||||
}
|
||||
if root.crown: Icon {
|
||||
x: root.size - self.width * 0.7;
|
||||
y: -self.height * 0.35;
|
||||
source: Icons.crown;
|
||||
size: max(12px, root.size * 0.34);
|
||||
tint: Theme.gold;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icon } from "icon.slint";
|
||||
|
||||
// A red count bubble (unread, requests).
|
||||
export component CountBadge inherits Rectangle {
|
||||
in property <int> count;
|
||||
in property <color> fill: Theme.live;
|
||||
width: max(18px, label.preferred-width + 10px);
|
||||
height: 18px;
|
||||
border-radius: 9px;
|
||||
background: fill;
|
||||
accessible-role: AccessibleRole.text;
|
||||
accessible-label: count;
|
||||
HorizontalLayout {
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
label := Text {
|
||||
text: root.count > 99 ? "99+" : root.count;
|
||||
color: #ffffff;
|
||||
font-size: Theme.font-xs;
|
||||
font-weight: Theme.weight-bold;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The red LIVE tag.
|
||||
export component LiveBadge inherits Rectangle {
|
||||
in property <string> text: @tr("LIVE");
|
||||
in property <bool> large;
|
||||
height: large ? 26px : 18px;
|
||||
width: label.preferred-width + (large ? 16px : 10px);
|
||||
horizontal-stretch: 0;
|
||||
vertical-stretch: 0;
|
||||
border-radius: Theme.radius-xs;
|
||||
background: Theme.live;
|
||||
accessible-role: AccessibleRole.text;
|
||||
accessible-label: text;
|
||||
label := Text {
|
||||
text: root.text;
|
||||
color: #ffffff;
|
||||
font-size: root.large ? Theme.font-body : Theme.font-xs;
|
||||
font-weight: Theme.weight-bold;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
|
||||
// A small rounded label: tags, stream facts ("1080p"), roles ("Moderator").
|
||||
export component Chip inherits Rectangle {
|
||||
in property <string> text;
|
||||
in property <image> icon;
|
||||
in property <color> tint: Theme.text-secondary;
|
||||
in property <brush> fill: Theme.surface-3;
|
||||
in property <bool> outlined;
|
||||
height: 22px;
|
||||
width: row.preferred-width;
|
||||
horizontal-stretch: 0;
|
||||
vertical-stretch: 0;
|
||||
border-radius: Theme.radius-pill;
|
||||
background: fill;
|
||||
border-width: outlined ? 1px : 0px;
|
||||
border-color: Theme.border-strong;
|
||||
accessible-role: AccessibleRole.text;
|
||||
accessible-label: text;
|
||||
row := HorizontalLayout {
|
||||
padding-left: Theme.space-3;
|
||||
padding-right: Theme.space-3;
|
||||
spacing: Theme.space-2;
|
||||
if root.icon.width > 0: Icon {
|
||||
source: root.icon;
|
||||
size: 12px;
|
||||
tint: root.tint;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: root.text;
|
||||
color: root.tint;
|
||||
font-size: Theme.font-xs;
|
||||
font-weight: Theme.weight-medium;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A coloured dot (online, connection state).
|
||||
export component Dot inherits Rectangle {
|
||||
in property <length> size: 8px;
|
||||
width: size;
|
||||
height: size;
|
||||
border-radius: size / 2;
|
||||
background: Theme.success;
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icon } from "icon.slint";
|
||||
|
||||
export enum ButtonKind {
|
||||
// Filled accent: the main action.
|
||||
primary,
|
||||
// Surface with a border.
|
||||
secondary,
|
||||
// Destructive: leave, end stream, delete.
|
||||
danger,
|
||||
// No background until hovered.
|
||||
ghost,
|
||||
}
|
||||
|
||||
// The focus ring shared by controls.
|
||||
export component FocusRing inherits Rectangle {
|
||||
in property <bool> shown;
|
||||
in property <length> radius: Theme.radius-md;
|
||||
// The size of the ringed element.
|
||||
in property <length> w;
|
||||
in property <length> h;
|
||||
x: -Theme.glow-width;
|
||||
y: -Theme.glow-width;
|
||||
width: w + 2 * Theme.glow-width;
|
||||
height: h + 2 * Theme.glow-width;
|
||||
border-radius: radius + Theme.glow-width;
|
||||
border-width: shown ? Theme.glow-width : 0px;
|
||||
border-color: Theme.glow;
|
||||
}
|
||||
|
||||
// A button with a label, an icon or both.
|
||||
export component Button inherits Rectangle {
|
||||
in property <string> text;
|
||||
in property <image> icon;
|
||||
in property <ButtonKind> kind: ButtonKind.secondary;
|
||||
in property <bool> enabled: true;
|
||||
// Toggled on: drawn as selected (e.g. an open panel).
|
||||
in property <bool> checked;
|
||||
// Smaller height and padding.
|
||||
in property <bool> small;
|
||||
// Stretch the label to the full width.
|
||||
in property <bool> centered: true;
|
||||
callback clicked();
|
||||
|
||||
property <bool> active: touch.pressed || checked;
|
||||
property <color> fill: kind == ButtonKind.primary ? (active ? Theme.accent-pressed : touch.has-hover ? Theme.accent-hover : Theme.accent)
|
||||
: kind == ButtonKind.danger ? (active ? Theme.danger : touch.has-hover ? Theme.danger-soft.brighter(0.3) : Theme.danger-soft)
|
||||
: kind == ButtonKind.ghost ? (active ? Theme.surface-4 : touch.has-hover ? Theme.surface-3 : transparent)
|
||||
: (active ? Theme.surface-4 : touch.has-hover ? Theme.surface-3 : Theme.surface-2);
|
||||
property <color> ink: !enabled ? Theme.text-disabled
|
||||
: kind == ButtonKind.primary ? Theme.on-accent
|
||||
: kind == ButtonKind.danger ? (active ? Theme.on-accent : Theme.danger)
|
||||
: checked ? Theme.accent-text : Theme.text;
|
||||
|
||||
min-width: self.min-height;
|
||||
min-height: small ? Theme.control-height-sm : Theme.control-height;
|
||||
max-height: self.min-height;
|
||||
horizontal-stretch: 0;
|
||||
vertical-stretch: 0;
|
||||
border-radius: Theme.radius-md;
|
||||
background: fill;
|
||||
border-width: kind == ButtonKind.secondary || kind == ButtonKind.danger || checked ? 1px : 0px;
|
||||
border-color: checked ? Theme.accent : kind == ButtonKind.danger ? Theme.danger.transparentize(55%) : Theme.border-strong;
|
||||
opacity: enabled ? 1.0 : 0.6;
|
||||
animate background { duration: Theme.fast; }
|
||||
|
||||
accessible-role: AccessibleRole.button;
|
||||
accessible-label: text;
|
||||
accessible-enabled: enabled;
|
||||
accessible-checkable: checked;
|
||||
accessible-checked: checked;
|
||||
accessible-action-default => { if enabled { clicked(); } }
|
||||
|
||||
FocusRing {
|
||||
shown: focus.has-focus;
|
||||
w: root.width;
|
||||
h: root.height;
|
||||
}
|
||||
focus := FocusScope {
|
||||
enabled: root.enabled;
|
||||
key-pressed(event) => {
|
||||
if event.text == " " || event.text == "\n" {
|
||||
root.clicked();
|
||||
return accept;
|
||||
}
|
||||
reject
|
||||
}
|
||||
touch := TouchArea {
|
||||
enabled: root.enabled;
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => {
|
||||
focus.focus();
|
||||
root.clicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
padding-left: text == "" ? 0px : small ? Theme.space-4 : Theme.space-5;
|
||||
padding-right: self.padding-left;
|
||||
spacing: Theme.space-3;
|
||||
alignment: centered ? center : start;
|
||||
if icon.width > 0: Icon {
|
||||
source: icon;
|
||||
size: small ? Theme.icon-sm : Theme.icon-md;
|
||||
tint: ink;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
if text != "": Text {
|
||||
text: root.text;
|
||||
color: ink;
|
||||
font-size: small ? Theme.font-sm : Theme.font-body;
|
||||
font-weight: Theme.weight-medium;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A square (or round) button with only an icon; `label` is for screen
|
||||
// readers and the tooltip-less toolbar.
|
||||
export component IconButton inherits Rectangle {
|
||||
in property <image> icon;
|
||||
in property <string> label;
|
||||
in property <bool> enabled: true;
|
||||
in property <bool> checked;
|
||||
in property <bool> round;
|
||||
// Drawn on a surface instead of transparent.
|
||||
in property <bool> filled;
|
||||
// Red while checked (muted microphone).
|
||||
in property <bool> danger;
|
||||
in property <length> size: Theme.control-height;
|
||||
in property <length> icon-size: Theme.icon-md;
|
||||
in property <brush> tint: checked ? (danger ? Theme.danger : Theme.accent-text) : Theme.icon;
|
||||
// A small dot at the top right (unread, live).
|
||||
in property <bool> dot;
|
||||
in property <color> dot-color: Theme.live;
|
||||
callback clicked();
|
||||
|
||||
width: size;
|
||||
height: size;
|
||||
border-radius: round ? size / 2 : Theme.radius-md;
|
||||
background: touch.pressed ? Theme.surface-4
|
||||
: checked ? (danger ? Theme.danger-soft : Theme.accent-soft)
|
||||
: touch.has-hover ? Theme.surface-3
|
||||
: filled ? Theme.surface-2 : transparent;
|
||||
border-width: filled || checked ? 1px : 0px;
|
||||
border-color: checked ? (danger ? Theme.danger.transparentize(50%) : Theme.accent) : Theme.border;
|
||||
opacity: enabled ? 1.0 : 0.45;
|
||||
animate background { duration: Theme.fast; }
|
||||
|
||||
accessible-role: AccessibleRole.button;
|
||||
accessible-label: label;
|
||||
accessible-enabled: enabled;
|
||||
accessible-action-default => { if enabled { clicked(); } }
|
||||
|
||||
FocusRing {
|
||||
shown: focus.has-focus;
|
||||
radius: root.border-radius;
|
||||
w: root.width;
|
||||
h: root.height;
|
||||
}
|
||||
focus := FocusScope {
|
||||
enabled: root.enabled;
|
||||
key-pressed(event) => {
|
||||
if event.text == " " || event.text == "\n" {
|
||||
root.clicked();
|
||||
return accept;
|
||||
}
|
||||
reject
|
||||
}
|
||||
touch := TouchArea {
|
||||
enabled: root.enabled;
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => {
|
||||
focus.focus();
|
||||
root.clicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
Icon {
|
||||
source: icon;
|
||||
size: icon-size;
|
||||
tint: root.tint;
|
||||
}
|
||||
if dot: Rectangle {
|
||||
x: parent.width - self.width - root.size * 0.18;
|
||||
y: root.size * 0.16;
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
border-radius: 4.5px;
|
||||
background: dot-color;
|
||||
border-width: 2px;
|
||||
border-color: Theme.surface;
|
||||
}
|
||||
}
|
||||
|
||||
// A round control with a caption below (voice bar: Mute, Deafen, Go Live).
|
||||
export component ActionButton inherits VerticalLayout {
|
||||
in property <image> icon;
|
||||
in property <string> text;
|
||||
in property <bool> checked;
|
||||
in property <bool> danger;
|
||||
in property <bool> enabled: true;
|
||||
in property <length> size: 40px;
|
||||
callback clicked();
|
||||
spacing: Theme.space-1;
|
||||
alignment: center;
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
IconButton {
|
||||
icon: root.icon;
|
||||
label: root.text;
|
||||
checked: root.checked;
|
||||
danger: root.danger;
|
||||
enabled: root.enabled;
|
||||
round: true;
|
||||
filled: true;
|
||||
size: root.size;
|
||||
clicked => { root.clicked(); }
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: root.text;
|
||||
font-size: Theme.font-xs;
|
||||
color: root.checked ? (root.danger ? Theme.danger : Theme.accent-text) : Theme.text-secondary;
|
||||
horizontal-alignment: center;
|
||||
accessible-role: AccessibleRole.none;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Icon } from "icon.slint";
|
||||
|
||||
// A section title with an optional count and a "See All >" link.
|
||||
export component SectionHeader inherits HorizontalLayout {
|
||||
in property <string> text;
|
||||
in property <image> icon;
|
||||
in property <string> count;
|
||||
in property <string> action;
|
||||
// Uppercase-ish small header (sidebar sections) instead of a title.
|
||||
in property <bool> small;
|
||||
callback action-clicked();
|
||||
spacing: Theme.space-3;
|
||||
min-height: small ? 24px : 32px;
|
||||
if icon.width > 0: Icon {
|
||||
source: root.icon;
|
||||
size: small ? Theme.icon-sm : Theme.icon-md;
|
||||
tint: Theme.text-secondary;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: root.count != "" ? root.text + " — " + root.count : root.text;
|
||||
color: root.small ? Theme.text-secondary : Theme.text;
|
||||
font-size: root.small ? Theme.font-sm : Theme.font-lg;
|
||||
font-weight: root.small ? Theme.weight-semibold : Theme.weight-semibold;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
overflow: elide;
|
||||
accessible-role: AccessibleRole.text;
|
||||
}
|
||||
if action != "": Rectangle {
|
||||
accessible-role: AccessibleRole.button;
|
||||
accessible-label: root.action;
|
||||
accessible-action-default => { root.action-clicked(); }
|
||||
min-width: link.preferred-width;
|
||||
link := HorizontalLayout {
|
||||
spacing: 2px;
|
||||
Text {
|
||||
text: root.action;
|
||||
color: link-area.has-hover ? Theme.accent-hover : Theme.accent-text;
|
||||
font-size: Theme.font-sm;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
Icon {
|
||||
source: Icons.chevron-right;
|
||||
size: 14px;
|
||||
tint: Theme.accent-text;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
}
|
||||
link-area := TouchArea {
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => { root.action-clicked(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A panel card: surface, border, rounded corners; an optional header with
|
||||
// icon, title and a trailing slot.
|
||||
export component Card inherits Rectangle {
|
||||
in property <string> title;
|
||||
in property <image> icon;
|
||||
in property <string> subtitle;
|
||||
in property <length> inset: Theme.space-5;
|
||||
in property <length> gap: Theme.space-4;
|
||||
// Highlighted border (selected cards).
|
||||
in property <bool> selected;
|
||||
background: Theme.surface-2.transparentize(0.25);
|
||||
border-radius: Theme.radius-lg;
|
||||
border-width: 1px;
|
||||
border-color: selected ? Theme.accent : Theme.border;
|
||||
accessible-role: AccessibleRole.groupbox;
|
||||
accessible-label: title;
|
||||
VerticalLayout {
|
||||
padding: root.inset;
|
||||
spacing: root.gap;
|
||||
if root.title != "": HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
if root.icon.width > 0: Icon {
|
||||
source: root.icon;
|
||||
size: Theme.icon-md;
|
||||
tint: Theme.accent-text;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Text {
|
||||
text: root.title;
|
||||
font-size: Theme.font-lg;
|
||||
font-weight: Theme.weight-semibold;
|
||||
color: Theme.text;
|
||||
}
|
||||
if root.subtitle != "": Text {
|
||||
text: root.subtitle;
|
||||
font-size: Theme.font-sm;
|
||||
color: Theme.text-muted;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
@children
|
||||
}
|
||||
}
|
||||
|
||||
// A thin horizontal separator line.
|
||||
export component Divider inherits Rectangle {
|
||||
height: 1px;
|
||||
horizontal-stretch: 1;
|
||||
vertical-stretch: 0;
|
||||
background: Theme.border;
|
||||
}
|
||||
|
||||
// A warning or error strip with actions (crash notice, share errors).
|
||||
export component Banner inherits Rectangle {
|
||||
in property <string> text;
|
||||
in property <image> icon: Icons.triangle-alert;
|
||||
in property <color> tone: Theme.warning;
|
||||
background: tone.transparentize(0.85);
|
||||
border-radius: Theme.radius-md;
|
||||
border-width: 1px;
|
||||
border-color: tone.transparentize(0.55);
|
||||
accessible-role: AccessibleRole.groupbox;
|
||||
accessible-label: text;
|
||||
HorizontalLayout {
|
||||
padding: Theme.space-3;
|
||||
padding-left: Theme.space-4;
|
||||
spacing: Theme.space-3;
|
||||
Icon {
|
||||
source: root.icon;
|
||||
tint: root.tone;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: root.text;
|
||||
color: Theme.text;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
@children
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
// Emoji as images (Twemoji through Rust's image cache): chat text with
|
||||
// inline emoji, and the picker.
|
||||
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Images, Emoji, TextRun, EmojiCell } from "../bridge.slint";
|
||||
import { Icon } from "icon.slint";
|
||||
import { SearchBox } from "text-field.slint";
|
||||
import { ListView } from "std-widgets.slint";
|
||||
|
||||
// Text with inline emoji: the runs flow and wrap like text (a flexbox of
|
||||
// words and emoji). Plain text needs no runs: use a Text then (faster).
|
||||
export component RichText inherits FlexboxLayout {
|
||||
in property <[TextRun]> runs;
|
||||
in property <length> font-size: Theme.font-body;
|
||||
in property <color> color: Theme.text;
|
||||
in property <length> emoji-size: font-size * 1.4;
|
||||
spacing: 0px;
|
||||
cross-axis-alignment: center;
|
||||
for run in root.runs: HorizontalLayout {
|
||||
if run.emoji == "": Text {
|
||||
text: run.text;
|
||||
font-size: root.font-size;
|
||||
color: root.color;
|
||||
accessible-role: AccessibleRole.none;
|
||||
}
|
||||
if run.emoji != "": Image {
|
||||
width: root.emoji-size;
|
||||
height: root.emoji-size;
|
||||
source: Images.emoji(run.emoji);
|
||||
image-fit: contain;
|
||||
accessible-role: AccessibleRole.image;
|
||||
accessible-label: run.text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// One emoji of the picker grid.
|
||||
component EmojiButton inherits Rectangle {
|
||||
in property <EmojiCell> cell;
|
||||
in property <length> size: 36px;
|
||||
callback picked(EmojiCell);
|
||||
width: size;
|
||||
height: size;
|
||||
border-radius: Theme.radius-sm;
|
||||
background: touch.has-hover ? Theme.surface-4 : transparent;
|
||||
accessible-role: AccessibleRole.button;
|
||||
accessible-label: cell.name;
|
||||
accessible-action-default => { picked(cell); }
|
||||
touch := TouchArea {
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => { root.picked(root.cell); }
|
||||
}
|
||||
Image {
|
||||
width: root.size - 10px;
|
||||
height: root.size - 10px;
|
||||
source: Images.emoji(root.cell.key);
|
||||
image-fit: contain;
|
||||
}
|
||||
}
|
||||
|
||||
// The emoji picker: search, categories, a scrolling grid (only the visible
|
||||
// rows are built). Rust fills `Emoji.rows` for the category or search.
|
||||
export component EmojiPicker inherits Rectangle {
|
||||
callback picked(EmojiCell);
|
||||
callback close();
|
||||
property <[image]> category-icons: [
|
||||
Icons.smile, Icons.hand, Icons.leaf, Icons.coffee, Icons.gamepad-2,
|
||||
Icons.plane, Icons.lightbulb, Icons.heart, Icons.flag,
|
||||
];
|
||||
property <[string]> category-names: [
|
||||
@tr("Smileys"), @tr("People"), @tr("Nature"), @tr("Food"), @tr("Activities"),
|
||||
@tr("Travel"), @tr("Objects"), @tr("Symbols"), @tr("Flags"),
|
||||
];
|
||||
property <length> cell: 36px;
|
||||
property <string> hovered;
|
||||
|
||||
init => { Emoji.load(); }
|
||||
|
||||
width: Emoji.columns * cell + 2 * Theme.space-3 + 14px;
|
||||
height: 400px;
|
||||
border-radius: Theme.radius-lg;
|
||||
background: Theme.surface;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border-strong;
|
||||
accessible-role: AccessibleRole.groupbox;
|
||||
accessible-label: @tr("Emoji");
|
||||
FocusScope {
|
||||
key-pressed(event) => {
|
||||
if event.text == Key.Escape {
|
||||
root.close();
|
||||
return accept;
|
||||
}
|
||||
reject
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
padding: Theme.space-3;
|
||||
spacing: Theme.space-3;
|
||||
search := SearchBox {
|
||||
placeholder: @tr("Search emoji");
|
||||
show-shortcut: false;
|
||||
edited(text) => { Emoji.search(text); }
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: 2px;
|
||||
for icon[i] in root.category-icons: Rectangle {
|
||||
height: 30px;
|
||||
horizontal-stretch: 1;
|
||||
border-radius: Theme.radius-sm;
|
||||
background: Emoji.category == i ? Theme.accent-soft : cat.has-hover ? Theme.surface-3 : transparent;
|
||||
accessible-role: AccessibleRole.tab;
|
||||
accessible-label: root.category-names[i];
|
||||
accessible-item-selectable: true;
|
||||
accessible-item-selected: Emoji.category == i;
|
||||
accessible-action-default => { Emoji.show-category(i); }
|
||||
cat := TouchArea {
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => {
|
||||
search.clear();
|
||||
Emoji.show-category(i);
|
||||
}
|
||||
}
|
||||
Icon {
|
||||
source: icon;
|
||||
size: Theme.icon-sm;
|
||||
tint: Emoji.category == i ? Theme.accent-text : Theme.icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: Emoji.category >= 0 ? root.category-names[Emoji.category] : Emoji.rows.length == 0 ? @tr("No emoji found") : @tr("Search results");
|
||||
font-size: Theme.font-sm;
|
||||
color: Theme.text-muted;
|
||||
font-weight: Theme.weight-semibold;
|
||||
}
|
||||
ListView {
|
||||
vertical-stretch: 1;
|
||||
for row in Emoji.rows: HorizontalLayout {
|
||||
height: root.cell;
|
||||
alignment: start;
|
||||
for cell in row.cells: EmojiButton {
|
||||
cell: cell;
|
||||
size: root.cell;
|
||||
picked(c) => { root.picked(c); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Theme } from "../theme.slint";
|
||||
|
||||
// A tinted icon from `Icons`.
|
||||
export component Icon inherits Image {
|
||||
in property <length> size: Theme.icon-md;
|
||||
in property <brush> tint: Theme.icon;
|
||||
width: size;
|
||||
height: size;
|
||||
colorize: tint;
|
||||
image-fit: contain;
|
||||
accessible-role: AccessibleRole.none;
|
||||
}
|
||||
|
||||
// A spinning indicator of work in progress: dots on a circle, one lit
|
||||
// after the other.
|
||||
export component Spinner inherits Rectangle {
|
||||
in property <length> size: 20px;
|
||||
in property <color> tint: Theme.accent-text;
|
||||
in property <bool> running: true;
|
||||
property <int> step;
|
||||
width: size;
|
||||
height: size;
|
||||
accessible-role: AccessibleRole.progress-indicator;
|
||||
accessible-label: @tr("Loading");
|
||||
Timer {
|
||||
interval: 90ms;
|
||||
running: root.running;
|
||||
triggered => { root.step = mod(root.step + 1, 8); }
|
||||
}
|
||||
for i in 8: Rectangle {
|
||||
property <angle> a: i * 45deg;
|
||||
property <length> dot: root.size / 5;
|
||||
x: root.size / 2 + (root.size / 2 - dot / 2) * cos(a) - dot / 2;
|
||||
y: root.size / 2 + (root.size / 2 - dot / 2) * sin(a) - dot / 2;
|
||||
width: dot;
|
||||
height: dot;
|
||||
border-radius: dot / 2;
|
||||
background: root.tint;
|
||||
opacity: mod(i - root.step + 8, 8) == 0 ? 1.0 : 0.15 + (8 - mod(root.step - i + 8, 8)) * 0.08;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// All components, for screens: import { Button, Card, ... } from "../components/index.slint";
|
||||
// The catalogue is in docs/ui.md.
|
||||
|
||||
export { Icon, Spinner } from "icon.slint";
|
||||
export { ButtonKind, FocusRing, Button, IconButton, ActionButton } from "button.slint";
|
||||
export { TextField, Kbd, SearchBox, Field } from "text-field.slint";
|
||||
export { Select } from "select.slint";
|
||||
export { Toggle, ToggleRow, RadioRow } from "toggle.slint";
|
||||
export { Slider } from "slider.slint";
|
||||
export { SegmentedTabs, TabItem } from "tabs.slint";
|
||||
export { Status, Avatar } from "avatar.slint";
|
||||
export { CountBadge, LiveBadge, Chip, Dot } from "badge.slint";
|
||||
export { SectionHeader, Card, Divider, Banner } from "card.slint";
|
||||
export { Meter, SpeakingBars } from "meter.slint";
|
||||
export { NavItem, ListItem } from "list-item.slint";
|
||||
export { MenuEntry, PopupMenu, Tooltip, Modal, Toast, ResizeHandle } from "overlay.slint";
|
||||
export { RichText, EmojiPicker } from "emoji.slint";
|
||||
// Virtualised lists and scrolling come from the standard widgets (styled by
|
||||
// the fluent-dark style); ListView builds only the visible rows.
|
||||
export { ListView, ScrollView } from "std-widgets.slint";
|
||||
@@ -0,0 +1,158 @@
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Icon } from "icon.slint";
|
||||
|
||||
// A navigation entry: icon, title, optional subtitle and count; the
|
||||
// selected one filled with the accent and ringed (settings navigation,
|
||||
// sidebar links).
|
||||
export component NavItem inherits Rectangle {
|
||||
in property <image> icon;
|
||||
in property <string> text;
|
||||
in property <string> subtitle;
|
||||
in property <bool> selected;
|
||||
in property <int> badge;
|
||||
// Show a chevron at the right (mobile lists).
|
||||
in property <bool> chevron;
|
||||
callback clicked();
|
||||
|
||||
min-height: subtitle != "" ? 52px * Theme.font-scale : 40px * Theme.font-scale;
|
||||
border-radius: Theme.radius-md;
|
||||
background: selected ? Theme.accent-soft : touch.has-hover ? Theme.surface-3 : transparent;
|
||||
border-width: selected ? 1px : 0px;
|
||||
border-color: Theme.accent;
|
||||
animate background { duration: Theme.fast; }
|
||||
accessible-role: AccessibleRole.list-item;
|
||||
accessible-label: text;
|
||||
accessible-description: subtitle;
|
||||
accessible-item-selectable: true;
|
||||
accessible-item-selected: selected;
|
||||
accessible-action-default => { clicked(); }
|
||||
|
||||
touch := TouchArea {
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => { root.clicked(); }
|
||||
}
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-4;
|
||||
padding-right: Theme.space-3;
|
||||
spacing: Theme.space-4;
|
||||
if root.icon.width > 0: Icon {
|
||||
source: root.icon;
|
||||
size: root.subtitle != "" ? Theme.icon-lg : Theme.icon-md;
|
||||
tint: root.selected ? Theme.text : Theme.icon;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
Text {
|
||||
text: root.text;
|
||||
color: root.selected ? Theme.text : Theme.text;
|
||||
font-weight: root.selected ? Theme.weight-semibold : Theme.weight-medium;
|
||||
font-size: Theme.font-body;
|
||||
overflow: elide;
|
||||
}
|
||||
if root.subtitle != "": Text {
|
||||
text: root.subtitle;
|
||||
color: root.selected ? Theme.text-secondary : Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
if root.badge > 0: VerticalLayout {
|
||||
alignment: center;
|
||||
Rectangle {
|
||||
min-width: 18px;
|
||||
height: 18px;
|
||||
border-radius: 9px;
|
||||
background: Theme.live;
|
||||
HorizontalLayout {
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
Text {
|
||||
text: root.badge > 99 ? "99+" : root.badge;
|
||||
color: #ffffff;
|
||||
font-size: Theme.font-xs;
|
||||
font-weight: Theme.weight-bold;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if root.chevron: Icon {
|
||||
source: Icons.chevron-right;
|
||||
size: Theme.icon-sm;
|
||||
tint: Theme.text-muted;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A list row: a leading slot (@children, e.g. an Avatar), title and
|
||||
// subtitle, and trailing text. For lists of people, conversations, sources.
|
||||
export component ListItem inherits Rectangle {
|
||||
in property <string> title;
|
||||
in property <string> subtitle;
|
||||
in property <color> title-color: Theme.text;
|
||||
in property <color> subtitle-color: Theme.text-muted;
|
||||
in property <string> trailing;
|
||||
in property <bool> selected;
|
||||
in property <bool> interactive: true;
|
||||
in property <length> leading-width: 36px;
|
||||
callback clicked();
|
||||
callback double-clicked();
|
||||
|
||||
min-height: 44px * Theme.font-scale;
|
||||
border-radius: Theme.radius-md;
|
||||
background: selected ? Theme.accent-soft : touch.has-hover && interactive ? Theme.surface-3 : transparent;
|
||||
border-width: selected ? 1px : 0px;
|
||||
border-color: Theme.accent;
|
||||
accessible-role: AccessibleRole.list-item;
|
||||
accessible-label: title;
|
||||
accessible-description: subtitle;
|
||||
accessible-item-selectable: interactive;
|
||||
accessible-item-selected: selected;
|
||||
accessible-action-default => { clicked(); }
|
||||
|
||||
touch := TouchArea {
|
||||
enabled: root.interactive;
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => { root.clicked(); }
|
||||
double-clicked => { root.double-clicked(); }
|
||||
}
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-3;
|
||||
padding-right: Theme.space-3;
|
||||
padding-top: Theme.space-2;
|
||||
padding-bottom: Theme.space-2;
|
||||
spacing: Theme.space-4;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
width: root.leading-width;
|
||||
@children
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
Text {
|
||||
text: root.title;
|
||||
color: root.title-color;
|
||||
font-weight: Theme.weight-medium;
|
||||
overflow: elide;
|
||||
}
|
||||
if root.subtitle != "": Text {
|
||||
text: root.subtitle;
|
||||
color: root.subtitle-color;
|
||||
font-size: Theme.font-sm;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
if root.trailing != "": Text {
|
||||
text: root.trailing;
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-xs;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import { Theme } from "../theme.slint";
|
||||
|
||||
// The segmented audio level meter: green, then yellow, red at the top; unlit
|
||||
// segments dim. `level` is dBFS; an optional threshold marker (voice
|
||||
// activation).
|
||||
export component Meter inherits Rectangle {
|
||||
in property <float> level: -100;
|
||||
in property <float> threshold: -40;
|
||||
in property <bool> show-threshold;
|
||||
// Dimmed while nothing is sent.
|
||||
in property <bool> active: true;
|
||||
in property <int> segments: 20;
|
||||
// dBFS at the left edge.
|
||||
in property <float> floor: -70;
|
||||
in property <length> gap: 3px;
|
||||
|
||||
property <float> lit: clamp((level - floor) / (0 - floor), 0, 1) * segments;
|
||||
|
||||
height: 10px;
|
||||
min-width: 80px;
|
||||
horizontal-stretch: 1;
|
||||
accessible-role: AccessibleRole.progress-indicator;
|
||||
accessible-label: @tr("Microphone level");
|
||||
accessible-value: @tr("{} dB", round(level));
|
||||
accessible-value-minimum: floor;
|
||||
accessible-value-maximum: 0;
|
||||
|
||||
for i in root.segments: Rectangle {
|
||||
property <float> part: i / root.segments;
|
||||
x: i * (root.width + root.gap) / root.segments;
|
||||
width: (root.width + root.gap) / root.segments - root.gap;
|
||||
border-radius: 2px;
|
||||
background: i < root.lit
|
||||
? (part >= 0.9 ? Theme.meter-high : part >= 0.7 ? Theme.meter-mid : Theme.meter-low).transparentize(root.active ? 0 : 0.45)
|
||||
: Theme.meter-off;
|
||||
}
|
||||
if root.show-threshold: Rectangle {
|
||||
x: root.width * clamp((root.threshold - root.floor) / (0 - root.floor), 0, 1) - 1px;
|
||||
y: -3px;
|
||||
width: 2px;
|
||||
height: root.height + 6px;
|
||||
border-radius: 1px;
|
||||
background: Theme.text;
|
||||
}
|
||||
}
|
||||
|
||||
// Three bars that move while someone speaks (the "speaking" glyph).
|
||||
export component SpeakingBars inherits Rectangle {
|
||||
in property <bool> active: true;
|
||||
in property <color> tint: Theme.success;
|
||||
property <int> phase;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
Timer {
|
||||
interval: 160ms;
|
||||
running: root.active;
|
||||
triggered => { root.phase = mod(root.phase + 1, 4); }
|
||||
}
|
||||
for i in 3: Rectangle {
|
||||
property <float> h: !root.active ? 0.35 : mod(i + root.phase, 4) == 0 ? 1.0 : mod(i + root.phase, 4) == 1 ? 0.6 : mod(i + root.phase, 4) == 2 ? 0.8 : 0.45;
|
||||
x: i * 5px;
|
||||
y: root.height * (1 - h) / 2;
|
||||
width: 3px;
|
||||
height: root.height * h;
|
||||
border-radius: 1.5px;
|
||||
background: root.tint;
|
||||
animate height, y { duration: 140ms; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
// Floating things: menus, tooltips, modal dialogs, toasts, the resize
|
||||
// handle of side panels.
|
||||
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Icon } from "icon.slint";
|
||||
import { IconButton } from "button.slint";
|
||||
|
||||
// An entry of a `PopupMenu`.
|
||||
export struct MenuEntry {
|
||||
text: string,
|
||||
icon: image,
|
||||
// Red (leave, delete).
|
||||
danger: bool,
|
||||
enabled: bool,
|
||||
// A line above this entry.
|
||||
separator: bool,
|
||||
}
|
||||
|
||||
// A themed menu: open with `show(x, y)` (relative to the element that
|
||||
// contains it); `activated(index)` when an entry is chosen. For right-click
|
||||
// menus wrap a `TouchArea` and call `show` on `pointer-event` of the right
|
||||
// button.
|
||||
export component PopupMenu inherits Rectangle {
|
||||
in property <[MenuEntry]> entries;
|
||||
in property <length> menu-width: 220px;
|
||||
callback activated(int);
|
||||
property <length> px;
|
||||
property <length> py;
|
||||
property <length> row-height: Theme.control-height;
|
||||
|
||||
public function show(x: length, y: length) {
|
||||
px = x;
|
||||
py = y;
|
||||
popup.show();
|
||||
}
|
||||
|
||||
width: 0;
|
||||
height: 0;
|
||||
popup := PopupWindow {
|
||||
x: root.px;
|
||||
y: root.py;
|
||||
width: root.menu-width;
|
||||
close-policy: PopupClosePolicy.close-on-click-outside;
|
||||
Rectangle {
|
||||
border-radius: Theme.radius-md;
|
||||
background: Theme.surface-3;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border-strong;
|
||||
accessible-role: AccessibleRole.list;
|
||||
VerticalLayout {
|
||||
padding: Theme.space-2;
|
||||
for entry[i] in root.entries: VerticalLayout {
|
||||
if entry.separator: Rectangle {
|
||||
height: 9px;
|
||||
Rectangle {
|
||||
height: 1px;
|
||||
background: Theme.border;
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
height: root.row-height;
|
||||
border-radius: Theme.radius-sm;
|
||||
background: item.has-hover && entry.enabled ? (entry.danger ? Theme.danger-soft : Theme.surface-4) : transparent;
|
||||
opacity: entry.enabled ? 1.0 : 0.5;
|
||||
accessible-role: AccessibleRole.button;
|
||||
accessible-label: entry.text;
|
||||
accessible-enabled: entry.enabled;
|
||||
accessible-action-default => {
|
||||
root.activated(i);
|
||||
popup.close();
|
||||
}
|
||||
item := TouchArea {
|
||||
enabled: entry.enabled;
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => {
|
||||
root.activated(i);
|
||||
popup.close();
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-3;
|
||||
padding-right: Theme.space-3;
|
||||
spacing: Theme.space-3;
|
||||
if entry.icon.width > 0: Icon {
|
||||
source: entry.icon;
|
||||
size: Theme.icon-sm;
|
||||
tint: entry.danger ? Theme.danger : Theme.icon;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: entry.text;
|
||||
color: entry.danger ? Theme.danger : Theme.text;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Hover help: wraps @children and shows `text` in a bubble after a moment.
|
||||
export component Tooltip inherits Rectangle {
|
||||
in property <string> text;
|
||||
// Above (default) or below the element.
|
||||
in property <bool> below;
|
||||
area := TouchArea {
|
||||
@children
|
||||
}
|
||||
Timer {
|
||||
interval: 600ms;
|
||||
running: area.has-hover && root.text != "";
|
||||
triggered => {
|
||||
self.running = false;
|
||||
bubble.show();
|
||||
}
|
||||
}
|
||||
bubble := PopupWindow {
|
||||
x: (root.width - self.width) / 2;
|
||||
y: root.below ? root.height + 6px : -self.height - 6px;
|
||||
width: label.preferred-width + 20px;
|
||||
height: label.preferred-height + 12px;
|
||||
close-policy: PopupClosePolicy.close-on-click-outside;
|
||||
Rectangle {
|
||||
border-radius: Theme.radius-sm;
|
||||
background: Theme.surface-4;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border-strong;
|
||||
label := Text {
|
||||
text: root.text;
|
||||
color: Theme.text;
|
||||
font-size: Theme.font-sm;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A modal dialog: a dimmed backdrop and a card with a title, a close button,
|
||||
// the content (@children) and usually a footer row inside the content.
|
||||
// Clicking the backdrop or Escape dismisses it.
|
||||
export component Modal inherits Rectangle {
|
||||
in property <string> title;
|
||||
in property <string> subtitle;
|
||||
in property <image> icon;
|
||||
// Tint the icon with the accent (off for full-colour images).
|
||||
in property <bool> tint-icon: true;
|
||||
in property <length> card-width: 520px;
|
||||
in property <length> card-height: 520px;
|
||||
callback dismissed();
|
||||
|
||||
background: Theme.scrim;
|
||||
accessible-role: AccessibleRole.none;
|
||||
TouchArea {
|
||||
clicked => { root.dismissed(); }
|
||||
}
|
||||
FocusScope {
|
||||
key-pressed(event) => {
|
||||
if event.text == Key.Escape {
|
||||
root.dismissed();
|
||||
return accept;
|
||||
}
|
||||
reject
|
||||
}
|
||||
}
|
||||
card := Rectangle {
|
||||
width: min(root.width - 32px, root.card-width);
|
||||
height: min(root.height - 32px, root.card-height);
|
||||
background: Theme.surface;
|
||||
border-radius: Theme.radius-xl;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border-strong;
|
||||
accessible-role: AccessibleRole.groupbox;
|
||||
accessible-label: root.title;
|
||||
// Clicks inside the card do not dismiss it.
|
||||
TouchArea { }
|
||||
// A faint accent line along the top edge.
|
||||
Rectangle {
|
||||
y: 0;
|
||||
x: Theme.radius-xl;
|
||||
width: parent.width - 2 * Theme.radius-xl;
|
||||
height: 1px;
|
||||
background: @linear-gradient(90deg, transparent 0%, Theme.accent 50%, transparent 100%);
|
||||
}
|
||||
VerticalLayout {
|
||||
padding: Theme.space-6;
|
||||
spacing: Theme.space-5;
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-4;
|
||||
if root.icon.width > 0: Rectangle {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: Theme.radius-md;
|
||||
background: Theme.accent-soft;
|
||||
if root.tint-icon: Icon {
|
||||
source: root.icon;
|
||||
tint: Theme.accent-text;
|
||||
}
|
||||
if !root.tint-icon: Image {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
source: root.icon;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
Text {
|
||||
text: root.title;
|
||||
font-size: Theme.font-xl;
|
||||
font-weight: Theme.weight-semibold;
|
||||
color: Theme.text;
|
||||
overflow: elide;
|
||||
}
|
||||
if root.subtitle != "": Text {
|
||||
text: root.subtitle;
|
||||
font-size: Theme.font-sm;
|
||||
color: Theme.text-muted;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
IconButton {
|
||||
icon: Icons.x;
|
||||
label: @tr("Close");
|
||||
size: 32px;
|
||||
clicked => { root.dismissed(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@children
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A short message at the bottom of the window that hides itself.
|
||||
export component Toast inherits Rectangle {
|
||||
in property <string> text;
|
||||
in property <image> icon: Icons.info;
|
||||
in property <duration> timeout: 5s;
|
||||
in-out property <bool> shown;
|
||||
height: shown ? row.preferred-height + 16px : 0px;
|
||||
width: min(row.preferred-width + 24px, 560px);
|
||||
visible: shown;
|
||||
border-radius: Theme.radius-lg;
|
||||
background: Theme.surface-3;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border-strong;
|
||||
accessible-role: AccessibleRole.text;
|
||||
accessible-label: text;
|
||||
accessible-live-region: polite;
|
||||
Timer {
|
||||
interval: root.timeout;
|
||||
running: root.shown;
|
||||
triggered => { root.shown = false; }
|
||||
}
|
||||
TouchArea {
|
||||
clicked => { root.shown = false; }
|
||||
}
|
||||
row := HorizontalLayout {
|
||||
padding-left: Theme.space-4;
|
||||
padding-right: Theme.space-4;
|
||||
spacing: Theme.space-3;
|
||||
Icon {
|
||||
source: root.icon;
|
||||
size: Theme.icon-sm;
|
||||
tint: Theme.accent-text;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: root.text;
|
||||
color: Theme.text;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A vertical grip between panels: drag to resize. `size` is the width of
|
||||
// the panel on the `left` or right side of the handle, kept within bounds.
|
||||
export component ResizeHandle inherits Rectangle {
|
||||
in-out property <length> size;
|
||||
in property <length> minimum: 160px;
|
||||
in property <length> maximum: 600px;
|
||||
// The panel is left of the handle (dragging right grows it).
|
||||
in property <bool> left;
|
||||
width: 8px;
|
||||
horizontal-stretch: 0;
|
||||
accessible-role: AccessibleRole.slider;
|
||||
accessible-label: @tr("Panel width");
|
||||
accessible-value: round(size / 1px);
|
||||
accessible-action-increment => { size = min(maximum, size + 16px); }
|
||||
accessible-action-decrement => { size = max(minimum, size - 16px); }
|
||||
Rectangle {
|
||||
width: 2px;
|
||||
height: 36px;
|
||||
border-radius: 1px;
|
||||
background: touch.has-hover || touch.pressed ? Theme.accent : Theme.border-strong;
|
||||
}
|
||||
// The handle moves with the edge, so each move adds the distance from
|
||||
// where it was pressed.
|
||||
touch := TouchArea {
|
||||
mouse-cursor: MouseCursor.col-resize;
|
||||
moved => {
|
||||
if self.pressed {
|
||||
root.size = clamp(root.size + (root.left ? 1 : -1) * (self.mouse-x - self.pressed-x), root.minimum, root.maximum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Icon } from "icon.slint";
|
||||
import { FocusRing } from "button.slint";
|
||||
import { ScrollView } from "std-widgets.slint";
|
||||
|
||||
// A drop-down choice (ComboBox). Bind `current-index` (and read
|
||||
// `current-value`), or bind `current-value` two-way for a string choice.
|
||||
export component Select inherits Rectangle {
|
||||
in property <[string]> model;
|
||||
in-out property <int> current-index: 0;
|
||||
in-out property <string> current-value;
|
||||
in property <bool> enabled: true;
|
||||
in property <image> icon;
|
||||
in property <string> label;
|
||||
in property <string> placeholder;
|
||||
callback selected(string);
|
||||
|
||||
property <length> row-height: Theme.control-height;
|
||||
|
||||
function pick(i: int) {
|
||||
current-index = i;
|
||||
current-value = model[i];
|
||||
selected(current-value);
|
||||
}
|
||||
|
||||
init => {
|
||||
if current-value == "" && current-index >= 0 && current-index < model.length {
|
||||
current-value = model[current-index];
|
||||
}
|
||||
}
|
||||
changed current-index => {
|
||||
if current-index >= 0 && current-index < model.length {
|
||||
current-value = model[current-index];
|
||||
}
|
||||
}
|
||||
changed model => {
|
||||
if current-index >= 0 && current-index < model.length {
|
||||
current-value = model[current-index];
|
||||
}
|
||||
}
|
||||
|
||||
min-width: 80px;
|
||||
min-height: Theme.control-height;
|
||||
max-height: Theme.control-height;
|
||||
horizontal-stretch: 1;
|
||||
vertical-stretch: 0;
|
||||
border-radius: Theme.radius-md;
|
||||
background: touch.has-hover ? Theme.surface-3 : Theme.surface-2;
|
||||
border-width: 1px;
|
||||
border-color: focus.has-focus ? Theme.accent : Theme.border;
|
||||
opacity: enabled ? 1.0 : 0.6;
|
||||
|
||||
accessible-role: AccessibleRole.combobox;
|
||||
accessible-label: label;
|
||||
accessible-value: current-value;
|
||||
accessible-enabled: enabled;
|
||||
accessible-expandable: true;
|
||||
accessible-action-default => { popup.show(); }
|
||||
|
||||
FocusRing {
|
||||
shown: focus.has-focus;
|
||||
w: root.width;
|
||||
h: root.height;
|
||||
}
|
||||
focus := FocusScope {
|
||||
enabled: root.enabled;
|
||||
key-pressed(event) => {
|
||||
if event.text == Key.UpArrow && root.current-index > 0 {
|
||||
root.pick(root.current-index - 1);
|
||||
return accept;
|
||||
}
|
||||
if event.text == Key.DownArrow && root.current-index < root.model.length - 1 {
|
||||
root.pick(root.current-index + 1);
|
||||
return accept;
|
||||
}
|
||||
if event.text == " " || event.text == "\n" {
|
||||
popup.show();
|
||||
return accept;
|
||||
}
|
||||
reject
|
||||
}
|
||||
touch := TouchArea {
|
||||
enabled: root.enabled;
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => {
|
||||
focus.focus();
|
||||
popup.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-4;
|
||||
padding-right: Theme.space-3;
|
||||
spacing: Theme.space-3;
|
||||
if icon.width > 0: Icon {
|
||||
source: icon;
|
||||
size: Theme.icon-sm;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: root.current-value != "" ? root.current-value : root.placeholder;
|
||||
color: root.current-value != "" ? Theme.text : Theme.text-muted;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
overflow: elide;
|
||||
}
|
||||
Icon {
|
||||
source: Icons.chevron-down;
|
||||
size: Theme.icon-sm;
|
||||
tint: Theme.text-secondary;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
popup := PopupWindow {
|
||||
x: 0;
|
||||
y: root.height + 4px;
|
||||
width: root.width;
|
||||
height: min(root.model.length * root.row-height + 2 * Theme.space-2 + 2px, 320px);
|
||||
close-policy: PopupClosePolicy.close-on-click-outside;
|
||||
Rectangle {
|
||||
border-radius: Theme.radius-md;
|
||||
background: Theme.surface-3;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border-strong;
|
||||
clip: true;
|
||||
ScrollView {
|
||||
VerticalLayout {
|
||||
padding: Theme.space-2;
|
||||
for item[i] in root.model: Rectangle {
|
||||
height: root.row-height;
|
||||
border-radius: Theme.radius-sm;
|
||||
background: i == root.current-index ? Theme.accent-soft : item-touch.has-hover ? Theme.surface-4 : transparent;
|
||||
accessible-role: AccessibleRole.list-item;
|
||||
accessible-label: item;
|
||||
accessible-item-selectable: true;
|
||||
accessible-item-selected: i == root.current-index;
|
||||
accessible-action-default => {
|
||||
root.pick(i);
|
||||
popup.close();
|
||||
}
|
||||
item-touch := TouchArea {
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => {
|
||||
root.pick(i);
|
||||
popup.close();
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-3;
|
||||
padding-right: Theme.space-3;
|
||||
Text {
|
||||
text: item;
|
||||
color: i == root.current-index ? Theme.text : Theme.text-secondary;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import { Theme } from "../theme.slint";
|
||||
|
||||
// A horizontal slider: blue track and a round knob. `changed` fires while
|
||||
// dragging, `released` at the end.
|
||||
export component Slider inherits Rectangle {
|
||||
in-out property <float> value;
|
||||
in property <float> minimum: 0;
|
||||
in property <float> maximum: 100;
|
||||
// Arrow keys move by this much.
|
||||
in property <float> step: 1;
|
||||
in property <bool> enabled: true;
|
||||
in property <string> label;
|
||||
callback changed(float);
|
||||
callback released(float);
|
||||
|
||||
property <length> knob-size: 16px;
|
||||
property <float> ratio: maximum > minimum ? clamp((value - minimum) / (maximum - minimum), 0, 1) : 0;
|
||||
|
||||
function set(v: float) {
|
||||
let clamped = clamp(v, minimum, maximum);
|
||||
if clamped != value {
|
||||
value = clamped;
|
||||
changed(clamped);
|
||||
}
|
||||
}
|
||||
|
||||
min-width: 80px;
|
||||
height: 24px;
|
||||
horizontal-stretch: 1;
|
||||
vertical-stretch: 0;
|
||||
opacity: enabled ? 1.0 : 0.45;
|
||||
|
||||
accessible-role: AccessibleRole.slider;
|
||||
accessible-label: label;
|
||||
accessible-value: round(value);
|
||||
accessible-value-minimum: minimum;
|
||||
accessible-value-maximum: maximum;
|
||||
accessible-value-step: step;
|
||||
accessible-enabled: enabled;
|
||||
accessible-action-increment => { set(value + step); }
|
||||
accessible-action-decrement => { set(value - step); }
|
||||
|
||||
track := Rectangle {
|
||||
x: knob-size / 2;
|
||||
width: parent.width - knob-size;
|
||||
height: 6px;
|
||||
border-radius: 3px;
|
||||
background: Theme.meter-off;
|
||||
Rectangle {
|
||||
x: 0;
|
||||
width: parent.width * root.ratio;
|
||||
height: 100%;
|
||||
border-radius: 3px;
|
||||
background: Theme.accent;
|
||||
}
|
||||
}
|
||||
knob := Rectangle {
|
||||
x: track.x + track.width * root.ratio - self.width / 2;
|
||||
width: knob-size;
|
||||
height: knob-size;
|
||||
border-radius: knob-size / 2;
|
||||
background: #ffffff;
|
||||
border-width: focus.has-focus || touch.pressed ? 3px : 2px;
|
||||
border-color: Theme.accent;
|
||||
}
|
||||
focus := FocusScope {
|
||||
enabled: root.enabled;
|
||||
key-pressed(event) => {
|
||||
if event.text == Key.RightArrow || event.text == Key.UpArrow {
|
||||
root.set(root.value + root.step);
|
||||
root.released(root.value);
|
||||
return accept;
|
||||
}
|
||||
if event.text == Key.LeftArrow || event.text == Key.DownArrow {
|
||||
root.set(root.value - root.step);
|
||||
root.released(root.value);
|
||||
return accept;
|
||||
}
|
||||
reject
|
||||
}
|
||||
touch := TouchArea {
|
||||
enabled: root.enabled;
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
property <float> start-value;
|
||||
pointer-event(e) => {
|
||||
if e.button == PointerEventButton.left && e.kind == PointerEventKind.down {
|
||||
focus.focus();
|
||||
root.set(root.minimum + (self.mouse-x - track.x) / max(track.width, 1px) * (root.maximum - root.minimum));
|
||||
self.start-value = root.value;
|
||||
} else if e.kind == PointerEventKind.up {
|
||||
root.released(root.value);
|
||||
}
|
||||
}
|
||||
moved => {
|
||||
if self.pressed && root.enabled {
|
||||
root.set(self.start-value + (self.mouse-x - self.pressed-x) / max(track.width, 1px) * (root.maximum - root.minimum));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import { Theme } from "../theme.slint";
|
||||
|
||||
// Choices side by side in a rounded frame; the selected one filled
|
||||
// ("All | DMs | Groups", "Auto | 720p | 1080p").
|
||||
export component SegmentedTabs inherits Rectangle {
|
||||
in property <[string]> model;
|
||||
in-out property <int> current-index;
|
||||
in property <string> label;
|
||||
callback selected(int);
|
||||
|
||||
min-height: Theme.control-height;
|
||||
horizontal-stretch: 1;
|
||||
vertical-stretch: 0;
|
||||
border-radius: Theme.radius-md;
|
||||
background: Theme.surface-2;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border;
|
||||
accessible-role: AccessibleRole.tab-list;
|
||||
accessible-label: label;
|
||||
|
||||
HorizontalLayout {
|
||||
padding: 3px;
|
||||
spacing: 3px;
|
||||
for item[i] in root.model: Rectangle {
|
||||
horizontal-stretch: 1;
|
||||
border-radius: Theme.radius-sm;
|
||||
background: i == root.current-index ? Theme.accent-soft : seg.has-hover ? Theme.surface-3 : transparent;
|
||||
border-width: i == root.current-index ? 1px : 0px;
|
||||
border-color: Theme.accent;
|
||||
accessible-role: AccessibleRole.tab;
|
||||
accessible-label: item;
|
||||
accessible-item-selectable: true;
|
||||
accessible-item-selected: i == root.current-index;
|
||||
accessible-action-default => {
|
||||
root.current-index = i;
|
||||
root.selected(i);
|
||||
}
|
||||
seg := TouchArea {
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => {
|
||||
root.current-index = i;
|
||||
root.selected(i);
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: item;
|
||||
color: i == root.current-index ? Theme.text : Theme.text-secondary;
|
||||
font-weight: i == root.current-index ? Theme.weight-semibold : Theme.weight-regular;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// One tab of a `TabBar`: a label with an underline when selected, and an
|
||||
// optional unread count and close button.
|
||||
export component TabItem inherits Rectangle {
|
||||
in property <string> text;
|
||||
in property <bool> selected;
|
||||
in property <int> badge;
|
||||
in property <bool> closable;
|
||||
callback clicked();
|
||||
callback close();
|
||||
|
||||
min-width: row.preferred-width;
|
||||
height: Theme.control-height + 4px;
|
||||
accessible-role: AccessibleRole.tab;
|
||||
accessible-label: text;
|
||||
accessible-description: badge > 0 ? @tr("{} unread", badge) : "";
|
||||
accessible-item-selectable: true;
|
||||
accessible-item-selected: selected;
|
||||
accessible-action-default => { clicked(); }
|
||||
|
||||
area := TouchArea {
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => { root.clicked(); }
|
||||
}
|
||||
Rectangle {
|
||||
y: parent.height - 2px;
|
||||
height: 2px;
|
||||
border-radius: 1px;
|
||||
background: root.selected ? Theme.accent : transparent;
|
||||
}
|
||||
row := HorizontalLayout {
|
||||
padding-left: Theme.space-4;
|
||||
padding-right: root.closable ? Theme.space-2 : Theme.space-4;
|
||||
spacing: Theme.space-2;
|
||||
Text {
|
||||
text: root.text;
|
||||
color: root.selected ? Theme.text : area.has-hover ? Theme.text : Theme.text-secondary;
|
||||
font-weight: root.selected || root.badge > 0 ? Theme.weight-semibold : Theme.weight-regular;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
if root.badge > 0: VerticalLayout {
|
||||
alignment: center;
|
||||
Rectangle {
|
||||
min-width: 18px;
|
||||
height: 18px;
|
||||
border-radius: 9px;
|
||||
background: Theme.live;
|
||||
HorizontalLayout {
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
Text {
|
||||
text: root.badge > 99 ? "99+" : root.badge;
|
||||
color: #ffffff;
|
||||
font-size: Theme.font-xs;
|
||||
font-weight: Theme.weight-bold;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if root.closable: Rectangle {
|
||||
width: 20px;
|
||||
border-radius: Theme.radius-xs;
|
||||
background: close-area.has-hover ? Theme.surface-3 : transparent;
|
||||
accessible-role: AccessibleRole.button;
|
||||
accessible-label: @tr("Close {}", root.text);
|
||||
accessible-action-default => { root.close(); }
|
||||
close-area := TouchArea {
|
||||
clicked => { root.close(); }
|
||||
}
|
||||
Text {
|
||||
text: "×";
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-lg;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Icon } from "icon.slint";
|
||||
|
||||
// A single-line text input on a surface, with an optional leading icon.
|
||||
export component TextField inherits Rectangle {
|
||||
in-out property <string> text <=> input.text;
|
||||
in property <string> placeholder;
|
||||
in property <InputType> input-type: InputType.text;
|
||||
in property <bool> enabled <=> input.enabled;
|
||||
in property <bool> read-only <=> input.read-only;
|
||||
in property <image> icon;
|
||||
// For screen readers; defaults to the placeholder.
|
||||
in property <string> label: placeholder;
|
||||
in property <length> font-size: Theme.font-body;
|
||||
// Drawn without its own background and border (inside a composer).
|
||||
in property <bool> bare;
|
||||
out property <bool> has-focus: input.has-focus;
|
||||
callback accepted(string);
|
||||
callback edited(string);
|
||||
callback key-pressed(KeyEvent) -> EventResult;
|
||||
|
||||
public function clear() {
|
||||
input.text = "";
|
||||
}
|
||||
|
||||
public function select-all() {
|
||||
input.select-all();
|
||||
}
|
||||
|
||||
property <length> margin: Theme.space-2;
|
||||
|
||||
min-width: 60px;
|
||||
min-height: Theme.control-height;
|
||||
max-height: bare ? 1000px : Theme.control-height + 8px;
|
||||
horizontal-stretch: 1;
|
||||
vertical-stretch: 0;
|
||||
border-radius: Theme.radius-md;
|
||||
background: bare ? transparent : Theme.surface-2;
|
||||
border-width: bare ? 0px : 1px;
|
||||
border-color: input.has-focus ? Theme.accent : touch.has-hover ? Theme.border-strong : Theme.border;
|
||||
opacity: enabled ? 1.0 : 0.6;
|
||||
forward-focus: input;
|
||||
accessible-role: AccessibleRole.text-input;
|
||||
accessible-label: label;
|
||||
accessible-value: input-type == InputType.password ? "" : text;
|
||||
accessible-placeholder-text: placeholder;
|
||||
accessible-enabled: enabled;
|
||||
accessible-read-only: read-only;
|
||||
accessible-action-set-value(v) => { text = v; edited(v); }
|
||||
|
||||
touch := TouchArea {
|
||||
mouse-cursor: MouseCursor.text;
|
||||
clicked => { input.focus(); }
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
padding-left: bare ? 0px : Theme.space-4;
|
||||
padding-right: bare ? 0px : Theme.space-4;
|
||||
spacing: Theme.space-3;
|
||||
if icon.width > 0: Icon {
|
||||
source: icon;
|
||||
size: Theme.icon-sm;
|
||||
tint: Theme.text-muted;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Rectangle {
|
||||
clip: true;
|
||||
horizontal-stretch: 1;
|
||||
placeholder-text := Text {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
vertical-alignment: center;
|
||||
text: root.text == "" && input.preedit-text == "" ? root.placeholder : "";
|
||||
font-size: root.font-size;
|
||||
color: Theme.text-muted;
|
||||
overflow: elide;
|
||||
accessible-role: AccessibleRole.none;
|
||||
}
|
||||
ContextMenuArea {
|
||||
enabled: root.enabled;
|
||||
Menu {
|
||||
MenuItem {
|
||||
title: @tr("Cut");
|
||||
enabled: !root.read-only && root.enabled;
|
||||
activated => { input.cut(); }
|
||||
}
|
||||
MenuItem {
|
||||
title: @tr("Copy");
|
||||
enabled: root.text != "";
|
||||
activated => { input.copy(); }
|
||||
}
|
||||
MenuItem {
|
||||
title: @tr("Paste");
|
||||
enabled: !root.read-only && root.enabled;
|
||||
activated => { input.paste(); }
|
||||
}
|
||||
MenuItem {
|
||||
title: @tr("Select All");
|
||||
enabled: root.text != "";
|
||||
activated => { input.select-all(); }
|
||||
}
|
||||
}
|
||||
input := TextInput {
|
||||
property <length> computed-x;
|
||||
x: min(0px, max(parent.width - self.width - self.text-cursor-width, self.computed-x));
|
||||
width: max(parent.width - self.text-cursor-width, self.preferred-width);
|
||||
height: 100%;
|
||||
vertical-alignment: center;
|
||||
single-line: true;
|
||||
color: Theme.text;
|
||||
font-size: root.font-size;
|
||||
selection-background-color: Theme.accent-soft;
|
||||
selection-foreground-color: Theme.text;
|
||||
input-type: root.input-type;
|
||||
accessible-role: AccessibleRole.none;
|
||||
cursor-position-changed(pos) => {
|
||||
if pos.x + self.computed-x < root.margin {
|
||||
self.computed-x = - pos.x + root.margin;
|
||||
} else if pos.x + self.computed-x > parent.width - root.margin - self.text-cursor-width {
|
||||
self.computed-x = parent.width - pos.x - root.margin - self.text-cursor-width;
|
||||
}
|
||||
}
|
||||
accepted => { root.accepted(self.text); }
|
||||
edited => { root.edited(self.text); }
|
||||
key-pressed(event) => { root.key-pressed(event) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@children
|
||||
}
|
||||
}
|
||||
|
||||
// A key cap ("Ctrl", "K").
|
||||
export component Kbd inherits Rectangle {
|
||||
in property <string> text;
|
||||
min-width: 20px;
|
||||
height: 20px;
|
||||
border-radius: Theme.radius-xs;
|
||||
background: Theme.surface-3;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border-strong;
|
||||
HorizontalLayout {
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
Text {
|
||||
text: root.text;
|
||||
font-size: Theme.font-xs;
|
||||
color: Theme.text-secondary;
|
||||
vertical-alignment: center;
|
||||
horizontal-alignment: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The search field of the top bar: a magnifier, and the Ctrl K hint while
|
||||
// empty. Ctrl+K is bound by the shell (focus()).
|
||||
export component SearchBox inherits TextField {
|
||||
in property <bool> show-shortcut: true;
|
||||
icon: Icons.search;
|
||||
border-radius: Theme.radius-md;
|
||||
background: Theme.surface-2.transparentize(0.2);
|
||||
if show-shortcut && root.text == "" && !root.has-focus: VerticalLayout {
|
||||
alignment: center;
|
||||
HorizontalLayout {
|
||||
spacing: 3px;
|
||||
Kbd { text: "Ctrl"; }
|
||||
Kbd { text: "K"; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A form row: a label above (or beside) a control, with an optional hint.
|
||||
export component Field inherits VerticalLayout {
|
||||
in property <string> label;
|
||||
in property <string> hint;
|
||||
spacing: Theme.space-2;
|
||||
if label != "": Text {
|
||||
text: root.label;
|
||||
font-size: Theme.font-sm;
|
||||
color: Theme.text-secondary;
|
||||
font-weight: Theme.weight-medium;
|
||||
}
|
||||
@children
|
||||
if hint != "": Text {
|
||||
text: root.hint;
|
||||
font-size: Theme.font-xs;
|
||||
color: Theme.text-muted;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icon } from "icon.slint";
|
||||
import { FocusRing } from "button.slint";
|
||||
|
||||
// The pill switch.
|
||||
export component Toggle inherits Rectangle {
|
||||
in-out property <bool> checked;
|
||||
in property <bool> enabled: true;
|
||||
in property <string> label;
|
||||
callback toggled(bool);
|
||||
|
||||
function flip() {
|
||||
if enabled {
|
||||
checked = !checked;
|
||||
toggled(checked);
|
||||
}
|
||||
}
|
||||
|
||||
width: 44px;
|
||||
height: 24px;
|
||||
border-radius: self.height / 2;
|
||||
background: checked ? (touch.has-hover ? Theme.accent-hover : Theme.accent) : (touch.has-hover ? Theme.surface-4 : Theme.surface-3);
|
||||
border-width: 1px;
|
||||
border-color: checked ? Theme.accent-hover : Theme.border-strong;
|
||||
opacity: enabled ? 1.0 : 0.5;
|
||||
animate background { duration: Theme.fast; }
|
||||
|
||||
accessible-role: AccessibleRole.switch;
|
||||
accessible-label: label;
|
||||
accessible-checkable: true;
|
||||
accessible-checked: checked;
|
||||
accessible-enabled: enabled;
|
||||
accessible-action-default => { flip(); }
|
||||
|
||||
FocusRing {
|
||||
shown: focus.has-focus;
|
||||
radius: root.border-radius;
|
||||
w: root.width;
|
||||
h: root.height;
|
||||
}
|
||||
focus := FocusScope {
|
||||
enabled: root.enabled;
|
||||
key-pressed(event) => {
|
||||
if event.text == " " || event.text == "\n" {
|
||||
root.flip();
|
||||
return accept;
|
||||
}
|
||||
reject
|
||||
}
|
||||
touch := TouchArea {
|
||||
enabled: root.enabled;
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => {
|
||||
focus.focus();
|
||||
root.flip();
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
width: parent.height - 6px;
|
||||
height: self.width;
|
||||
y: 3px;
|
||||
x: root.checked ? parent.width - self.width - 3px : 3px;
|
||||
border-radius: self.width / 2;
|
||||
background: root.checked ? #ffffff : Theme.text-secondary;
|
||||
animate x { duration: Theme.fast; easing: ease-out; }
|
||||
}
|
||||
}
|
||||
|
||||
// A settings row: icon, title and description, a switch at the right; the
|
||||
// whole row toggles.
|
||||
export component ToggleRow inherits Rectangle {
|
||||
in-out property <bool> checked;
|
||||
in property <bool> enabled: true;
|
||||
in property <string> text;
|
||||
in property <string> description;
|
||||
in property <image> icon;
|
||||
callback toggled(bool);
|
||||
|
||||
min-height: Theme.row-height + 8px;
|
||||
accessible-role: AccessibleRole.none;
|
||||
TouchArea {
|
||||
enabled: root.enabled;
|
||||
clicked => {
|
||||
root.checked = !root.checked;
|
||||
root.toggled(root.checked);
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-4;
|
||||
padding-top: Theme.space-2;
|
||||
padding-bottom: Theme.space-2;
|
||||
if icon.width > 0: Icon {
|
||||
source: root.icon;
|
||||
size: Theme.icon-md;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
spacing: 1px;
|
||||
Text {
|
||||
text: root.text;
|
||||
color: root.enabled ? Theme.text : Theme.text-disabled;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
if root.description != "": Text {
|
||||
text: root.description;
|
||||
font-size: Theme.font-sm;
|
||||
color: Theme.text-muted;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Toggle {
|
||||
checked <=> root.checked;
|
||||
enabled: root.enabled;
|
||||
label: root.text;
|
||||
toggled(on) => { root.toggled(on); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A round radio button with a title and description (a choice among rows).
|
||||
export component RadioRow inherits Rectangle {
|
||||
in property <bool> checked;
|
||||
in property <bool> enabled: true;
|
||||
in property <string> text;
|
||||
in property <string> description;
|
||||
in property <image> icon;
|
||||
callback clicked();
|
||||
|
||||
min-height: Theme.row-height + 8px;
|
||||
accessible-role: AccessibleRole.radio-button;
|
||||
accessible-label: text;
|
||||
accessible-checkable: true;
|
||||
accessible-checked: checked;
|
||||
accessible-action-default => { clicked(); }
|
||||
TouchArea {
|
||||
enabled: root.enabled;
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => { root.clicked(); }
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-4;
|
||||
padding-top: Theme.space-2;
|
||||
padding-bottom: Theme.space-2;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Rectangle {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 10px;
|
||||
border-width: 2px;
|
||||
border-color: root.checked ? Theme.accent : Theme.border-strong;
|
||||
if root.checked: Rectangle {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 5px;
|
||||
background: Theme.accent;
|
||||
}
|
||||
}
|
||||
}
|
||||
if icon.width > 0: Icon {
|
||||
source: root.icon;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
Text {
|
||||
text: root.text;
|
||||
color: Theme.text;
|
||||
}
|
||||
if root.description != "": Text {
|
||||
text: root.description;
|
||||
font-size: Theme.font-sm;
|
||||
color: Theme.text-muted;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
// Lucide icons (lucide-static 1.48.0, ISC; assets/icons/LICENSE), one
|
||||
// property per icon. They are black strokes: tint them with `colorize`
|
||||
// (the `Icon` component does). Add an icon by copying its SVG from Lucide
|
||||
// into assets/icons/ and adding a line here.
|
||||
|
||||
export global Icons {
|
||||
out property <image> activity: @image-url("assets/icons/activity.svg");
|
||||
out property <image> arrow-left: @image-url("assets/icons/arrow-left.svg");
|
||||
out property <image> arrow-right: @image-url("assets/icons/arrow-right.svg");
|
||||
out property <image> at-sign: @image-url("assets/icons/at-sign.svg");
|
||||
out property <image> audio-lines: @image-url("assets/icons/audio-lines.svg");
|
||||
out property <image> bell: @image-url("assets/icons/bell.svg");
|
||||
out property <image> bookmark: @image-url("assets/icons/bookmark.svg");
|
||||
out property <image> calendar: @image-url("assets/icons/calendar.svg");
|
||||
out property <image> camera: @image-url("assets/icons/camera.svg");
|
||||
out property <image> cast: @image-url("assets/icons/cast.svg");
|
||||
out property <image> check: @image-url("assets/icons/check.svg");
|
||||
out property <image> chevron-down: @image-url("assets/icons/chevron-down.svg");
|
||||
out property <image> chevron-left: @image-url("assets/icons/chevron-left.svg");
|
||||
out property <image> chevron-right: @image-url("assets/icons/chevron-right.svg");
|
||||
out property <image> chevron-up: @image-url("assets/icons/chevron-up.svg");
|
||||
out property <image> circle-alert: @image-url("assets/icons/circle-alert.svg");
|
||||
out property <image> record: @image-url("assets/icons/circle-dot.svg");
|
||||
out property <image> help: @image-url("assets/icons/circle-help.svg");
|
||||
out property <image> circle: @image-url("assets/icons/circle.svg");
|
||||
out property <image> clock: @image-url("assets/icons/clock.svg");
|
||||
out property <image> coffee: @image-url("assets/icons/coffee.svg");
|
||||
out property <image> compass: @image-url("assets/icons/compass.svg");
|
||||
out property <image> copy: @image-url("assets/icons/copy.svg");
|
||||
out property <image> crown: @image-url("assets/icons/crown.svg");
|
||||
out property <image> download: @image-url("assets/icons/download.svg");
|
||||
out property <image> more-vertical: @image-url("assets/icons/ellipsis-vertical.svg");
|
||||
out property <image> more-horizontal: @image-url("assets/icons/ellipsis.svg");
|
||||
out property <image> external-link: @image-url("assets/icons/external-link.svg");
|
||||
out property <image> eye-off: @image-url("assets/icons/eye-off.svg");
|
||||
out property <image> eye: @image-url("assets/icons/eye.svg");
|
||||
out property <image> file-text: @image-url("assets/icons/file-text.svg");
|
||||
out property <image> file: @image-url("assets/icons/file.svg");
|
||||
out property <image> flag: @image-url("assets/icons/flag.svg");
|
||||
out property <image> flame: @image-url("assets/icons/flame.svg");
|
||||
out property <image> folder-open: @image-url("assets/icons/folder-open.svg");
|
||||
out property <image> gamepad-2: @image-url("assets/icons/gamepad-2.svg");
|
||||
out property <image> gift: @image-url("assets/icons/gift.svg");
|
||||
out property <image> globe: @image-url("assets/icons/globe.svg");
|
||||
out property <image> grip-vertical: @image-url("assets/icons/grip-vertical.svg");
|
||||
out property <image> hand: @image-url("assets/icons/hand.svg");
|
||||
out property <image> hard-drive: @image-url("assets/icons/hard-drive.svg");
|
||||
out property <image> hash: @image-url("assets/icons/hash.svg");
|
||||
out property <image> headphone-off: @image-url("assets/icons/headphone-off.svg");
|
||||
out property <image> headphones: @image-url("assets/icons/headphones.svg");
|
||||
out property <image> heart: @image-url("assets/icons/heart.svg");
|
||||
out property <image> home: @image-url("assets/icons/house.svg");
|
||||
out property <image> image: @image-url("assets/icons/image.svg");
|
||||
out property <image> info: @image-url("assets/icons/info.svg");
|
||||
out property <image> keyboard: @image-url("assets/icons/keyboard.svg");
|
||||
out property <image> layout-grid: @image-url("assets/icons/layout-grid.svg");
|
||||
out property <image> leaf: @image-url("assets/icons/leaf.svg");
|
||||
out property <image> library: @image-url("assets/icons/library.svg");
|
||||
out property <image> lightbulb: @image-url("assets/icons/lightbulb.svg");
|
||||
out property <image> link: @image-url("assets/icons/link.svg");
|
||||
out property <image> loader: @image-url("assets/icons/loader-circle.svg");
|
||||
out property <image> lock: @image-url("assets/icons/lock.svg");
|
||||
out property <image> log-in: @image-url("assets/icons/log-in.svg");
|
||||
out property <image> log-out: @image-url("assets/icons/log-out.svg");
|
||||
out property <image> maximize: @image-url("assets/icons/maximize.svg");
|
||||
out property <image> message-circle: @image-url("assets/icons/message-circle.svg");
|
||||
out property <image> message-square: @image-url("assets/icons/message-square.svg");
|
||||
out property <image> messages-square: @image-url("assets/icons/messages-square.svg");
|
||||
out property <image> mic-off: @image-url("assets/icons/mic-off.svg");
|
||||
out property <image> mic: @image-url("assets/icons/mic.svg");
|
||||
out property <image> minimize-2: @image-url("assets/icons/minimize-2.svg");
|
||||
out property <image> minus: @image-url("assets/icons/minus.svg");
|
||||
out property <image> monitor-off: @image-url("assets/icons/monitor-off.svg");
|
||||
out property <image> monitor-up: @image-url("assets/icons/monitor-up.svg");
|
||||
out property <image> monitor: @image-url("assets/icons/monitor.svg");
|
||||
out property <image> moon: @image-url("assets/icons/moon.svg");
|
||||
out property <image> music: @image-url("assets/icons/music.svg");
|
||||
out property <image> palette: @image-url("assets/icons/palette.svg");
|
||||
out property <image> panel-right: @image-url("assets/icons/panel-right.svg");
|
||||
out property <image> paperclip: @image-url("assets/icons/paperclip.svg");
|
||||
out property <image> pause: @image-url("assets/icons/pause.svg");
|
||||
out property <image> pencil: @image-url("assets/icons/pencil.svg");
|
||||
out property <image> phone-off: @image-url("assets/icons/phone-off.svg");
|
||||
out property <image> pin: @image-url("assets/icons/pin.svg");
|
||||
out property <image> plane: @image-url("assets/icons/plane.svg");
|
||||
out property <image> play: @image-url("assets/icons/play.svg");
|
||||
out property <image> plus: @image-url("assets/icons/plus.svg");
|
||||
out property <image> puzzle: @image-url("assets/icons/puzzle.svg");
|
||||
out property <image> radio: @image-url("assets/icons/radio.svg");
|
||||
out property <image> refresh-cw: @image-url("assets/icons/refresh-cw.svg");
|
||||
out property <image> screen-share: @image-url("assets/icons/screen-share.svg");
|
||||
out property <image> search: @image-url("assets/icons/search.svg");
|
||||
out property <image> send: @image-url("assets/icons/send-horizontal.svg");
|
||||
out property <image> server: @image-url("assets/icons/server.svg");
|
||||
out property <image> settings: @image-url("assets/icons/settings.svg");
|
||||
out property <image> shield-check: @image-url("assets/icons/shield-check.svg");
|
||||
out property <image> shield: @image-url("assets/icons/shield.svg");
|
||||
out property <image> sliders-horizontal: @image-url("assets/icons/sliders-horizontal.svg");
|
||||
out property <image> smartphone: @image-url("assets/icons/smartphone.svg");
|
||||
out property <image> smile-plus: @image-url("assets/icons/smile-plus.svg");
|
||||
out property <image> smile: @image-url("assets/icons/smile.svg");
|
||||
out property <image> sparkles: @image-url("assets/icons/sparkles.svg");
|
||||
out property <image> square: @image-url("assets/icons/square.svg");
|
||||
out property <image> star: @image-url("assets/icons/star.svg");
|
||||
out property <image> sun: @image-url("assets/icons/sun.svg");
|
||||
out property <image> trash-2: @image-url("assets/icons/trash-2.svg");
|
||||
out property <image> triangle-alert: @image-url("assets/icons/triangle-alert.svg");
|
||||
out property <image> type: @image-url("assets/icons/type.svg");
|
||||
out property <image> user-plus: @image-url("assets/icons/user-plus.svg");
|
||||
out property <image> user: @image-url("assets/icons/user.svg");
|
||||
out property <image> users: @image-url("assets/icons/users.svg");
|
||||
out property <image> video-off: @image-url("assets/icons/video-off.svg");
|
||||
out property <image> video: @image-url("assets/icons/video.svg");
|
||||
out property <image> volume-2: @image-url("assets/icons/volume-2.svg");
|
||||
out property <image> volume-x: @image-url("assets/icons/volume-x.svg");
|
||||
out property <image> x: @image-url("assets/icons/x.svg");
|
||||
// The app mark (full colour, not for colorize).
|
||||
out property <image> logo: @image-url("assets/logo.svg");
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
// Where the user is: the page, open dialogs, panel sizes. Any screen can
|
||||
// navigate through these functions; Rust sets the same properties for the
|
||||
// development switch VOELIN_OPEN (src/dev.rs).
|
||||
|
||||
import { Bridge, BookmarkForm, ShareForm } from "bridge.slint";
|
||||
|
||||
export enum Page {
|
||||
// Welcome page: servers at a glance.
|
||||
home,
|
||||
// A server: channels, chat or the stream viewer, members and streams.
|
||||
server,
|
||||
settings,
|
||||
}
|
||||
|
||||
// Sections of the settings page, in the order of its navigation.
|
||||
export enum SettingsSection {
|
||||
voice,
|
||||
keybinds,
|
||||
streaming,
|
||||
privacy,
|
||||
appearance,
|
||||
}
|
||||
|
||||
// Tabs of the bottom navigation in the narrow (mobile) layout.
|
||||
export enum MobileTab {
|
||||
home,
|
||||
servers,
|
||||
chat,
|
||||
activity,
|
||||
you,
|
||||
}
|
||||
|
||||
export global Nav {
|
||||
in-out property <Page> page: Page.server;
|
||||
in-out property <SettingsSection> settings-section: SettingsSection.voice;
|
||||
in-out property <MobileTab> mobile-tab: MobileTab.chat;
|
||||
// Narrow windows use the mobile layout; the breakpoint is the setting
|
||||
// `ui.narrow_breakpoint`.
|
||||
in-out property <bool> narrow: false;
|
||||
in-out property <length> narrow-breakpoint: 800px;
|
||||
in-out property <bool> right-panel-open: true;
|
||||
in-out property <length> right-panel-width: 280px;
|
||||
// Incremented to focus the search field (Ctrl+K).
|
||||
in-out property <int> search-requests;
|
||||
|
||||
// Dialogs.
|
||||
in-out property <bool> about-open;
|
||||
in-out property <bool> share-open;
|
||||
in-out property <bool> client-open;
|
||||
in-out property <bool> bookmark-open;
|
||||
// The emoji picker over the composer, and the composer's text.
|
||||
in-out property <bool> emoji-open;
|
||||
in-out property <string> draft;
|
||||
in-out property <BookmarkForm> bookmark-form;
|
||||
in-out property <ShareForm> share-form;
|
||||
|
||||
// Settings were opened (so leaving them tells Rust).
|
||||
property <bool> settings-active;
|
||||
|
||||
public function show(p: Page) {
|
||||
if p != Page.settings && settings-active {
|
||||
settings-active = false;
|
||||
Bridge.close-settings();
|
||||
}
|
||||
page = p;
|
||||
}
|
||||
|
||||
public function open-settings(section: SettingsSection) {
|
||||
if !settings-active {
|
||||
settings-active = true;
|
||||
Bridge.open-settings();
|
||||
}
|
||||
settings-section = section;
|
||||
page = Page.settings;
|
||||
}
|
||||
|
||||
public function close-settings() {
|
||||
show(Page.server);
|
||||
}
|
||||
|
||||
public function open-about() {
|
||||
Bridge.open-about();
|
||||
about-open = true;
|
||||
}
|
||||
|
||||
public function open-share() {
|
||||
share-form = Bridge.open-share();
|
||||
share-open = true;
|
||||
}
|
||||
|
||||
public function add-server() {
|
||||
bookmark-form = Bridge.edit-bookmark(-1);
|
||||
bookmark-open = true;
|
||||
}
|
||||
|
||||
public function edit-server(id: int) {
|
||||
bookmark-form = Bridge.edit-bookmark(id);
|
||||
bookmark-open = true;
|
||||
}
|
||||
|
||||
public function open-client(id: int) {
|
||||
if Bridge.open-client(id) {
|
||||
client-open = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function select-server(id: int) {
|
||||
show(Page.server);
|
||||
Bridge.select-server(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
// The server's sidebar: the server card, connect and observe, and the
|
||||
// channel tree with its clients.
|
||||
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Bridge, TreeItem } from "../bridge.slint";
|
||||
import { Nav } from "../nav.slint";
|
||||
import { Icon, Button, ButtonKind, IconButton, Avatar, LiveBadge, Chip, SectionHeader, SpeakingBars, PopupMenu, MenuEntry, ListView } from "../components/index.slint";
|
||||
|
||||
// The banner at the top of the sidebar: server name, counts, a menu.
|
||||
export component ServerHeader inherits Rectangle {
|
||||
height: 132px;
|
||||
border-radius: Theme.radius-lg;
|
||||
clip: true;
|
||||
background: Theme.surface-2;
|
||||
accessible-role: AccessibleRole.groupbox;
|
||||
accessible-label: Bridge.server-title;
|
||||
// Painted banner: a night sky gradient with a horizon glow.
|
||||
Rectangle {
|
||||
height: 72px;
|
||||
y: 0;
|
||||
background: @linear-gradient(180deg, #1a2d7a 0%, #3a2a8f 45%, #0b1330 100%);
|
||||
Rectangle {
|
||||
y: parent.height - 30px;
|
||||
height: 30px;
|
||||
background: @linear-gradient(180deg, transparent 0%, Theme.surface-2 100%);
|
||||
}
|
||||
for star[i] in [
|
||||
{ x: 0.12, y: 0.2 }, { x: 0.3, y: 0.45 }, { x: 0.52, y: 0.15 }, { x: 0.7, y: 0.35 },
|
||||
{ x: 0.86, y: 0.18 }, { x: 0.42, y: 0.62 }, { x: 0.93, y: 0.55 }, { x: 0.2, y: 0.7 },
|
||||
]: Rectangle {
|
||||
x: parent.width * star.x;
|
||||
y: parent.height * star.y;
|
||||
width: mod(i, 3) == 0 ? 3px : 2px;
|
||||
height: self.width;
|
||||
border-radius: self.width / 2;
|
||||
background: #ffffffb0;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
padding: Theme.space-4;
|
||||
padding-top: 64px;
|
||||
spacing: 2px;
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
Text {
|
||||
text: Bridge.server-title;
|
||||
font-size: Theme.font-lg;
|
||||
font-weight: Theme.weight-semibold;
|
||||
color: Theme.text;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
overflow: elide;
|
||||
}
|
||||
if Bridge.current-server >= 0: IconButton {
|
||||
icon: Icons.chevron-down;
|
||||
label: @tr("Server menu");
|
||||
size: 28px;
|
||||
icon-size: Theme.icon-sm;
|
||||
clicked => { menu.show(self.x + self.width - 220px, self.y + self.height + 4px); }
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
Rectangle {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
border-radius: 4px;
|
||||
background: Bridge.voice-connected ? Theme.success : Bridge.observing ? Theme.info : Bridge.voice-connecting ? Theme.warning : Theme.offline;
|
||||
}
|
||||
Text {
|
||||
text: Bridge.server-stats != "" ? Bridge.server-stats
|
||||
: Bridge.voice-connecting ? @tr("Connecting…")
|
||||
: Bridge.current-server >= 0 ? @tr("Not connected") : @tr("Add a server to start");
|
||||
font-size: Theme.font-sm;
|
||||
color: Theme.text-secondary;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
}
|
||||
menu := PopupMenu {
|
||||
entries: [
|
||||
{ text: @tr("Edit server"), icon: Icons.pencil, enabled: Bridge.current-server >= 0 },
|
||||
{ text: Bridge.observing ? @tr("Stop observing") : @tr("Observe invisibly"), icon: Icons.eye, enabled: Bridge.can-observe },
|
||||
{ text: @tr("Add server"), icon: Icons.plus, enabled: true, separator: true },
|
||||
];
|
||||
activated(i) => {
|
||||
if i == 0 {
|
||||
Nav.edit-server(Bridge.current-server);
|
||||
} else if i == 1 {
|
||||
Bridge.toggle-observe();
|
||||
} else {
|
||||
Nav.add-server();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Connect and observe while not connected.
|
||||
export component ConnectActions inherits HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
Button {
|
||||
horizontal-stretch: 1;
|
||||
kind: ButtonKind.primary;
|
||||
icon: Icons.log-in;
|
||||
text: Bridge.voice-connecting ? @tr("Connecting…") : @tr("Connect");
|
||||
enabled: Bridge.current-server >= 0 && !Bridge.voice-connecting;
|
||||
clicked => { Bridge.connect-voice(); }
|
||||
}
|
||||
Button {
|
||||
icon: Bridge.observing ? Icons.eye-off : Icons.eye;
|
||||
text: Bridge.observing ? @tr("Stop observing") : @tr("Observe");
|
||||
enabled: Bridge.can-observe;
|
||||
checked: Bridge.observing;
|
||||
clicked => { Bridge.toggle-observe(); }
|
||||
}
|
||||
}
|
||||
|
||||
// One row of the tree: a channel or a client.
|
||||
component TreeRow inherits Rectangle {
|
||||
in property <TreeItem> item;
|
||||
callback client-clicked(int);
|
||||
property <length> indent: item.depth * 14px;
|
||||
height: item.is-channel ? 34px * Theme.font-scale : 30px * Theme.font-scale;
|
||||
border-radius: Theme.radius-md;
|
||||
background: item.is-channel && item.own ? Theme.accent-soft : area.has-hover ? Theme.surface-3 : transparent;
|
||||
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-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 {
|
||||
Bridge.open-channel-chat(item.id);
|
||||
} else {
|
||||
client-clicked(item.id);
|
||||
}
|
||||
}
|
||||
area := TouchArea {
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
double-clicked => {
|
||||
if item.is-channel {
|
||||
Bridge.join-channel(item.id);
|
||||
}
|
||||
}
|
||||
clicked => {
|
||||
if item.is-channel {
|
||||
Bridge.open-channel-chat(item.id);
|
||||
} else if !item.myself {
|
||||
client-clicked(item.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
if item.is-channel: HorizontalLayout {
|
||||
padding-left: Theme.space-2 + root.indent;
|
||||
padding-right: Theme.space-3;
|
||||
spacing: Theme.space-2;
|
||||
Rectangle {
|
||||
width: 18px;
|
||||
accessible-role: AccessibleRole.button;
|
||||
accessible-label: item.collapsed ? @tr("Expand") : @tr("Collapse");
|
||||
accessible-action-default => { Bridge.toggle-collapse(item.id); }
|
||||
Icon {
|
||||
source: item.collapsed ? Icons.chevron-right : Icons.chevron-down;
|
||||
size: 14px;
|
||||
tint: Theme.text-muted;
|
||||
}
|
||||
TouchArea {
|
||||
clicked => { Bridge.toggle-collapse(item.id); }
|
||||
}
|
||||
}
|
||||
Icon {
|
||||
source: item.locked ? Icons.lock : Icons.volume-2;
|
||||
size: 18px;
|
||||
tint: item.own ? Theme.text : Theme.icon;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: item.name;
|
||||
color: item.own ? Theme.text : Theme.text-secondary;
|
||||
font-weight: item.own ? Theme.weight-semibold : Theme.weight-medium;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
overflow: elide;
|
||||
}
|
||||
if item.members > 0 || item.max-members >= 0: HorizontalLayout {
|
||||
spacing: 3px;
|
||||
if item.own: Icon {
|
||||
source: Icons.users;
|
||||
size: 14px;
|
||||
tint: Theme.text-secondary;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: item.max-members >= 0 ? item.members + "/" + item.max-members : item.members;
|
||||
color: item.own ? Theme.text : Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
if !item.is-channel: HorizontalLayout {
|
||||
padding-left: Theme.space-2 + root.indent + 12px;
|
||||
padding-right: Theme.space-3;
|
||||
spacing: Theme.space-3;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Avatar {
|
||||
size: 22px;
|
||||
initials: item.initials;
|
||||
tint: item.tint;
|
||||
speaking: item.talking;
|
||||
label: item.name;
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: item.name;
|
||||
color: item.away ? Theme.text-muted : item.myself ? Theme.accent-text : Theme.text-secondary;
|
||||
font-weight: item.myself ? Theme.weight-semibold : Theme.weight-regular;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
overflow: elide;
|
||||
}
|
||||
if item.talking: VerticalLayout {
|
||||
alignment: center;
|
||||
SpeakingBars { }
|
||||
}
|
||||
if item.streaming: VerticalLayout {
|
||||
alignment: center;
|
||||
LiveBadge { }
|
||||
}
|
||||
if item.local-muted: Icon {
|
||||
source: Icons.volume-x;
|
||||
size: 14px;
|
||||
tint: Theme.warning;
|
||||
y: (parent.height - self.height) / 2;
|
||||
accessible-role: AccessibleRole.image;
|
||||
accessible-label: @tr("muted for you");
|
||||
}
|
||||
if !item.local-muted && item.local-volume != 100: Text {
|
||||
text: @tr("{}%", item.local-volume);
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-xs;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
if item.muted: Icon {
|
||||
source: Icons.mic-off;
|
||||
size: 14px;
|
||||
tint: Theme.danger;
|
||||
y: (parent.height - self.height) / 2;
|
||||
accessible-role: AccessibleRole.image;
|
||||
accessible-label: @tr("mic off");
|
||||
}
|
||||
if item.sound-off: Icon {
|
||||
source: Icons.headphone-off;
|
||||
size: 14px;
|
||||
tint: Theme.danger;
|
||||
y: (parent.height - self.height) / 2;
|
||||
accessible-role: AccessibleRole.image;
|
||||
accessible-label: @tr("sound off");
|
||||
}
|
||||
if item.away: Text {
|
||||
text: @tr("away");
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-xs;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Channels and the clients in them. Click a channel for its chat,
|
||||
// double-click to join; click a client for its volume.
|
||||
export component ChannelTree inherits VerticalLayout {
|
||||
spacing: Theme.space-2;
|
||||
SectionHeader {
|
||||
text: @tr("Channels");
|
||||
icon: Icons.volume-2;
|
||||
small: true;
|
||||
}
|
||||
if Bridge.tree.length == 0: Text {
|
||||
text: Bridge.current-server < 0 ? @tr("No server yet.") : @tr("Connect or observe to see the channels.");
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
ListView {
|
||||
vertical-stretch: 1;
|
||||
accessible-role: AccessibleRole.list;
|
||||
accessible-label: @tr("Channels and clients");
|
||||
for row in Bridge.tree: TreeRow {
|
||||
item: row;
|
||||
client-clicked(id) => { Nav.open-client(id); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
// The chat: header, chat tabs, messages (virtualised), the composer with
|
||||
// the emoji picker.
|
||||
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Bridge, ChatLine } from "../bridge.slint";
|
||||
import { Nav } from "../nav.slint";
|
||||
import { Icon, IconButton, Avatar, Chip, TabItem, TextField, RichText, Banner, Button, ButtonKind, ListView } from "../components/index.slint";
|
||||
|
||||
// The header of the main area: an icon, a title and a description, and
|
||||
// actions (@children) at the right.
|
||||
export component PageHeader inherits Rectangle {
|
||||
in property <image> icon: Icons.hash;
|
||||
in property <string> title;
|
||||
in property <string> description;
|
||||
min-height: 60px;
|
||||
border-width: 0px;
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-6;
|
||||
padding-right: Theme.space-4;
|
||||
spacing: Theme.space-4;
|
||||
Icon {
|
||||
source: root.icon;
|
||||
size: 26px;
|
||||
tint: Theme.text-secondary;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: root.title;
|
||||
font-size: Theme.font-xl;
|
||||
font-weight: Theme.weight-semibold;
|
||||
color: Theme.text;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
max-width: self.preferred-width;
|
||||
}
|
||||
if root.description != "": Rectangle {
|
||||
width: 1px;
|
||||
height: 22px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
background: Theme.border-strong;
|
||||
}
|
||||
Text {
|
||||
text: root.description;
|
||||
font-size: Theme.font-sm;
|
||||
color: Theme.text-muted;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
overflow: elide;
|
||||
}
|
||||
@children
|
||||
}
|
||||
Rectangle {
|
||||
y: parent.height - 1px;
|
||||
height: 1px;
|
||||
background: Theme.border;
|
||||
}
|
||||
}
|
||||
|
||||
// One message; `continued` lines (same author just before) omit the header.
|
||||
component MessageRow inherits Rectangle {
|
||||
in property <ChatLine> line;
|
||||
property <length> avatar: 40px;
|
||||
min-height: body.preferred-height;
|
||||
accessible-role: AccessibleRole.list-item;
|
||||
accessible-label: line.author + ": " + line.text;
|
||||
accessible-description: line.time;
|
||||
body := HorizontalLayout {
|
||||
padding-left: Theme.space-6;
|
||||
padding-right: Theme.space-6;
|
||||
padding-top: line.continued ? 1px : Theme.space-4;
|
||||
padding-bottom: 1px;
|
||||
spacing: Theme.space-4;
|
||||
VerticalLayout {
|
||||
width: root.avatar;
|
||||
alignment: start;
|
||||
if !line.continued: Avatar {
|
||||
size: root.avatar;
|
||||
initials: line.initials;
|
||||
tint: line.tint;
|
||||
label: line.author;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
spacing: 2px;
|
||||
if !line.continued: HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
alignment: start;
|
||||
Text {
|
||||
text: line.author;
|
||||
color: line.relayed ? Theme.accent-text : Theme.name-text;
|
||||
font-size: Theme.font-md;
|
||||
font-weight: Theme.weight-semibold;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
Text {
|
||||
text: line.time;
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-xs;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
if line.relayed: Chip {
|
||||
text: @tr("via relay");
|
||||
icon: Icons.radio;
|
||||
tint: Theme.accent-text;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
}
|
||||
if !line.rich: Text {
|
||||
text: line.text;
|
||||
color: Theme.text;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
if line.rich: RichText {
|
||||
runs: line.runs;
|
||||
emoji-size: line.jumbo ? 44px : Theme.font-body * 1.4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tabs, messages and the composer of the current chat.
|
||||
export component ChatView inherits VerticalLayout {
|
||||
// Hide the header (mobile shows its own).
|
||||
in property <bool> header: true;
|
||||
property <string> tab-title: Bridge.current-tab >= 0 && Bridge.current-tab < Bridge.tabs.length ? Bridge.tabs[Bridge.current-tab].title : "";
|
||||
property <string> tab-topic: Bridge.current-tab >= 0 && Bridge.current-tab < Bridge.tabs.length ? Bridge.tabs[Bridge.current-tab].topic : "";
|
||||
|
||||
if root.header: PageHeader {
|
||||
icon: Icons.hash;
|
||||
title: root.tab-title;
|
||||
description: root.tab-topic != "" ? root.tab-topic : Bridge.server-title;
|
||||
if Bridge.presence-source != "": Chip {
|
||||
text: Bridge.presence-source;
|
||||
icon: Icons.radio;
|
||||
tint: Theme.accent-text;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
if Bridge.viewer-open == false && Bridge.streams.length > 0: Button {
|
||||
small: true;
|
||||
icon: Icons.monitor-up;
|
||||
text: @tr("Streams ({})", Bridge.streams.length);
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Nav.right-panel-open = true; }
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.users;
|
||||
label: @tr("Members and streams");
|
||||
checked: Nav.right-panel-open;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Nav.right-panel-open = !Nav.right-panel-open; }
|
||||
}
|
||||
}
|
||||
if Bridge.crash-notice != "": Rectangle {
|
||||
HorizontalLayout {
|
||||
padding: Theme.space-3;
|
||||
padding-left: Theme.space-5;
|
||||
padding-right: Theme.space-5;
|
||||
Banner {
|
||||
text: Bridge.crash-notice;
|
||||
Button {
|
||||
small: true;
|
||||
text: @tr("Open folder");
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Bridge.open-crash-folder(); }
|
||||
}
|
||||
Button {
|
||||
small: true;
|
||||
kind: ButtonKind.danger;
|
||||
text: @tr("Delete");
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Bridge.delete-crash-reports(); }
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.x;
|
||||
label: @tr("Dismiss");
|
||||
size: 28px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Bridge.dismiss-crash-notice(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Chat tabs: server chat, channel chats, private chats.
|
||||
Rectangle {
|
||||
height: Theme.control-height + 4px;
|
||||
accessible-role: AccessibleRole.tab-list;
|
||||
accessible-label: @tr("Chats");
|
||||
Rectangle {
|
||||
y: parent.height - 1px;
|
||||
height: 1px;
|
||||
background: Theme.border;
|
||||
}
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-5;
|
||||
alignment: start;
|
||||
for tab[i] in Bridge.tabs: TabItem {
|
||||
text: tab.title;
|
||||
selected: Bridge.current-tab == i;
|
||||
badge: tab.unread;
|
||||
closable: tab.kind == 1;
|
||||
clicked => { Bridge.select-tab(i); }
|
||||
close => { Bridge.close-tab(i); }
|
||||
}
|
||||
}
|
||||
}
|
||||
messages := ListView {
|
||||
vertical-stretch: 1;
|
||||
accessible-label: @tr("Messages");
|
||||
for line in Bridge.messages: MessageRow {
|
||||
line: line;
|
||||
}
|
||||
}
|
||||
// Composer.
|
||||
HorizontalLayout {
|
||||
padding: Theme.space-4;
|
||||
padding-left: Theme.space-5;
|
||||
padding-right: Theme.space-5;
|
||||
spacing: Theme.space-3;
|
||||
composer := Rectangle {
|
||||
horizontal-stretch: 1;
|
||||
min-height: 48px;
|
||||
border-radius: Theme.radius-lg;
|
||||
background: Theme.surface-2;
|
||||
border-width: 1px;
|
||||
border-color: input.has-focus ? Theme.accent : Theme.border;
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-5;
|
||||
padding-right: Theme.space-2;
|
||||
spacing: Theme.space-2;
|
||||
input := TextField {
|
||||
text <=> Nav.draft;
|
||||
bare: true;
|
||||
placeholder: root.tab-title != "" ? @tr("Message {}", root.tab-title) : @tr("Message");
|
||||
label: @tr("Message");
|
||||
accepted(text) => {
|
||||
if text != "" {
|
||||
Bridge.send-message(text);
|
||||
self.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.smile;
|
||||
label: @tr("Emoji");
|
||||
checked: Nav.emoji-open;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Nav.emoji-open = !Nav.emoji-open; }
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.send;
|
||||
label: @tr("Send");
|
||||
round: true;
|
||||
enabled: input.text != "";
|
||||
tint: input.text != "" ? Theme.on-accent : Theme.text-muted;
|
||||
filled: input.text != "";
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => {
|
||||
if input.text != "" {
|
||||
Bridge.send-message(input.text);
|
||||
input.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,528 @@
|
||||
// Dialogs: add/edit a server, share the screen, a client's volume, About.
|
||||
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Bridge, BookmarkForm, ShareForm } from "../bridge.slint";
|
||||
import { Nav } from "../nav.slint";
|
||||
import { Icon, Button, ButtonKind, IconButton, TextField, Field, Select, Toggle, ToggleRow, Slider, Modal, Card, Chip, Banner, Avatar, Status, ListView, ScrollView } from "../components/index.slint";
|
||||
import { AboutSlint } from "std-widgets.slint";
|
||||
|
||||
// Buttons at the bottom right of a dialog.
|
||||
component Footer inherits HorizontalLayout {
|
||||
alignment: end;
|
||||
spacing: Theme.space-3;
|
||||
}
|
||||
|
||||
export component BookmarkDialog inherits Modal {
|
||||
in-out property <BookmarkForm> form;
|
||||
callback done();
|
||||
title: form.id < 0 ? @tr("Add server") : @tr("Edit server");
|
||||
subtitle: @tr("TeamSpeak 3 or 6 server address and your nickname there.");
|
||||
icon: Icons.server;
|
||||
card-width: 560px;
|
||||
card-height: 640px;
|
||||
dismissed => { done(); }
|
||||
ScrollView {
|
||||
vertical-stretch: 1;
|
||||
VerticalLayout {
|
||||
spacing: Theme.space-4;
|
||||
padding-right: Theme.space-3;
|
||||
Field {
|
||||
label: @tr("Name");
|
||||
TextField { text <=> form.name; placeholder: @tr("My server"); label: @tr("Name"); }
|
||||
}
|
||||
Field {
|
||||
label: @tr("Address");
|
||||
TextField { text <=> form.address; placeholder: "ts.example.org:9987"; label: @tr("Address"); icon: Icons.globe; }
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-4;
|
||||
Field {
|
||||
label: @tr("Nickname");
|
||||
TextField { text <=> form.nickname; label: @tr("Nickname"); icon: Icons.user; }
|
||||
}
|
||||
Field {
|
||||
label: @tr("Server password");
|
||||
TextField { text <=> form.server-password; input-type: InputType.password; label: @tr("Server password"); icon: Icons.lock; }
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: @tr("Invisible presence and chat without joining (optional)");
|
||||
font-weight: Theme.weight-semibold;
|
||||
color: Theme.text;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
Field {
|
||||
label: @tr("Gateway URL");
|
||||
TextField { text <=> form.gateway-url; placeholder: "wss://gw.example.org/v1"; label: @tr("Gateway URL"); }
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-4;
|
||||
Field {
|
||||
label: @tr("Query transport");
|
||||
Select {
|
||||
model: ["none", "ssh", "raw", "http"];
|
||||
current-value <=> form.query-transport;
|
||||
current-index: form.query-transport == "ssh" ? 1 : form.query-transport == "raw" ? 2 : form.query-transport == "http" ? 3 : 0;
|
||||
label: @tr("Query transport");
|
||||
}
|
||||
}
|
||||
Field {
|
||||
label: @tr("Query address");
|
||||
TextField { text <=> form.query-addr; placeholder: "ts.example.org:10022"; label: @tr("Query address"); }
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-4;
|
||||
Field {
|
||||
label: @tr("Query login");
|
||||
TextField { text <=> form.query-user; label: @tr("Query login"); }
|
||||
}
|
||||
Field {
|
||||
label: @tr("Query password");
|
||||
TextField { text <=> form.query-password; input-type: InputType.password; label: @tr("Query password"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Footer {
|
||||
if form.id >= 0: Button {
|
||||
kind: ButtonKind.danger;
|
||||
icon: Icons.trash-2;
|
||||
text: @tr("Delete");
|
||||
clicked => {
|
||||
Bridge.delete-bookmark(form.id);
|
||||
done();
|
||||
}
|
||||
}
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
Button {
|
||||
text: @tr("Cancel");
|
||||
clicked => { done(); }
|
||||
}
|
||||
Button {
|
||||
kind: ButtonKind.primary;
|
||||
text: @tr("Save");
|
||||
enabled: form.address != "" && form.nickname != "";
|
||||
clicked => {
|
||||
Bridge.save-bookmark(form);
|
||||
done();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A capture source as a selectable card.
|
||||
component SourceCard inherits Rectangle {
|
||||
in property <string> name;
|
||||
in property <string> detail;
|
||||
in property <bool> selected;
|
||||
callback clicked();
|
||||
height: 52px;
|
||||
border-radius: Theme.radius-md;
|
||||
background: selected ? Theme.accent-soft : touch.has-hover ? Theme.surface-3 : Theme.surface-2;
|
||||
border-width: 1px;
|
||||
border-color: selected ? Theme.accent : Theme.border;
|
||||
accessible-role: AccessibleRole.list-item;
|
||||
accessible-label: name;
|
||||
accessible-description: detail;
|
||||
accessible-item-selectable: true;
|
||||
accessible-item-selected: selected;
|
||||
accessible-action-default => { clicked(); }
|
||||
touch := TouchArea {
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => { root.clicked(); }
|
||||
}
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-4;
|
||||
padding-right: Theme.space-4;
|
||||
spacing: Theme.space-3;
|
||||
Icon {
|
||||
source: Icons.monitor;
|
||||
tint: root.selected ? Theme.accent-text : Theme.icon;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
Text {
|
||||
text: root.name;
|
||||
color: Theme.text;
|
||||
font-weight: Theme.weight-medium;
|
||||
overflow: elide;
|
||||
}
|
||||
if root.detail != "": Text {
|
||||
text: root.detail;
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-xs;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
border-radius: 9px;
|
||||
border-width: 2px;
|
||||
border-color: root.selected ? Theme.accent : Theme.border-strong;
|
||||
if root.selected: Rectangle {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 4px;
|
||||
background: Theme.accent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export component ShareDialog inherits Modal {
|
||||
in-out property <ShareForm> form;
|
||||
callback done();
|
||||
property <bool> live: Bridge.share-state == "live" || Bridge.share-state == "starting";
|
||||
title: Bridge.share-state == "live" ? @tr("You are sharing your screen") : Bridge.share-state == "starting" ? @tr("Starting…") : @tr("Share screen");
|
||||
subtitle: live ? Bridge.share-status : @tr("Stream to the people in your channel.");
|
||||
icon: Icons.radio;
|
||||
card-width: 600px;
|
||||
card-height: 660px;
|
||||
dismissed => { done(); }
|
||||
|
||||
if live: VerticalLayout {
|
||||
spacing: Theme.space-4;
|
||||
vertical-stretch: 1;
|
||||
Text {
|
||||
text: @tr("Viewers");
|
||||
font-weight: Theme.weight-semibold;
|
||||
color: Theme.text;
|
||||
}
|
||||
if Bridge.share-viewers.length == 0: Text {
|
||||
text: @tr("Nobody is watching yet. Viewers in your channel can join from their streams list.");
|
||||
color: Theme.text-muted;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
ListView {
|
||||
vertical-stretch: 1;
|
||||
accessible-label: @tr("Viewers");
|
||||
for viewer in Bridge.share-viewers: HorizontalLayout {
|
||||
padding-top: Theme.space-2;
|
||||
padding-bottom: Theme.space-2;
|
||||
spacing: Theme.space-3;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Avatar {
|
||||
size: 32px;
|
||||
initials: "";
|
||||
status: viewer.state == "connected" ? Status.online : viewer.state == "requested" ? Status.idle : Status.offline;
|
||||
Icon {
|
||||
source: Icons.user;
|
||||
size: 16px;
|
||||
tint: #ffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
alignment: center;
|
||||
Text {
|
||||
text: viewer.name;
|
||||
color: Theme.text;
|
||||
font-weight: Theme.weight-semibold;
|
||||
overflow: elide;
|
||||
}
|
||||
Text {
|
||||
text: viewer.state == "requested" ? (viewer.message == "" ? @tr("asks to watch") : @tr("asks to watch: {}", viewer.message)) : viewer.state == "connecting" ? @tr("connecting") : @tr("watching");
|
||||
font-size: Theme.font-sm;
|
||||
color: viewer.state == "requested" ? Theme.warning : viewer.state == "connected" ? Theme.success : Theme.text-muted;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
if viewer.state == "requested": Button {
|
||||
small: true;
|
||||
kind: ButtonKind.primary;
|
||||
text: @tr("Accept");
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Bridge.respond-viewer(viewer.client, true); }
|
||||
}
|
||||
if viewer.state == "requested": Button {
|
||||
small: true;
|
||||
text: @tr("Deny");
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Bridge.respond-viewer(viewer.client, false); }
|
||||
}
|
||||
if viewer.state != "requested": Button {
|
||||
small: true;
|
||||
text: @tr("Remove");
|
||||
accessible-label: @tr("Remove {}", viewer.name);
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Bridge.kick-viewer(viewer.client); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Footer {
|
||||
Button {
|
||||
text: @tr("Close");
|
||||
clicked => { done(); }
|
||||
}
|
||||
Button {
|
||||
kind: ButtonKind.danger;
|
||||
icon: Icons.square;
|
||||
text: @tr("Stop sharing");
|
||||
clicked => { Bridge.stop-share(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
if !live: VerticalLayout {
|
||||
spacing: Theme.space-4;
|
||||
vertical-stretch: 1;
|
||||
Text {
|
||||
text: @tr("What to share");
|
||||
font-weight: Theme.weight-semibold;
|
||||
color: Theme.text;
|
||||
}
|
||||
ListView {
|
||||
vertical-stretch: 1;
|
||||
min-height: 120px;
|
||||
accessible-label: @tr("What to share");
|
||||
for source[i] in Bridge.share-sources: VerticalLayout {
|
||||
padding-bottom: Theme.space-2;
|
||||
SourceCard {
|
||||
name: source.name;
|
||||
detail: source.detail;
|
||||
selected: form.source == i;
|
||||
clicked => { form.source = i; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Field {
|
||||
label: @tr("Stream name");
|
||||
TextField { text <=> form.name; label: @tr("Stream name"); }
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-4;
|
||||
Field {
|
||||
label: @tr("Frame rate");
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
Select {
|
||||
model: [@tr("15 fps"), @tr("30 fps"), @tr("60 fps")];
|
||||
current-index <=> form.fps-index;
|
||||
label: @tr("Frame rate");
|
||||
selected => { form.fps = [15, 30, 60][self.current-index]; }
|
||||
}
|
||||
TextField {
|
||||
text <=> form.fps;
|
||||
input-type: number;
|
||||
placeholder: @tr("fps");
|
||||
label: @tr("Frames per second");
|
||||
width: 80px;
|
||||
horizontal-stretch: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Field {
|
||||
label: @tr("Quality");
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
Select {
|
||||
model: [@tr("Low (2.5 Mbit/s)"), @tr("Standard (4.6 Mbit/s)"), @tr("High (8 Mbit/s)"), @tr("Best (10 Mbit/s)")];
|
||||
current-index <=> form.bitrate-index;
|
||||
label: @tr("Quality");
|
||||
selected => { form.bitrate = [2500, 4608, 8000, 10000][self.current-index]; }
|
||||
}
|
||||
TextField {
|
||||
text <=> form.bitrate;
|
||||
input-type: number;
|
||||
placeholder: @tr("kbit/s");
|
||||
label: @tr("Bitrate in kbit/s");
|
||||
width: 80px;
|
||||
horizontal-stretch: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ToggleRow {
|
||||
text: @tr("Share system audio");
|
||||
icon: Icons.volume-2;
|
||||
checked <=> form.audio;
|
||||
}
|
||||
ToggleRow {
|
||||
text: @tr("Let everyone in the channel watch without asking");
|
||||
icon: Icons.users;
|
||||
checked <=> form.auto-accept;
|
||||
}
|
||||
if Bridge.share-error != "": Banner {
|
||||
text: Bridge.share-error;
|
||||
tone: Theme.danger;
|
||||
icon: Icons.circle-alert;
|
||||
}
|
||||
Footer {
|
||||
Button {
|
||||
text: @tr("Cancel");
|
||||
clicked => { done(); }
|
||||
}
|
||||
Button {
|
||||
kind: ButtonKind.primary;
|
||||
icon: Icons.radio;
|
||||
text: Bridge.share-busy ? @tr("Starting…") : @tr("Start sharing");
|
||||
enabled: !Bridge.share-busy && Bridge.streams-available && Bridge.share-sources.length > 0;
|
||||
clicked => { Bridge.start-share(form); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Local volume and mute of one client.
|
||||
export component ClientAudioDialog inherits Modal {
|
||||
callback done();
|
||||
title: Bridge.client-audio.name;
|
||||
subtitle: @tr("Only changes what you hear.");
|
||||
icon: Icons.volume-2;
|
||||
card-width: 420px;
|
||||
card-height: 300px;
|
||||
dismissed => { done(); }
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
Text {
|
||||
text: @tr("Volume");
|
||||
color: Theme.text;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
Slider {
|
||||
y: (parent.height - self.height) / 2;
|
||||
minimum: 0;
|
||||
maximum: 400;
|
||||
step: 5;
|
||||
value: Bridge.client-audio.volume;
|
||||
enabled: !Bridge.client-audio.muted;
|
||||
label: @tr("Volume of {}", Bridge.client-audio.name);
|
||||
changed(v) => {
|
||||
Bridge.client-audio.volume = round(v / 5) * 5;
|
||||
Bridge.client-audio-changed(Bridge.client-audio);
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: @tr("{}%", round(Bridge.client-audio.volume));
|
||||
width: 48px;
|
||||
color: Theme.text-secondary;
|
||||
vertical-alignment: center;
|
||||
horizontal-alignment: right;
|
||||
}
|
||||
}
|
||||
ToggleRow {
|
||||
text: @tr("Mute for me");
|
||||
icon: Icons.volume-x;
|
||||
checked: Bridge.client-audio.muted;
|
||||
toggled(on) => {
|
||||
Bridge.client-audio.muted = on;
|
||||
Bridge.client-audio-changed(Bridge.client-audio);
|
||||
}
|
||||
}
|
||||
Rectangle { vertical-stretch: 1; }
|
||||
Footer {
|
||||
Button {
|
||||
text: @tr("Reset");
|
||||
icon: Icons.refresh-cw;
|
||||
clicked => {
|
||||
Bridge.client-audio.volume = 100;
|
||||
Bridge.client-audio.muted = false;
|
||||
Bridge.client-audio-changed(Bridge.client-audio);
|
||||
}
|
||||
}
|
||||
Button {
|
||||
kind: ButtonKind.primary;
|
||||
text: @tr("Close");
|
||||
clicked => { done(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bundled assets that need crediting where the app shows its notices.
|
||||
export component Credits inherits VerticalLayout {
|
||||
spacing: Theme.space-2;
|
||||
Text {
|
||||
text: @tr("Fonts, icons and emoji");
|
||||
font-weight: Theme.weight-semibold;
|
||||
color: Theme.text;
|
||||
}
|
||||
Text {
|
||||
text: "Inter — Copyright (c) 2016 The Inter Project Authors, SIL Open Font License 1.1.";
|
||||
color: Theme.text-secondary;
|
||||
font-size: Theme.font-sm;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
Text {
|
||||
text: "Lucide icons — Copyright (c) Lucide Icons and Contributors, ISC License.";
|
||||
color: Theme.text-secondary;
|
||||
font-size: Theme.font-sm;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
Text {
|
||||
text: "Twemoji graphics by Twitter, Inc and other contributors, licensed under CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/).";
|
||||
color: Theme.text-secondary;
|
||||
font-size: Theme.font-sm;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
}
|
||||
|
||||
export component AboutDialog inherits Modal {
|
||||
callback done();
|
||||
title: Bridge.app-name + " " + Bridge.app-version;
|
||||
subtitle: @tr("Unofficial TeamSpeak 3/6 compatible client. Not affiliated with TeamSpeak Systems GmbH.");
|
||||
icon: Icons.logo;
|
||||
tint-icon: false;
|
||||
card-width: 760px;
|
||||
card-height: 720px;
|
||||
dismissed => { done(); }
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-5;
|
||||
Rectangle {
|
||||
width: 200px;
|
||||
height: 110px;
|
||||
border-radius: Theme.radius-md;
|
||||
// AboutSlint is required by Slint's royalty-free license; it is
|
||||
// drawn for a light background.
|
||||
background: #ffffff;
|
||||
AboutSlint {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
Credits {
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
}
|
||||
if Bridge.h264-enabled: Text {
|
||||
text: Bridge.h264-attribution;
|
||||
color: Theme.text-secondary;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
Text {
|
||||
text: @tr("Third-party notices");
|
||||
font-weight: Theme.weight-semibold;
|
||||
color: Theme.text;
|
||||
}
|
||||
Rectangle {
|
||||
vertical-stretch: 1;
|
||||
background: Theme.surface-2;
|
||||
border-radius: Theme.radius-md;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border;
|
||||
ListView {
|
||||
accessible-label: @tr("Third-party notices");
|
||||
for line in Bridge.notices: Text {
|
||||
x: 10px;
|
||||
width: parent.width - 20px;
|
||||
text: line;
|
||||
font-size: Theme.font-xs;
|
||||
color: Theme.text-secondary;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
Footer {
|
||||
Button {
|
||||
kind: ButtonKind.primary;
|
||||
text: @tr("Close");
|
||||
clicked => { done(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
// The home page: a welcome banner and the servers at a glance. Later
|
||||
// versions add friends, live rooms and activity here.
|
||||
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Bridge, ServerItem } from "../bridge.slint";
|
||||
import { Nav, Page, SettingsSection } from "../nav.slint";
|
||||
import { Icon, Button, ButtonKind, Avatar, Status, Chip, SectionHeader, NavItem, Divider, CountBadge, LiveBadge, ScrollView } from "../components/index.slint";
|
||||
|
||||
// The sidebar next to the home page.
|
||||
export component HomeNav inherits VerticalLayout {
|
||||
spacing: Theme.space-2;
|
||||
NavItem {
|
||||
icon: Icons.home;
|
||||
text: @tr("Home");
|
||||
selected: true;
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.server;
|
||||
text: @tr("Servers");
|
||||
badge: 0;
|
||||
clicked => { Nav.show(Page.server); }
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.settings;
|
||||
text: @tr("Settings");
|
||||
clicked => { Nav.open-settings(SettingsSection.voice); }
|
||||
}
|
||||
VerticalLayout {
|
||||
padding-top: Theme.space-5;
|
||||
padding-left: Theme.space-3;
|
||||
padding-bottom: Theme.space-2;
|
||||
Text {
|
||||
text: @tr("Quick Actions");
|
||||
font-size: Theme.font-sm;
|
||||
font-weight: Theme.weight-semibold;
|
||||
color: Theme.text-secondary;
|
||||
}
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.plus;
|
||||
text: @tr("Add a server");
|
||||
clicked => { Nav.add-server(); }
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.info;
|
||||
text: @tr("About {}", Bridge.app-name);
|
||||
clicked => { Nav.open-about(); }
|
||||
}
|
||||
}
|
||||
|
||||
// A server as a card with its state and a button to open it.
|
||||
component ServerCard inherits Rectangle {
|
||||
in property <ServerItem> server;
|
||||
min-width: 220px;
|
||||
max-width: 340px;
|
||||
horizontal-stretch: 1;
|
||||
height: 176px;
|
||||
border-radius: Theme.radius-lg;
|
||||
clip: true;
|
||||
background: Theme.surface-2;
|
||||
border-width: 1px;
|
||||
border-color: area.has-hover ? Theme.border-strong : Theme.border;
|
||||
accessible-role: AccessibleRole.list-item;
|
||||
accessible-label: server.name;
|
||||
accessible-description: server.address;
|
||||
accessible-action-default => { Nav.select-server(server.id); }
|
||||
area := TouchArea {
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => { Nav.select-server(root.server.id); }
|
||||
}
|
||||
Rectangle {
|
||||
height: 56px;
|
||||
y: 0;
|
||||
background: @linear-gradient(120deg, root.server.tint 0%, root.server.tint.darker(0.6) 100%);
|
||||
opacity: 0.8;
|
||||
}
|
||||
VerticalLayout {
|
||||
padding: Theme.space-4;
|
||||
spacing: Theme.space-2;
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
Avatar {
|
||||
size: 52px;
|
||||
square: true;
|
||||
initials: root.server.initials;
|
||||
tint: root.server.tint;
|
||||
label: root.server.name;
|
||||
status: root.server.status == "connected" ? Status.online : root.server.status == "observing" ? Status.info : root.server.status == "connecting" ? Status.idle : Status.none;
|
||||
}
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
if root.server.live: VerticalLayout {
|
||||
alignment: start;
|
||||
LiveBadge { }
|
||||
}
|
||||
if root.server.unread > 0: VerticalLayout {
|
||||
alignment: start;
|
||||
CountBadge { count: root.server.unread; }
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: root.server.name;
|
||||
color: Theme.text;
|
||||
font-size: Theme.font-md;
|
||||
font-weight: Theme.weight-semibold;
|
||||
overflow: elide;
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
Rectangle {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
border-radius: 4px;
|
||||
background: root.server.status == "connected" ? Theme.success : root.server.status == "observing" ? Theme.info : root.server.status == "connecting" ? Theme.warning : Theme.offline;
|
||||
}
|
||||
Text {
|
||||
text: root.server.status == "connected" ? @tr("Connected") : root.server.status == "observing" ? @tr("Observing") : root.server.status == "connecting" ? @tr("Connecting…") : root.server.address;
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export component HomePage inherits Rectangle {
|
||||
ScrollView {
|
||||
VerticalLayout {
|
||||
padding: Theme.space-6;
|
||||
spacing: Theme.space-6;
|
||||
alignment: start;
|
||||
// Welcome banner.
|
||||
Rectangle {
|
||||
height: 220px;
|
||||
border-radius: Theme.radius-xl;
|
||||
clip: true;
|
||||
background: @linear-gradient(115deg, #0e1d5c 0%, #1c1470 45%, #3a1f86 75%, #0b2a6b 100%);
|
||||
border-width: 1px;
|
||||
border-color: Theme.border-strong;
|
||||
// A moon.
|
||||
Rectangle {
|
||||
x: parent.width - 260px;
|
||||
y: 24px;
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
border-radius: 75px;
|
||||
background: @radial-gradient(circle, #9fb6ff 0%, #5a6fd6 55%, #2a2f86 100%);
|
||||
opacity: 0.55;
|
||||
}
|
||||
for star[i] in [
|
||||
{ x: 0.55, y: 0.18 }, { x: 0.62, y: 0.52 }, { x: 0.71, y: 0.1 }, { x: 0.9, y: 0.3 },
|
||||
{ x: 0.95, y: 0.75 }, { x: 0.83, y: 0.86 }, { x: 0.6, y: 0.8 }, { x: 0.5, y: 0.6 },
|
||||
]: Rectangle {
|
||||
x: parent.width * star.x;
|
||||
y: parent.height * star.y;
|
||||
width: mod(i, 3) == 0 ? 3px : 2px;
|
||||
height: self.width;
|
||||
border-radius: self.width / 2;
|
||||
background: #ffffffc0;
|
||||
}
|
||||
VerticalLayout {
|
||||
padding: Theme.space-7;
|
||||
spacing: Theme.space-3;
|
||||
alignment: center;
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-4;
|
||||
alignment: start;
|
||||
Image {
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
source: Icons.logo;
|
||||
}
|
||||
Text {
|
||||
text: Bridge.app-name;
|
||||
color: #ffffff;
|
||||
font-size: 40px * Theme.font-scale;
|
||||
font-weight: Theme.weight-bold;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: @tr("Voice, chat and streams on TeamSpeak servers.");
|
||||
color: #ffffff;
|
||||
font-size: Theme.font-xl;
|
||||
font-weight: Theme.weight-medium;
|
||||
}
|
||||
Text {
|
||||
text: @tr("Talk. Watch. Share. Or look in without joining.");
|
||||
color: #c9d4ff;
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
spacing: Theme.space-3;
|
||||
Button {
|
||||
kind: ButtonKind.primary;
|
||||
icon: Icons.plus;
|
||||
text: @tr("Add a server");
|
||||
clicked => { Nav.add-server(); }
|
||||
}
|
||||
if Bridge.servers.length > 0: Button {
|
||||
icon: Icons.arrow-right;
|
||||
text: @tr("Open {}", Bridge.server-title);
|
||||
clicked => { Nav.show(Page.server); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SectionHeader {
|
||||
text: @tr("Your servers");
|
||||
icon: Icons.server;
|
||||
count: Bridge.servers.length;
|
||||
action: @tr("Add");
|
||||
action-clicked => { Nav.add-server(); }
|
||||
}
|
||||
if Bridge.servers.length == 0: Text {
|
||||
text: @tr("No servers yet. Add one with its address and your nickname.");
|
||||
color: Theme.text-muted;
|
||||
}
|
||||
FlexboxLayout {
|
||||
spacing: Theme.space-4;
|
||||
alignment: stretch;
|
||||
for server in Bridge.servers: ServerCard {
|
||||
server: server;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
// Pages of the narrow (phone) layout that the desktop shows elsewhere:
|
||||
// the server list with the channels, activity, and the "You" page.
|
||||
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Bridge } from "../bridge.slint";
|
||||
import { Nav, Page, SettingsSection } from "../nav.slint";
|
||||
import { Icon, Button, ButtonKind, IconButton, Avatar, Status, CountBadge, LiveBadge, NavItem, ListItem, SectionHeader, Card, Banner, ScrollView, ActionButton } from "../components/index.slint";
|
||||
import { ServerHeader, ConnectActions, ChannelTree } from "channels.slint";
|
||||
import { StreamsPanel } from "streams.slint";
|
||||
import { VoiceCard, VoiceButtons } from "../shells/common.slint";
|
||||
|
||||
// Servers as a horizontal strip, the current server, its channels.
|
||||
export component MobileServers inherits VerticalLayout {
|
||||
padding: Theme.space-3;
|
||||
spacing: Theme.space-3;
|
||||
ScrollView {
|
||||
height: 64px;
|
||||
vertical-stretch: 0;
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
alignment: start;
|
||||
for server in Bridge.servers: Rectangle {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
accessible-role: AccessibleRole.list-item;
|
||||
accessible-label: server.name;
|
||||
accessible-item-selectable: true;
|
||||
accessible-item-selected: Bridge.current-server == server.id;
|
||||
accessible-action-default => { Nav.select-server(server.id); }
|
||||
if Bridge.current-server == server.id: Rectangle {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: Theme.radius-lg + 3px;
|
||||
border-width: 2px;
|
||||
border-color: Theme.accent;
|
||||
}
|
||||
Avatar {
|
||||
size: 46px;
|
||||
square: true;
|
||||
initials: server.initials;
|
||||
tint: server.tint;
|
||||
status: server.status == "connected" ? Status.online : server.status == "observing" ? Status.info : Status.none;
|
||||
}
|
||||
if server.unread > 0: CountBadge {
|
||||
x: parent.width - self.width;
|
||||
y: 0;
|
||||
count: server.unread;
|
||||
}
|
||||
TouchArea {
|
||||
clicked => { Nav.select-server(server.id); }
|
||||
double-clicked => { Nav.edit-server(server.id); }
|
||||
}
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.plus;
|
||||
label: @tr("Add server");
|
||||
round: true;
|
||||
filled: true;
|
||||
size: 46px;
|
||||
tint: Theme.success;
|
||||
y: 5px;
|
||||
clicked => { Nav.add-server(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
ServerHeader { }
|
||||
if !Bridge.voice-connected && !Bridge.voice-connecting: ConnectActions { }
|
||||
if Bridge.voice-connected || Bridge.voice-connecting: VoiceCard { }
|
||||
ChannelTree {
|
||||
vertical-stretch: 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Streams, requests and the app's status.
|
||||
export component ActivityPage inherits VerticalLayout {
|
||||
spacing: Theme.space-3;
|
||||
if Bridge.crash-notice != "": HorizontalLayout {
|
||||
padding: Theme.space-3;
|
||||
Banner {
|
||||
text: Bridge.crash-notice;
|
||||
IconButton {
|
||||
icon: Icons.x;
|
||||
label: @tr("Dismiss");
|
||||
size: 28px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Bridge.dismiss-crash-notice(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
if Bridge.status-text != "": HorizontalLayout {
|
||||
padding-left: Theme.space-4;
|
||||
padding-right: Theme.space-4;
|
||||
spacing: Theme.space-3;
|
||||
Icon {
|
||||
source: Icons.info;
|
||||
size: Theme.icon-sm;
|
||||
tint: Theme.accent-text;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: Bridge.status-text;
|
||||
color: Theme.text-secondary;
|
||||
font-size: Theme.font-sm;
|
||||
wrap: word-wrap;
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
}
|
||||
StreamsPanel {
|
||||
vertical-stretch: 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Profile, voice controls, settings and About.
|
||||
export component YouPage inherits ScrollView {
|
||||
VerticalLayout {
|
||||
padding: Theme.space-4;
|
||||
spacing: Theme.space-4;
|
||||
alignment: start;
|
||||
Card {
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-4;
|
||||
Avatar {
|
||||
size: 56px;
|
||||
initials: "";
|
||||
tint: Theme.accent;
|
||||
status: Bridge.voice-connected ? Status.online : Bridge.observing ? Status.info : Status.offline;
|
||||
Icon {
|
||||
source: Icons.user;
|
||||
size: 28px;
|
||||
tint: #ffffff;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
Text {
|
||||
text: Bridge.nickname != "" ? Bridge.nickname : Bridge.app-name;
|
||||
color: Theme.text;
|
||||
font-size: Theme.font-lg;
|
||||
font-weight: Theme.weight-semibold;
|
||||
}
|
||||
Text {
|
||||
text: Bridge.voice-connected ? Bridge.server-title : @tr("Offline");
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: space-around;
|
||||
ActionButton {
|
||||
icon: Bridge.input-muted ? Icons.mic-off : Icons.mic;
|
||||
text: Bridge.input-muted ? @tr("Unmute") : @tr("Mute");
|
||||
checked: Bridge.input-muted;
|
||||
danger: true;
|
||||
enabled: Bridge.voice-connected;
|
||||
clicked => { Bridge.set-input-muted(!Bridge.input-muted); }
|
||||
}
|
||||
ActionButton {
|
||||
icon: Bridge.output-muted ? Icons.headphone-off : Icons.headphones;
|
||||
text: Bridge.output-muted ? @tr("Undeafen") : @tr("Deafen");
|
||||
checked: Bridge.output-muted;
|
||||
danger: true;
|
||||
enabled: Bridge.voice-connected;
|
||||
clicked => { Bridge.set-output-muted(!Bridge.output-muted); }
|
||||
}
|
||||
if Bridge.streams-available && Bridge.can-share: ActionButton {
|
||||
icon: Icons.radio;
|
||||
text: Bridge.share-state == "live" ? @tr("Live") : @tr("Go Live");
|
||||
checked: Bridge.share-state == "live";
|
||||
clicked => { Nav.open-share(); }
|
||||
}
|
||||
ActionButton {
|
||||
icon: Icons.phone-off;
|
||||
text: @tr("Leave");
|
||||
danger: true;
|
||||
checked: Bridge.voice-connected;
|
||||
enabled: Bridge.voice-connected;
|
||||
clicked => { Bridge.disconnect-voice(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
SectionHeader {
|
||||
text: @tr("Settings");
|
||||
small: true;
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.mic;
|
||||
text: @tr("Voice & Video");
|
||||
chevron: true;
|
||||
clicked => { Nav.open-settings(SettingsSection.voice); }
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.keyboard;
|
||||
text: @tr("Keybinds");
|
||||
chevron: true;
|
||||
clicked => { Nav.open-settings(SettingsSection.keybinds); }
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.radio;
|
||||
text: @tr("Streaming");
|
||||
chevron: true;
|
||||
clicked => { Nav.open-settings(SettingsSection.streaming); }
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.shield;
|
||||
text: @tr("Privacy & Safety");
|
||||
chevron: true;
|
||||
clicked => { Nav.open-settings(SettingsSection.privacy); }
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.palette;
|
||||
text: @tr("Appearance");
|
||||
chevron: true;
|
||||
clicked => { Nav.open-settings(SettingsSection.appearance); }
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.info;
|
||||
text: @tr("About {}", Bridge.app-name);
|
||||
chevron: true;
|
||||
clicked => { Nav.open-about(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,514 @@
|
||||
// The settings page: navigation (sidebar) and the sections as cards.
|
||||
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Bridge } from "../bridge.slint";
|
||||
import { Nav, SettingsSection } from "../nav.slint";
|
||||
import { Icon, Button, ButtonKind, TextField, Field, Select, Toggle, ToggleRow, Slider, SegmentedTabs, Card, Meter, NavItem, Divider, ScrollView } from "../components/index.slint";
|
||||
|
||||
// A label, a control (@children) and a value at the right.
|
||||
component SliderRow inherits HorizontalLayout {
|
||||
in property <string> label;
|
||||
in property <string> value;
|
||||
spacing: Theme.space-4;
|
||||
min-height: Theme.control-height;
|
||||
Text {
|
||||
text: root.label;
|
||||
color: Theme.text;
|
||||
vertical-alignment: center;
|
||||
min-width: 130px;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
@children
|
||||
Text {
|
||||
text: root.value;
|
||||
color: Theme.text-secondary;
|
||||
width: 64px;
|
||||
vertical-alignment: center;
|
||||
horizontal-alignment: right;
|
||||
}
|
||||
}
|
||||
|
||||
// Small print under a control.
|
||||
component Hint inherits Text {
|
||||
font-size: Theme.font-sm;
|
||||
color: Theme.text-muted;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
|
||||
// The navigation of the settings, for the sidebar.
|
||||
export component SettingsNav inherits VerticalLayout {
|
||||
spacing: Theme.space-2;
|
||||
VerticalLayout {
|
||||
padding-left: Theme.space-3;
|
||||
padding-bottom: Theme.space-4;
|
||||
Text {
|
||||
text: @tr("Settings");
|
||||
font-size: Theme.font-2xl;
|
||||
font-weight: Theme.weight-bold;
|
||||
color: Theme.text;
|
||||
}
|
||||
Text {
|
||||
text: @tr("Customize your {} experience", Bridge.app-name);
|
||||
font-size: Theme.font-sm;
|
||||
color: Theme.text-muted;
|
||||
}
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.mic;
|
||||
text: @tr("Voice & Video");
|
||||
subtitle: @tr("Microphone, speakers, processing");
|
||||
selected: Nav.settings-section == SettingsSection.voice;
|
||||
clicked => { Nav.open-settings(SettingsSection.voice); }
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.keyboard;
|
||||
text: @tr("Keybinds");
|
||||
subtitle: @tr("Push-to-talk");
|
||||
selected: Nav.settings-section == SettingsSection.keybinds;
|
||||
clicked => { Nav.open-settings(SettingsSection.keybinds); }
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.radio;
|
||||
text: @tr("Streaming");
|
||||
subtitle: @tr("Codecs for streams");
|
||||
selected: Nav.settings-section == SettingsSection.streaming;
|
||||
clicked => { Nav.open-settings(SettingsSection.streaming); }
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.shield;
|
||||
text: @tr("Privacy & Safety");
|
||||
subtitle: @tr("Crash reports");
|
||||
selected: Nav.settings-section == SettingsSection.privacy;
|
||||
clicked => { Nav.open-settings(SettingsSection.privacy); }
|
||||
}
|
||||
NavItem {
|
||||
icon: Icons.palette;
|
||||
text: @tr("Appearance");
|
||||
subtitle: @tr("Theme, text size, layout");
|
||||
selected: Nav.settings-section == SettingsSection.appearance;
|
||||
clicked => { Nav.open-settings(SettingsSection.appearance); }
|
||||
}
|
||||
Divider { }
|
||||
NavItem {
|
||||
icon: Icons.info;
|
||||
text: @tr("About");
|
||||
subtitle: @tr("Version and notices");
|
||||
clicked => { Nav.open-about(); }
|
||||
}
|
||||
}
|
||||
|
||||
component VoiceSection inherits FlexboxLayout {
|
||||
spacing: Theme.space-5;
|
||||
alignment: stretch;
|
||||
Card {
|
||||
min-width: 340px;
|
||||
horizontal-stretch: 1;
|
||||
title: @tr("Microphone");
|
||||
icon: Icons.mic;
|
||||
Select {
|
||||
model: Bridge.input-devices;
|
||||
current-index: Bridge.audio.input-index;
|
||||
icon: Icons.mic;
|
||||
label: @tr("Microphone");
|
||||
selected => {
|
||||
Bridge.audio.input-index = self.current-index;
|
||||
Bridge.audio-changed(Bridge.audio);
|
||||
}
|
||||
}
|
||||
Field {
|
||||
label: @tr("Transmit");
|
||||
SegmentedTabs {
|
||||
model: [@tr("Push-to-talk"), @tr("Voice activation"), @tr("Continuously")];
|
||||
current-index: Bridge.audio.transmit;
|
||||
label: @tr("Transmit");
|
||||
selected(i) => {
|
||||
Bridge.audio.transmit = i;
|
||||
Bridge.audio-changed(Bridge.audio);
|
||||
}
|
||||
}
|
||||
}
|
||||
SliderRow {
|
||||
label: @tr("Voice activation level");
|
||||
value: @tr("{} dB", round(Bridge.audio.vad-threshold));
|
||||
Slider {
|
||||
y: (parent.height - self.height) / 2;
|
||||
minimum: -70;
|
||||
maximum: -10;
|
||||
value: Bridge.audio.vad-threshold;
|
||||
enabled: Bridge.audio.transmit == 1;
|
||||
label: @tr("Voice activation level");
|
||||
changed(v) => {
|
||||
Bridge.audio.vad-threshold = round(v);
|
||||
Bridge.audio-changed(Bridge.audio);
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-4;
|
||||
Text {
|
||||
text: @tr("Input level");
|
||||
color: Theme.text;
|
||||
vertical-alignment: center;
|
||||
min-width: 130px;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
Meter {
|
||||
level: Bridge.input-level;
|
||||
threshold: Bridge.audio.vad-threshold;
|
||||
show-threshold: Bridge.audio.transmit == 1;
|
||||
active: Bridge.input-sending || Bridge.mic-test;
|
||||
}
|
||||
}
|
||||
Button {
|
||||
small: true;
|
||||
icon: Icons.mic;
|
||||
text: Bridge.mic-test ? @tr("Stop test") : @tr("Test mic");
|
||||
checked: Bridge.mic-test;
|
||||
enabled: !Bridge.voice-connected;
|
||||
accessible-label: Bridge.mic-test ? @tr("Stop the microphone test") : @tr("Test the microphone");
|
||||
clicked => { Bridge.toggle-mic-test(); }
|
||||
}
|
||||
}
|
||||
Hint {
|
||||
text: Bridge.voice-connected ? (Bridge.input-sending ? @tr("Sending voice") : @tr("Not sending")) : @tr("The meter shows the microphone while connected or during a test.");
|
||||
color: Bridge.input-sending ? Theme.success : Theme.text-muted;
|
||||
}
|
||||
SliderRow {
|
||||
label: @tr("Microphone gain");
|
||||
value: @tr("{} dB", round(Bridge.audio.input-gain));
|
||||
Slider {
|
||||
y: (parent.height - self.height) / 2;
|
||||
minimum: -30;
|
||||
maximum: 30;
|
||||
value: Bridge.audio.input-gain;
|
||||
label: @tr("Microphone gain");
|
||||
changed(v) => {
|
||||
Bridge.audio.input-gain = round(v);
|
||||
Bridge.audio-changed(Bridge.audio);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Card {
|
||||
min-width: 340px;
|
||||
horizontal-stretch: 1;
|
||||
title: @tr("Processing");
|
||||
icon: Icons.audio-lines;
|
||||
ToggleRow {
|
||||
icon: Icons.volume-x;
|
||||
text: @tr("Echo cancellation");
|
||||
description: @tr("Prevents audio feedback");
|
||||
checked: Bridge.audio.echo-cancellation;
|
||||
toggled(on) => {
|
||||
Bridge.audio.echo-cancellation = on;
|
||||
Bridge.audio-changed(Bridge.audio);
|
||||
}
|
||||
}
|
||||
ToggleRow {
|
||||
icon: Icons.audio-lines;
|
||||
text: @tr("Noise suppression");
|
||||
description: @tr("Reduces background noise");
|
||||
checked: Bridge.audio.noise-suppression;
|
||||
toggled(on) => {
|
||||
Bridge.audio.noise-suppression = on;
|
||||
Bridge.audio-changed(Bridge.audio);
|
||||
}
|
||||
}
|
||||
Field {
|
||||
label: @tr("Noise suppression level");
|
||||
SegmentedTabs {
|
||||
model: [@tr("Low"), @tr("Moderate"), @tr("High"), @tr("Very high")];
|
||||
current-index: Bridge.audio.noise-level;
|
||||
label: @tr("Noise suppression level");
|
||||
opacity: Bridge.audio.noise-suppression ? 1.0 : 0.5;
|
||||
selected(i) => {
|
||||
Bridge.audio.noise-level = i;
|
||||
Bridge.audio-changed(Bridge.audio);
|
||||
}
|
||||
}
|
||||
}
|
||||
ToggleRow {
|
||||
icon: Icons.sliders-horizontal;
|
||||
text: @tr("Automatic gain control");
|
||||
description: @tr("Keeps your volume consistent");
|
||||
checked: Bridge.audio.auto-gain;
|
||||
toggled(on) => {
|
||||
Bridge.audio.auto-gain = on;
|
||||
Bridge.audio-changed(Bridge.audio);
|
||||
}
|
||||
}
|
||||
}
|
||||
Card {
|
||||
min-width: 340px;
|
||||
horizontal-stretch: 1;
|
||||
title: @tr("Output");
|
||||
icon: Icons.volume-2;
|
||||
Select {
|
||||
model: Bridge.output-devices;
|
||||
current-index: Bridge.audio.output-index;
|
||||
icon: Icons.headphones;
|
||||
label: @tr("Speakers");
|
||||
selected => {
|
||||
Bridge.audio.output-index = self.current-index;
|
||||
Bridge.audio-changed(Bridge.audio);
|
||||
}
|
||||
}
|
||||
SliderRow {
|
||||
label: @tr("Output volume");
|
||||
value: @tr("{}%", round(Bridge.audio.output-volume));
|
||||
Slider {
|
||||
y: (parent.height - self.height) / 2;
|
||||
minimum: 0;
|
||||
maximum: 200;
|
||||
value: Bridge.audio.output-volume;
|
||||
label: @tr("Playback volume");
|
||||
changed(v) => {
|
||||
Bridge.audio.output-volume = round(v);
|
||||
Bridge.audio-changed(Bridge.audio);
|
||||
}
|
||||
}
|
||||
}
|
||||
SliderRow {
|
||||
label: @tr("Playback buffer");
|
||||
value: @tr("{} ms", round(Bridge.audio.playback-buffer));
|
||||
Slider {
|
||||
y: (parent.height - self.height) / 2;
|
||||
minimum: 20;
|
||||
maximum: 180;
|
||||
step: 10;
|
||||
value: Bridge.audio.playback-buffer;
|
||||
label: @tr("Playback buffer");
|
||||
changed(v) => {
|
||||
Bridge.audio.playback-buffer = round(v / 10) * 10;
|
||||
Bridge.audio-changed(Bridge.audio);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component KeybindsSection inherits VerticalLayout {
|
||||
alignment: start;
|
||||
Card {
|
||||
title: @tr("Push-to-talk");
|
||||
icon: Icons.keyboard;
|
||||
ToggleRow {
|
||||
text: @tr("Global push-to-talk key");
|
||||
description: @tr("Works while other windows have focus");
|
||||
checked <=> Bridge.global-ptt;
|
||||
toggled => { Bridge.apply-ptt(Bridge.global-ptt, Bridge.ptt-key); }
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
TextField {
|
||||
text <=> Bridge.ptt-key;
|
||||
placeholder: "Ctrl+Shift+T";
|
||||
icon: Icons.keyboard;
|
||||
enabled: Bridge.global-ptt;
|
||||
label: @tr("Push-to-talk key");
|
||||
accepted => { Bridge.apply-ptt(Bridge.global-ptt, Bridge.ptt-key); }
|
||||
}
|
||||
Button {
|
||||
text: @tr("Apply");
|
||||
kind: ButtonKind.primary;
|
||||
enabled: Bridge.global-ptt;
|
||||
clicked => { Bridge.apply-ptt(Bridge.global-ptt, Bridge.ptt-key); }
|
||||
}
|
||||
}
|
||||
if Bridge.ptt-status != "": Text {
|
||||
text: Bridge.ptt-status;
|
||||
color: Theme.text-secondary;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
Hint {
|
||||
text: @tr("Keys are written like Ctrl+Shift+T, Alt+F1, CapsLock or MouseBack. On Wayland the desktop asks to confirm the key and may let you pick another one. The \"Hold to talk\" button in the window always works.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component StreamingSection inherits VerticalLayout {
|
||||
alignment: start;
|
||||
Card {
|
||||
title: @tr("H.264");
|
||||
icon: Icons.video;
|
||||
ToggleRow {
|
||||
text: @tr("Enable H.264");
|
||||
description: @tr("Downloads OpenH264 from Cisco");
|
||||
checked <=> Bridge.h264-enabled;
|
||||
toggled => { Bridge.set-h264(Bridge.h264-enabled); }
|
||||
}
|
||||
Hint { text: Bridge.h264-attribution; }
|
||||
if Bridge.h264-enabled: HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
Text {
|
||||
text: Bridge.h264-status;
|
||||
color: Theme.text-secondary;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
if !Bridge.h264-loaded: Button {
|
||||
icon: Icons.download;
|
||||
text: Bridge.h264-busy ? @tr("Downloading…") : @tr("Download OpenH264");
|
||||
enabled: !Bridge.h264-busy;
|
||||
clicked => { Bridge.download-h264(); }
|
||||
}
|
||||
}
|
||||
Hint {
|
||||
text: @tr("VP8 and VP9 work without it. H.264 lets you watch streams that other clients send as H.264. The library is downloaded from Cisco only when you click Download, and Cisco's license covers its patent royalties.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component PrivacySection inherits VerticalLayout {
|
||||
alignment: start;
|
||||
Card {
|
||||
title: @tr("Crash reports");
|
||||
icon: Icons.shield;
|
||||
ToggleRow {
|
||||
text: @tr("Save crash reports on this device");
|
||||
description: @tr("Never uploaded");
|
||||
checked <=> Bridge.crash-reports;
|
||||
toggled => { Bridge.set-crash-reports(Bridge.crash-reports); }
|
||||
}
|
||||
Hint {
|
||||
text: @tr("A report is a text file with the error and where it happened. It may contain a server address from the error message. You can attach it to a bug report yourself; the app never sends it anywhere.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component AppearanceSection inherits VerticalLayout {
|
||||
alignment: start;
|
||||
spacing: Theme.space-5;
|
||||
Card {
|
||||
title: @tr("Theme");
|
||||
icon: Icons.palette;
|
||||
SegmentedTabs {
|
||||
model: [@tr("Dark"), @tr("Light"), @tr("System")];
|
||||
current-index: Bridge.appearance.theme == "light" ? 1 : Bridge.appearance.theme == "system" ? 2 : 0;
|
||||
label: @tr("Theme");
|
||||
selected(i) => {
|
||||
Bridge.appearance.theme = i == 1 ? "light" : i == 2 ? "system" : "dark";
|
||||
Bridge.appearance-changed(Bridge.appearance);
|
||||
}
|
||||
}
|
||||
SliderRow {
|
||||
label: @tr("Text size");
|
||||
value: @tr("{}%", round(Bridge.appearance.font-scale * 100));
|
||||
Slider {
|
||||
y: (parent.height - self.height) / 2;
|
||||
minimum: 0.75;
|
||||
maximum: 2.0;
|
||||
step: 0.05;
|
||||
value: Bridge.appearance.font-scale;
|
||||
label: @tr("Text size");
|
||||
released(v) => {
|
||||
Bridge.appearance.font-scale = round(v * 20) / 20;
|
||||
Bridge.appearance-changed(Bridge.appearance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Card {
|
||||
title: @tr("Layout");
|
||||
icon: Icons.layout-grid;
|
||||
Field {
|
||||
label: @tr("Phone layout below this window width (pixels)");
|
||||
hint: @tr("Narrower windows show one page at a time with a bottom navigation.");
|
||||
TextField {
|
||||
text: round(Bridge.appearance.narrow-breakpoint);
|
||||
input-type: number;
|
||||
icon: Icons.smartphone;
|
||||
label: @tr("Phone layout below this width");
|
||||
accepted(t) => {
|
||||
if t.is-float() && t.to-float() >= 0 {
|
||||
Bridge.appearance.narrow-breakpoint = t.to-float();
|
||||
Bridge.appearance-changed(Bridge.appearance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Field {
|
||||
label: @tr("Image cache (MB)");
|
||||
hint: @tr("Decoded avatars, icons and emoji kept in memory. In use: {}", Bridge.image-cache-usage);
|
||||
TextField {
|
||||
text: round(Bridge.appearance.image-cache-mb);
|
||||
input-type: number;
|
||||
icon: Icons.hard-drive;
|
||||
label: @tr("Image cache in megabytes");
|
||||
accepted(t) => {
|
||||
if t.is-float() && t.to-float() >= 0 {
|
||||
Bridge.appearance.image-cache-mb = t.to-float();
|
||||
Bridge.appearance-changed(Bridge.appearance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The page of the selected section.
|
||||
export component SettingsPage inherits Rectangle {
|
||||
// Show the section navigation above the content (narrow windows).
|
||||
in property <bool> compact;
|
||||
property <image> section-icon: Nav.settings-section == SettingsSection.voice ? Icons.mic
|
||||
: Nav.settings-section == SettingsSection.keybinds ? Icons.keyboard
|
||||
: Nav.settings-section == SettingsSection.streaming ? Icons.radio
|
||||
: Nav.settings-section == SettingsSection.privacy ? Icons.shield : Icons.palette;
|
||||
property <string> section-title: Nav.settings-section == SettingsSection.voice ? @tr("Voice & Video")
|
||||
: Nav.settings-section == SettingsSection.keybinds ? @tr("Keybinds")
|
||||
: Nav.settings-section == SettingsSection.streaming ? @tr("Streaming")
|
||||
: Nav.settings-section == SettingsSection.privacy ? @tr("Privacy & Safety") : @tr("Appearance");
|
||||
property <string> section-subtitle: Nav.settings-section == SettingsSection.voice ? @tr("Set up your microphone, speakers and voice processing.")
|
||||
: Nav.settings-section == SettingsSection.keybinds ? @tr("Talk with a key, even while other windows have focus.")
|
||||
: Nav.settings-section == SettingsSection.streaming ? @tr("Codecs for watching streams.")
|
||||
: Nav.settings-section == SettingsSection.privacy ? @tr("What the app keeps on this device.") : @tr("Theme, text size and layout. Changes apply at once.");
|
||||
accessible-role: AccessibleRole.groupbox;
|
||||
accessible-label: section-title;
|
||||
ScrollView {
|
||||
VerticalLayout {
|
||||
padding: compact ? Theme.space-4 : Theme.space-7;
|
||||
spacing: Theme.space-5;
|
||||
alignment: start;
|
||||
if root.compact: SegmentedTabs {
|
||||
model: [@tr("Voice"), @tr("Keys"), @tr("Streams"), @tr("Privacy"), @tr("Look")];
|
||||
current-index: Nav.settings-section == SettingsSection.voice ? 0 : Nav.settings-section == SettingsSection.keybinds ? 1 : Nav.settings-section == SettingsSection.streaming ? 2 : Nav.settings-section == SettingsSection.privacy ? 3 : 4;
|
||||
label: @tr("Settings sections");
|
||||
selected(i) => {
|
||||
Nav.open-settings(i == 0 ? SettingsSection.voice : i == 1 ? SettingsSection.keybinds : i == 2 ? SettingsSection.streaming : i == 3 ? SettingsSection.privacy : SettingsSection.appearance);
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-4;
|
||||
Icon {
|
||||
source: root.section-icon;
|
||||
size: 34px;
|
||||
tint: Theme.accent-text;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Text {
|
||||
text: root.section-title;
|
||||
font-size: Theme.font-3xl;
|
||||
font-weight: Theme.weight-bold;
|
||||
color: Theme.text;
|
||||
}
|
||||
Text {
|
||||
text: root.section-subtitle;
|
||||
color: Theme.text-secondary;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
if Nav.settings-section == SettingsSection.voice: VoiceSection { }
|
||||
if Nav.settings-section == SettingsSection.keybinds: KeybindsSection { }
|
||||
if Nav.settings-section == SettingsSection.streaming: StreamingSection { }
|
||||
if Nav.settings-section == SettingsSection.privacy: PrivacySection { }
|
||||
if Nav.settings-section == SettingsSection.appearance: AppearanceSection { }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,414 @@
|
||||
// Streams: the right panel (people in our channel, streams, requests to
|
||||
// watch ours) and the viewer.
|
||||
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Bridge, StreamItem, MemberItem } from "../bridge.slint";
|
||||
import { Nav } from "../nav.slint";
|
||||
import { Icon, Button, ButtonKind, IconButton, Avatar, Status, LiveBadge, Chip, SectionHeader, SpeakingBars, Slider, Spinner, ListView, ScrollView } from "../components/index.slint";
|
||||
|
||||
// A stream card: the streamer, the title, watch / show / leave.
|
||||
component StreamCard inherits Rectangle {
|
||||
in property <StreamItem> stream;
|
||||
border-radius: Theme.radius-lg;
|
||||
background: stream.watching ? Theme.accent-soft : Theme.surface-2;
|
||||
border-width: 1px;
|
||||
border-color: stream.watching ? Theme.accent : Theme.border;
|
||||
accessible-role: AccessibleRole.groupbox;
|
||||
accessible-label: stream.name;
|
||||
VerticalLayout {
|
||||
padding: Theme.space-4;
|
||||
spacing: Theme.space-3;
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
// A picture-less preview: the live mark on a gradient.
|
||||
Rectangle {
|
||||
width: 64px;
|
||||
height: 40px;
|
||||
border-radius: Theme.radius-sm;
|
||||
background: @linear-gradient(135deg, #2b1f6e 0%, #0f2a66 100%);
|
||||
Icon {
|
||||
source: Icons.monitor-up;
|
||||
size: Theme.icon-md;
|
||||
tint: #ffffffc0;
|
||||
}
|
||||
if stream.id != "": LiveBadge {
|
||||
x: 3px;
|
||||
y: 3px;
|
||||
height: 14px;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
Text {
|
||||
text: stream.id == "" ? @tr("{} is streaming", stream.streamer) : stream.name == "" ? @tr("Untitled stream") : stream.name;
|
||||
color: Theme.text;
|
||||
font-weight: Theme.weight-semibold;
|
||||
overflow: elide;
|
||||
}
|
||||
Text {
|
||||
text: stream.id == "" ? @tr("Started before you joined; looking it up…") : stream.own ? @tr("your stream") : stream.audio ? @tr("by {} · with sound", stream.streamer) : @tr("by {}", stream.streamer);
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
}
|
||||
if stream.id != "" && !stream.own: HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
if !stream.watching: Button {
|
||||
horizontal-stretch: 1;
|
||||
small: true;
|
||||
kind: ButtonKind.primary;
|
||||
icon: Icons.eye;
|
||||
text: @tr("Watch");
|
||||
accessible-label: @tr("Watch {}", stream.name);
|
||||
clicked => { Bridge.watch-stream(stream.id); }
|
||||
}
|
||||
if stream.watching && !Bridge.viewer-open: Button {
|
||||
horizontal-stretch: 1;
|
||||
small: true;
|
||||
icon: Icons.monitor;
|
||||
text: @tr("Show");
|
||||
clicked => { Bridge.show-viewer(); }
|
||||
}
|
||||
if stream.watching: Button {
|
||||
horizontal-stretch: 1;
|
||||
small: true;
|
||||
kind: ButtonKind.danger;
|
||||
icon: Icons.log-out;
|
||||
text: @tr("Leave");
|
||||
clicked => { Bridge.leave-stream(); }
|
||||
}
|
||||
}
|
||||
if stream.id == "": Spinner {
|
||||
size: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A person in our channel.
|
||||
component MemberRow inherits Rectangle {
|
||||
in property <MemberItem> member;
|
||||
height: 48px * Theme.font-scale;
|
||||
border-radius: Theme.radius-md;
|
||||
background: area.has-hover ? Theme.surface-3 : transparent;
|
||||
accessible-role: AccessibleRole.list-item;
|
||||
accessible-label: member.name;
|
||||
accessible-description: member.status;
|
||||
accessible-action-default => { Nav.open-client(member.id); }
|
||||
area := TouchArea {
|
||||
enabled: !member.myself;
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => { Nav.open-client(member.id); }
|
||||
}
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-2;
|
||||
padding-right: Theme.space-2;
|
||||
spacing: Theme.space-3;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Avatar {
|
||||
size: 34px;
|
||||
initials: member.initials;
|
||||
tint: member.tint;
|
||||
speaking: member.talking;
|
||||
status: member.away ? Status.idle : member.sound-off ? Status.dnd : Status.online;
|
||||
label: member.name;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
Text {
|
||||
text: member.name;
|
||||
color: member.myself ? Theme.accent-text : Theme.name-text;
|
||||
font-weight: Theme.weight-medium;
|
||||
overflow: elide;
|
||||
}
|
||||
if member.streaming: VerticalLayout {
|
||||
alignment: center;
|
||||
LiveBadge { }
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
Text {
|
||||
text: member.status;
|
||||
color: member.talking ? Theme.success : Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
overflow: elide;
|
||||
}
|
||||
if member.talking: SpeakingBars {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if member.muted: Icon {
|
||||
source: Icons.mic-off;
|
||||
size: 16px;
|
||||
tint: Theme.danger;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
if member.sound-off: Icon {
|
||||
source: Icons.headphone-off;
|
||||
size: 16px;
|
||||
tint: Theme.danger;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The right panel of a server: who is in our channel, the streams there,
|
||||
// and requests to watch ours.
|
||||
export component StreamsPanel inherits VerticalLayout {
|
||||
padding: Theme.space-4;
|
||||
spacing: Theme.space-3;
|
||||
HorizontalLayout {
|
||||
Text {
|
||||
text: Bridge.own-channel != "" ? @tr("In voice — {} ({})", Bridge.own-channel, Bridge.members.length) : @tr("Members");
|
||||
font-size: Theme.font-lg;
|
||||
font-weight: Theme.weight-semibold;
|
||||
color: Theme.text;
|
||||
horizontal-stretch: 1;
|
||||
overflow: elide;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.x;
|
||||
label: @tr("Close the panel");
|
||||
size: 28px;
|
||||
icon-size: Theme.icon-sm;
|
||||
clicked => { Nav.right-panel-open = false; }
|
||||
}
|
||||
}
|
||||
if Bridge.members.length == 0: Text {
|
||||
text: @tr("Join a channel with voice to see who is there.");
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
ScrollView {
|
||||
vertical-stretch: 1;
|
||||
VerticalLayout {
|
||||
spacing: Theme.space-2;
|
||||
alignment: start;
|
||||
for member in Bridge.members: MemberRow {
|
||||
member: member;
|
||||
}
|
||||
if Bridge.streams-available: VerticalLayout {
|
||||
padding-top: Theme.space-4;
|
||||
spacing: Theme.space-3;
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
SectionHeader {
|
||||
text: @tr("Streams");
|
||||
icon: Icons.radio;
|
||||
count: Bridge.streams.length;
|
||||
small: true;
|
||||
}
|
||||
if Bridge.share-state == "live": VerticalLayout {
|
||||
alignment: center;
|
||||
LiveBadge { text: @tr("YOU ARE LIVE"); }
|
||||
}
|
||||
}
|
||||
if Bridge.streams.length == 0: Text {
|
||||
text: @tr("No streams in your channel.");
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
}
|
||||
for stream in Bridge.streams: StreamCard {
|
||||
stream: stream;
|
||||
}
|
||||
if Bridge.share-state == "live" || Bridge.share-state == "starting": Button {
|
||||
icon: Icons.users;
|
||||
text: Bridge.share-requests > 0 ? @tr("Viewers ({})", Bridge.share-requests) : @tr("Manage");
|
||||
kind: Bridge.share-requests > 0 ? ButtonKind.primary : ButtonKind.secondary;
|
||||
clicked => { Nav.open-share(); }
|
||||
}
|
||||
for viewer in Bridge.share-viewers: HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
if viewer.state == "requested": Text {
|
||||
text: @tr("{} wants to watch", viewer.name);
|
||||
horizontal-stretch: 1;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
color: Theme.warning;
|
||||
}
|
||||
if viewer.state == "requested": Button {
|
||||
small: true;
|
||||
kind: ButtonKind.primary;
|
||||
text: @tr("Accept");
|
||||
clicked => { Bridge.respond-viewer(viewer.client, true); }
|
||||
}
|
||||
if viewer.state == "requested": Button {
|
||||
small: true;
|
||||
text: @tr("Deny");
|
||||
clicked => { Bridge.respond-viewer(viewer.client, false); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The stream we watch: title bar, picture, player controls.
|
||||
export component StreamViewer inherits Rectangle {
|
||||
background: Theme.dark ? #03060f : #0b1330;
|
||||
accessible-role: AccessibleRole.groupbox;
|
||||
accessible-label: @tr("Stream viewer");
|
||||
VerticalLayout {
|
||||
// Title bar.
|
||||
Rectangle {
|
||||
height: 64px;
|
||||
background: Theme.surface;
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-5;
|
||||
padding-right: Theme.space-4;
|
||||
spacing: Theme.space-4;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Avatar {
|
||||
size: 40px;
|
||||
initials: "";
|
||||
tint: Theme.accent-soft;
|
||||
label: Bridge.viewer-title;
|
||||
Icon {
|
||||
source: Icons.monitor-up;
|
||||
tint: #ffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
Text {
|
||||
text: Bridge.viewer-title;
|
||||
color: Theme.text;
|
||||
font-size: Theme.font-md;
|
||||
font-weight: Theme.weight-semibold;
|
||||
overflow: elide;
|
||||
}
|
||||
Text {
|
||||
text: Bridge.viewer-info;
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
if !Bridge.viewer-ended: VerticalLayout {
|
||||
alignment: center;
|
||||
LiveBadge { large: true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
// Picture.
|
||||
Rectangle {
|
||||
vertical-stretch: 1;
|
||||
Image {
|
||||
width: parent.width;
|
||||
height: parent.height;
|
||||
source: Bridge.viewer-frame;
|
||||
image-fit: contain;
|
||||
visible: Bridge.viewer-has-frame;
|
||||
accessible-role: AccessibleRole.image;
|
||||
accessible-label: @tr("Stream picture");
|
||||
}
|
||||
if Bridge.viewer-status != "": Rectangle {
|
||||
width: min(parent.width - 32px, status-text.preferred-width + 40px);
|
||||
height: status-text.preferred-height + 24px;
|
||||
border-radius: Theme.radius-lg;
|
||||
background: Theme.overlay;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border-strong;
|
||||
status-text := Text {
|
||||
width: min(root.width - 72px, self.preferred-width);
|
||||
text: Bridge.viewer-status;
|
||||
color: #ffffff;
|
||||
horizontal-alignment: center;
|
||||
wrap: word-wrap;
|
||||
accessible-live-region: polite;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Controls.
|
||||
Rectangle {
|
||||
height: 52px;
|
||||
background: Theme.surface;
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-4;
|
||||
padding-right: Theme.space-4;
|
||||
spacing: Theme.space-3;
|
||||
Icon {
|
||||
source: Bridge.viewer-volume > 0 ? Icons.volume-2 : Icons.volume-x;
|
||||
tint: Theme.text-secondary;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Slider {
|
||||
width: 140px;
|
||||
horizontal-stretch: 0;
|
||||
y: (parent.height - self.height) / 2;
|
||||
minimum: 0;
|
||||
maximum: 200;
|
||||
step: 5;
|
||||
value <=> Bridge.viewer-volume;
|
||||
enabled: !Bridge.viewer-ended;
|
||||
label: @tr("Stream volume");
|
||||
changed(v) => { Bridge.set-stream-volume(v); }
|
||||
}
|
||||
Text {
|
||||
text: @tr("{}%", round(Bridge.viewer-volume));
|
||||
width: 44px;
|
||||
vertical-alignment: center;
|
||||
color: Theme.text-secondary;
|
||||
font-size: Theme.font-sm;
|
||||
}
|
||||
if !Bridge.viewer-ended: HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
Rectangle {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
border-radius: 4px;
|
||||
background: Theme.live;
|
||||
}
|
||||
Text {
|
||||
text: @tr("LIVE");
|
||||
color: Theme.text;
|
||||
font-size: Theme.font-sm;
|
||||
font-weight: Theme.weight-semibold;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
IconButton {
|
||||
icon: Bridge.viewer-fullscreen ? Icons.minimize-2 : Icons.maximize;
|
||||
label: Bridge.viewer-fullscreen ? @tr("Exit full screen") : @tr("Full screen");
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Bridge.toggle-fullscreen(); }
|
||||
}
|
||||
if !Bridge.viewer-fullscreen: Button {
|
||||
small: true;
|
||||
icon: Icons.message-square;
|
||||
text: @tr("Chat");
|
||||
accessible-label: @tr("Back to the chat");
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Bridge.hide-viewer(); }
|
||||
}
|
||||
Button {
|
||||
small: true;
|
||||
kind: ButtonKind.danger;
|
||||
icon: Icons.log-out;
|
||||
text: Bridge.viewer-ended ? @tr("Close") : @tr("Leave");
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Bridge.leave-stream(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
// Pieces both shells use: the voice controls and the user card.
|
||||
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Bridge } from "../bridge.slint";
|
||||
import { Nav, SettingsSection } from "../nav.slint";
|
||||
import { Icon, IconButton, Avatar, Status } from "../components/index.slint";
|
||||
|
||||
// A rounded panel of the frame (sidebar, main area, right panel).
|
||||
export component Panel inherits Rectangle {
|
||||
background: Theme.surface.transparentize(0.08);
|
||||
border-radius: Theme.radius-xl;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border;
|
||||
clip: true;
|
||||
}
|
||||
|
||||
// Push-to-talk in the window: talks while held.
|
||||
export component HoldToTalk inherits Rectangle {
|
||||
height: Theme.control-height;
|
||||
border-radius: Theme.radius-md;
|
||||
background: Bridge.transmitting ? Theme.success.transparentize(0.2) : ptt-area.has-hover ? Theme.surface-3 : Theme.surface-2;
|
||||
border-width: 1px;
|
||||
border-color: Bridge.transmitting ? Theme.success : Theme.border;
|
||||
opacity: Bridge.voice-connected ? 1.0 : 0.4;
|
||||
accessible-role: AccessibleRole.button;
|
||||
accessible-label: @tr("Hold to talk");
|
||||
accessible-enabled: Bridge.voice-connected;
|
||||
accessible-checkable: true;
|
||||
accessible-checked: Bridge.transmitting;
|
||||
accessible-action-default => { Bridge.push-to-talk(!Bridge.transmitting); }
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
spacing: Theme.space-2;
|
||||
Icon {
|
||||
source: Icons.mic;
|
||||
size: Theme.icon-sm;
|
||||
tint: Bridge.transmitting ? Theme.on-accent : Theme.text-secondary;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: Bridge.transmitting ? @tr("Talking…") : @tr("Hold to talk");
|
||||
color: Bridge.transmitting ? Theme.on-accent : Theme.text-secondary;
|
||||
font-size: Theme.font-sm;
|
||||
font-weight: Theme.weight-medium;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
ptt-area := TouchArea {
|
||||
enabled: Bridge.voice-connected;
|
||||
pointer-event(e) => {
|
||||
if e.kind == PointerEventKind.down {
|
||||
Bridge.push-to-talk(true);
|
||||
} else if e.kind == PointerEventKind.up || e.kind == PointerEventKind.cancel {
|
||||
Bridge.push-to-talk(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// "Voice Connected — channel / server", disconnect, and hold-to-talk.
|
||||
export component VoiceCard inherits Rectangle {
|
||||
border-radius: Theme.radius-lg;
|
||||
background: Theme.surface-2;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border;
|
||||
accessible-role: AccessibleRole.groupbox;
|
||||
accessible-label: @tr("Voice");
|
||||
VerticalLayout {
|
||||
padding: Theme.space-3;
|
||||
spacing: Theme.space-3;
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
Rectangle {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
border-radius: 5px;
|
||||
background: Bridge.voice-connected ? Theme.success : Theme.warning;
|
||||
}
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
alignment: center;
|
||||
Text {
|
||||
text: Bridge.voice-connected ? @tr("Voice Connected") : @tr("Connecting…");
|
||||
color: Bridge.voice-connected ? Theme.success : Theme.warning;
|
||||
font-size: Theme.font-sm;
|
||||
font-weight: Theme.weight-semibold;
|
||||
}
|
||||
Text {
|
||||
text: Bridge.own-channel != "" ? Bridge.own-channel + " / " + Bridge.server-title : Bridge.server-title;
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-xs;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.phone-off;
|
||||
label: @tr("Disconnect");
|
||||
size: 32px;
|
||||
icon-size: Theme.icon-sm;
|
||||
tint: Theme.danger;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Bridge.disconnect-voice(); }
|
||||
}
|
||||
}
|
||||
if Bridge.voice-connected: HoldToTalk { }
|
||||
}
|
||||
}
|
||||
|
||||
// Mute, deafen, share, settings.
|
||||
export component VoiceButtons inherits HorizontalLayout {
|
||||
in property <length> size: 34px;
|
||||
spacing: Theme.space-1;
|
||||
IconButton {
|
||||
icon: Bridge.input-muted ? Icons.mic-off : Icons.mic;
|
||||
label: Bridge.input-muted ? @tr("Microphone off") : @tr("Microphone on");
|
||||
checked: Bridge.input-muted;
|
||||
danger: true;
|
||||
size: root.size;
|
||||
enabled: Bridge.voice-connected;
|
||||
clicked => { Bridge.set-input-muted(!Bridge.input-muted); }
|
||||
}
|
||||
IconButton {
|
||||
icon: Bridge.output-muted ? Icons.headphone-off : Icons.headphones;
|
||||
label: Bridge.output-muted ? @tr("Sound off") : @tr("Sound on");
|
||||
checked: Bridge.output-muted;
|
||||
danger: true;
|
||||
size: root.size;
|
||||
enabled: Bridge.voice-connected;
|
||||
clicked => { Bridge.set-output-muted(!Bridge.output-muted); }
|
||||
}
|
||||
if Bridge.streams-available && Bridge.can-share: IconButton {
|
||||
icon: Icons.monitor-up;
|
||||
label: Bridge.share-state == "live" ? @tr("Sharing") : @tr("Share screen");
|
||||
checked: Bridge.share-state == "live";
|
||||
size: root.size;
|
||||
clicked => { Nav.open-share(); }
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.settings;
|
||||
label: @tr("Settings");
|
||||
size: root.size;
|
||||
clicked => { Nav.open-settings(SettingsSection.voice); }
|
||||
}
|
||||
}
|
||||
|
||||
// Who we are on the current server, and the voice buttons.
|
||||
export component UserCard inherits Rectangle {
|
||||
min-height: 60px;
|
||||
border-radius: Theme.radius-lg;
|
||||
background: Theme.surface-2.transparentize(0.3);
|
||||
accessible-role: AccessibleRole.groupbox;
|
||||
accessible-label: @tr("You");
|
||||
HorizontalLayout {
|
||||
padding: Theme.space-2;
|
||||
padding-left: Theme.space-3;
|
||||
spacing: Theme.space-3;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Avatar {
|
||||
size: 38px;
|
||||
initials: Bridge.nickname != "" ? "" : "?";
|
||||
tint: Theme.accent;
|
||||
label: Bridge.nickname;
|
||||
status: Bridge.voice-connected ? Status.online : Bridge.observing ? Status.info : Status.offline;
|
||||
Icon {
|
||||
source: Icons.user;
|
||||
size: 20px;
|
||||
tint: #ffffff;
|
||||
visible: Bridge.nickname != "";
|
||||
}
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
Text {
|
||||
text: Bridge.nickname != "" ? Bridge.nickname : Bridge.app-name;
|
||||
color: Theme.text;
|
||||
font-weight: Theme.weight-semibold;
|
||||
overflow: elide;
|
||||
}
|
||||
Text {
|
||||
text: Bridge.voice-connected ? @tr("Online") : Bridge.observing ? @tr("Observing") : @tr("Offline");
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-xs;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
VoiceButtons { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
// The desktop frame: the server rail at the far left, the top bar, and the
|
||||
// page's panels (@children: a sidebar, the main area, a right panel). The
|
||||
// window keeps its native decorations.
|
||||
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Bridge, ServerItem } from "../bridge.slint";
|
||||
import { Nav, Page, SettingsSection } from "../nav.slint";
|
||||
import { Icon, IconButton, Avatar, Status, CountBadge, SearchBox, ScrollView, Tooltip } from "../components/index.slint";
|
||||
import { Panel, VoiceCard, UserCard } from "common.slint";
|
||||
|
||||
// A server in the rail: its icon (initials), the selection pill, state and
|
||||
// unread marks.
|
||||
component RailServer inherits Rectangle {
|
||||
in property <ServerItem> server;
|
||||
in property <bool> selected;
|
||||
callback clicked();
|
||||
callback edit();
|
||||
width: Theme.rail-width;
|
||||
height: 56px;
|
||||
accessible-role: AccessibleRole.list-item;
|
||||
accessible-label: server.name;
|
||||
accessible-description: server.address;
|
||||
accessible-item-selectable: true;
|
||||
accessible-item-selected: selected;
|
||||
accessible-action-default => { clicked(); }
|
||||
// Selection pill.
|
||||
Rectangle {
|
||||
x: 0;
|
||||
width: 4px;
|
||||
height: selected ? 36px : touch.has-hover ? 18px : 0px;
|
||||
border-radius: 2px;
|
||||
background: Theme.text;
|
||||
animate height { duration: Theme.fast; }
|
||||
}
|
||||
// Ring of the selected server.
|
||||
if selected: Rectangle {
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
border-radius: Theme.radius-lg + 2px;
|
||||
border-width: 2px;
|
||||
border-color: Theme.accent;
|
||||
background: Theme.glow.transparentize(0.6);
|
||||
}
|
||||
Avatar {
|
||||
size: 46px;
|
||||
square: true;
|
||||
initials: server.initials;
|
||||
tint: server.tint;
|
||||
label: server.name;
|
||||
status: server.status == "connected" ? Status.online : server.status == "observing" ? Status.info : server.status == "connecting" ? Status.idle : Status.none;
|
||||
}
|
||||
if server.unread > 0: CountBadge {
|
||||
x: min(parent.width - self.width - 4px, 50px);
|
||||
y: 0px;
|
||||
count: server.unread;
|
||||
}
|
||||
if server.live && server.unread == 0: Rectangle {
|
||||
x: parent.width - 20px;
|
||||
y: 4px;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 6px;
|
||||
background: Theme.live;
|
||||
border-width: 2px;
|
||||
border-color: Theme.bg-rail;
|
||||
}
|
||||
touch := TouchArea {
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => { root.clicked(); }
|
||||
double-clicked => { root.edit(); }
|
||||
}
|
||||
}
|
||||
|
||||
// The column of servers.
|
||||
export component ServerRail inherits Rectangle {
|
||||
width: Theme.rail-width;
|
||||
background: Theme.bg-rail.transparentize(0.1);
|
||||
accessible-role: AccessibleRole.list;
|
||||
accessible-label: @tr("Servers");
|
||||
Rectangle {
|
||||
x: parent.width - 1px;
|
||||
width: 1px;
|
||||
background: Theme.border;
|
||||
}
|
||||
VerticalLayout {
|
||||
padding-top: Theme.space-3;
|
||||
padding-bottom: Theme.space-3;
|
||||
spacing: Theme.space-2;
|
||||
// App mark: home.
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
Rectangle {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: Theme.radius-lg;
|
||||
background: Nav.page == Page.home ? Theme.accent-soft : logo-touch.has-hover ? Theme.surface-3 : Theme.surface-2;
|
||||
border-width: 1px;
|
||||
border-color: Nav.page == Page.home ? Theme.accent : Theme.border;
|
||||
accessible-role: AccessibleRole.button;
|
||||
accessible-label: @tr("Home");
|
||||
accessible-action-default => { Nav.show(Page.home); }
|
||||
Image {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
source: Icons.logo;
|
||||
}
|
||||
logo-touch := TouchArea {
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => { Nav.show(Page.home); }
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
padding-top: Theme.space-2;
|
||||
padding-bottom: Theme.space-2;
|
||||
Rectangle {
|
||||
width: 32px;
|
||||
height: 2px;
|
||||
border-radius: 1px;
|
||||
background: Theme.border-strong;
|
||||
}
|
||||
}
|
||||
ScrollView {
|
||||
vertical-stretch: 1;
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
spacing: Theme.space-2;
|
||||
for server in Bridge.servers: RailServer {
|
||||
server: server;
|
||||
selected: Nav.page == Page.server && Bridge.current-server == server.id;
|
||||
clicked => { Nav.select-server(server.id); }
|
||||
edit => { Nav.edit-server(server.id); }
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
padding-top: Theme.space-2;
|
||||
IconButton {
|
||||
icon: Icons.plus;
|
||||
label: @tr("Add server");
|
||||
round: true;
|
||||
filled: true;
|
||||
size: 46px;
|
||||
tint: Theme.success;
|
||||
clicked => { Nav.add-server(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
IconButton {
|
||||
icon: Icons.settings;
|
||||
label: @tr("Settings");
|
||||
round: true;
|
||||
size: 46px;
|
||||
checked: Nav.page == Page.settings;
|
||||
clicked => { Nav.open-settings(SettingsSection.voice); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The bar at the top: the app name and page, search, notifications.
|
||||
export component TopBar inherits Rectangle {
|
||||
in property <string> context;
|
||||
height: Theme.topbar-height;
|
||||
accessible-role: AccessibleRole.banner;
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-4;
|
||||
padding-right: Theme.space-4;
|
||||
spacing: Theme.space-4;
|
||||
HorizontalLayout {
|
||||
width: Theme.sidebar-width - Theme.space-4;
|
||||
spacing: Theme.space-3;
|
||||
Image {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
source: Icons.logo;
|
||||
}
|
||||
Text {
|
||||
text: Bridge.app-name;
|
||||
color: Theme.text;
|
||||
font-size: Theme.font-xl;
|
||||
font-weight: Theme.weight-semibold;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
if root.context != "": Text {
|
||||
text: root.context;
|
||||
color: Theme.accent-text;
|
||||
font-size: Theme.font-md;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
horizontal-stretch: 1;
|
||||
alignment: center;
|
||||
search := SearchBox {
|
||||
max-width: 680px;
|
||||
height: 40px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
placeholder: Bridge.current-server >= 0 ? @tr("Search channels and people in {}…", Bridge.server-title) : @tr("Search channels and people…");
|
||||
label: @tr("Search");
|
||||
edited(text) => { Bridge.search(text); }
|
||||
}
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.bell;
|
||||
label: Bridge.share-requests > 0 ? @tr("{} requests to watch your stream", Bridge.share-requests) : @tr("Notifications");
|
||||
dot: Bridge.share-requests > 0 || Bridge.crash-notice != "";
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => {
|
||||
if Bridge.share-requests > 0 {
|
||||
Nav.open-share();
|
||||
}
|
||||
}
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.users;
|
||||
label: @tr("Members and streams");
|
||||
checked: Nav.right-panel-open && Nav.page == Page.server;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => {
|
||||
Nav.show(Page.server);
|
||||
Nav.right-panel-open = !Nav.right-panel-open;
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
width: 1px;
|
||||
height: 24px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
background: Theme.border-strong;
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.help;
|
||||
label: @tr("About {}", Bridge.app-name);
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Nav.open-about(); }
|
||||
}
|
||||
}
|
||||
// Ctrl+K focuses the search.
|
||||
property <int> requests: Nav.search-requests;
|
||||
changed requests => { search.focus(); }
|
||||
}
|
||||
|
||||
// A sidebar panel: the page's navigation (@children) above the voice card
|
||||
// and the user card.
|
||||
export component Sidebar inherits Panel {
|
||||
width: Theme.sidebar-width;
|
||||
horizontal-stretch: 0;
|
||||
VerticalLayout {
|
||||
padding: Theme.space-3;
|
||||
spacing: Theme.space-3;
|
||||
VerticalLayout {
|
||||
vertical-stretch: 1;
|
||||
spacing: Theme.space-3;
|
||||
@children
|
||||
}
|
||||
if Bridge.voice-connected || Bridge.voice-connecting: VoiceCard { }
|
||||
UserCard { }
|
||||
}
|
||||
}
|
||||
|
||||
// The frame: rail | (top bar / panels).
|
||||
export component DesktopShell inherits Rectangle {
|
||||
in property <string> context;
|
||||
background: Theme.backdrop;
|
||||
HorizontalLayout {
|
||||
ServerRail { }
|
||||
VerticalLayout {
|
||||
TopBar {
|
||||
context: root.context;
|
||||
}
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-3;
|
||||
padding-right: Theme.space-3;
|
||||
padding-bottom: Theme.space-3;
|
||||
spacing: Theme.space-3;
|
||||
@children
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
// The narrow (phone) frame: a top bar, one page at a time (@children), and
|
||||
// the bottom navigation (Home, Servers, Chat, Activity, You). Used while
|
||||
// the window is narrower than `Nav.narrow-breakpoint`.
|
||||
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Bridge } from "../bridge.slint";
|
||||
import { Nav, Page, MobileTab, SettingsSection } from "../nav.slint";
|
||||
import { Icon, IconButton, CountBadge } from "../components/index.slint";
|
||||
|
||||
// One entry of the bottom navigation.
|
||||
component NavTab inherits Rectangle {
|
||||
in property <image> icon;
|
||||
in property <string> text;
|
||||
in property <bool> selected;
|
||||
in property <int> badge;
|
||||
in property <bool> dot;
|
||||
callback clicked();
|
||||
horizontal-stretch: 1;
|
||||
accessible-role: AccessibleRole.tab;
|
||||
accessible-label: text;
|
||||
accessible-item-selectable: true;
|
||||
accessible-item-selected: selected;
|
||||
accessible-action-default => { clicked(); }
|
||||
touch := TouchArea {
|
||||
clicked => { root.clicked(); }
|
||||
}
|
||||
if selected: Rectangle {
|
||||
width: 56px;
|
||||
height: 32px;
|
||||
y: 6px;
|
||||
border-radius: 16px;
|
||||
background: Theme.accent-soft;
|
||||
border-width: 1px;
|
||||
border-color: Theme.glow;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
spacing: 3px;
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
Icon {
|
||||
source: root.icon;
|
||||
size: 22px;
|
||||
tint: root.selected ? Theme.accent-text : Theme.icon;
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: root.text;
|
||||
color: root.selected ? Theme.accent-text : Theme.text-secondary;
|
||||
font-size: Theme.font-xs;
|
||||
font-weight: root.selected ? Theme.weight-semibold : Theme.weight-regular;
|
||||
horizontal-alignment: center;
|
||||
}
|
||||
}
|
||||
if badge > 0: CountBadge {
|
||||
x: parent.width / 2 + 4px;
|
||||
y: 2px;
|
||||
count: root.badge;
|
||||
}
|
||||
if dot && badge == 0: Rectangle {
|
||||
x: parent.width / 2 + 8px;
|
||||
y: 6px;
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
border-radius: 4.5px;
|
||||
background: Theme.success;
|
||||
}
|
||||
}
|
||||
|
||||
export component MobileShell inherits Rectangle {
|
||||
in property <string> title;
|
||||
in property <string> subtitle;
|
||||
// Total unread messages (the Chat tab's badge).
|
||||
in property <int> unread;
|
||||
// Show a back arrow (sub-pages such as the settings).
|
||||
in property <bool> back;
|
||||
callback go-back();
|
||||
background: Theme.backdrop;
|
||||
VerticalLayout {
|
||||
// Top bar.
|
||||
Rectangle {
|
||||
height: 60px;
|
||||
accessible-role: AccessibleRole.banner;
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-4;
|
||||
padding-right: Theme.space-3;
|
||||
spacing: Theme.space-3;
|
||||
if root.back: IconButton {
|
||||
icon: Icons.arrow-left;
|
||||
label: @tr("Back");
|
||||
round: true;
|
||||
filled: true;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { root.go-back(); }
|
||||
}
|
||||
if !root.back: Image {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
source: Icons.logo;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
Text {
|
||||
text: root.title;
|
||||
color: Theme.text;
|
||||
font-size: Theme.font-xl;
|
||||
font-weight: Theme.weight-semibold;
|
||||
overflow: elide;
|
||||
}
|
||||
if root.subtitle != "": Text {
|
||||
text: root.subtitle;
|
||||
color: Theme.accent-text;
|
||||
font-size: Theme.font-sm;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.bell;
|
||||
label: @tr("Notifications");
|
||||
round: true;
|
||||
filled: true;
|
||||
dot: Bridge.share-requests > 0 || Bridge.crash-notice != "";
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Nav.mobile-tab = MobileTab.activity; Nav.show(Page.server); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
vertical-stretch: 1;
|
||||
@children
|
||||
}
|
||||
// Bottom navigation.
|
||||
Rectangle {
|
||||
height: 64px;
|
||||
background: Theme.surface;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border;
|
||||
accessible-role: AccessibleRole.tab-list;
|
||||
accessible-label: @tr("Navigation");
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-2;
|
||||
padding-right: Theme.space-2;
|
||||
NavTab {
|
||||
icon: Icons.home;
|
||||
text: @tr("Home");
|
||||
selected: Nav.mobile-tab == MobileTab.home && Nav.page != Page.settings;
|
||||
clicked => { Nav.show(Page.home); Nav.mobile-tab = MobileTab.home; }
|
||||
}
|
||||
NavTab {
|
||||
icon: Icons.server;
|
||||
text: @tr("Servers");
|
||||
selected: Nav.mobile-tab == MobileTab.servers && Nav.page != Page.settings;
|
||||
dot: Bridge.voice-connected;
|
||||
clicked => { Nav.show(Page.server); Nav.mobile-tab = MobileTab.servers; }
|
||||
}
|
||||
NavTab {
|
||||
icon: Bridge.viewer-open ? Icons.monitor : Icons.message-circle;
|
||||
text: Bridge.viewer-open ? @tr("Stream") : @tr("Chat");
|
||||
selected: Nav.mobile-tab == MobileTab.chat && Nav.page != Page.settings;
|
||||
badge: root.unread;
|
||||
clicked => { Nav.show(Page.server); Nav.mobile-tab = MobileTab.chat; }
|
||||
}
|
||||
NavTab {
|
||||
icon: Icons.activity;
|
||||
text: @tr("Activity");
|
||||
selected: Nav.mobile-tab == MobileTab.activity && Nav.page != Page.settings;
|
||||
badge: Bridge.share-requests;
|
||||
clicked => { Nav.show(Page.server); Nav.mobile-tab = MobileTab.activity; }
|
||||
}
|
||||
NavTab {
|
||||
icon: Icons.user;
|
||||
text: @tr("You");
|
||||
selected: Nav.mobile-tab == MobileTab.you || Nav.page == Page.settings;
|
||||
clicked => { Nav.show(Page.server); Nav.mobile-tab = MobileTab.you; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
// Design tokens: colours, radii, spacing, type sizes. Components and screens
|
||||
// use these instead of literal values, so the theme and the font scale can
|
||||
// change while the app runs (Rust sets `mode` and `font-scale` from the
|
||||
// settings `ui.theme` and `ui.font_scale`).
|
||||
//
|
||||
// The software renderer draws no drop shadows and no gradient window
|
||||
// background, so "glow" is a translucent accent ring (`glow`, `glow-width`)
|
||||
// and the backdrop gradient is a rectangle (`backdrop`).
|
||||
|
||||
import { Palette } from "std-widgets.slint";
|
||||
|
||||
export global Theme {
|
||||
// "dark", "light" or "system" (the setting `ui.theme`).
|
||||
in-out property <string> mode: "dark";
|
||||
// Dark or light colours. The standard widgets (scroll bars, context
|
||||
// menus) follow the system's scheme.
|
||||
out property <bool> dark: mode == "system" ? Palette.color-scheme != ColorScheme.light : mode != "light";
|
||||
// Multiplies every type size (and the sizes that follow text).
|
||||
in-out property <float> font-scale: 1.0;
|
||||
|
||||
// Backgrounds, from the window outwards in.
|
||||
out property <color> bg-app: dark ? #060a18 : #e9eef9;
|
||||
out property <brush> backdrop: dark
|
||||
? @linear-gradient(160deg, #0a1230 0%, #060a18 55%, #0a1638 100%)
|
||||
: @linear-gradient(160deg, #f4f7fd 0%, #e6ecf8 60%, #dde6f7 100%);
|
||||
// The server rail, the far left.
|
||||
out property <color> bg-rail: dark ? #070c1d : #dfe6f4;
|
||||
// Panels: sidebar, main area, right panel.
|
||||
out property <color> surface: dark ? #0b1330 : #f7f9fe;
|
||||
// Cards and inputs inside panels.
|
||||
out property <color> surface-2: dark ? #101a3c : #ffffff;
|
||||
// Raised: hovered rows, menus, popups.
|
||||
out property <color> surface-3: dark ? #16224b : #eaf0fb;
|
||||
// Pressed or strongly highlighted.
|
||||
out property <color> surface-4: dark ? #1c2b5c : #dce5f7;
|
||||
// Dimmed backdrop behind modals.
|
||||
out property <color> scrim: dark ? #02050fc0 : #0b132b80;
|
||||
// Translucent bar over video.
|
||||
out property <color> overlay: dark ? #060a18c8 : #0b1330b0;
|
||||
|
||||
out property <color> border: dark ? #1b2750 : #d3dcee;
|
||||
out property <color> border-strong: dark ? #2a3a6e : #b9c6e2;
|
||||
|
||||
// Accent (buttons, selection, links).
|
||||
out property <color> accent: dark ? #2d6bff : #2458e6;
|
||||
out property <color> accent-hover: dark ? #4a82ff : #3a6cf0;
|
||||
out property <color> accent-pressed: dark ? #1f55d9 : #1b47c0;
|
||||
// Selected rows and chips.
|
||||
out property <color> accent-soft: dark ? #18348a : #d6e2ff;
|
||||
out property <color> accent-soft-hover: dark ? #1d3d9c : #c8d8ff;
|
||||
// Links, "See All", highlighted names.
|
||||
out property <color> accent-text: dark ? #5c9dff : #1d4fd6;
|
||||
// Author names in chat.
|
||||
out property <color> name-text: dark ? #45b9ff : #0f6cc4;
|
||||
out property <color> on-accent: #ffffff;
|
||||
// The ring around focused and selected items.
|
||||
out property <color> glow: dark ? #3f7bff90 : #2458e660;
|
||||
out property <length> glow-width: 2px;
|
||||
|
||||
// States.
|
||||
out property <color> live: dark ? #ff2d55 : #e0203f;
|
||||
out property <color> live-soft: dark ? #3a0f22 : #ffe0e6;
|
||||
out property <color> danger: dark ? #ff4d5e : #d92c3c;
|
||||
out property <color> danger-soft: dark ? #3b1020 : #ffe3e6;
|
||||
out property <color> success: dark ? #22d36b : #16a557;
|
||||
out property <color> success-soft: dark ? #0d3326 : #d7f5e4;
|
||||
out property <color> warning: dark ? #f5b301 : #b77f00;
|
||||
out property <color> warning-soft: dark ? #3a2a06 : #fff0c8;
|
||||
out property <color> idle: dark ? #f5b301 : #c98b00;
|
||||
out property <color> dnd: dark ? #ff4d5e : #d92c3c;
|
||||
out property <color> offline: dark ? #5f6d93 : #8d99b5;
|
||||
out property <color> gold: dark ? #ffc233 : #d99a00;
|
||||
out property <color> info: dark ? #3fb3ff : #1180d6;
|
||||
|
||||
// Text.
|
||||
out property <color> text: dark ? #eef2ff : #0e1733;
|
||||
out property <color> text-secondary: dark ? #aeb9d8 : #43506f;
|
||||
out property <color> text-muted: dark ? #6d7ca6 : #6f7b98;
|
||||
out property <color> text-disabled: dark ? #46527a : #a7b1c8;
|
||||
// Icons without their own colour.
|
||||
out property <color> icon: dark ? #b9c4e2 : #43506f;
|
||||
|
||||
// Audio meter segments.
|
||||
out property <color> meter-low: #21d07a;
|
||||
out property <color> meter-mid: #f5d000;
|
||||
out property <color> meter-high: #ff4d5e;
|
||||
out property <color> meter-off: dark ? #1a2550 : #d5ddef;
|
||||
|
||||
// Radii.
|
||||
out property <length> radius-xs: 4px;
|
||||
out property <length> radius-sm: 6px;
|
||||
out property <length> radius-md: 8px;
|
||||
out property <length> radius-lg: 12px;
|
||||
out property <length> radius-xl: 16px;
|
||||
out property <length> radius-pill: 999px;
|
||||
|
||||
// Spacing scale.
|
||||
out property <length> space-1: 2px;
|
||||
out property <length> space-2: 4px;
|
||||
out property <length> space-3: 8px;
|
||||
out property <length> space-4: 12px;
|
||||
out property <length> space-5: 16px;
|
||||
out property <length> space-6: 20px;
|
||||
out property <length> space-7: 24px;
|
||||
out property <length> space-8: 32px;
|
||||
|
||||
// Type sizes (scaled).
|
||||
out property <length> font-xs: 11px * font-scale;
|
||||
out property <length> font-sm: 12px * font-scale;
|
||||
out property <length> font-body: 14px * font-scale;
|
||||
out property <length> font-md: 15px * font-scale;
|
||||
out property <length> font-lg: 17px * font-scale;
|
||||
out property <length> font-xl: 20px * font-scale;
|
||||
out property <length> font-2xl: 24px * font-scale;
|
||||
out property <length> font-3xl: 30px * font-scale;
|
||||
out property <int> weight-regular: 400;
|
||||
out property <int> weight-medium: 500;
|
||||
out property <int> weight-semibold: 600;
|
||||
out property <int> weight-bold: 700;
|
||||
out property <string> font-family: "Inter";
|
||||
|
||||
// Sizes that follow the text.
|
||||
out property <length> row-height: 32px * font-scale;
|
||||
out property <length> control-height: 36px * font-scale;
|
||||
out property <length> control-height-sm: 28px * font-scale;
|
||||
out property <length> icon-sm: 16px;
|
||||
out property <length> icon-md: 20px;
|
||||
out property <length> icon-lg: 24px;
|
||||
|
||||
// Shell dimensions.
|
||||
out property <length> rail-width: 72px;
|
||||
out property <length> sidebar-width: 264px;
|
||||
out property <length> topbar-height: 56px;
|
||||
out property <length> right-panel-min: 220px;
|
||||
out property <length> right-panel-max: 420px;
|
||||
|
||||
// Motion.
|
||||
out property <duration> fast: 120ms;
|
||||
out property <duration> normal: 200ms;
|
||||
}
|
||||
+19
-9
@@ -165,8 +165,15 @@ RANGES = [
|
||||
((0x1F3FB, 0x1F3FF), "people"),
|
||||
]
|
||||
|
||||
# Emoji newer than Python 3.11's Unicode database (14.0).
|
||||
# Emoji newer than Python 3.11's Unicode database (14.0), and common
|
||||
# emoji whose character name differs from the name people search for.
|
||||
EXTRA_NAMES = {
|
||||
0x2764: "red heart",
|
||||
0x2B50: "star",
|
||||
0x1F44D: "thumbs up",
|
||||
0x1F44E: "thumbs down",
|
||||
0x1F525: "fire",
|
||||
0x1F602: "face with tears of joy laughing",
|
||||
0x1F6DC: "wireless",
|
||||
0x1FA75: "light blue heart",
|
||||
0x1FA76: "grey heart",
|
||||
@@ -212,16 +219,17 @@ def entry_name(cps):
|
||||
|
||||
|
||||
def category(cps):
|
||||
"""The category and the position of the matching range (for ordering)."""
|
||||
if all(0x1F1E6 <= cp <= 0x1F1FF for cp in cps) and len(cps) == 2:
|
||||
return "flags"
|
||||
return "flags", 0
|
||||
first = cps[0]
|
||||
# Keycaps and other text symbols.
|
||||
if first < 0x2000 or (0x20E3 in cps):
|
||||
return "symbols"
|
||||
for (lo, hi), cat in RANGES:
|
||||
return "symbols", len(RANGES)
|
||||
for i, ((lo, hi), cat) in enumerate(RANGES):
|
||||
if lo <= first <= hi:
|
||||
return cat
|
||||
return "symbols"
|
||||
return cat, i
|
||||
return "symbols", len(RANGES)
|
||||
|
||||
|
||||
def in_picker(cps):
|
||||
@@ -248,17 +256,19 @@ def main():
|
||||
cps = [int(p, 16) for p in key.split("-")]
|
||||
with open(os.path.join(src, file), "rb") as f:
|
||||
svg = f.read().strip()
|
||||
cat = category(cps)
|
||||
cat, order = category(cps)
|
||||
items.append({
|
||||
"key": key,
|
||||
"cps": cps,
|
||||
"svg": svg,
|
||||
"cat": CATEGORIES.index(cat),
|
||||
"order": order,
|
||||
"name": entry_name(cps),
|
||||
"picker": in_picker(cps) and entry_name(cps) != "",
|
||||
})
|
||||
# Data in picker order: category, then code points.
|
||||
items.sort(key=lambda it: (it["cat"], it["cps"]))
|
||||
# Data in picker order: category, the order of RANGES (smileys start
|
||||
# with the smiling faces), then code points.
|
||||
items.sort(key=lambda it: (it["cat"], it["order"], it["cps"]))
|
||||
blocks = []
|
||||
raw = bytearray()
|
||||
for it in items:
|
||||
|
||||
Reference in new issue
Block a user