1558 lines
60 KiB
Rust
1558 lines
60 KiB
Rust
use crate::api::models::Track;
|
||
use crate::app::state::{AppAction, AppState, CollectionTab, Route};
|
||
use crate::covers::CoverCache;
|
||
use crate::engine::input::WidgetId;
|
||
use crate::engine::scroll::visible_row_range;
|
||
use crate::engine::text::{RichSpan, TextAlign, TextStyle};
|
||
use crate::engine::theme::{YmPalette, TRACK_ROW_HEIGHT};
|
||
use crate::engine::types::{Color, CursorKind, Pos2, Rect, Vec2};
|
||
use crate::engine::widgets::{
|
||
draw_cover_art, icon_button, media_card, secondary_pill_button, track_row, yellow_pill_button,
|
||
TrackRowAction, TrackRowOptions,
|
||
};
|
||
use crate::engine::UiContext;
|
||
use crate::icons::Icon;
|
||
use crate::views::overlays::{EntityContextMenuState, ShellUiState};
|
||
|
||
/// 1-to-1 Official Yandex Music Desktop 5.129.0 `My Collection` (`web_collection`):
|
||
/// - Default view (`CollectionTab::Tracks`): clean vertical feed:
|
||
/// - Header (`Коллекция` / `My Collection`) + colored subtitle (`У вашей музыки есть цвет`)
|
||
/// - Section 1: `❤️ Мне нравится >` transparent header + 2-column × 4-row compact track grid
|
||
/// - Section 2: `Любимые исполнители >` horizontal circular artist carousel
|
||
/// - Section 3: `Плейлисты >` horizontal carousel starting with `+ Создать плейлист`
|
||
/// - Section 4: `Альбомы >` horizontal carousel
|
||
/// - Section 5: `Подкасты и книги >` horizontal carousel (when non-empty)
|
||
/// - Section 6: `История >` 2-column × 4-row compact track grid (when non-empty)
|
||
/// - Section 7: `Скачанное >` 2-column × 4-row compact track grid (when non-empty)
|
||
/// - Sub-views (`Artists`, `Playlists`, `Albums`, `PodcastsAndBooks`, `History`, `Downloaded`):
|
||
/// clean `← Коллекция` back button + full interactive grid/list with full CRUD & menus.
|
||
pub fn render_collection(
|
||
ctx: &mut UiContext,
|
||
pal: &YmPalette,
|
||
covers: &mut CoverCache,
|
||
app: &mut AppState,
|
||
shell: &mut ShellUiState,
|
||
rect: Rect,
|
||
actions: &mut Vec<AppAction>,
|
||
) {
|
||
let t = app.i18n();
|
||
let ru = t.is_ru();
|
||
let is_playing = app.is_audio_playing();
|
||
let current_track_id = app.current_track().map(|tr| tr.id.clone());
|
||
|
||
let scroll_id = WidgetId::new("collection_scroll");
|
||
let scroll_y = ctx.begin_scroll_v(scroll_id, rect, 0.0);
|
||
|
||
let x = rect.left();
|
||
let avail_w = (rect.width() - 6.0).max(320.0);
|
||
let mut y = rect.top() + 8.0 - scroll_y;
|
||
|
||
// -------------------------------------------------------------------------
|
||
// DEFAULT VERTICAL OVERVIEW (`CollectionTab::Tracks`)
|
||
// -------------------------------------------------------------------------
|
||
if app.collection_tab == CollectionTab::Tracks {
|
||
// Header: Bold 34px Headline + official colored subtitle
|
||
ctx.draw_text_ellipsis(
|
||
t.collection(),
|
||
TextStyle::headline(34.0, pal.text_bright),
|
||
Rect::from_xywh(x, y, avail_w, 42.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 44.0;
|
||
|
||
let pink_accent = Color::rgb(0xE8, 0x3E, 0x8C);
|
||
let spans = if ru {
|
||
[
|
||
RichSpan::new(
|
||
"У вашей музыки есть ",
|
||
TextStyle::medium(14.0, pal.text_secondary),
|
||
),
|
||
RichSpan::new("цвет", TextStyle::medium(14.0, pink_accent)),
|
||
]
|
||
} else {
|
||
[
|
||
RichSpan::new(
|
||
"Your music has a ",
|
||
TextStyle::medium(14.0, pal.text_secondary),
|
||
),
|
||
RichSpan::new("color", TextStyle::medium(14.0, pink_accent)),
|
||
]
|
||
};
|
||
ctx.draw_rich_text(
|
||
&spans,
|
||
Rect::from_xywh(x, y, avail_w, 24.0),
|
||
Some(1),
|
||
TextAlign::Left,
|
||
);
|
||
y += 38.0;
|
||
|
||
// ---------------------------------------------------------------------
|
||
// SECTION 1: ❤️ My Favorites > (transparent header + 2×4 compact grid)
|
||
// ---------------------------------------------------------------------
|
||
let fav_title = t.liked_playlist();
|
||
{
|
||
let hdr_r = Rect::from_xywh(x, y, avail_w.min(460.0), 58.0);
|
||
let hdr_resp = ctx.interact(WidgetId::new("col_fav_header"), hdr_r);
|
||
|
||
let cov_r = Rect::from_xywh(x, y + 1.0, 56.0, 56.0);
|
||
draw_cover_art(ctx, pal, covers, cov_r, None, "likes", 10.0, false, true);
|
||
|
||
let tx = cov_r.right() + 14.0;
|
||
let title_style = TextStyle::headline(
|
||
22.0,
|
||
if hdr_resp.hovered {
|
||
pal.text_bright
|
||
} else {
|
||
pal.text_primary
|
||
},
|
||
);
|
||
let title_w = ctx.measure_text(fav_title, title_style, None).x;
|
||
ctx.draw_text_ellipsis(
|
||
fav_title,
|
||
title_style,
|
||
Rect::from_xywh(tx, y + 4.0, (avail_w - 110.0).max(120.0), 28.0),
|
||
TextAlign::Left,
|
||
);
|
||
ctx.draw_icon(
|
||
Icon::ArrowRight,
|
||
Rect::from_center_size(
|
||
Pos2::new(
|
||
(tx + title_w + 14.0).min(x + avail_w - 14.0),
|
||
y + 18.0,
|
||
),
|
||
Vec2::splat(20.0),
|
||
),
|
||
if hdr_resp.hovered {
|
||
pal.text_bright
|
||
} else {
|
||
pal.text_secondary
|
||
},
|
||
);
|
||
ctx.draw_text_ellipsis(
|
||
&t.count_tracks(app.liked_tracks.len()),
|
||
TextStyle::regular(13.5, pal.text_secondary),
|
||
Rect::from_xywh(tx, y + 34.0, (avail_w - 90.0).max(120.0), 20.0),
|
||
TextAlign::Left,
|
||
);
|
||
|
||
if hdr_resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if hdr_resp.clicked {
|
||
actions.push(AppAction::Navigate(Route::LikedTracks));
|
||
}
|
||
}
|
||
y += 58.0 + 16.0;
|
||
|
||
if app.liked_tracks.is_empty() {
|
||
ctx.draw_text_wrapped(
|
||
if ru {
|
||
"Ставьте лайки трекам или войдите в аккаунт Яндекс Музыки — они появятся здесь."
|
||
} else {
|
||
"Like tracks or sign in to Yandex Music — they will appear here."
|
||
},
|
||
TextStyle::regular(14.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 40.0),
|
||
Some(2),
|
||
TextAlign::Left,
|
||
);
|
||
y += 48.0;
|
||
} else {
|
||
let liked_tracks = app.liked_tracks.clone();
|
||
y = render_compact_two_col_track_grid(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
app,
|
||
shell,
|
||
rect,
|
||
x,
|
||
y,
|
||
avail_w,
|
||
&liked_tracks,
|
||
"col_ov_fav",
|
||
fav_title,
|
||
"likes",
|
||
current_track_id.as_deref(),
|
||
is_playing,
|
||
actions,
|
||
);
|
||
y += 28.0;
|
||
}
|
||
|
||
// ---------------------------------------------------------------------
|
||
// SECTION 2: Favorite Artists > (horizontal circular carousel)
|
||
// ---------------------------------------------------------------------
|
||
{
|
||
let art_title = if ru {
|
||
"Любимые исполнители"
|
||
} else {
|
||
"Favorite Artists"
|
||
};
|
||
let h_id = WidgetId::new("col_ov_artists_h");
|
||
if draw_section_heading(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("col_sec_artists"),
|
||
art_title,
|
||
x,
|
||
y,
|
||
avail_w,
|
||
Some(h_id),
|
||
!app.liked_artists.is_empty(),
|
||
) {
|
||
app.collection_tab = CollectionTab::Artists;
|
||
}
|
||
y += 38.0;
|
||
|
||
if app.liked_artists.is_empty() {
|
||
ctx.draw_text_ellipsis(
|
||
if ru {
|
||
"Здесь появятся ваши любимые исполнители."
|
||
} else {
|
||
"Your favorite artists will appear here."
|
||
},
|
||
TextStyle::regular(13.5, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 22.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 34.0;
|
||
} else {
|
||
let artists = app.liked_artists.clone();
|
||
let card_w = 168.0;
|
||
let card_h = card_w + 52.0;
|
||
let gap = 16.0;
|
||
let row_vp = Rect::from_xywh(x, y, avail_w, card_h);
|
||
let sx = ctx.begin_scroll_h(h_id, row_vp, 0.0);
|
||
let mut cx = x - sx;
|
||
|
||
for art in artists.iter().take(24) {
|
||
let cr = Rect::from_xywh(cx, y, card_w, card_h);
|
||
if cr.right() >= row_vp.left() - 24.0 && cr.left() <= row_vp.right() + 24.0 {
|
||
let m = media_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair("col_ov_art", &art.id),
|
||
cr,
|
||
&art.name,
|
||
t.artist(),
|
||
art.cover_uri.as_deref(),
|
||
&format!("art_{}", art.id),
|
||
true,
|
||
false,
|
||
);
|
||
if let Some(pos) = m.right_clicked_pos {
|
||
shell.open_entity_menu(EntityContextMenuState {
|
||
kind: "artist".into(),
|
||
id: art.id.clone(),
|
||
title: art.name.clone(),
|
||
subtitle: t.artist().into(),
|
||
cover_uri: art.cover_uri.clone(),
|
||
owner_uid: None,
|
||
is_own_playlist: false,
|
||
tracks: Vec::new(),
|
||
anchor: pos,
|
||
share_url: format!("https://music.yandex.ru/artist/{}", art.id),
|
||
});
|
||
} else if m.play_clicked {
|
||
actions.push(AppAction::PlayArtist {
|
||
id: art.id.clone(),
|
||
name: art.name.clone(),
|
||
});
|
||
} else if m.clicked {
|
||
actions.push(AppAction::Navigate(Route::Artist {
|
||
id: art.id.clone(),
|
||
name: art.name.clone(),
|
||
}));
|
||
}
|
||
}
|
||
cx += card_w + gap;
|
||
}
|
||
ctx.end_scroll_h(
|
||
h_id,
|
||
pal,
|
||
artists.len().min(24) as f32 * (card_w + gap),
|
||
false,
|
||
);
|
||
y += card_h + 26.0;
|
||
}
|
||
}
|
||
|
||
// ---------------------------------------------------------------------
|
||
// SECTION 3: Playlists > (horizontal carousel starting with `+ Create`)
|
||
// ---------------------------------------------------------------------
|
||
{
|
||
let h_id = WidgetId::new("col_ov_playlists_h");
|
||
if draw_section_heading(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("col_sec_playlists"),
|
||
t.playlists(),
|
||
x,
|
||
y,
|
||
avail_w,
|
||
Some(h_id),
|
||
true,
|
||
) {
|
||
app.collection_tab = CollectionTab::Playlists;
|
||
}
|
||
y += 38.0;
|
||
|
||
let playlists = app.user_playlists.clone();
|
||
let my_uid = app.account.as_ref().map(|a| a.uid.to_string());
|
||
let card_w = 168.0;
|
||
let card_h = card_w + 54.0;
|
||
let gap = 16.0;
|
||
let row_vp = Rect::from_xywh(x, y, avail_w, card_h);
|
||
let sx = ctx.begin_scroll_h(h_id, row_vp, 0.0);
|
||
let mut cx = x - sx;
|
||
|
||
// Slot 0: compact `+ Создать плейлист` card
|
||
{
|
||
let cr = Rect::from_xywh(cx, y, card_w, card_h);
|
||
if cr.right() >= row_vp.left() - 24.0 && cr.left() <= row_vp.right() + 24.0 {
|
||
let cov_r = Rect::from_xywh(cr.left(), cr.top(), card_w, card_w);
|
||
let resp = ctx.interact(WidgetId::new("col_ov_create_pl"), cr);
|
||
ctx.dl().push_rect_bordered(
|
||
cov_r,
|
||
10.0,
|
||
if resp.hovered {
|
||
pal.surface_hover
|
||
} else {
|
||
pal.surface_secondary
|
||
},
|
||
1.0,
|
||
pal.border_control,
|
||
);
|
||
ctx.draw_icon(
|
||
Icon::AddXxs,
|
||
Rect::from_center_size(cov_r.center(), Vec2::splat(34.0)),
|
||
if resp.hovered {
|
||
pal.text_bright
|
||
} else {
|
||
pal.text_secondary
|
||
},
|
||
);
|
||
ctx.draw_text_ellipsis(
|
||
t.create_playlist(),
|
||
TextStyle::medium(13.5, pal.text_primary),
|
||
Rect::from_xywh(cr.left(), cov_r.bottom() + 8.0, card_w, 20.0),
|
||
TextAlign::Left,
|
||
);
|
||
if resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if resp.clicked {
|
||
actions.push(AppAction::OpenCreatePlaylistModal {
|
||
initial_track: None,
|
||
});
|
||
}
|
||
}
|
||
cx += card_w + gap;
|
||
}
|
||
|
||
for (idx, pl) in playlists.iter().take(60).enumerate() {
|
||
let cr = Rect::from_xywh(cx, y, card_w, card_h);
|
||
if cr.right() >= row_vp.left() - 24.0 && cr.left() <= row_vp.right() + 24.0 {
|
||
let sub = t.count_tracks(pl.track_count as usize);
|
||
let is_own = pl.kind != "3"
|
||
&& (pl.owner_uid == "local"
|
||
|| my_uid.as_deref() == Some(pl.owner_uid.as_str()));
|
||
let m = media_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair(
|
||
"col_ov_pl",
|
||
(idx, format!("{}_{}", pl.owner_uid, pl.kind)),
|
||
),
|
||
cr,
|
||
&pl.title,
|
||
&sub,
|
||
pl.cover_uri.as_deref(),
|
||
&format!("upl_{}_{}", pl.owner_uid, pl.kind),
|
||
false,
|
||
pl.kind == "3" && pl.cover_uri.is_none(),
|
||
);
|
||
if let Some(pos) = m.right_clicked_pos {
|
||
shell.open_entity_menu(EntityContextMenuState {
|
||
kind: "playlist".into(),
|
||
id: format!("{}:{}", pl.owner_uid, pl.kind),
|
||
title: pl.title.clone(),
|
||
subtitle: t.playlist().into(),
|
||
cover_uri: pl.cover_uri.clone(),
|
||
owner_uid: Some(pl.owner_uid.clone()),
|
||
is_own_playlist: is_own,
|
||
tracks: Vec::new(),
|
||
anchor: pos,
|
||
share_url: format!(
|
||
"https://music.yandex.ru/users/{}/playlists/{}",
|
||
pl.owner_uid, pl.kind
|
||
),
|
||
});
|
||
} else if m.play_clicked {
|
||
actions.push(AppAction::PlayPlaylist {
|
||
owner_uid: pl.owner_uid.clone(),
|
||
kind: pl.kind.clone(),
|
||
title: pl.title.clone(),
|
||
});
|
||
} else if m.clicked {
|
||
actions.push(AppAction::Navigate(Route::Playlist {
|
||
owner_uid: pl.owner_uid.clone(),
|
||
kind: pl.kind.clone(),
|
||
title: pl.title.clone(),
|
||
}));
|
||
}
|
||
}
|
||
cx += card_w + gap;
|
||
}
|
||
ctx.end_scroll_h(
|
||
h_id,
|
||
pal,
|
||
(playlists.len().min(60) + 1) as f32 * (card_w + gap),
|
||
false,
|
||
);
|
||
y += card_h + 26.0;
|
||
}
|
||
|
||
// ---------------------------------------------------------------------
|
||
// SECTION 4: Albums > (horizontal carousel)
|
||
// ---------------------------------------------------------------------
|
||
{
|
||
let h_id = WidgetId::new("col_ov_albums_h");
|
||
if draw_section_heading(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("col_sec_albums"),
|
||
t.albums(),
|
||
x,
|
||
y,
|
||
avail_w,
|
||
Some(h_id),
|
||
!app.liked_albums.is_empty(),
|
||
) {
|
||
app.collection_tab = CollectionTab::Albums;
|
||
}
|
||
y += 38.0;
|
||
|
||
if app.liked_albums.is_empty() {
|
||
ctx.draw_text_ellipsis(
|
||
if ru {
|
||
"Здесь появятся ваши любимые альбомы."
|
||
} else {
|
||
"Your favorite albums will appear here."
|
||
},
|
||
TextStyle::regular(13.5, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 22.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 34.0;
|
||
} else {
|
||
let albums = app.liked_albums.clone();
|
||
let card_w = 168.0;
|
||
let card_h = card_w + 54.0;
|
||
let gap = 16.0;
|
||
let row_vp = Rect::from_xywh(x, y, avail_w, card_h);
|
||
let sx = ctx.begin_scroll_h(h_id, row_vp, 0.0);
|
||
let mut cx = x - sx;
|
||
|
||
for (idx, alb) in albums.iter().take(60).enumerate() {
|
||
let cr = Rect::from_xywh(cx, y, card_w, card_h);
|
||
if cr.right() >= row_vp.left() - 24.0 && cr.left() <= row_vp.right() + 24.0 {
|
||
let alb_title = alb.full_title();
|
||
let sub = alb
|
||
.artists
|
||
.first()
|
||
.map(|a| a.name.as_str())
|
||
.unwrap_or(t.album());
|
||
let m = media_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair("col_ov_alb", (idx, &alb.id)),
|
||
cr,
|
||
&alb_title,
|
||
sub,
|
||
alb.cover_uri.as_deref(),
|
||
&format!("alb_{}", alb.id),
|
||
false,
|
||
false,
|
||
);
|
||
if let Some(pos) = m.right_clicked_pos {
|
||
shell.open_entity_menu(EntityContextMenuState {
|
||
kind: "album".into(),
|
||
id: alb.id.clone(),
|
||
title: alb_title.clone(),
|
||
subtitle: t.album().into(),
|
||
cover_uri: alb.cover_uri.clone(),
|
||
owner_uid: None,
|
||
is_own_playlist: false,
|
||
tracks: Vec::new(),
|
||
anchor: pos,
|
||
share_url: format!("https://music.yandex.ru/album/{}", alb.id),
|
||
});
|
||
} else if m.play_clicked {
|
||
actions.push(AppAction::PlayAlbum {
|
||
id: alb.id.clone(),
|
||
title: alb_title,
|
||
});
|
||
} else if m.clicked {
|
||
actions.push(AppAction::Navigate(Route::Album {
|
||
id: alb.id.clone(),
|
||
title: alb_title,
|
||
}));
|
||
}
|
||
}
|
||
cx += card_w + gap;
|
||
}
|
||
ctx.end_scroll_h(
|
||
h_id,
|
||
pal,
|
||
albums.len().min(60) as f32 * (card_w + gap),
|
||
false,
|
||
);
|
||
y += card_h + 26.0;
|
||
}
|
||
}
|
||
|
||
// ---------------------------------------------------------------------
|
||
// SECTION 5: Podcasts & Audiobooks > (when non-empty)
|
||
// ---------------------------------------------------------------------
|
||
if !app.bookshelf_items.is_empty() {
|
||
let h_id = WidgetId::new("col_ov_books_h");
|
||
if draw_section_heading(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("col_sec_books"),
|
||
t.podcasts_and_books(),
|
||
x,
|
||
y,
|
||
avail_w,
|
||
Some(h_id),
|
||
true,
|
||
) {
|
||
app.collection_tab = CollectionTab::PodcastsAndBooks;
|
||
}
|
||
y += 38.0;
|
||
|
||
let items = app.bookshelf_items.clone();
|
||
let card_w = 168.0;
|
||
let card_h = card_w + 54.0;
|
||
let gap = 16.0;
|
||
let row_vp = Rect::from_xywh(x, y, avail_w, card_h);
|
||
let sx = ctx.begin_scroll_h(h_id, row_vp, 0.0);
|
||
let mut cx = x - sx;
|
||
|
||
for pod in items.iter().take(24) {
|
||
let cr = Rect::from_xywh(cx, y, card_w, card_h);
|
||
if cr.right() >= row_vp.left() - 24.0 && cr.left() <= row_vp.right() + 24.0 {
|
||
let sub = pod
|
||
.artists
|
||
.first()
|
||
.map(|a| a.name.as_str())
|
||
.unwrap_or(if ru { "Подкаст" } else { "Podcast" });
|
||
let m = media_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair("col_ov_pod", &pod.id),
|
||
cr,
|
||
&pod.title,
|
||
sub,
|
||
pod.cover_uri.as_deref(),
|
||
&format!("pod_{}", pod.id),
|
||
false,
|
||
false,
|
||
);
|
||
if let Some(pos) = m.right_clicked_pos {
|
||
shell.open_entity_menu(EntityContextMenuState {
|
||
kind: "album".into(),
|
||
id: pod.id.clone(),
|
||
title: pod.title.clone(),
|
||
subtitle: sub.to_string(),
|
||
cover_uri: pod.cover_uri.clone(),
|
||
owner_uid: None,
|
||
is_own_playlist: false,
|
||
tracks: Vec::new(),
|
||
anchor: pos,
|
||
share_url: format!("https://music.yandex.ru/album/{}", pod.id),
|
||
});
|
||
} else if m.play_clicked {
|
||
actions.push(AppAction::PlayAlbum {
|
||
id: pod.id.clone(),
|
||
title: pod.title.clone(),
|
||
});
|
||
} else if m.clicked {
|
||
actions.push(AppAction::Navigate(Route::Album {
|
||
id: pod.id.clone(),
|
||
title: pod.title.clone(),
|
||
}));
|
||
}
|
||
}
|
||
cx += card_w + gap;
|
||
}
|
||
ctx.end_scroll_h(
|
||
h_id,
|
||
pal,
|
||
items.len().min(24) as f32 * (card_w + gap),
|
||
false,
|
||
);
|
||
y += card_h + 26.0;
|
||
}
|
||
|
||
// ---------------------------------------------------------------------
|
||
// SECTION 6: History > (2-col × 4-row compact track grid when non-empty)
|
||
// ---------------------------------------------------------------------
|
||
if !app.play_history.is_empty() {
|
||
if draw_section_heading(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("col_sec_history"),
|
||
t.history(),
|
||
x,
|
||
y,
|
||
avail_w,
|
||
None,
|
||
false,
|
||
) {
|
||
app.collection_tab = CollectionTab::History;
|
||
}
|
||
y += 38.0;
|
||
|
||
let hist = app.play_history.clone();
|
||
y = render_compact_two_col_track_grid(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
app,
|
||
shell,
|
||
rect,
|
||
x,
|
||
y,
|
||
avail_w,
|
||
&hist,
|
||
"col_ov_hist",
|
||
t.history(),
|
||
"history",
|
||
current_track_id.as_deref(),
|
||
is_playing,
|
||
actions,
|
||
);
|
||
y += 28.0;
|
||
}
|
||
|
||
// ---------------------------------------------------------------------
|
||
// SECTION 7: Downloaded > (compact preview list when non-empty)
|
||
// ---------------------------------------------------------------------
|
||
if !app.config.downloaded_tracks.is_empty() {
|
||
if draw_section_heading(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("col_sec_downloaded"),
|
||
t.downloaded(),
|
||
x,
|
||
y,
|
||
avail_w,
|
||
None,
|
||
false,
|
||
) {
|
||
app.collection_tab = CollectionTab::Downloaded;
|
||
}
|
||
y += 38.0;
|
||
|
||
let dl = app.config.downloaded_tracks.clone();
|
||
y = render_compact_two_col_track_grid(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
app,
|
||
shell,
|
||
rect,
|
||
x,
|
||
y,
|
||
avail_w,
|
||
&dl,
|
||
"col_ov_dl",
|
||
t.downloaded_tracks(),
|
||
"downloads",
|
||
current_track_id.as_deref(),
|
||
is_playing,
|
||
actions,
|
||
);
|
||
y += 16.0;
|
||
}
|
||
|
||
y += 20.0;
|
||
let total_h = y - (rect.top() - scroll_y);
|
||
ctx.end_scroll_v(scroll_id, pal, total_h, true);
|
||
return;
|
||
}
|
||
|
||
// -------------------------------------------------------------------------
|
||
// SUB-VIEWS (Back button `← Коллекция` + full grid/list)
|
||
// -------------------------------------------------------------------------
|
||
let (back_resp, _) = secondary_pill_button(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("col_sub_back"),
|
||
Pos2::new(x, y),
|
||
Some(Icon::ArrowLeft),
|
||
t.collection(),
|
||
34.0,
|
||
false,
|
||
);
|
||
if back_resp.clicked {
|
||
app.collection_tab = CollectionTab::Tracks;
|
||
}
|
||
y += 48.0;
|
||
|
||
let sub_title = match app.collection_tab {
|
||
CollectionTab::Tracks => t.collection(),
|
||
CollectionTab::Playlists => t.playlists(),
|
||
CollectionTab::Albums => t.albums(),
|
||
CollectionTab::Artists => {
|
||
if ru {
|
||
"Любимые исполнители"
|
||
} else {
|
||
"Favorite Artists"
|
||
}
|
||
}
|
||
CollectionTab::PodcastsAndBooks => t.podcasts_and_books(),
|
||
CollectionTab::Downloaded => t.downloaded(),
|
||
CollectionTab::History => t.history(),
|
||
};
|
||
ctx.draw_text_ellipsis(
|
||
sub_title,
|
||
TextStyle::headline(32.0, pal.text_bright),
|
||
Rect::from_xywh(x, y, avail_w, 40.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 52.0;
|
||
|
||
match app.collection_tab {
|
||
CollectionTab::Tracks => {}
|
||
|
||
CollectionTab::Playlists => {
|
||
let gap = 16.0;
|
||
let cols = ((avail_w + gap) / 184.0).floor().clamp(2.0, 6.0) as usize;
|
||
let card_w = ((avail_w - gap * (cols as f32 - 1.0)) / cols as f32).max(132.0);
|
||
let card_h = card_w + 62.0;
|
||
|
||
let playlists = app.user_playlists.clone();
|
||
let my_uid = app.account.as_ref().map(|a| a.uid.to_string());
|
||
|
||
// Slot 0: "+ Создать плейлист" visual card
|
||
{
|
||
let cr = Rect::from_xywh(x, y, card_w, card_h);
|
||
let cov_r = Rect::from_xywh(cr.left(), cr.top(), card_w, card_w);
|
||
let resp = ctx.interact(WidgetId::new("col_create_pl_card"), cr);
|
||
ctx.dl().push_rect_bordered(
|
||
cov_r,
|
||
8.0,
|
||
if resp.hovered {
|
||
pal.surface_hover
|
||
} else {
|
||
pal.surface_secondary
|
||
},
|
||
1.0,
|
||
pal.border_control,
|
||
);
|
||
ctx.draw_icon(
|
||
Icon::AddXxs,
|
||
Rect::from_center_size(cov_r.center(), Vec2::splat(36.0)),
|
||
if resp.hovered {
|
||
pal.text_bright
|
||
} else {
|
||
pal.text_secondary
|
||
},
|
||
);
|
||
ctx.draw_text_ellipsis(
|
||
t.create_playlist(),
|
||
TextStyle::medium(13.5, pal.text_primary),
|
||
Rect::from_xywh(cr.left(), cov_r.bottom() + 8.0, card_w, 20.0),
|
||
TextAlign::Left,
|
||
);
|
||
if resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if resp.clicked {
|
||
actions.push(AppAction::OpenCreatePlaylistModal {
|
||
initial_track: None,
|
||
});
|
||
}
|
||
}
|
||
|
||
for (i, pl) in playlists.iter().enumerate() {
|
||
let slot = i + 1;
|
||
let col = slot % cols;
|
||
let row = slot / cols;
|
||
let cr = Rect::from_xywh(
|
||
x + col as f32 * (card_w + gap),
|
||
y + row as f32 * (card_h + 16.0),
|
||
card_w,
|
||
card_h,
|
||
);
|
||
if cr.bottom() < rect.top() - 40.0 || cr.top() > rect.bottom() + 40.0 {
|
||
continue;
|
||
}
|
||
let sub = t.count_tracks(pl.track_count as usize);
|
||
let wid = WidgetId::from_pair("col_pl", (i, format!("{}_{}", pl.owner_uid, pl.kind)));
|
||
let m = media_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
wid,
|
||
Rect::from_xywh(cr.left(), cr.top(), card_w, card_w + 48.0),
|
||
&pl.title,
|
||
&sub,
|
||
pl.cover_uri.as_deref(),
|
||
&format!("upl_{}_{}", pl.owner_uid, pl.kind),
|
||
false,
|
||
pl.kind == "3" && pl.cover_uri.is_none(),
|
||
);
|
||
|
||
// Own playlists (not Liked kind=3) get quick Rename & Delete action icons on hover!
|
||
let is_own = pl.kind != "3"
|
||
&& (pl.owner_uid == "local"
|
||
|| my_uid.as_deref() == Some(pl.owner_uid.as_str()));
|
||
let card_hovered = ctx.is_hovered(cr);
|
||
if is_own && card_hovered {
|
||
let ren_r = Rect::from_xywh(cr.right() - 62.0, cr.top() + 8.0, 26.0, 26.0);
|
||
let del_r = Rect::from_xywh(cr.right() - 32.0, cr.top() + 8.0, 26.0, 26.0);
|
||
ctx.dl().push_circle(ren_r.center(), 13.0, pal.bg_overlay);
|
||
ctx.dl().push_circle(del_r.center(), 13.0, pal.bg_overlay);
|
||
let ren_resp = icon_button(
|
||
ctx,
|
||
wid.with("rename"),
|
||
ren_r,
|
||
Icon::EditXxs,
|
||
15.0,
|
||
Color::WHITE,
|
||
pal.yellow,
|
||
Color::TRANSPARENT,
|
||
false,
|
||
t.rename(),
|
||
);
|
||
let del_resp = icon_button(
|
||
ctx,
|
||
wid.with("delete"),
|
||
del_r,
|
||
Icon::BucketXxs,
|
||
15.0,
|
||
Color::WHITE,
|
||
pal.error,
|
||
Color::TRANSPARENT,
|
||
false,
|
||
t.delete_playlist(),
|
||
);
|
||
if ren_resp.clicked {
|
||
actions.push(AppAction::OpenRenamePlaylistModal {
|
||
owner_uid: pl.owner_uid.clone(),
|
||
kind: pl.kind.clone(),
|
||
current_title: pl.title.clone(),
|
||
});
|
||
continue;
|
||
}
|
||
if del_resp.clicked {
|
||
if let Ok(uid) = pl.owner_uid.parse::<u64>() {
|
||
shell.confirm_delete_playlist =
|
||
Some((uid, pl.kind.clone(), pl.title.clone()));
|
||
} else {
|
||
actions.push(AppAction::DeletePlaylist {
|
||
owner_uid: pl.owner_uid.clone(),
|
||
kind: pl.kind.clone(),
|
||
});
|
||
}
|
||
continue;
|
||
}
|
||
}
|
||
|
||
if let Some(pos) = m.right_clicked_pos {
|
||
shell.open_entity_menu(EntityContextMenuState {
|
||
kind: "playlist".into(),
|
||
id: format!("{}:{}", pl.owner_uid, pl.kind),
|
||
title: pl.title.clone(),
|
||
subtitle: t.playlist().into(),
|
||
cover_uri: pl.cover_uri.clone(),
|
||
owner_uid: Some(pl.owner_uid.clone()),
|
||
is_own_playlist: is_own,
|
||
tracks: Vec::new(),
|
||
anchor: pos,
|
||
share_url: format!(
|
||
"https://music.yandex.ru/users/{}/playlists/{}",
|
||
pl.owner_uid, pl.kind
|
||
),
|
||
});
|
||
} else if m.play_clicked {
|
||
actions.push(AppAction::PlayPlaylist {
|
||
owner_uid: pl.owner_uid.clone(),
|
||
kind: pl.kind.clone(),
|
||
title: pl.title.clone(),
|
||
});
|
||
} else if m.clicked {
|
||
actions.push(AppAction::Navigate(Route::Playlist {
|
||
owner_uid: pl.owner_uid.clone(),
|
||
kind: pl.kind.clone(),
|
||
title: pl.title.clone(),
|
||
}));
|
||
}
|
||
}
|
||
let total_slots = playlists.len() + 1;
|
||
let rows = total_slots.div_ceil(cols);
|
||
y += rows as f32 * (card_h + 16.0) + 12.0;
|
||
}
|
||
|
||
CollectionTab::Albums => {
|
||
let albums = app.liked_albums.clone();
|
||
if albums.is_empty() {
|
||
ctx.draw_text_ellipsis(
|
||
if ru {
|
||
"Здесь появятся ваши любимые альбомы."
|
||
} else {
|
||
"Your favorite albums will appear here."
|
||
},
|
||
TextStyle::regular(14.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 24.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 32.0;
|
||
} else {
|
||
let gap = 16.0;
|
||
let cols = ((avail_w + gap) / 184.0).floor().clamp(2.0, 6.0) as usize;
|
||
let card_w = ((avail_w - gap * (cols as f32 - 1.0)) / cols as f32).max(132.0);
|
||
let card_h = card_w + 54.0;
|
||
for (idx, alb) in albums.iter().enumerate() {
|
||
let col = idx % cols;
|
||
let row = idx / cols;
|
||
let cr = Rect::from_xywh(
|
||
x + col as f32 * (card_w + gap),
|
||
y + row as f32 * (card_h + 16.0),
|
||
card_w,
|
||
card_h,
|
||
);
|
||
if cr.bottom() >= rect.top() - 40.0 && cr.top() <= rect.bottom() + 40.0 {
|
||
let alb_title = alb.full_title();
|
||
let sub = alb
|
||
.artists
|
||
.first()
|
||
.map(|a| a.name.as_str())
|
||
.unwrap_or(t.album());
|
||
let m = media_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair("col_alb", (idx, &alb.id)),
|
||
cr,
|
||
&alb_title,
|
||
sub,
|
||
alb.cover_uri.as_deref(),
|
||
&format!("alb_{}", alb.id),
|
||
false,
|
||
false,
|
||
);
|
||
if let Some(pos) = m.right_clicked_pos {
|
||
shell.open_entity_menu(EntityContextMenuState {
|
||
kind: "album".into(),
|
||
id: alb.id.clone(),
|
||
title: alb_title.clone(),
|
||
subtitle: t.album().into(),
|
||
cover_uri: alb.cover_uri.clone(),
|
||
owner_uid: None,
|
||
is_own_playlist: false,
|
||
tracks: Vec::new(),
|
||
anchor: pos,
|
||
share_url: format!("https://music.yandex.ru/album/{}", alb.id),
|
||
});
|
||
} else if m.play_clicked {
|
||
actions.push(AppAction::PlayAlbum {
|
||
id: alb.id.clone(),
|
||
title: alb_title,
|
||
});
|
||
} else if m.clicked {
|
||
actions.push(AppAction::Navigate(Route::Album {
|
||
id: alb.id.clone(),
|
||
title: alb_title,
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
let rows = albums.len().div_ceil(cols);
|
||
y += rows as f32 * (card_h + 16.0) + 12.0;
|
||
}
|
||
}
|
||
|
||
CollectionTab::Artists => {
|
||
if app.liked_artists.is_empty() {
|
||
ctx.draw_text_ellipsis(
|
||
if ru {
|
||
"Здесь появятся ваши любимые исполнители."
|
||
} else {
|
||
"Your favorite artists will appear here."
|
||
},
|
||
TextStyle::regular(14.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 24.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 32.0;
|
||
} else {
|
||
let artists = app.liked_artists.clone();
|
||
let gap = 16.0;
|
||
let cols = ((avail_w + gap) / 176.0).floor().clamp(2.0, 6.0) as usize;
|
||
let card_w = ((avail_w - gap * (cols as f32 - 1.0)) / cols as f32).max(120.0);
|
||
let card_h = card_w + 52.0;
|
||
for (idx, art) in artists.iter().enumerate() {
|
||
let col = idx % cols;
|
||
let row = idx / cols;
|
||
let cr = Rect::from_xywh(
|
||
x + col as f32 * (card_w + gap),
|
||
y + row as f32 * (card_h + 16.0),
|
||
card_w,
|
||
card_h,
|
||
);
|
||
if cr.bottom() >= rect.top() - 40.0 && cr.top() <= rect.bottom() + 40.0 {
|
||
let m = media_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair("col_art", &art.id),
|
||
cr,
|
||
&art.name,
|
||
t.artist(),
|
||
art.cover_uri.as_deref(),
|
||
&format!("art_{}", art.id),
|
||
true,
|
||
false,
|
||
);
|
||
if let Some(pos) = m.right_clicked_pos {
|
||
shell.open_entity_menu(EntityContextMenuState {
|
||
kind: "artist".into(),
|
||
id: art.id.clone(),
|
||
title: art.name.clone(),
|
||
subtitle: t.artist().into(),
|
||
cover_uri: art.cover_uri.clone(),
|
||
owner_uid: None,
|
||
is_own_playlist: false,
|
||
tracks: Vec::new(),
|
||
anchor: pos,
|
||
share_url: format!("https://music.yandex.ru/artist/{}", art.id),
|
||
});
|
||
} else if m.play_clicked {
|
||
actions.push(AppAction::PlayArtist {
|
||
id: art.id.clone(),
|
||
name: art.name.clone(),
|
||
});
|
||
} else if m.clicked {
|
||
actions.push(AppAction::Navigate(Route::Artist {
|
||
id: art.id.clone(),
|
||
name: art.name.clone(),
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
let rows = artists.len().div_ceil(cols);
|
||
y += rows as f32 * (card_h + 16.0) + 12.0;
|
||
}
|
||
}
|
||
|
||
CollectionTab::PodcastsAndBooks => {
|
||
let items = if !app.bookshelf_items.is_empty() {
|
||
app.bookshelf_items.clone()
|
||
} else {
|
||
app.landing.podcasts.clone()
|
||
};
|
||
if items.is_empty() {
|
||
ctx.draw_text_ellipsis(
|
||
if ru {
|
||
"Здесь появятся ваши подкасты и аудиокниги."
|
||
} else {
|
||
"Your saved podcasts and audiobooks will appear here."
|
||
},
|
||
TextStyle::regular(14.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 24.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 32.0;
|
||
} else {
|
||
let gap = 16.0;
|
||
let cols = ((avail_w + gap) / 184.0).floor().clamp(2.0, 6.0) as usize;
|
||
let card_w = ((avail_w - gap * (cols as f32 - 1.0)) / cols as f32).max(132.0);
|
||
let card_h = card_w + 54.0;
|
||
for (idx, pod) in items.iter().enumerate() {
|
||
let col = idx % cols;
|
||
let row = idx / cols;
|
||
let cr = Rect::from_xywh(
|
||
x + col as f32 * (card_w + gap),
|
||
y + row as f32 * (card_h + 16.0),
|
||
card_w,
|
||
card_h,
|
||
);
|
||
if cr.bottom() >= rect.top() - 40.0 && cr.top() <= rect.bottom() + 40.0 {
|
||
let sub = pod
|
||
.artists
|
||
.first()
|
||
.map(|a| a.name.as_str())
|
||
.unwrap_or(if ru { "Подкаст" } else { "Podcast" });
|
||
let m = media_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair("col_pod", &pod.id),
|
||
cr,
|
||
&pod.title,
|
||
sub,
|
||
pod.cover_uri.as_deref(),
|
||
&format!("pod_{}", pod.id),
|
||
false,
|
||
false,
|
||
);
|
||
if let Some(pos) = m.right_clicked_pos {
|
||
shell.open_entity_menu(EntityContextMenuState {
|
||
kind: "album".into(),
|
||
id: pod.id.clone(),
|
||
title: pod.title.clone(),
|
||
subtitle: sub.to_string(),
|
||
cover_uri: pod.cover_uri.clone(),
|
||
owner_uid: None,
|
||
is_own_playlist: false,
|
||
tracks: Vec::new(),
|
||
anchor: pos,
|
||
share_url: format!("https://music.yandex.ru/album/{}", pod.id),
|
||
});
|
||
} else if m.play_clicked {
|
||
actions.push(AppAction::PlayAlbum {
|
||
id: pod.id.clone(),
|
||
title: pod.title.clone(),
|
||
});
|
||
} else if m.clicked {
|
||
actions.push(AppAction::Navigate(Route::Album {
|
||
id: pod.id.clone(),
|
||
title: pod.title.clone(),
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
let rows = items.len().div_ceil(cols);
|
||
y += rows as f32 * (card_h + 16.0) + 12.0;
|
||
}
|
||
}
|
||
|
||
CollectionTab::Downloaded => {
|
||
let dl_tracks = app.config.downloaded_tracks.clone();
|
||
if dl_tracks.is_empty() {
|
||
ctx.draw_text_wrapped(
|
||
if ru {
|
||
"Скачанные треки появятся здесь — их можно слушать без интернета."
|
||
} else {
|
||
"Downloaded tracks will appear here for offline playback."
|
||
},
|
||
TextStyle::regular(14.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 44.0),
|
||
Some(2),
|
||
TextAlign::Left,
|
||
);
|
||
y += 48.0;
|
||
} else {
|
||
let dl_playing = app.is_context_playing("downloads");
|
||
let (play_r, pr) = yellow_pill_button(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("col_dl_play"),
|
||
Pos2::new(x, y),
|
||
Some(if dl_playing {
|
||
Icon::PauseXxs
|
||
} else {
|
||
Icon::PlayXxs
|
||
}),
|
||
if dl_playing { t.pause() } else { t.listen() },
|
||
38.0,
|
||
false,
|
||
);
|
||
if play_r.clicked {
|
||
actions.push(AppAction::ToggleContextPlay {
|
||
tracks: dl_tracks.clone(),
|
||
context_name: t.downloaded_tracks().into(),
|
||
context_key: "downloads".into(),
|
||
is_vibe: false,
|
||
});
|
||
}
|
||
let (del_all, _) = secondary_pill_button(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("col_dl_clear"),
|
||
Pos2::new(pr.right() + 10.0, y),
|
||
Some(Icon::BucketXxs),
|
||
t.delete_from_device(),
|
||
38.0,
|
||
false,
|
||
);
|
||
if del_all.clicked {
|
||
let ids: Vec<String> = dl_tracks.iter().map(|tr| tr.id.clone()).collect();
|
||
actions.push(AppAction::RemoveDownloadedTracks(ids));
|
||
}
|
||
y += 52.0;
|
||
|
||
y = render_virtual_track_list(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
app,
|
||
shell,
|
||
rect,
|
||
x,
|
||
y,
|
||
avail_w,
|
||
&dl_tracks,
|
||
"col_dl",
|
||
t.downloaded_tracks(),
|
||
"downloads",
|
||
current_track_id.as_deref(),
|
||
is_playing,
|
||
actions,
|
||
);
|
||
}
|
||
}
|
||
|
||
CollectionTab::History => {
|
||
if app.play_history.is_empty() {
|
||
ctx.draw_text_ellipsis(
|
||
if ru {
|
||
"Здесь будут треки, которые вы недавно слушали."
|
||
} else {
|
||
"Tracks you recently listened to will appear here."
|
||
},
|
||
TextStyle::regular(14.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 24.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 32.0;
|
||
} else {
|
||
let hist = app.play_history.clone();
|
||
y = render_virtual_track_list(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
app,
|
||
shell,
|
||
rect,
|
||
x,
|
||
y,
|
||
avail_w,
|
||
&hist,
|
||
"col_hist",
|
||
t.history(),
|
||
"history",
|
||
current_track_id.as_deref(),
|
||
is_playing,
|
||
actions,
|
||
);
|
||
}
|
||
}
|
||
}
|
||
|
||
y += 24.0;
|
||
let total_h = y - (rect.top() - scroll_y);
|
||
ctx.end_scroll_v(scroll_id, pal, total_h, true);
|
||
}
|
||
|
||
/// Clickable `Section Title >` heading with optional `<` `>` carousel scroll arrows on the right.
|
||
#[allow(clippy::too_many_arguments)]
|
||
fn draw_section_heading(
|
||
ctx: &mut UiContext,
|
||
pal: &YmPalette,
|
||
id: WidgetId,
|
||
title: &str,
|
||
x: f32,
|
||
y: f32,
|
||
avail_w: f32,
|
||
h_scroll_id: Option<WidgetId>,
|
||
show_arrows: bool,
|
||
) -> bool {
|
||
let style_idle = TextStyle::headline(22.0, pal.text_primary);
|
||
let tw = ctx.measure_text(title, style_idle, None).x;
|
||
let head_w = (tw + 30.0).min((avail_w - 84.0).max(140.0));
|
||
let head_r = Rect::from_xywh(x, y, head_w, 28.0);
|
||
let resp = ctx.interact(id, head_r);
|
||
|
||
ctx.draw_text_ellipsis(
|
||
title,
|
||
TextStyle::headline(
|
||
22.0,
|
||
if resp.hovered {
|
||
pal.text_bright
|
||
} else {
|
||
pal.text_primary
|
||
},
|
||
),
|
||
Rect::from_xywh(x, y, (head_w - 24.0).max(60.0), 28.0),
|
||
TextAlign::Left,
|
||
);
|
||
ctx.draw_icon(
|
||
Icon::ArrowRight,
|
||
Rect::from_center_size(
|
||
Pos2::new(head_r.right() - 10.0, head_r.center_y()),
|
||
Vec2::splat(20.0),
|
||
),
|
||
if resp.hovered {
|
||
pal.text_bright
|
||
} else {
|
||
pal.text_secondary
|
||
},
|
||
);
|
||
if resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
|
||
if let (Some(h_id), true) = (h_scroll_id, show_arrows) {
|
||
let right_x = x + avail_w;
|
||
let cy = y + 14.0;
|
||
let next_r = Rect::from_center_size(Pos2::new(right_x - 15.0, cy), Vec2::splat(30.0));
|
||
let prev_r = Rect::from_center_size(Pos2::new(right_x - 51.0, cy), Vec2::splat(30.0));
|
||
|
||
let (off_x, max_x) = {
|
||
let st = ctx.scrolls.get_or_create(h_id);
|
||
(st.offset.x, st.max_offset().x)
|
||
};
|
||
let can_prev = off_x > 2.0;
|
||
let can_next = max_x > 2.0 && off_x < max_x - 2.0;
|
||
|
||
let prev_resp = ctx.interact(h_id.with("prev"), prev_r);
|
||
let next_resp = ctx.interact(h_id.with("next"), next_r);
|
||
|
||
ctx.dl().push_rect_bordered(
|
||
prev_r,
|
||
15.0,
|
||
if prev_resp.hovered && can_prev {
|
||
pal.surface_hover
|
||
} else {
|
||
pal.surface_secondary
|
||
},
|
||
1.0,
|
||
pal.border_subtle,
|
||
);
|
||
ctx.draw_icon(
|
||
Icon::ArrowLeft,
|
||
Rect::from_center_size(prev_r.center(), Vec2::splat(16.0)),
|
||
if can_prev {
|
||
pal.text_bright
|
||
} else {
|
||
pal.text_secondary.scale_alpha(0.35)
|
||
},
|
||
);
|
||
ctx.dl().push_rect_bordered(
|
||
next_r,
|
||
15.0,
|
||
if next_resp.hovered && can_next {
|
||
pal.surface_hover
|
||
} else {
|
||
pal.surface_secondary
|
||
},
|
||
1.0,
|
||
pal.border_subtle,
|
||
);
|
||
ctx.draw_icon(
|
||
Icon::ArrowRight,
|
||
Rect::from_center_size(next_r.center(), Vec2::splat(16.0)),
|
||
if can_next {
|
||
pal.text_bright
|
||
} else {
|
||
pal.text_secondary.scale_alpha(0.35)
|
||
},
|
||
);
|
||
if (prev_resp.hovered && can_prev) || (next_resp.hovered && can_next) {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if prev_resp.clicked && can_prev {
|
||
ctx.scrolls.get_or_create(h_id).scroll_by_x(-552.0);
|
||
ctx.request_repaint();
|
||
}
|
||
if next_resp.clicked && can_next {
|
||
ctx.scrolls.get_or_create(h_id).scroll_by_x(552.0);
|
||
ctx.request_repaint();
|
||
}
|
||
}
|
||
|
||
resp.clicked
|
||
}
|
||
|
||
/// Official 5.129.0 2-column × 4-row compact track grid (tracks 0..4 left, 4..8 right, 24px gap, 56px row height).
|
||
/// Gracefully collapses to 1 column of up to 6 tracks when `avail_w < 660.0`.
|
||
#[allow(clippy::too_many_arguments)]
|
||
fn render_compact_two_col_track_grid(
|
||
ctx: &mut UiContext,
|
||
pal: &YmPalette,
|
||
covers: &mut CoverCache,
|
||
app: &AppState,
|
||
shell: &mut ShellUiState,
|
||
viewport: Rect,
|
||
x: f32,
|
||
top_y: f32,
|
||
avail_w: f32,
|
||
tracks: &[Track],
|
||
salt: &str,
|
||
context_name: &str,
|
||
context_key: &str,
|
||
current_track_id: Option<&str>,
|
||
is_playing: bool,
|
||
actions: &mut Vec<AppAction>,
|
||
) -> f32 {
|
||
let t = app.i18n();
|
||
let row_h = 56.0;
|
||
let two_cols = avail_w >= 660.0;
|
||
let col_gap = 24.0;
|
||
let max_items = if two_cols { 8 } else { 6 };
|
||
let count = tracks.len().min(max_items);
|
||
let rows_per_col = if two_cols { 4 } else { count };
|
||
let col_w = if two_cols {
|
||
(avail_w - col_gap) * 0.5
|
||
} else {
|
||
avail_w
|
||
};
|
||
|
||
for idx in 0..count {
|
||
let col = if two_cols { idx / 4 } else { 0 };
|
||
let row = if two_cols { idx % 4 } else { idx };
|
||
let row_r = Rect::from_xywh(
|
||
x + col as f32 * (col_w + col_gap),
|
||
top_y + row as f32 * row_h,
|
||
col_w,
|
||
row_h,
|
||
);
|
||
if row_r.bottom() < viewport.top() - 40.0 || row_r.top() > viewport.bottom() + 40.0 {
|
||
continue;
|
||
}
|
||
let tr = &tracks[idx];
|
||
let is_curr = current_track_id == Some(tr.id.as_str());
|
||
match track_row(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair(salt, idx),
|
||
row_r,
|
||
tr,
|
||
TrackRowOptions {
|
||
index: None,
|
||
show_chart_rank: false,
|
||
show_cover: true,
|
||
is_current: is_curr,
|
||
is_playing: is_curr && is_playing,
|
||
is_liked: app.liked_ids.contains(&tr.id),
|
||
is_disliked: app.disliked_ids.contains(&tr.id),
|
||
is_downloaded: app.is_track_downloaded(&tr.id),
|
||
menu_open: shell.is_track_menu_open(&tr.id),
|
||
},
|
||
) {
|
||
TrackRowAction::Play => {
|
||
actions.push(AppAction::PlayTracks {
|
||
tracks: tracks.to_vec(),
|
||
start_index: idx,
|
||
context_name: context_name.to_string(),
|
||
context_key: context_key.to_string(),
|
||
is_vibe: false,
|
||
});
|
||
}
|
||
TrackRowAction::ToggleLike => actions.push(AppAction::ToggleLike(tr.clone())),
|
||
TrackRowAction::ToggleDislike => actions.push(AppAction::ToggleDislike(tr.clone())),
|
||
TrackRowAction::OpenArtist(id, name) => {
|
||
actions.push(AppAction::Navigate(Route::Artist { id, name }));
|
||
}
|
||
TrackRowAction::OpenAlbum(id) => {
|
||
actions.push(AppAction::Navigate(Route::Album {
|
||
id,
|
||
title: tr
|
||
.album_title
|
||
.clone()
|
||
.unwrap_or_else(|| t.album().into()),
|
||
}));
|
||
}
|
||
TrackRowAction::OpenContextMenu(pos) => {
|
||
shell.open_track_menu(tr.clone(), pos);
|
||
}
|
||
TrackRowAction::None => {}
|
||
}
|
||
}
|
||
|
||
let used_rows = if two_cols {
|
||
count.min(rows_per_col)
|
||
} else {
|
||
count
|
||
};
|
||
top_y + used_rows as f32 * row_h
|
||
}
|
||
|
||
#[allow(clippy::too_many_arguments)]
|
||
fn render_virtual_track_list(
|
||
ctx: &mut UiContext,
|
||
pal: &YmPalette,
|
||
covers: &mut CoverCache,
|
||
app: &AppState,
|
||
shell: &mut ShellUiState,
|
||
viewport: Rect,
|
||
x: f32,
|
||
list_top_y: f32,
|
||
avail_w: f32,
|
||
tracks: &[Track],
|
||
salt: &str,
|
||
context_name: &str,
|
||
context_key: &str,
|
||
current_track_id: Option<&str>,
|
||
is_playing: bool,
|
||
actions: &mut Vec<AppAction>,
|
||
) -> f32 {
|
||
let t = app.i18n();
|
||
let range = visible_row_range(viewport, list_top_y, TRACK_ROW_HEIGHT, tracks.len(), 2);
|
||
for idx in range {
|
||
let tr = &tracks[idx];
|
||
let row_y = list_top_y + idx as f32 * TRACK_ROW_HEIGHT;
|
||
let row_r = Rect::from_xywh(x, row_y, avail_w, TRACK_ROW_HEIGHT);
|
||
let is_curr = current_track_id == Some(tr.id.as_str());
|
||
match track_row(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair(salt, idx),
|
||
row_r,
|
||
tr,
|
||
TrackRowOptions {
|
||
index: Some(idx),
|
||
show_chart_rank: false,
|
||
show_cover: true,
|
||
is_current: is_curr,
|
||
is_playing: is_curr && is_playing,
|
||
is_liked: app.liked_ids.contains(&tr.id),
|
||
is_disliked: app.disliked_ids.contains(&tr.id),
|
||
is_downloaded: app.is_track_downloaded(&tr.id),
|
||
menu_open: shell.is_track_menu_open(&tr.id),
|
||
},
|
||
) {
|
||
TrackRowAction::Play => {
|
||
actions.push(AppAction::PlayTracks {
|
||
tracks: tracks.to_vec(),
|
||
start_index: idx,
|
||
context_name: context_name.to_string(),
|
||
context_key: context_key.to_string(),
|
||
is_vibe: false,
|
||
});
|
||
}
|
||
TrackRowAction::ToggleLike => actions.push(AppAction::ToggleLike(tr.clone())),
|
||
TrackRowAction::ToggleDislike => actions.push(AppAction::ToggleDislike(tr.clone())),
|
||
TrackRowAction::OpenArtist(id, name) => {
|
||
actions.push(AppAction::Navigate(Route::Artist { id, name }));
|
||
}
|
||
TrackRowAction::OpenAlbum(id) => {
|
||
actions.push(AppAction::Navigate(Route::Album {
|
||
id,
|
||
title: tr
|
||
.album_title
|
||
.clone()
|
||
.unwrap_or_else(|| t.album().into()),
|
||
}));
|
||
}
|
||
TrackRowAction::OpenContextMenu(pos) => {
|
||
shell.open_track_menu(tr.clone(), pos);
|
||
}
|
||
TrackRowAction::None => {}
|
||
}
|
||
}
|
||
list_top_y + tracks.len() as f32 * TRACK_ROW_HEIGHT
|
||
}
|