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
This commit is contained in:
12 files changed
+461
-154
No files matched your search
@@ -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<u32>, sample_rate: Option<f64>) -> 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)));
|
||||
|
||||
|
||||
+183
-68
@@ -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::<NavState>();
|
||||
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<AppRuntime<SlintAdapter>>,
|
||||
weak: slint::Weak<AppWindow>,
|
||||
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::<NavState>().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::<AlbumState>().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::<AlbumState>().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<AppRuntime<SlintAdapter>>,
|
||||
weak: slint::Weak<AppWindow>,
|
||||
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::<NavState>().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::<ArtistState>().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::<ArtistState>().set_loading(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Apply a history entry — set the view and re-load entity pages.
|
||||
fn apply_entry(
|
||||
entry: nav::NavEntry,
|
||||
runtime: &Arc<AppRuntime<SlintAdapter>>,
|
||||
weak: &slint::Weak<AppWindow>,
|
||||
handle: &tokio::runtime::Handle,
|
||||
image_cache: &artwork::ImageCache,
|
||||
) {
|
||||
match entry {
|
||||
nav::NavEntry::Home => {
|
||||
let _ = weak.upgrade_in_event_loop(|w| {
|
||||
w.global::<NavState>().set_view(ContentView::Home);
|
||||
});
|
||||
}
|
||||
nav::NavEntry::Settings => {
|
||||
let _ = weak.upgrade_in_event_loop(|w| {
|
||||
w.global::<NavState>().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<dyn std::error::Error>> {
|
||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
||||
|
||||
@@ -262,91 +380,88 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
});
|
||||
}
|
||||
|
||||
// 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::<NavState>().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::<AlbumState>().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::<AlbumState>().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::<NavState>().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::<ArtistState>().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::<ArtistState>().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::<NavState>().on_request_settings(move || {
|
||||
nav::record(nav::NavEntry::Settings);
|
||||
if let Some(w) = weak.upgrade() {
|
||||
w.global::<NavState>().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::<NavState>().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::<NavState>().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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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<NavEntry>,
|
||||
/// Index of the entry currently shown.
|
||||
cursor: usize,
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static HISTORY: RefCell<History> = 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<NavEntry> {
|
||||
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<NavEntry> {
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -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 <image> 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;
|
||||
|
||||
@@ -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 <image> 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; }
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M10 12h11" />
|
||||
<path d="M10 18h11" />
|
||||
<path d="M10 6h11" />
|
||||
<path d="M4 10h2" />
|
||||
<path d="M4 6h1v4" />
|
||||
<path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 351 B |
@@ -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 <string> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 <image> icon;
|
||||
in property <bool> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,8 @@ export global AlbumState {
|
||||
in property <string> quality-detail;
|
||||
// Editorial description / review (HTML stripped). May be empty.
|
||||
in property <string> description;
|
||||
// Truncated description for the header; full text lives in the modal.
|
||||
in property <string> description-short;
|
||||
in property <image> artwork;
|
||||
// Artwork-derived tint for the header gradient.
|
||||
in property <color> header-color: #181820;
|
||||
@@ -117,6 +119,13 @@ export global SettingsState {
|
||||
|
||||
export global NavState {
|
||||
in-out property <ContentView> view: ContentView.home;
|
||||
// Browser-like history flags, driven by the Rust nav module.
|
||||
in property <bool> can-back: false;
|
||||
in property <bool> 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.
|
||||
|
||||
Reference in new issue
Block a user