Document the public functions, constants and types of voelin-ui-vm that had no docs
The items moved from a private module of voelin-ui, where they needed none; as public API of the new crate they get a line each. The fields of the bridge structs, which mirror bridge.slint field by field (module docs), and a few self-describing fields and variants are left as they are. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
668c1a8038
commit
5d66be43d4
5 files changed
+29
No files matched your search
@@ -29,6 +29,7 @@ pub struct Previous {
|
||||
}
|
||||
|
||||
impl Previous {
|
||||
/// The line `message` is, as the line after it sees it.
|
||||
pub fn of(message: &ChatMessage) -> Self {
|
||||
Self { author: message.author_name.clone(), ts_ms: message.ts_ms }
|
||||
}
|
||||
@@ -615,6 +616,7 @@ pub fn picture_link(message: &ChatMessage, index: usize) -> Option<String> {
|
||||
index.checked_sub(read.files.len()).and_then(|i| read.images.into_iter().nth(i))
|
||||
}
|
||||
|
||||
/// Whether a file name is a picture's, by its extension.
|
||||
pub fn is_picture(name: &str) -> bool {
|
||||
let lower = name.to_ascii_lowercase();
|
||||
[".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg"].iter().any(|e| lower.ends_with(e))
|
||||
|
||||
@@ -119,6 +119,7 @@ impl Archive {
|
||||
.map(|i| &self.entries[i])
|
||||
}
|
||||
|
||||
/// The archive has an emoji for this key (code points joined by `-`).
|
||||
pub fn contains(&self, key: &str) -> bool {
|
||||
self.find(key).is_some()
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ pub enum ThemeChoice {
|
||||
}
|
||||
|
||||
impl ThemeChoice {
|
||||
/// The value stored for this choice.
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Dark => "dark",
|
||||
@@ -47,6 +48,7 @@ impl ThemeChoice {
|
||||
}
|
||||
}
|
||||
|
||||
/// The choice a stored value names (dark for any other).
|
||||
pub fn parse(text: &str) -> Self {
|
||||
match text {
|
||||
"light" => Self::Light,
|
||||
@@ -133,10 +135,12 @@ pub enum NotifyLevel {
|
||||
}
|
||||
|
||||
impl NotifyLevel {
|
||||
/// The position in the settings' list (off, app, desktop).
|
||||
pub fn index(self) -> i32 {
|
||||
self as i32
|
||||
}
|
||||
|
||||
/// The choice at a list position (desktop for any other).
|
||||
pub fn from_index(index: i32) -> Self {
|
||||
match index {
|
||||
0 => Self::Off,
|
||||
@@ -155,22 +159,26 @@ pub static NOTIFY_MENTIONS: Key<NotifyLevel> = Key::new(
|
||||
"Our name in a channel or server chat: off, app (the bell) or desktop.",
|
||||
NotifyLevel::default,
|
||||
);
|
||||
/// Private messages: off, app (the bell) or desktop.
|
||||
pub static NOTIFY_MESSAGES: Key<NotifyLevel> = Key::new(
|
||||
"notify.private_messages",
|
||||
NOTIFY_LEVELS,
|
||||
"Private messages: off, app (the bell) or desktop.",
|
||||
NotifyLevel::default,
|
||||
);
|
||||
/// Pokes: off, app (the bell) or desktop.
|
||||
pub static NOTIFY_POKES: Key<NotifyLevel> =
|
||||
Key::new("notify.pokes", NOTIFY_LEVELS, "Pokes: off, app (the bell) or desktop.", || {
|
||||
NotifyLevel::Desktop
|
||||
});
|
||||
/// Reminders of scheduled events: off, app (the bell) or desktop.
|
||||
pub static NOTIFY_EVENTS: Key<NotifyLevel> = Key::new(
|
||||
"notify.event_reminders",
|
||||
NOTIFY_LEVELS,
|
||||
"Reminders of scheduled events: off, app (the bell) or desktop.",
|
||||
NotifyLevel::default,
|
||||
);
|
||||
/// Friends coming online: off, app (the bell) or desktop.
|
||||
pub static NOTIFY_FRIENDS: Key<NotifyLevel> = Key::new(
|
||||
"notify.friends_online",
|
||||
NOTIFY_LEVELS,
|
||||
@@ -253,11 +261,14 @@ pub fn page_keys() -> [&'static dyn voelin_core::settings::Setting; 10] {
|
||||
/// offers, in the order of its lists (`dialogs.slint`); any other value can
|
||||
/// be typed in.
|
||||
pub const FPS_CHOICES: [u32; 7] = [15, 30, 60, 120, 144, 240, 320];
|
||||
/// The bitrates (kbit/s, 0 for automatic) the share dialog offers, in the
|
||||
/// order of its list.
|
||||
pub const BITRATE_CHOICES: [u32; 8] = [0, 2500, 4608, 8000, 10_000, 20_000, 40_000, 60_000];
|
||||
|
||||
/// The share dialog's lists before they grew, which [`ShareDefaults`]
|
||||
/// indexes for older versions.
|
||||
pub const LEGACY_FPS_CHOICES: [u32; 3] = [15, 30, 60];
|
||||
/// The bitrates of the share dialog's list before it grew.
|
||||
pub const LEGACY_BITRATE_CHOICES: [u32; 4] = [2500, 4608, 8000, 10_000];
|
||||
|
||||
/// The index of the choice closest to `value`.
|
||||
@@ -270,6 +281,8 @@ pub fn parse_positive(text: &str) -> Option<u32> {
|
||||
text.trim().parse().ok().filter(|v| *v > 0)
|
||||
}
|
||||
|
||||
/// The `ui` settings: what the front end keeps about itself (the push-to-talk
|
||||
/// hotkey, codecs, the share dialog's defaults, the last voice channel).
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct UiSettings {
|
||||
@@ -347,11 +360,13 @@ impl Default for ClientPlayback {
|
||||
}
|
||||
|
||||
impl ClientPlayback {
|
||||
/// Nothing differs from the defaults, so there is nothing to store.
|
||||
pub fn is_default(&self) -> bool {
|
||||
*self == Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Each client's playback settings, by the client's unique id.
|
||||
pub type ClientPlaybackMap = BTreeMap<String, ClientPlayback>;
|
||||
|
||||
/// Audio devices as listed in the settings: the system default first.
|
||||
@@ -387,10 +402,14 @@ impl DeviceChoices {
|
||||
choices
|
||||
}
|
||||
|
||||
/// The index of the choice for device `id` (the system default for `None` or
|
||||
/// an unknown id).
|
||||
pub fn index_of(&self, id: Option<&str>) -> usize {
|
||||
self.ids.iter().position(|i| i.as_deref() == id).unwrap_or(0)
|
||||
}
|
||||
|
||||
/// The device id of choice `index`; `None` for the system default or an index
|
||||
/// outside the list.
|
||||
pub fn id_at(&self, index: i32) -> Option<String> {
|
||||
usize::try_from(index).ok().and_then(|i| self.ids.get(i).cloned()).flatten()
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ pub fn ago(ts_ms: i64) -> String {
|
||||
ago_at(ts_ms, chrono::Utc::now().timestamp_millis())
|
||||
}
|
||||
|
||||
/// [`ago`] for a given time `now_ms`.
|
||||
pub fn ago_at(ts_ms: i64, now_ms: i64) -> String {
|
||||
if ts_ms <= 0 {
|
||||
return String::new();
|
||||
@@ -56,6 +57,7 @@ pub fn list_time(ts_ms: i64) -> String {
|
||||
local(ts_ms).map(|t| list_time_at(t, now_local())).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// [`list_time`] for a given local time `now`.
|
||||
pub fn list_time_at(then: NaiveDateTime, now: NaiveDateTime) -> String {
|
||||
use chrono::Datelike;
|
||||
let days = (now.date() - then.date()).num_days();
|
||||
|
||||
@@ -39,6 +39,7 @@ fn summary(scene: &Scene) -> String {
|
||||
if names.is_empty() { "Empty".into() } else { names.join(" + ") }
|
||||
}
|
||||
|
||||
/// The kind of a background by name: keep, blur, image or colour.
|
||||
pub fn background_name(background: &Background) -> &'static str {
|
||||
match background {
|
||||
Background::Keep => "keep",
|
||||
@@ -262,6 +263,7 @@ pub fn parse_colour(text: &str) -> Option<Colour> {
|
||||
Some(Colour::rgba(byte(0)?, byte(2)?, byte(4)?, a))
|
||||
}
|
||||
|
||||
/// A colour as `#rrggbb`, or `#rrggbbaa` when it is not opaque.
|
||||
pub fn colour_text(c: Colour) -> String {
|
||||
if c.a == 255 {
|
||||
format!("#{:02x}{:02x}{:02x}", c.r, c.g, c.b)
|
||||
@@ -504,8 +506,11 @@ pub struct Overlay {
|
||||
pub text: Option<String>,
|
||||
}
|
||||
|
||||
/// The overlay source that shows how many are watching.
|
||||
pub const OVERLAY_VIEWERS: &str = "Viewer count";
|
||||
/// The overlay source that shows the stream chat's last lines.
|
||||
pub const OVERLAY_CHAT: &str = "Chat overlay";
|
||||
/// The overlay source that names what plays.
|
||||
pub const OVERLAY_NOW_PLAYING: &str = "Now playing";
|
||||
|
||||
fn overlay_kind(name: &str, text: &str) -> SourceKind {
|
||||
|
||||
Reference in new issue
Block a user