From 12ed5a7c4a2372260699a50ba5af518db7dc6c4f Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Mon, 18 May 2026 20:17:54 -0600 Subject: [PATCH] feat(slint): browser-like back/forward navigation history Add a navigation history so pages can be walked back and forward. - nav.rs: a back/forward stack of NavEntry (home, album, artist, settings); record() on fresh navigation, go_back/go_forward to walk it - NavButtons: a [<] [>] pair styled like the Discover tab group; inline beside the Discover tabs and in place of the per-page Back button on album, artist and settings views - All navigation routes through Rust (open-album/-artist record entries; the gear and header menu use NavState.request-settings) so the history stays accurate; back/forward re-apply entries, re-loading entity pages - AppShell listens for the mouse back/forward buttons - can-back / can-forward drive the buttons' enabled state Also in this round: - Album header description: render a pre-truncated short string so it wraps to a couple of lines instead of overflowing the header; the full text stays in the Read-more modal - Header queue button uses an ordered-list icon (the previous one read as a playlist) cc --- crates/qbz-slint/src/album.rs | 17 ++ crates/qbz-slint/src/main.rs | 251 +++++++++++++----- crates/qbz-slint/src/nav.rs | 133 ++++++++++ crates/qbz-slint/ui/album/AlbumPageView.slint | 42 +-- .../qbz-slint/ui/artist/ArtistPageView.slint | 31 +-- .../ui/assets/icons/list-ordered.svg | 8 + crates/qbz-slint/ui/discover/HomeView.slint | 10 +- .../qbz-slint/ui/settings/SettingsView.slint | 29 +- crates/qbz-slint/ui/shell/AppShell.slint | 15 ++ crates/qbz-slint/ui/shell/HeaderBar.slint | 4 +- crates/qbz-slint/ui/shell/NavButtons.slint | 66 +++++ crates/qbz-slint/ui/state.slint | 9 + 12 files changed, 461 insertions(+), 154 deletions(-) create mode 100644 crates/qbz-slint/src/nav.rs create mode 100644 crates/qbz-slint/ui/assets/icons/list-ordered.svg create mode 100644 crates/qbz-slint/ui/shell/NavButtons.slint diff --git a/crates/qbz-slint/src/album.rs b/crates/qbz-slint/src/album.rs index 0e0dbbc5b..155642b87 100644 --- a/crates/qbz-slint/src/album.rs +++ b/crates/qbz-slint/src/album.rs @@ -34,6 +34,8 @@ pub struct AlbumData { pub quality_detail: String, /// Editorial description / review (HTML stripped). May be empty. pub description: String, + /// Short, truncated description for the header (full text in a modal). + pub description_short: String, pub artwork_url: String, /// Record label name, for the sidebar (empty when unknown). pub label: String, @@ -101,6 +103,7 @@ fn map_album(album: Album) -> AlbumData { .as_deref() .map(strip_html) .unwrap_or_default(); + let description_short = truncate_words(&description, 200); let artwork_url = album.image.best().cloned().unwrap_or_default(); let label = album .label @@ -132,6 +135,7 @@ fn map_album(album: Album) -> AlbumData { quality_tier, quality_detail, description, + description_short, artwork_url, label, awards, @@ -139,6 +143,18 @@ fn map_album(album: Album) -> AlbumData { } } +/// Truncate text to at most `max` characters, cutting back to the last +/// word boundary and appending an ellipsis. Returns the text unchanged +/// when it is already short enough. +fn truncate_words(text: &str, max: usize) -> String { + if text.chars().count() <= max { + return text.to_string(); + } + let truncated: String = text.chars().take(max).collect(); + let cut = truncated.rfind(' ').unwrap_or(truncated.len()); + format!("{}…", truncated[..cut].trim_end()) +} + /// "24-bit / 96 kHz" — the quality-badge detail string. fn quality_detail(bit_depth: Option, sample_rate: Option) -> String { let hi_res = matches!(bit_depth, Some(depth) if depth >= 24); @@ -257,6 +273,7 @@ pub fn apply_album(window: &AppWindow, data: AlbumData) { state.set_quality_tier(data.quality_tier.into()); state.set_quality_detail(data.quality_detail.into()); state.set_description(data.description.into()); + state.set_description_short(data.description_short.into()); state.set_label(data.label.into()); state.set_awards(ModelRc::new(VecModel::from(awards))); diff --git a/crates/qbz-slint/src/main.rs b/crates/qbz-slint/src/main.rs index b133dcf3a..ed7f85917 100644 --- a/crates/qbz-slint/src/main.rs +++ b/crates/qbz-slint/src/main.rs @@ -21,6 +21,7 @@ mod artwork; mod auth; mod commands; mod home; +mod nav; mod recently; mod settings; @@ -150,6 +151,123 @@ async fn enter_shell( } } +/// Push the navigation history flags onto `NavState`. UI thread only. +fn update_nav_flags(window: &AppWindow) { + let state = window.global::(); + state.set_can_back(nav::can_back()); + state.set_can_forward(nav::can_forward()); +} + +/// Load an album and show the album view, then fetch its artwork. Shared +/// by the `open-album` callback and by history back/forward. +fn navigate_album( + runtime: Arc>, + weak: slint::Weak, + handle: &tokio::runtime::Handle, + image_cache: artwork::ImageCache, + album_id: String, +) { + handle.spawn(async move { + let _ = weak.upgrade_in_event_loop(|w| { + album::reset_album(&w); + w.global::().set_view(ContentView::Album); + }); + match album::load_album(&runtime, &album_id).await { + Ok(data) => { + let artwork_url = data.artwork_url.clone(); + let _ = weak.upgrade_in_event_loop(move |w| { + album::apply_album(&w, data); + w.global::().set_loading(false); + }); + if !artwork_url.is_empty() { + if let Some((pixels, width, height)) = + artwork::fetch_and_decode(&artwork_url, &image_cache, 448).await + { + let _ = weak.upgrade_in_event_loop(move |w| { + album::apply_artwork(&w, &pixels, width, height); + }); + } + } + } + Err(e) => { + log::error!("[qbz-slint] album load failed: {e}"); + let _ = weak.upgrade_in_event_loop(|w| { + w.global::().set_loading(false); + }); + } + } + }); +} + +/// Load an artist page and show the artist view, then fetch the portrait. +/// Shared by the `open-artist` callback and by history back/forward. +fn navigate_artist( + runtime: Arc>, + weak: slint::Weak, + handle: &tokio::runtime::Handle, + image_cache: artwork::ImageCache, + artist_id: String, +) { + handle.spawn(async move { + let _ = weak.upgrade_in_event_loop(|w| { + artist::reset_artist(&w); + w.global::().set_view(ContentView::Artist); + }); + match artist::load_artist(&runtime, &artist_id).await { + Ok(data) => { + let artwork_url = data.artwork_url.clone(); + let _ = weak.upgrade_in_event_loop(move |w| { + artist::apply_artist(&w, data); + w.global::().set_loading(false); + }); + if !artwork_url.is_empty() { + if let Some((pixels, width, height)) = + artwork::fetch_and_decode(&artwork_url, &image_cache, 440).await + { + let _ = weak.upgrade_in_event_loop(move |w| { + artist::apply_artwork(&w, &pixels, width, height); + }); + } + } + } + Err(e) => { + log::error!("[qbz-slint] artist load failed: {e}"); + let _ = weak.upgrade_in_event_loop(|w| { + w.global::().set_loading(false); + }); + } + } + }); +} + +/// Apply a history entry — set the view and re-load entity pages. +fn apply_entry( + entry: nav::NavEntry, + runtime: &Arc>, + weak: &slint::Weak, + handle: &tokio::runtime::Handle, + image_cache: &artwork::ImageCache, +) { + match entry { + nav::NavEntry::Home => { + let _ = weak.upgrade_in_event_loop(|w| { + w.global::().set_view(ContentView::Home); + }); + } + nav::NavEntry::Settings => { + let _ = weak.upgrade_in_event_loop(|w| { + w.global::().set_view(ContentView::Settings); + }); + } + nav::NavEntry::Album(id) => { + navigate_album(runtime.clone(), weak.clone(), handle, image_cache.clone(), id); + } + nav::NavEntry::Artist(id) => { + navigate_artist(runtime.clone(), weak.clone(), handle, image_cache.clone(), id); + } + } +} + fn main() -> Result<(), Box> { env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); @@ -262,91 +380,88 @@ fn main() -> Result<(), Box> { }); } - // Open an album: load it, show the album view, then fetch its artwork. + // Open an album: record history, then load and show it. { let runtime = app_runtime.clone(); let weak = window.as_weak(); let handle = tokio_rt.handle().clone(); let image_cache = image_cache.clone(); window.on_open_album(move |album_id| { - let runtime = runtime.clone(); - let weak = weak.clone(); - let image_cache = image_cache.clone(); let album_id = album_id.to_string(); - handle.spawn(async move { - let _ = weak.upgrade_in_event_loop(|w| { - album::reset_album(&w); - w.global::().set_view(ContentView::Album); - }); - match album::load_album(&runtime, &album_id).await { - Ok(data) => { - let artwork_url = data.artwork_url.clone(); - let _ = weak.upgrade_in_event_loop(move |w| { - album::apply_album(&w, data); - w.global::().set_loading(false); - }); - if !artwork_url.is_empty() { - if let Some((pixels, width, height)) = - artwork::fetch_and_decode(&artwork_url, &image_cache, 448).await - { - let _ = weak.upgrade_in_event_loop(move |w| { - album::apply_artwork(&w, &pixels, width, height); - }); - } - } - } - Err(e) => { - log::error!("[qbz-slint] album load failed: {e}"); - let _ = weak.upgrade_in_event_loop(|w| { - w.global::().set_loading(false); - }); - } - } - }); + nav::record(nav::NavEntry::Album(album_id.clone())); + navigate_album( + runtime.clone(), + weak.clone(), + &handle, + image_cache.clone(), + album_id, + ); + if let Some(w) = weak.upgrade() { + update_nav_flags(&w); + } }); } - // Open an artist: load the artist page, show it, then fetch the portrait. + // Open an artist: record history, then load and show the page. { let runtime = app_runtime.clone(); let weak = window.as_weak(); let handle = tokio_rt.handle().clone(); let image_cache = image_cache.clone(); window.on_open_artist(move |artist_id| { - let runtime = runtime.clone(); - let weak = weak.clone(); - let image_cache = image_cache.clone(); let artist_id = artist_id.to_string(); - handle.spawn(async move { - let _ = weak.upgrade_in_event_loop(|w| { - artist::reset_artist(&w); - w.global::().set_view(ContentView::Artist); - }); - match artist::load_artist(&runtime, &artist_id).await { - Ok(data) => { - let artwork_url = data.artwork_url.clone(); - let _ = weak.upgrade_in_event_loop(move |w| { - artist::apply_artist(&w, data); - w.global::().set_loading(false); - }); - if !artwork_url.is_empty() { - if let Some((pixels, width, height)) = - artwork::fetch_and_decode(&artwork_url, &image_cache, 440).await - { - let _ = weak.upgrade_in_event_loop(move |w| { - artist::apply_artwork(&w, &pixels, width, height); - }); - } - } - } - Err(e) => { - log::error!("[qbz-slint] artist load failed: {e}"); - let _ = weak.upgrade_in_event_loop(|w| { - w.global::().set_loading(false); - }); - } - } - }); + nav::record(nav::NavEntry::Artist(artist_id.clone())); + navigate_artist( + runtime.clone(), + weak.clone(), + &handle, + image_cache.clone(), + artist_id, + ); + if let Some(w) = weak.upgrade() { + update_nav_flags(&w); + } + }); + } + + // History navigation — back / forward / settings, all recorded by the + // nav module so the [<] [>] pair and the mouse buttons stay in sync. + { + let weak = window.as_weak(); + window.global::().on_request_settings(move || { + nav::record(nav::NavEntry::Settings); + if let Some(w) = weak.upgrade() { + w.global::().set_view(ContentView::Settings); + update_nav_flags(&w); + } + }); + } + { + let runtime = app_runtime.clone(); + let weak = window.as_weak(); + let handle = tokio_rt.handle().clone(); + let image_cache = image_cache.clone(); + window.global::().on_request_back(move || { + if let Some(entry) = nav::go_back() { + apply_entry(entry, &runtime, &weak, &handle, &image_cache); + } + if let Some(w) = weak.upgrade() { + update_nav_flags(&w); + } + }); + } + { + let runtime = app_runtime.clone(); + let weak = window.as_weak(); + let handle = tokio_rt.handle().clone(); + let image_cache = image_cache.clone(); + window.global::().on_request_forward(move || { + if let Some(entry) = nav::go_forward() { + apply_entry(entry, &runtime, &weak, &handle, &image_cache); + } + if let Some(w) = weak.upgrade() { + update_nav_flags(&w); + } }); } diff --git a/crates/qbz-slint/src/nav.rs b/crates/qbz-slint/src/nav.rs new file mode 100644 index 000000000..ce04cdcfd --- /dev/null +++ b/crates/qbz-slint/src/nav.rs @@ -0,0 +1,133 @@ +//! Page navigation history — a browser-like back/forward stack. +//! +//! The shell records a [`NavEntry`] on every fresh navigation; the +//! `[<] [>]` button pair (and the mouse back/forward buttons) walk the +//! stack. UI thread only, hence `thread_local`. +//! +//! Scroll-position restoration per entry is a planned follow-up; for now +//! the stack tracks which page was visited, not where it was scrolled. + +use std::cell::RefCell; + +/// One navigable destination. +#[derive(Clone, Debug, PartialEq)] +pub enum NavEntry { + Home, + Album(String), + Artist(String), + Settings, +} + +struct History { + entries: Vec, + /// Index of the entry currently shown. + cursor: usize, +} + +thread_local! { + static HISTORY: RefCell = RefCell::new(History { + entries: vec![NavEntry::Home], + cursor: 0, + }); +} + +/// Record a fresh forward navigation, dropping any forward history. A +/// no-op when the destination already is the current entry, so repeated +/// clicks on the same page do not pile up. +pub fn record(entry: NavEntry) { + HISTORY.with(|h| { + let h = &mut *h.borrow_mut(); + if h.entries.get(h.cursor) == Some(&entry) { + return; + } + h.entries.truncate(h.cursor + 1); + h.entries.push(entry); + h.cursor = h.entries.len() - 1; + }); +} + +/// Step back; returns the entry that is now current, or `None` at the +/// start of the stack. +pub fn go_back() -> Option { + HISTORY.with(|h| { + let h = &mut *h.borrow_mut(); + if h.cursor == 0 { + return None; + } + h.cursor -= 1; + h.entries.get(h.cursor).cloned() + }) +} + +/// Step forward; returns the entry that is now current, or `None` at the +/// end of the stack. +pub fn go_forward() -> Option { + HISTORY.with(|h| { + let h = &mut *h.borrow_mut(); + if h.cursor + 1 >= h.entries.len() { + return None; + } + h.cursor += 1; + h.entries.get(h.cursor).cloned() + }) +} + +/// Whether a back step is available. +pub fn can_back() -> bool { + HISTORY.with(|h| h.borrow().cursor > 0) +} + +/// Whether a forward step is available. +pub fn can_forward() -> bool { + HISTORY.with(|h| { + let h = h.borrow(); + h.cursor + 1 < h.entries.len() + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn reset() { + HISTORY.with(|h| { + *h.borrow_mut() = History { + entries: vec![NavEntry::Home], + cursor: 0, + }; + }); + } + + #[test] + fn record_then_back_and_forward() { + reset(); + assert!(!can_back()); + record(NavEntry::Album("1".into())); + record(NavEntry::Artist("2".into())); + assert!(can_back()); + assert!(!can_forward()); + assert_eq!(go_back(), Some(NavEntry::Album("1".into()))); + assert_eq!(go_back(), Some(NavEntry::Home)); + assert_eq!(go_back(), None); + assert_eq!(go_forward(), Some(NavEntry::Album("1".into()))); + } + + #[test] + fn record_truncates_forward_history() { + reset(); + record(NavEntry::Album("1".into())); + record(NavEntry::Album("2".into())); + go_back(); + record(NavEntry::Artist("3".into())); + assert!(!can_forward()); + assert_eq!(go_back(), Some(NavEntry::Album("1".into()))); + } + + #[test] + fn record_dedupes_current_entry() { + reset(); + record(NavEntry::Album("1".into())); + record(NavEntry::Album("1".into())); + assert_eq!(go_back(), Some(NavEntry::Home)); + } +} diff --git a/crates/qbz-slint/ui/album/AlbumPageView.slint b/crates/qbz-slint/ui/album/AlbumPageView.slint index caf0d988c..f7332d1f8 100644 --- a/crates/qbz-slint/ui/album/AlbumPageView.slint +++ b/crates/qbz-slint/ui/album/AlbumPageView.slint @@ -14,6 +14,7 @@ import { QbzIcon } from "../primitives/QbzIcon.slint"; import { ContextMenu } from "../primitives/ContextMenu.slint"; import { ContextMenuItem } from "../primitives/ContextMenuItem.slint"; import { QualityBadgeFull } from "../primitives/QualityBadgeFull.slint"; +import { NavButtons } from "../shell/NavButtons.slint"; component CircleAction inherits Rectangle { in property icon; @@ -320,32 +321,10 @@ export component AlbumPageView inherits Rectangle { spacing: 0px; alignment: start; - // --- Back button ------------------------------------------------- - back := TouchArea { - width: back-row.preferred-width; - height: 28px; - mouse-cursor: pointer; - clicked => { - NavState.view = ContentView.home; - } - back-row := HorizontalLayout { - spacing: 6px; - VerticalLayout { - alignment: center; - QbzIcon { - source: @image-url("../assets/icons/arrow-left.svg"); - width: 16px; - height: 16px; - tint: back.has-hover ? Theme.text-secondary : Theme.text-muted; - } - } - Text { - text: @tr("Back"); - color: back.has-hover ? Theme.text-secondary : Theme.text-muted; - font-size: Typography.body; - vertical-alignment: center; - } - } + // --- History navigation ------------------------------------------ + HorizontalLayout { + alignment: start; + NavButtons { } } Rectangle { height: 22px; } @@ -412,18 +391,17 @@ export component AlbumPageView inherits Rectangle { overflow: elide; } - // Editorial description — truncated, with a Read more - // link that opens the full text in a modal. + // Editorial description — a pre-truncated short string + // (so it naturally wraps to a couple of lines without + // overflowing), with a Read more link to the full modal. if AlbumState.description != "": Rectangle { height: 10px; } if AlbumState.description != "": Text { - text: AlbumState.description; + text: AlbumState.description-short; color: Theme.text-secondary; font-size: Typography.legal; wrap: word-wrap; - height: 34px; - overflow: elide; } - if AlbumState.description != "": read-more := TouchArea { + if AlbumState.description != AlbumState.description-short: read-more := TouchArea { width: read-more-row.preferred-width; height: 22px; mouse-cursor: pointer; diff --git a/crates/qbz-slint/ui/artist/ArtistPageView.slint b/crates/qbz-slint/ui/artist/ArtistPageView.slint index 7635a5631..bb5881376 100644 --- a/crates/qbz-slint/ui/artist/ArtistPageView.slint +++ b/crates/qbz-slint/ui/artist/ArtistPageView.slint @@ -13,6 +13,7 @@ import { QbzIcon } from "../primitives/QbzIcon.slint"; import { ContextMenu } from "../primitives/ContextMenu.slint"; import { ContextMenuItem } from "../primitives/ContextMenuItem.slint"; import { Carousel } from "../discover/Carousel.slint"; +import { NavButtons } from "../shell/NavButtons.slint"; component CircleAction inherits Rectangle { in property icon; @@ -199,32 +200,10 @@ export component ArtistPageView inherits Rectangle { spacing: 0px; alignment: start; - // --- Back button ------------------------------------------------- - back := TouchArea { - width: back-row.preferred-width; - height: 28px; - mouse-cursor: pointer; - clicked => { - NavState.view = ContentView.home; - } - back-row := HorizontalLayout { - spacing: 6px; - VerticalLayout { - alignment: center; - QbzIcon { - source: @image-url("../assets/icons/arrow-left.svg"); - width: 16px; - height: 16px; - tint: back.has-hover ? Theme.text-secondary : Theme.text-muted; - } - } - Text { - text: @tr("Back"); - color: back.has-hover ? Theme.text-secondary : Theme.text-muted; - font-size: Typography.body; - vertical-alignment: center; - } - } + // --- History navigation ------------------------------------------ + HorizontalLayout { + alignment: start; + NavButtons { } } Rectangle { height: 22px; } diff --git a/crates/qbz-slint/ui/assets/icons/list-ordered.svg b/crates/qbz-slint/ui/assets/icons/list-ordered.svg new file mode 100644 index 000000000..724d7f9c0 --- /dev/null +++ b/crates/qbz-slint/ui/assets/icons/list-ordered.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/crates/qbz-slint/ui/discover/HomeView.slint b/crates/qbz-slint/ui/discover/HomeView.slint index 6550ba9f5..a2cc26258 100644 --- a/crates/qbz-slint/ui/discover/HomeView.slint +++ b/crates/qbz-slint/ui/discover/HomeView.slint @@ -12,6 +12,7 @@ import { HomeState, NavState, ContentView } from "../state.slint"; import { Carousel } from "Carousel.slint"; import { GridSection } from "GridSection.slint"; import { QbzIcon } from "../primitives/QbzIcon.slint"; +import { NavButtons } from "../shell/NavButtons.slint"; component Tab inherits Rectangle { in property label; @@ -122,6 +123,13 @@ export component HomeView inherits Rectangle { padding-left: 32px; padding-right: 32px; + // Back / forward history pair, inline beside the tabs. + VerticalLayout { + alignment: center; + NavButtons { } + } + Rectangle { width: 16px; } + VerticalLayout { alignment: center; Rectangle { @@ -146,7 +154,7 @@ export component HomeView inherits Rectangle { GenreButton { } GearButton { clicked => { - NavState.view = ContentView.settings; + NavState.request-settings(); } } } diff --git a/crates/qbz-slint/ui/settings/SettingsView.slint b/crates/qbz-slint/ui/settings/SettingsView.slint index 45c14ebb3..465be9f2c 100644 --- a/crates/qbz-slint/ui/settings/SettingsView.slint +++ b/crates/qbz-slint/ui/settings/SettingsView.slint @@ -10,6 +10,7 @@ import { Typography } from "../foundation/typography.slint"; import { Radius } from "../foundation/radius.slint"; import { NavState, ContentView, SettingsState } from "../state.slint"; import { QbzIcon } from "../primitives/QbzIcon.slint"; +import { NavButtons } from "../shell/NavButtons.slint"; import { AudioSettings } from "AudioSettings.slint"; import { PlaybackSettings } from "PlaybackSettings.slint"; import { ScrollView } from "std-widgets.slint"; @@ -75,31 +76,9 @@ export component SettingsView inherits Rectangle { spacing: 12px; alignment: start; - back := TouchArea { - width: back-row.preferred-width; - height: 26px; - mouse-cursor: pointer; - clicked => { - NavState.view = ContentView.home; - } - back-row := HorizontalLayout { - spacing: 6px; - VerticalLayout { - alignment: center; - QbzIcon { - source: @image-url("../assets/icons/arrow-left.svg"); - width: 16px; - height: 16px; - tint: back.has-hover ? Theme.text-secondary : Theme.text-muted; - } - } - Text { - text: @tr("Back"); - color: back.has-hover ? Theme.text-secondary : Theme.text-muted; - font-size: Typography.body; - vertical-alignment: center; - } - } + HorizontalLayout { + alignment: start; + NavButtons { } } Text { diff --git a/crates/qbz-slint/ui/shell/AppShell.slint b/crates/qbz-slint/ui/shell/AppShell.slint index 4c9d46a62..41b8cd89c 100644 --- a/crates/qbz-slint/ui/shell/AppShell.slint +++ b/crates/qbz-slint/ui/shell/AppShell.slint @@ -26,6 +26,21 @@ export component AppShell inherits Rectangle { background: Theme.surface-main; + // Bottom layer: catches the mouse back / forward buttons for history + // navigation. Declared first so the real UI sits on top of it. + TouchArea { + pointer-event(e) => { + if (e.kind == PointerEventKind.down) { + if (e.button == PointerEventButton.back) { + NavState.request-back(); + } + if (e.button == PointerEventButton.forward) { + NavState.request-forward(); + } + } + } + } + VerticalLayout { spacing: 0px; diff --git a/crates/qbz-slint/ui/shell/HeaderBar.slint b/crates/qbz-slint/ui/shell/HeaderBar.slint index f38c69e3a..2d457296b 100644 --- a/crates/qbz-slint/ui/shell/HeaderBar.slint +++ b/crates/qbz-slint/ui/shell/HeaderBar.slint @@ -207,7 +207,7 @@ export component HeaderBar inherits Rectangle { height: 36px; spacing: 2px; HeaderIconButton { - icon: @image-url("../assets/icons/list-music.svg"); + icon: @image-url("../assets/icons/list-ordered.svg"); } HeaderIconButton { icon: @image-url("../assets/icons/captions.svg"); @@ -274,7 +274,7 @@ export component HeaderBar inherits Rectangle { icon: @image-url("../assets/icons/settings.svg"); label: @tr("Settings"); clicked => { - NavState.view = ContentView.settings; + NavState.request-settings(); } } MenuItem { diff --git a/crates/qbz-slint/ui/shell/NavButtons.slint b/crates/qbz-slint/ui/shell/NavButtons.slint new file mode 100644 index 000000000..38af2eecf --- /dev/null +++ b/crates/qbz-slint/ui/shell/NavButtons.slint @@ -0,0 +1,66 @@ +// Browser-like back / forward navigation pair. +// +// Same visual format as the Discover tab pill group (an elevated rounded +// container). Used inline beside the Discover tabs and in place of the +// per-page Back button. Both buttons drive the NavState global, so the +// Rust nav history records every move. + +import { Theme } from "../foundation/semantic-colors.slint"; +import { NavState } from "../state.slint"; +import { QbzIcon } from "../primitives/QbzIcon.slint"; + +component NavBtn inherits Rectangle { + in property icon; + in property enabled: true; + callback clicked(); + + width: 32px; + height: 28px; + border-radius: 4px; + background: ta.has-hover && root.enabled ? Theme.surface-hover : transparent; + opacity: root.enabled ? 1.0 : 0.3; + + QbzIcon { + source: root.icon; + width: 15px; + height: 15px; + x: (parent.width - self.width) / 2; + y: (parent.height - self.height) / 2; + tint: Theme.text-secondary; + } + + ta := TouchArea { + mouse-cursor: root.enabled ? pointer : default; + clicked => { + if (root.enabled) { + root.clicked(); + } + } + } +} + +export component NavButtons inherits Rectangle { + background: Theme.surface-elevated; + border-radius: 6px; + width: btn-row.preferred-width; + height: 34px; + + btn-row := HorizontalLayout { + padding: 3px; + spacing: 4px; + NavBtn { + icon: @image-url("../assets/icons/chevron-left.svg"); + enabled: NavState.can-back; + clicked => { + NavState.request-back(); + } + } + NavBtn { + icon: @image-url("../assets/icons/chevron-right.svg"); + enabled: NavState.can-forward; + clicked => { + NavState.request-forward(); + } + } + } +} diff --git a/crates/qbz-slint/ui/state.slint b/crates/qbz-slint/ui/state.slint index 80bef5b25..0eed98742 100644 --- a/crates/qbz-slint/ui/state.slint +++ b/crates/qbz-slint/ui/state.slint @@ -64,6 +64,8 @@ export global AlbumState { in property quality-detail; // Editorial description / review (HTML stripped). May be empty. in property description; + // Truncated description for the header; full text lives in the modal. + in property description-short; in property artwork; // Artwork-derived tint for the header gradient. in property header-color: #181820; @@ -117,6 +119,13 @@ export global SettingsState { export global NavState { in-out property view: ContentView.home; + // Browser-like history flags, driven by the Rust nav module. + in property can-back: false; + in property can-forward: false; + // Navigation requests routed to Rust so history is recorded. + callback request-back(); + callback request-forward(); + callback request-settings(); } // Artist detail screen state.