diff --git a/CHANGELOG.md b/CHANGELOG.md index 0eed1fe..c4631ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ One section per version, newest first. +## v0.6.4 (2026-11-04) + +### Features + +- Settings has a Cover backdrop slider for how much of the cover shows behind the now-playing screen, from off to 100 in steps of 10. Left and right change it. The default looks as before, and the strongest setting still keeps the text readable over a bright cover. + ## v0.6.3 (2026-11-04) ### Features diff --git a/Cargo.lock b/Cargo.lock index a369aee..fb90c7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4385,7 +4385,7 @@ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" [[package]] name = "remus" -version = "0.6.3" +version = "0.6.4" dependencies = [ "anyhow", "directories", diff --git a/Cargo.toml b/Cargo.toml index f7db2be..870ad8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "remus" -version = "0.6.3" +version = "0.6.4" edition = "2024" license = "MIT" diff --git a/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml b/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml index a430109..3027522 100644 --- a/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml +++ b/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml @@ -20,6 +20,7 @@ + diff --git a/src/app.rs b/src/app.rs index 3fb22ad..6bf2ecb 100644 --- a/src/app.rs +++ b/src/app.rs @@ -124,6 +124,7 @@ enum Target { #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum Setting { AlbumArtColours, + CoverBackdrop, } /// How long the UI takes to change from one palette to the next. @@ -338,6 +339,7 @@ impl App { } fn start(&mut self) { + self.render_backdrop(); let labels: Vec = SECTIONS.iter().map(|s| s.label().into()).collect(); self.ui.set_sections(ModelRc::new(VecModel::from(labels))); @@ -576,6 +578,9 @@ impl App { _ => {} }, Area::Content => match a { + Action::Left | Action::Right if let Some(s) = self.selected_range_setting() => { + self.adjust_setting(s, a == Action::Right) + } Action::Up | Action::Down | Action::Left | Action::Right | Action::PageUp | Action::PageDown => { self.move_sel(a) } @@ -871,12 +876,43 @@ impl App { } } + /// The range setting under the selection, which left and right adjust. + fn selected_range_setting(&self) -> Option { + let page = self.current_page()?; + match page.entries.get(page.sel)?.target { + Target::Setting(s @ Setting::CoverBackdrop) => Some(s), + _ => None, + } + } + // ---------------------------------------------------------------- settings fn toggle_setting(&mut self, setting: Setting) { match setting { Setting::AlbumArtColours => self.settings.album_art_colours = !self.settings.album_art_colours, + // A range: left and right change it, confirm does nothing. + Setting::CoverBackdrop => return, } + self.settings_changed(); + } + + /// Moves a range setting one step up or down. + fn adjust_setting(&mut self, setting: Setting, up: bool) { + match setting { + Setting::CoverBackdrop => { + let v = step_backdrop(self.settings.cover_backdrop, up); + if v == self.settings.cover_backdrop { + return; + } + self.settings.cover_backdrop = v; + } + Setting::AlbumArtColours => return, + } + self.settings_changed(); + } + + /// Saves the settings and shows what they change. + fn settings_changed(&mut self) { if let Err(e) = config::save_settings(&self.settings) { self.toast(format!("Could not save settings: {e:#}")); } @@ -888,9 +924,17 @@ impl App { self.sync_items(true); } } + self.render_backdrop(); self.update_theme(); } + fn render_backdrop(&self) { + let (opacity, left, right) = backdrop_look(self.settings.cover_backdrop); + self.ui.set_np_backdrop_opacity(opacity); + self.ui.set_np_backdrop_left(left); + self.ui.set_np_backdrop_right(right); + } + // ---------------------------------------------------------------- theme /// The palette the UI should show: from the playing track's cover when @@ -1299,6 +1343,10 @@ impl App { _ => false, }; let cover = entry.cover.as_deref().and_then(|id| self.cover(id, px)); + let level = match entry.target { + Target::Setting(Setting::CoverBackdrop) => Some(self.settings.cover_backdrop as f32 / 100.0), + _ => None, + }; Some(Item { index: index as i32, letter: initial(&entry.title).into(), @@ -1312,6 +1360,8 @@ impl App { round: entry.round, show_art: entry.show_art, playing, + slider: level.is_some(), + level: level.unwrap_or_default(), }) } @@ -1355,6 +1405,7 @@ impl App { .map(|e| &e.target); match target { Some(Target::Song(_)) => h(Control::Activate, "Play"), + Some(Target::Setting(Setting::CoverBackdrop)) => h(Control::Seek, "Adjust"), Some(Target::Setting(_)) => h(Control::Activate, "Change"), Some(_) => h(Control::Activate, "Open"), None if self.current_page().is_some_and(|p| p.error.is_some()) => { @@ -2010,6 +2061,8 @@ impl App { round: false, show_art: true, playing: Some(index) == self.current, + slider: false, + level: 0.0, } } } @@ -2098,20 +2151,70 @@ fn song_entry(s: &Song, index: usize) -> Entry { fn settings_data(s: &Settings) -> PageData { let on_off = |on: bool| if on { "On" } else { "Off" }.to_string(); PageData { - entries: vec![Entry { - title: "Colours from album art".to_string(), - subtitle: "Tint the interface with the cover of the playing track".to_string(), - detail: on_off(s.album_art_colours), - number: String::new(), - cover: None, - round: false, - show_art: false, - target: Target::Setting(Setting::AlbumArtColours), - }], + entries: vec![ + Entry { + title: "Colours from album art".to_string(), + subtitle: "Tint the interface with the cover of the playing track".to_string(), + detail: on_off(s.album_art_colours), + number: String::new(), + cover: None, + round: false, + show_art: false, + target: Target::Setting(Setting::AlbumArtColours), + }, + Entry { + title: "Cover backdrop".to_string(), + subtitle: "How much of the cover shows behind the now-playing screen".to_string(), + detail: if s.cover_backdrop == 0 { + "Off".to_string() + } else { + s.cover_backdrop.to_string() + }, + number: String::new(), + cover: None, + round: false, + show_art: false, + target: Target::Setting(Setting::CoverBackdrop), + }, + ], ..Default::default() } } +/// One step of the cover backdrop setting, kept within 0 to 100. +fn step_backdrop(v: u8, up: bool) -> u8 { + let v = v.min(100); + if up { (v + 10).min(100) } else { v.saturating_sub(10) } +} + +/// The now-playing backdrop for a strength of 0 to 100: the cover's opacity +/// and the background alpha over it at the left and right edges. +/// +/// Up to the default the cover fades in under today's overlay. Above it the +/// overlay thins too, but never below 0.55 on the left, where the title and +/// progress are, so the text stays readable over a bright cover. +fn backdrop_look(v: u8) -> (f32, f32, f32) { + // Today's look, reached at the default. + const OPACITY: f32 = 0.16; + const LEFT: f32 = 0.67; + const RIGHT: f32 = 0.95; + // The strongest, at 100. + const OPACITY_MAX: f32 = 0.40; + const LEFT_MIN: f32 = 0.55; + const RIGHT_MIN: f32 = 0.80; + let v = v.min(100) as f32; + let d = config::COVER_BACKDROP_DEFAULT as f32; + if v <= d { + return (OPACITY * v / d, LEFT, RIGHT); + } + let u = (v - d) / (100.0 - d); + ( + OPACITY + u * (OPACITY_MAX - OPACITY), + LEFT + u * (LEFT_MIN - LEFT), + RIGHT + u * (RIGHT_MIN - RIGHT), + ) +} + fn search_data(r: SearchResult) -> PageData { let mut entries: Vec = r.artist.into_iter().map(artist_entry).collect(); entries.extend(r.album.into_iter().map(|a| Entry { @@ -2293,6 +2396,34 @@ mod tests { assert_ne!(a, c); } + #[test] + fn default_backdrop_looks_like_before_it_was_a_setting() { + assert_eq!(backdrop_look(config::COVER_BACKDROP_DEFAULT), (0.16, 0.67, 0.95)); + } + + #[test] + fn backdrop_off_draws_no_cover() { + assert_eq!(backdrop_look(0).0, 0.0); + } + + #[test] + fn backdrop_strongest_keeps_an_overlay() { + let (opacity, left, right) = backdrop_look(100); + assert!((opacity - 0.40).abs() < 1e-6); + assert!((left - 0.55).abs() < 1e-6); + assert!((right - 0.80).abs() < 1e-6); + assert_eq!(backdrop_look(250), backdrop_look(100)); + } + + #[test] + fn backdrop_steps_stay_in_range() { + assert_eq!(step_backdrop(30, true), 40); + assert_eq!(step_backdrop(30, false), 20); + assert_eq!(step_backdrop(100, true), 100); + assert_eq!(step_backdrop(0, false), 0); + assert_eq!(step_backdrop(200, false), 90); + } + #[test] fn grid_window_is_row_aligned() { assert_eq!(window(1000, 0, 5, false), (0, 55)); diff --git a/src/config.rs b/src/config.rs index 0996669..07a6c2a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -88,11 +88,25 @@ pub fn save(cfg: &Config) -> Result<()> { } /// Preferences. Kept apart from the login, so logging out does not reset them. -#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(default)] pub struct Settings { /// Tint the UI with the colours of the playing track's cover. pub album_art_colours: bool, + /// How strongly the cover shows behind the now-playing screen, 0 to 100. + pub cover_backdrop: u8, +} + +/// The cover backdrop strength that looks like it did before it was a setting. +pub const COVER_BACKDROP_DEFAULT: u8 = 30; + +impl Default for Settings { + fn default() -> Self { + Settings { + album_art_colours: false, + cover_backdrop: COVER_BACKDROP_DEFAULT, + } + } } fn settings_path() -> Option { @@ -193,12 +207,21 @@ mod tests { let s: Settings = toml::from_str("").unwrap(); assert_eq!(s, Settings::default()); assert!(!s.album_art_colours); + assert_eq!(s.cover_backdrop, COVER_BACKDROP_DEFAULT); + } + + #[test] + fn settings_from_before_the_backdrop_load_its_default() { + let s: Settings = toml::from_str("album_art_colours = true\n").unwrap(); + assert!(s.album_art_colours); + assert_eq!(s.cover_backdrop, COVER_BACKDROP_DEFAULT); } #[test] fn settings_round_trip() { let s = Settings { album_art_colours: true, + cover_backdrop: 70, }; let back: Settings = toml::from_str(&toml::to_string(&s).unwrap()).unwrap(); assert_eq!(back, s); diff --git a/ui/app.slint b/ui/app.slint index 0ceae40..7b281ba 100644 --- a/ui/app.slint +++ b/ui/app.slint @@ -27,6 +27,9 @@ export struct Item { round: bool, show-art: bool, playing: bool, + // A setting with a range: draws `level` (0 to 1) as a slider before `detail`. + slider: bool, + level: float, } export struct Header { @@ -237,10 +240,38 @@ component Row inherits Rectangle { } } + if root.item.slider: VerticalLayout { + alignment: center; + Rectangle { + width: 180px * Theme.s; + height: 6px * Theme.s; + border-radius: 3px * Theme.s; + background: Theme.line; + Rectangle { + x: 0; + width: parent.width * root.item.level; + border-radius: 3px * Theme.s; + background: root.selected && root.active ? Theme.highlight : Theme.muted; + animate width { duration: 120ms; easing: ease-out; } + } + Rectangle { + x: parent.width * root.item.level - self.width / 2; + width: 16px * Theme.s; + height: 16px * Theme.s; + border-radius: 8px * Theme.s; + background: root.selected && root.active ? Theme.text : Theme.muted; + animate x { duration: 120ms; easing: ease-out; } + } + } + } + Text { + // Fixed for a slider, so the bar does not shift as the number grows. + min-width: root.item.slider ? 44px * Theme.s : 0; text: root.item.detail; font-size: 15px * Theme.s; color: Theme.muted; + horizontal-alignment: right; vertical-alignment: center; } } @@ -756,6 +787,11 @@ component NowPlayingView inherits Rectangle { in property duration; in property paused; in property has-track; + // From the cover backdrop setting: the blown-up cover's opacity and the + // alpha of the background drawn over it, at the left and right edges. + in property backdrop-opacity: 0.16; + in property backdrop-left: 0.67; + in property backdrop-right: 0.95; // True while the cover turns away; the app swaps the cover at edge-on and // sets it back to false to turn the new one in. in property flip-out; @@ -768,15 +804,15 @@ component NowPlayingView inherits Rectangle { out property art-size: 440px * Theme.s; // Blown-up cover as a dim backdrop. - if root.has-cover: Image { + if root.has-cover && root.backdrop-opacity > 0: Image { width: parent.width; height: parent.height; source: root.cover; image-fit: ImageFit.cover; - opacity: 0.16; + opacity: root.backdrop-opacity; } Rectangle { - background: @linear-gradient(90deg, Theme.bg.with-alpha(0.67), Theme.bg.with-alpha(0.95)); + background: @linear-gradient(90deg, Theme.bg.with-alpha(root.backdrop-left), Theme.bg.with-alpha(root.backdrop-right)); } HorizontalLayout { @@ -956,6 +992,9 @@ export component AppWindow inherits Window { in property np-duration; in property np-paused; in property np-flip-out; + in property np-backdrop-opacity: 0.16; + in property np-backdrop-left: 0.67; + in property np-backdrop-right: 0.95; in property <[Item]> queue-items; in property queue-count; in property queue-selected; @@ -1118,6 +1157,9 @@ export component AppWindow inherits Window { paused: root.np-paused; has-track: root.np-has-track; flip-out: root.np-flip-out; + backdrop-opacity: root.np-backdrop-opacity; + backdrop-left: root.np-backdrop-left; + backdrop-right: root.np-backdrop-right; queue: root.queue-items; queue-count: root.queue-count; queue-selected: root.queue-selected;