Musyx Mobile: Android TV player for Yandex Music
Kotlin, Compose for TV and Media3 port of the desktop Musyx, with device-code sign-in, Home, My Wave, search, collection, detail pages, Now Playing with queue and lyrics, and settings for streaming quality, appearance, font size (small, medium, large) and language. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
46610d95fa
217 files changed
+26144
No files matched your search
@@ -0,0 +1,99 @@
|
||||
//! Bundled Lucide 0.460 icons (ISC, see `assets/icons/LICENSE.txt`).
|
||||
//!
|
||||
//! The SVGs stroke with `currentColor`; iced ignores that, so every icon is tinted
|
||||
//! through `svg::Style::color` instead — pass the colour the surrounding text uses.
|
||||
|
||||
// Bundled ahead of the screens that use them.
|
||||
#![allow(dead_code)]
|
||||
|
||||
use iced::widget::{Svg, svg};
|
||||
use iced::{Color, Length, Theme};
|
||||
|
||||
use super::theme::shell;
|
||||
|
||||
macro_rules! icons {
|
||||
($($variant:ident => $file:literal),+ $(,)?) => {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum Icon { $($variant),+ }
|
||||
|
||||
impl Icon {
|
||||
pub const ALL: &[Icon] = &[$(Icon::$variant),+];
|
||||
|
||||
fn bytes(self) -> &'static [u8] {
|
||||
match self {
|
||||
$(Icon::$variant => include_bytes!(concat!("../../assets/icons/", $file, ".svg"))),+
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
icons! {
|
||||
Home => "house",
|
||||
Wave => "audio-lines",
|
||||
Search => "search",
|
||||
Library => "library",
|
||||
Podcast => "podcast",
|
||||
Plus => "plus",
|
||||
LogOut => "log-out",
|
||||
Back => "chevron-left",
|
||||
Forward => "chevron-right",
|
||||
Chart => "trending-up",
|
||||
Play => "play-fill",
|
||||
Pause => "pause-fill",
|
||||
Previous => "skip-back",
|
||||
Next => "skip-forward",
|
||||
Shuffle => "shuffle",
|
||||
Repeat => "repeat",
|
||||
RepeatOne => "repeat-1",
|
||||
Heart => "heart",
|
||||
HeartFilled => "heart-fill",
|
||||
Dislike => "ban",
|
||||
Lyrics => "mic-vocal",
|
||||
Queue => "list-music",
|
||||
Volume => "volume-2",
|
||||
Muted => "volume-x",
|
||||
More => "ellipsis",
|
||||
Disc => "disc-3",
|
||||
Lock => "lock",
|
||||
Globe => "globe",
|
||||
Pencil => "pencil",
|
||||
Trash => "trash-2",
|
||||
Grip => "grip-vertical",
|
||||
Close => "x",
|
||||
Copy => "copy",
|
||||
Clock => "clock-3",
|
||||
Tune => "sliders-horizontal",
|
||||
Settings => "settings",
|
||||
}
|
||||
|
||||
impl Icon {
|
||||
pub fn handle(self) -> svg::Handle {
|
||||
svg::Handle::from_memory(self.bytes())
|
||||
}
|
||||
}
|
||||
|
||||
/// An icon at the standard 18px size, tinted `color`.
|
||||
pub fn icon<'a>(icon: Icon, color: Color) -> Svg<'a, Theme> {
|
||||
sized(icon, shell::ICON, color)
|
||||
}
|
||||
|
||||
pub fn sized<'a>(icon: Icon, size: f32, color: Color) -> Svg<'a, Theme> {
|
||||
svg(icon.handle())
|
||||
.width(Length::Fixed(size))
|
||||
.height(Length::Fixed(size))
|
||||
.style(move |_, _| svg::Style { color: Some(color) })
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn every_icon_is_an_svg() {
|
||||
for icon in Icon::ALL {
|
||||
let text = std::str::from_utf8(icon.bytes()).expect("utf-8");
|
||||
assert!(text.contains("<svg"), "{icon:?} is not an SVG");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
pub mod icons;
|
||||
pub mod theme;
|
||||
|
||||
use iced::widget::{Text, text};
|
||||
use iced::widget::text::Wrapping;
|
||||
use iced::{Color, Font};
|
||||
|
||||
use crate::i18n::{self, Lang, trf};
|
||||
|
||||
/// Single-line text in the given face; long values are clipped by their container.
|
||||
pub fn line<'a>(content: impl text::IntoFragment<'a>, font: Font, size: f32, color: Color) -> Text<'a> {
|
||||
text(content).font(font).size(size).color(color).wrapping(Wrapping::None)
|
||||
}
|
||||
|
||||
/// Running text that wraps.
|
||||
pub fn para<'a>(content: impl text::IntoFragment<'a>, size: f32, color: Color) -> Text<'a> {
|
||||
text(content).font(theme::BODY).size(size).color(color).line_height(1.45)
|
||||
}
|
||||
|
||||
/// "47 min" or "1 h 12 min".
|
||||
pub fn duration_words(d: std::time::Duration) -> String {
|
||||
let mins = d.as_secs() / 60;
|
||||
if mins >= 60 {
|
||||
trf("{} h {} min", &[&(mins / 60), &(mins % 60)])
|
||||
} else {
|
||||
trf("{} min", &[&mins])
|
||||
}
|
||||
}
|
||||
|
||||
/// "1 track", "12 tracks".
|
||||
pub fn tracks_word(n: usize) -> String {
|
||||
i18n::count(n as u64, ["track", "tracks"], ["трек", "трека", "треков"])
|
||||
}
|
||||
|
||||
/// "4.1M", "830K", "912"; in Russian "4,1 млн", "830 тыс.", "912".
|
||||
pub fn compact(n: i64) -> String {
|
||||
let (value, en, ru) = match n {
|
||||
n if n >= 1_000_000 => (format!("{:.1}", n as f64 / 1e6), "M", " млн"),
|
||||
n if n >= 10_000 => ((n / 1000).to_string(), "K", " тыс."),
|
||||
n if n >= 1_000 => (format!("{:.1}", n as f64 / 1e3), "K", " тыс."),
|
||||
n => return n.to_string(),
|
||||
};
|
||||
let value = value.trim_end_matches(".0");
|
||||
match i18n::lang() {
|
||||
Lang::En => format!("{value}{en}"),
|
||||
Lang::Ru => format!("{}{ru}", value.replace('.', ",")),
|
||||
}
|
||||
}
|
||||
|
||||
/// A compact count and its noun: "4.1M listeners", "830 тыс. слушателей", "3 лайка".
|
||||
pub fn counted(n: i64, en: [&str; 2], ru: [&str; 3]) -> String {
|
||||
// An abbreviated number ("4,1 млн") reads as many.
|
||||
let form = if n >= 1_000 { 5 } else { n.max(0) as u64 };
|
||||
format!("{} {}", compact(n), i18n::plural(form, en, ru))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::time::Duration;
|
||||
|
||||
#[test]
|
||||
fn words() {
|
||||
assert_eq!(duration_words(Duration::from_secs(47 * 60 + 5)), "47 min");
|
||||
assert_eq!(duration_words(Duration::from_secs(72 * 60)), "1 h 12 min");
|
||||
assert_eq!(tracks_word(1), "1 track");
|
||||
assert_eq!(tracks_word(12), "12 tracks");
|
||||
assert_eq!(compact(4_100_000), "4.1M");
|
||||
assert_eq!(compact(2_000_000), "2M");
|
||||
assert_eq!(compact(830_412), "830K");
|
||||
assert_eq!(compact(1_250), "1.2K");
|
||||
assert_eq!(compact(912), "912");
|
||||
assert_eq!(counted(1, ["like", "likes"], ["лайк", "лайка", "лайков"]), "1 like");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn russian_words() {
|
||||
i18n::set(Lang::Ru);
|
||||
assert_eq!(duration_words(Duration::from_secs(72 * 60)), "1 ч 12 мин");
|
||||
assert_eq!(tracks_word(3), "3 трека");
|
||||
assert_eq!(compact(4_100_000), "4,1 млн");
|
||||
assert_eq!(compact(830_412), "830 тыс.");
|
||||
assert_eq!(compact(1_250), "1,2 тыс.");
|
||||
let listeners = ["listener", "listeners"];
|
||||
let ru = ["слушатель", "слушателя", "слушателей"];
|
||||
assert_eq!(counted(4_100_000, listeners, ru), "4,1 млн слушателей");
|
||||
assert_eq!(counted(21, listeners, ru), "21 слушатель");
|
||||
i18n::set(Lang::En);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,468 @@
|
||||
//! Design tokens and widget styles. Mirrors `DESIGN.md`; change both together.
|
||||
|
||||
// The token set is the whole design system; screens adopt pieces milestone by milestone.
|
||||
#![allow(dead_code)]
|
||||
|
||||
use iced::border::Radius;
|
||||
use iced::font::{Family, Weight};
|
||||
use iced::theme::{Mode, Palette};
|
||||
use iced::widget::{button, container, scrollable, slider, text_input};
|
||||
use iced::{Background, Border, Color, Font, Shadow, Theme, Vector};
|
||||
|
||||
/// Colour tokens for one theme mode.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct Tokens {
|
||||
pub bg: Color,
|
||||
pub panel: Color,
|
||||
pub raised: Color,
|
||||
pub line: Color,
|
||||
pub fg: Color,
|
||||
pub muted: Color,
|
||||
pub accent: Color,
|
||||
pub accent_ink: Color,
|
||||
pub like: Color,
|
||||
pub ok: Color,
|
||||
}
|
||||
|
||||
const fn hex(h: u32) -> Color {
|
||||
Color::from_rgb8((h >> 16) as u8, (h >> 8) as u8, h as u8)
|
||||
}
|
||||
|
||||
pub const DARK: Tokens = Tokens {
|
||||
bg: hex(0x1C1A22),
|
||||
panel: hex(0x23202B),
|
||||
raised: hex(0x2D2937),
|
||||
line: hex(0x3A3546),
|
||||
fg: hex(0xEEEAF3),
|
||||
muted: hex(0xA39CB0),
|
||||
accent: hex(0xF0B23E),
|
||||
accent_ink: hex(0x2A1D04),
|
||||
like: hex(0xF27286),
|
||||
ok: hex(0x7FCB9B),
|
||||
};
|
||||
|
||||
pub const LIGHT: Tokens = Tokens {
|
||||
bg: hex(0xF3F1F6),
|
||||
panel: hex(0xFFFFFF),
|
||||
raised: hex(0xEAE6F0),
|
||||
line: hex(0xDCD6E4),
|
||||
fg: hex(0x1F1B27),
|
||||
muted: hex(0x686178),
|
||||
accent: hex(0xA86C05),
|
||||
accent_ink: hex(0xFFF7E6),
|
||||
like: hex(0xD2405A),
|
||||
ok: hex(0x2E8A55),
|
||||
};
|
||||
|
||||
/// Tokens for whichever theme is active. Style closures only receive `&Theme`,
|
||||
/// so the tokens are recovered from the palette's darkness.
|
||||
pub fn tokens(theme: &Theme) -> &'static Tokens {
|
||||
if theme.extended_palette().is_dark { &DARK } else { &LIGHT }
|
||||
}
|
||||
|
||||
/// The iced theme for a system appearance. Musyx is dark-first, so "no preference" is dark.
|
||||
pub fn for_mode(mode: Mode) -> Theme {
|
||||
let (name, t) = match mode {
|
||||
Mode::Light => ("Musyx Light", &LIGHT),
|
||||
Mode::Dark | Mode::None => ("Musyx Dark", &DARK),
|
||||
};
|
||||
Theme::custom(
|
||||
name,
|
||||
Palette {
|
||||
background: t.bg,
|
||||
text: t.fg,
|
||||
primary: t.accent,
|
||||
success: t.ok,
|
||||
warning: t.accent,
|
||||
danger: t.like,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// ---- Type ----
|
||||
|
||||
pub const BODY: Font = Font::with_name("Onest");
|
||||
pub const MEDIUM: Font = Font { weight: Weight::Medium, ..BODY };
|
||||
pub const SEMIBOLD: Font = Font { weight: Weight::Semibold, ..BODY };
|
||||
pub const DISPLAY: Font = Font {
|
||||
family: Family::Name("Unbounded"),
|
||||
weight: Weight::Semibold,
|
||||
..Font::DEFAULT
|
||||
};
|
||||
|
||||
pub const FONTS: [&[u8]; 4] = [
|
||||
include_bytes!("../../assets/fonts/Onest-Regular.ttf"),
|
||||
include_bytes!("../../assets/fonts/Onest-Medium.ttf"),
|
||||
include_bytes!("../../assets/fonts/Onest-SemiBold.ttf"),
|
||||
include_bytes!("../../assets/fonts/Unbounded-SemiBold.ttf"),
|
||||
];
|
||||
|
||||
pub mod size {
|
||||
pub const DISPLAY_XL: f32 = 46.0;
|
||||
pub const DISPLAY_L: f32 = 40.0;
|
||||
pub const DISPLAY_M: f32 = 34.0;
|
||||
pub const DISPLAY_S: f32 = 30.0;
|
||||
pub const WORDMARK: f32 = 20.0;
|
||||
pub const SECTION: f32 = 19.0;
|
||||
pub const BODY: f32 = 14.0;
|
||||
pub const META: f32 = 13.0;
|
||||
pub const SMALL: f32 = 12.5;
|
||||
}
|
||||
|
||||
// ---- Space and shape ----
|
||||
|
||||
pub mod space {
|
||||
pub const XS: f32 = 4.0;
|
||||
pub const S: f32 = 8.0;
|
||||
pub const M: f32 = 12.0;
|
||||
pub const L: f32 = 18.0;
|
||||
pub const XL: f32 = 22.0;
|
||||
pub const GUTTER: f32 = 28.0;
|
||||
pub const SECTION: f32 = 34.0;
|
||||
}
|
||||
|
||||
pub mod radius {
|
||||
pub const COVER: f32 = 10.0;
|
||||
pub const CONTROL: f32 = 8.0;
|
||||
pub const SMALL_COVER: f32 = 6.0;
|
||||
pub const PILL: f32 = 999.0;
|
||||
pub const HERO: f32 = 16.0;
|
||||
pub const CARD: f32 = 14.0;
|
||||
}
|
||||
|
||||
pub mod shell {
|
||||
pub const SIDEBAR: f32 = 232.0;
|
||||
pub const PLAYER: f32 = 80.0;
|
||||
pub const DRAWER: f32 = 320.0;
|
||||
pub const ICON: f32 = 18.0;
|
||||
}
|
||||
|
||||
// ---- Containers ----
|
||||
|
||||
fn hairline(color: Color) -> Border {
|
||||
Border { color, width: 1.0, radius: Radius::from(0.0) }
|
||||
}
|
||||
|
||||
pub fn app(theme: &Theme) -> container::Style {
|
||||
let t = tokens(theme);
|
||||
container::Style {
|
||||
background: Some(t.bg.into()),
|
||||
text_color: Some(t.fg),
|
||||
..container::Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Sidebar, player bar and drawer share the panel fill; the divider is drawn separately.
|
||||
pub fn panel(theme: &Theme) -> container::Style {
|
||||
let t = tokens(theme);
|
||||
container::Style {
|
||||
background: Some(t.panel.into()),
|
||||
text_color: Some(t.fg),
|
||||
..container::Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn divider(theme: &Theme) -> container::Style {
|
||||
container::Style {
|
||||
background: Some(tokens(theme).line.into()),
|
||||
..container::Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// A bordered surface such as the empty-state card or the device-code box.
|
||||
pub fn card(theme: &Theme) -> container::Style {
|
||||
let t = tokens(theme);
|
||||
container::Style {
|
||||
background: Some(t.panel.into()),
|
||||
border: Border { radius: radius::CARD.into(), ..hairline(t.line) },
|
||||
..container::Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn badge(theme: &Theme) -> container::Style {
|
||||
let t = tokens(theme);
|
||||
container::Style {
|
||||
text_color: Some(t.muted),
|
||||
border: Border { radius: 5.0.into(), ..hairline(t.line) },
|
||||
..container::Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn accent_dot(theme: &Theme) -> container::Style {
|
||||
container::Style {
|
||||
background: Some(tokens(theme).accent.into()),
|
||||
border: Border { radius: radius::PILL.into(), ..Border::default() },
|
||||
..container::Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn avatar(theme: &Theme) -> container::Style {
|
||||
let t = tokens(theme);
|
||||
container::Style {
|
||||
background: Some(Background::Gradient(
|
||||
iced::gradient::Linear::new(std::f32::consts::FRAC_PI_4 * 3.0)
|
||||
.add_stop(0.0, hex(0x8E7AB5))
|
||||
.add_stop(1.0, hex(0xE0A84B))
|
||||
.into(),
|
||||
)),
|
||||
text_color: Some(hex(0x1C1A22)),
|
||||
border: Border { radius: radius::PILL.into(), ..hairline(t.line) },
|
||||
..container::Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Placeholder art for an item without a cover yet: two hues on a diagonal.
|
||||
pub fn cover(h1: f32, h2: f32, corner: f32) -> impl Fn(&Theme) -> container::Style {
|
||||
move |_| container::Style {
|
||||
background: Some(Background::Gradient(
|
||||
iced::gradient::Linear::new(std::f32::consts::FRAC_PI_4 * 3.0)
|
||||
.add_stop(0.0, hsl(h1, 0.70, 0.60))
|
||||
.add_stop(0.55, hsl((h1 + h2) / 2.0, 0.45, 0.30))
|
||||
.add_stop(1.0, hsl(h2, 0.40, 0.16))
|
||||
.into(),
|
||||
)),
|
||||
border: Border { radius: corner.into(), ..Border::default() },
|
||||
..container::Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn hsl(h: f32, s: f32, l: f32) -> Color {
|
||||
let c = (1.0 - (2.0 * l - 1.0).abs()) * s;
|
||||
let hp = (h.rem_euclid(360.0)) / 60.0;
|
||||
let x = c * (1.0 - (hp % 2.0 - 1.0).abs());
|
||||
let (r, g, b) = match hp as u32 {
|
||||
0 => (c, x, 0.0),
|
||||
1 => (x, c, 0.0),
|
||||
2 => (0.0, c, x),
|
||||
3 => (0.0, x, c),
|
||||
4 => (x, 0.0, c),
|
||||
_ => (c, 0.0, x),
|
||||
};
|
||||
let m = l - c / 2.0;
|
||||
Color::from_rgb(r + m, g + m, b + m)
|
||||
}
|
||||
|
||||
// ---- Buttons ----
|
||||
|
||||
/// Sidebar navigation item; `active` is the current page.
|
||||
pub fn nav_item(active: bool) -> impl Fn(&Theme, button::Status) -> button::Style {
|
||||
move |theme, status| {
|
||||
let t = tokens(theme);
|
||||
let lit = active || matches!(status, button::Status::Hovered | button::Status::Pressed);
|
||||
button::Style {
|
||||
background: lit.then(|| t.raised.into()),
|
||||
text_color: if lit { t.fg } else { t.muted },
|
||||
border: Border { radius: radius::CONTROL.into(), ..Border::default() },
|
||||
shadow: Shadow::default(),
|
||||
snap: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Square icon button. `on` tints it (accent for toggles, `like` for hearts).
|
||||
pub fn icon_button(on: Option<Color>) -> impl Fn(&Theme, button::Status) -> button::Style {
|
||||
move |theme, status| {
|
||||
let t = tokens(theme);
|
||||
let hovered = matches!(status, button::Status::Hovered | button::Status::Pressed);
|
||||
let disabled = matches!(status, button::Status::Disabled);
|
||||
button::Style {
|
||||
background: (hovered && !disabled).then(|| t.raised.into()),
|
||||
text_color: match (on, disabled, hovered) {
|
||||
(_, true, _) => t.muted.scale_alpha(0.45),
|
||||
(Some(c), _, _) => c,
|
||||
(None, _, true) => t.fg,
|
||||
(None, _, false) => t.muted,
|
||||
},
|
||||
border: Border { radius: radius::CONTROL.into(), ..Border::default() },
|
||||
shadow: Shadow::default(),
|
||||
snap: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The round play/pause disc in the player bar.
|
||||
pub fn play_disc(theme: &Theme, status: button::Status) -> button::Style {
|
||||
let t = tokens(theme);
|
||||
let disabled = matches!(status, button::Status::Disabled);
|
||||
button::Style {
|
||||
background: Some(if disabled { t.raised } else { t.fg }.into()),
|
||||
text_color: if disabled { t.muted } else { t.bg },
|
||||
border: Border { radius: radius::PILL.into(), ..Border::default() },
|
||||
shadow: Shadow::default(),
|
||||
snap: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn primary(theme: &Theme, status: button::Status) -> button::Style {
|
||||
let t = tokens(theme);
|
||||
let bg = match status {
|
||||
button::Status::Hovered => mix(t.accent, t.fg, 0.12),
|
||||
button::Status::Pressed => mix(t.accent, t.bg, 0.12),
|
||||
button::Status::Disabled => t.raised,
|
||||
button::Status::Active => t.accent,
|
||||
};
|
||||
button::Style {
|
||||
background: Some(bg.into()),
|
||||
text_color: if matches!(status, button::Status::Disabled) { t.muted } else { t.accent_ink },
|
||||
border: Border { radius: radius::PILL.into(), ..Border::default() },
|
||||
shadow: Shadow {
|
||||
color: Color::BLACK.scale_alpha(0.18),
|
||||
offset: Vector::new(0.0, 4.0),
|
||||
blur_radius: 12.0,
|
||||
},
|
||||
snap: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ghost(theme: &Theme, status: button::Status) -> button::Style {
|
||||
let t = tokens(theme);
|
||||
button::Style {
|
||||
background: matches!(status, button::Status::Hovered | button::Status::Pressed)
|
||||
.then(|| t.raised.into()),
|
||||
text_color: t.fg,
|
||||
border: Border { radius: radius::PILL.into(), ..hairline(t.line) },
|
||||
shadow: Shadow::default(),
|
||||
snap: true,
|
||||
}
|
||||
}
|
||||
|
||||
/// A pill in a segmented choice (My Wave settings). The selected one is filled.
|
||||
pub fn chip(selected: bool) -> impl Fn(&Theme, button::Status) -> button::Style {
|
||||
move |theme, status| {
|
||||
let t = tokens(theme);
|
||||
let hovered = matches!(status, button::Status::Hovered | button::Status::Pressed);
|
||||
button::Style {
|
||||
background: if selected {
|
||||
Some(t.accent.into())
|
||||
} else {
|
||||
hovered.then(|| t.raised.into())
|
||||
},
|
||||
text_color: if selected { t.accent_ink } else { t.fg },
|
||||
border: Border {
|
||||
radius: radius::PILL.into(),
|
||||
..hairline(if selected { t.accent } else { t.line })
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
snap: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Tab in a tab strip (drawer Queue | Lyrics, collection tabs).
|
||||
pub fn tab(selected: bool) -> impl Fn(&Theme, button::Status) -> button::Style {
|
||||
move |theme, status| {
|
||||
let t = tokens(theme);
|
||||
let hovered = matches!(status, button::Status::Hovered);
|
||||
button::Style {
|
||||
background: None,
|
||||
text_color: if selected || hovered { t.fg } else { t.muted },
|
||||
border: Border::default(),
|
||||
shadow: Shadow::default(),
|
||||
snap: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tab_underline(selected: bool) -> impl Fn(&Theme) -> container::Style {
|
||||
move |theme| container::Style {
|
||||
background: selected.then(|| tokens(theme).accent.into()),
|
||||
..container::Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Inputs ----
|
||||
|
||||
pub fn search_field(theme: &Theme, status: text_input::Status) -> text_input::Style {
|
||||
let t = tokens(theme);
|
||||
let focused = matches!(status, text_input::Status::Focused { .. });
|
||||
text_input::Style {
|
||||
background: t.panel.into(),
|
||||
border: Border {
|
||||
color: if focused { t.accent } else { t.line },
|
||||
width: 1.0,
|
||||
radius: radius::PILL.into(),
|
||||
},
|
||||
icon: t.muted,
|
||||
placeholder: t.muted,
|
||||
value: t.fg,
|
||||
selection: t.accent.scale_alpha(0.35),
|
||||
}
|
||||
}
|
||||
|
||||
/// Thin seek bar: amber fill, knob only while hovered or dragged.
|
||||
pub fn seek_bar(theme: &Theme, status: slider::Status) -> slider::Style {
|
||||
thin_slider(theme, status, tokens(theme).accent)
|
||||
}
|
||||
|
||||
pub fn volume_bar(theme: &Theme, status: slider::Status) -> slider::Style {
|
||||
thin_slider(theme, status, tokens(theme).fg)
|
||||
}
|
||||
|
||||
fn thin_slider(theme: &Theme, status: slider::Status, fill: Color) -> slider::Style {
|
||||
let t = tokens(theme);
|
||||
let engaged = matches!(status, slider::Status::Hovered | slider::Status::Dragged);
|
||||
slider::Style {
|
||||
rail: slider::Rail {
|
||||
backgrounds: (fill.into(), t.raised.into()),
|
||||
width: 4.0,
|
||||
border: Border { radius: 2.0.into(), ..Border::default() },
|
||||
},
|
||||
handle: slider::Handle {
|
||||
shape: slider::HandleShape::Circle { radius: if engaged { 6.0 } else { 0.0 } },
|
||||
background: t.fg.into(),
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn scroll(theme: &Theme, status: scrollable::Status) -> scrollable::Style {
|
||||
let t = tokens(theme);
|
||||
let mut style = scrollable::default(theme, status);
|
||||
let rail = scrollable::Rail {
|
||||
background: None,
|
||||
border: Border::default(),
|
||||
scroller: scrollable::Scroller {
|
||||
background: t.line.into(),
|
||||
border: Border { radius: radius::PILL.into(), ..Border::default() },
|
||||
},
|
||||
};
|
||||
style.vertical_rail = rail;
|
||||
style.horizontal_rail = rail;
|
||||
style
|
||||
}
|
||||
|
||||
/// Linear blend of two colours; `amount` is the share of `b`.
|
||||
pub fn mix(a: Color, b: Color, amount: f32) -> Color {
|
||||
Color {
|
||||
r: a.r + (b.r - a.r) * amount,
|
||||
g: a.g + (b.g - a.g) * amount,
|
||||
b: a.b + (b.b - a.b) * amount,
|
||||
a: a.a + (b.a - a.a) * amount,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn tokens_follow_theme_mode() {
|
||||
assert_eq!(tokens(&for_mode(Mode::Dark)), &DARK);
|
||||
assert_eq!(tokens(&for_mode(Mode::None)), &DARK);
|
||||
assert_eq!(tokens(&for_mode(Mode::Light)), &LIGHT);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hex_unpacks_channels() {
|
||||
assert_eq!(hex(0xF0B23E), Color::from_rgb8(0xF0, 0xB2, 0x3E));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hsl_primaries() {
|
||||
let red = hsl(0.0, 1.0, 0.5);
|
||||
assert!((red.r - 1.0).abs() < 1e-5 && red.g.abs() < 1e-5 && red.b.abs() < 1e-5);
|
||||
let blue = hsl(240.0, 1.0, 0.5);
|
||||
assert!((blue.b - 1.0).abs() < 1e-5 && blue.r.abs() < 1e-5);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user