1355 lines
49 KiB
Rust
1355 lines
49 KiB
Rust
use crate::api::models::AlbumSummary;
|
||
use crate::app::state::{AppAction, AppState, Route};
|
||
use crate::covers::CoverCache;
|
||
use crate::engine::input::WidgetId;
|
||
use crate::engine::scroll::visible_row_range;
|
||
use crate::engine::text::{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, media_card, secondary_pill_button, stacked_mix_card, track_row,
|
||
yellow_pill_button, TrackRowAction, TrackRowOptions,
|
||
};
|
||
use crate::engine::UiContext;
|
||
use crate::icons::Icon;
|
||
use crate::views::overlays::{EntityContextMenuState, ShellUiState};
|
||
|
||
fn is_audiobook_item(item: &AlbumSummary) -> bool {
|
||
item.content_type
|
||
.as_deref()
|
||
.map_or(false, |ct| ct.eq_ignore_ascii_case("audiobook"))
|
||
|| item.genre.as_deref().map_or(false, |g| {
|
||
g.eq_ignore_ascii_case("audiobooks") || g.eq_ignore_ascii_case("audiobook")
|
||
})
|
||
}
|
||
|
||
/// Books & Podcasts landing page (100% theme-aware & RU/EN localized):
|
||
/// - Category filter tabs (`Все` / `Подкасты` / `Аудиокниги`)
|
||
/// - "Продолжить слушать" / "Continue listening" horizontal shelf
|
||
/// - Podcasts & Audiobooks grids with right-click context menus
|
||
pub fn render_podcasts(
|
||
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 scroll_id = WidgetId::new("podcasts_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;
|
||
|
||
ctx.draw_text_ellipsis(
|
||
t.books_and_podcasts(),
|
||
TextStyle::headline(34.0, pal.text_bright),
|
||
Rect::from_xywh(x, y, avail_w, 42.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 46.0;
|
||
ctx.draw_text_ellipsis(
|
||
if ru {
|
||
"Шоу, интервью, аудиокниги и новые выпуски каждый день"
|
||
} else {
|
||
"Shows, interviews, audiobooks and new episodes every day"
|
||
},
|
||
TextStyle::regular(14.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 22.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 32.0;
|
||
|
||
// Category filter tabs (All / Podcasts / Audiobooks)
|
||
let active_tab = shell.podcast_filter_tab;
|
||
let mut tx = x;
|
||
for (idx, label) in [
|
||
(0u8, t.search_all()),
|
||
(1u8, if ru { "Подкасты" } else { "Podcasts" }),
|
||
(2u8, t.audiobooks()),
|
||
] {
|
||
let (resp, r) = secondary_pill_button(
|
||
ctx,
|
||
pal,
|
||
WidgetId::from_pair("pod_cat_tab", idx),
|
||
Pos2::new(tx, y),
|
||
None,
|
||
label,
|
||
36.0,
|
||
active_tab == idx,
|
||
);
|
||
if resp.clicked {
|
||
shell.podcast_filter_tab = idx;
|
||
}
|
||
tx = r.right() + 8.0;
|
||
}
|
||
y += 52.0;
|
||
|
||
// Merge bookshelf_items + landing.podcasts cleanly
|
||
let mut all_items: Vec<AlbumSummary> = Vec::new();
|
||
for item in app.bookshelf_items.iter().chain(app.landing.podcasts.iter()) {
|
||
if !all_items.iter().any(|existing| existing.id == item.id) {
|
||
all_items.push(item.clone());
|
||
}
|
||
}
|
||
|
||
if all_items.is_empty() {
|
||
ctx.draw_text_ellipsis(
|
||
if ru {
|
||
"Загрузка подкастов и книг…"
|
||
} else {
|
||
"Loading podcasts & audiobooks…"
|
||
},
|
||
TextStyle::regular(14.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 24.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 32.0;
|
||
} else {
|
||
// 1. "Continue listening" horizontal shelf (bookshelf + recently played podcasts/books)
|
||
let mut continue_items: Vec<AlbumSummary> = Vec::new();
|
||
for tr in &app.play_history {
|
||
if let Some(ref aid) = tr.album_id {
|
||
if let Some(found) = all_items.iter().find(|it| &it.id == aid) {
|
||
if !continue_items.iter().any(|c| c.id == found.id) {
|
||
continue_items.push(found.clone());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
for item in &app.bookshelf_items {
|
||
if !continue_items.iter().any(|c| c.id == item.id) {
|
||
continue_items.push(item.clone());
|
||
}
|
||
}
|
||
if continue_items.is_empty() {
|
||
continue_items = all_items.iter().take(4).cloned().collect();
|
||
}
|
||
|
||
if active_tab == 0 && !continue_items.is_empty() {
|
||
ctx.draw_text_ellipsis(
|
||
t.continue_listening(),
|
||
TextStyle::headline(22.0, pal.text_bright),
|
||
Rect::from_xywh(x, y, avail_w, 28.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 38.0;
|
||
|
||
let card_w = 164.0;
|
||
let card_h = card_w + 54.0;
|
||
let row_vp = Rect::from_xywh(x, y, avail_w, card_h);
|
||
let h_id = WidgetId::new("pod_continue_hscroll");
|
||
let sx = ctx.begin_scroll_h(h_id, row_vp, 0.0);
|
||
let mut cx = x - sx;
|
||
for item in continue_items.iter().take(12) {
|
||
let cr = Rect::from_xywh(cx, y, card_w, card_h);
|
||
if cr.right() >= row_vp.left() - 20.0 && cr.left() <= row_vp.right() + 20.0 {
|
||
let sub = item
|
||
.artists
|
||
.first()
|
||
.map(|a| a.name.as_str())
|
||
.unwrap_or(if is_audiobook_item(item) {
|
||
t.audiobooks()
|
||
} else if ru {
|
||
"Подкаст"
|
||
} else {
|
||
"Podcast"
|
||
});
|
||
let m = media_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair("pod_cont", &item.id),
|
||
cr,
|
||
&item.title,
|
||
sub,
|
||
item.cover_uri.as_deref(),
|
||
&format!("podc_{}", item.id),
|
||
false,
|
||
false,
|
||
);
|
||
if let Some(pos) = m.right_clicked_pos {
|
||
shell.open_entity_menu(EntityContextMenuState {
|
||
kind: "album".into(),
|
||
id: item.id.clone(),
|
||
title: item.title.clone(),
|
||
subtitle: sub.to_string(),
|
||
cover_uri: item.cover_uri.clone(),
|
||
owner_uid: None,
|
||
is_own_playlist: false,
|
||
tracks: Vec::new(),
|
||
anchor: pos,
|
||
share_url: format!("https://music.yandex.ru/album/{}", item.id),
|
||
});
|
||
} else if m.play_clicked {
|
||
actions.push(AppAction::PlayAlbum {
|
||
id: item.id.clone(),
|
||
title: item.title.clone(),
|
||
});
|
||
} else if m.clicked {
|
||
actions.push(AppAction::Navigate(Route::Album {
|
||
id: item.id.clone(),
|
||
title: item.title.clone(),
|
||
}));
|
||
}
|
||
}
|
||
cx += card_w + 16.0;
|
||
}
|
||
ctx.end_scroll_h(
|
||
h_id,
|
||
pal,
|
||
continue_items.len().min(12) as f32 * (card_w + 16.0),
|
||
false,
|
||
);
|
||
y += card_h + 28.0;
|
||
}
|
||
|
||
let mut podcasts_only: Vec<AlbumSummary> = Vec::new();
|
||
let mut audiobooks_only: Vec<AlbumSummary> = Vec::new();
|
||
for item in &all_items {
|
||
if is_audiobook_item(item) {
|
||
audiobooks_only.push(item.clone());
|
||
} else {
|
||
podcasts_only.push(item.clone());
|
||
}
|
||
}
|
||
// If API metadata did not tag audiobooks separately, surface bookshelf items in Audiobooks too
|
||
if audiobooks_only.is_empty() && !app.bookshelf_items.is_empty() {
|
||
audiobooks_only = app.bookshelf_items.clone();
|
||
}
|
||
|
||
// Helper closure to render a podcast/audiobook grid with right-click context menu
|
||
let draw_grid = |ctx: &mut UiContext,
|
||
covers: &mut CoverCache,
|
||
shell: &mut ShellUiState,
|
||
actions: &mut Vec<AppAction>,
|
||
items: &[AlbumSummary],
|
||
salt: &str,
|
||
fallback_kind: &str,
|
||
start_y: f32|
|
||
-> f32 {
|
||
let gap = 16.0;
|
||
let cols = ((avail_w + gap) / 196.0).floor().clamp(2.0, 6.0) as usize;
|
||
let card_w = ((avail_w - gap * (cols as f32 - 1.0)) / cols as f32).max(140.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),
|
||
start_y + row as f32 * (card_h + 18.0),
|
||
card_w,
|
||
card_h,
|
||
);
|
||
if cr.bottom() >= rect.top() - 40.0 && cr.top() <= rect.bottom() + 40.0 {
|
||
let author = pod
|
||
.artists
|
||
.first()
|
||
.map(|a| a.name.as_str())
|
||
.unwrap_or(fallback_kind);
|
||
let sub = if pod.track_count > 0 {
|
||
format!(
|
||
"{} · {} {}",
|
||
author,
|
||
pod.track_count,
|
||
if ru { "вып." } else { "ep." }
|
||
)
|
||
} else {
|
||
author.to_string()
|
||
};
|
||
let m = media_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair(salt, &pod.id),
|
||
cr,
|
||
&pod.title,
|
||
&sub,
|
||
pod.cover_uri.as_deref(),
|
||
&format!("{}_{}", salt, 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,
|
||
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);
|
||
start_y + rows as f32 * (card_h + 18.0) + 20.0
|
||
};
|
||
|
||
// 2. Podcasts Section
|
||
if (active_tab == 0 || active_tab == 1) && !podcasts_only.is_empty() {
|
||
ctx.draw_text_ellipsis(
|
||
if ru { "Подкасты" } else { "Podcasts" },
|
||
TextStyle::headline(22.0, pal.text_bright),
|
||
Rect::from_xywh(x, y, avail_w, 28.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 38.0;
|
||
y = draw_grid(
|
||
ctx,
|
||
covers,
|
||
shell,
|
||
actions,
|
||
&podcasts_only,
|
||
"pod_card",
|
||
if ru { "Подкаст" } else { "Podcast" },
|
||
y,
|
||
);
|
||
}
|
||
|
||
// 3. Audiobooks Section
|
||
if active_tab == 0 || active_tab == 2 {
|
||
ctx.draw_text_ellipsis(
|
||
t.audiobooks(),
|
||
TextStyle::headline(22.0, pal.text_bright),
|
||
Rect::from_xywh(x, y, avail_w, 28.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 38.0;
|
||
if audiobooks_only.is_empty() {
|
||
ctx.draw_text_ellipsis(
|
||
if ru {
|
||
"Добавляйте аудиокниги на книжную полку — они появятся здесь."
|
||
} else {
|
||
"Save audiobooks to your bookshelf and they 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 {
|
||
y = draw_grid(
|
||
ctx,
|
||
covers,
|
||
shell,
|
||
actions,
|
||
&audiobooks_only,
|
||
"book_card",
|
||
t.audiobooks(),
|
||
y,
|
||
);
|
||
}
|
||
}
|
||
}
|
||
|
||
let total_h = y - (rect.top() - scroll_y);
|
||
ctx.end_scroll_v(scroll_id, pal, total_h, true);
|
||
}
|
||
|
||
/// Kids section page.
|
||
pub fn render_kids(
|
||
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 scroll_id = WidgetId::new("kids_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;
|
||
|
||
ctx.draw_text_ellipsis(
|
||
t.kids(),
|
||
TextStyle::headline(34.0, pal.text_bright),
|
||
Rect::from_xywh(x, y, avail_w, 42.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 46.0;
|
||
ctx.draw_text_ellipsis(
|
||
if ru {
|
||
"Аудиосказки, колыбельные, подкасты и любимые песни из мультфильмов"
|
||
} else {
|
||
"Fairy tales, lullabies, podcasts and cartoon songs"
|
||
},
|
||
TextStyle::regular(14.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 22.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 38.0;
|
||
|
||
if app.landing.kids_playlists.is_empty() {
|
||
ctx.draw_text_ellipsis(
|
||
if ru {
|
||
"Раздел «Детям» загружается…"
|
||
} else {
|
||
"Loading Kids section…"
|
||
},
|
||
TextStyle::regular(14.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 24.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 32.0;
|
||
} else {
|
||
let pls = app.landing.kids_playlists.clone();
|
||
let gap = 16.0;
|
||
let cols = ((avail_w + gap) / 196.0).floor().clamp(2.0, 6.0) as usize;
|
||
let card_w = ((avail_w - gap * (cols as f32 - 1.0)) / cols as f32).max(140.0);
|
||
let card_h = card_w + 54.0;
|
||
for (idx, pl) in pls.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 + 18.0),
|
||
card_w,
|
||
card_h,
|
||
);
|
||
if cr.bottom() >= rect.top() - 40.0 && cr.top() <= rect.bottom() + 40.0 {
|
||
let sub = pl.description.as_deref().unwrap_or(if ru {
|
||
"Детский плейлист"
|
||
} else {
|
||
"Kids playlist"
|
||
});
|
||
let m = media_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair("kids_pl", format!("{}_{}", pl.owner_uid, pl.kind)),
|
||
cr,
|
||
&pl.title,
|
||
sub,
|
||
pl.cover_uri.as_deref(),
|
||
&format!("kids_{}", pl.kind),
|
||
false,
|
||
false,
|
||
);
|
||
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: sub.to_string(),
|
||
cover_uri: pl.cover_uri.clone(),
|
||
owner_uid: Some(pl.owner_uid.clone()),
|
||
is_own_playlist: false,
|
||
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 rows = pls.len().div_ceil(cols);
|
||
y += rows as f32 * (card_h + 18.0) + 16.0;
|
||
}
|
||
|
||
let total_h = y - (rect.top() - scroll_y);
|
||
ctx.end_scroll_v(scroll_id, pal, total_h, true);
|
||
}
|
||
|
||
/// Real Concerts Feed powered by `GET /concerts/feed`.
|
||
pub fn render_concerts(
|
||
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 scroll_id = WidgetId::new("concerts_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;
|
||
|
||
ctx.draw_text_ellipsis(
|
||
t.concerts(),
|
||
TextStyle::headline(34.0, pal.text_bright),
|
||
Rect::from_xywh(x, y, avail_w, 42.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 46.0;
|
||
ctx.draw_text_ellipsis(
|
||
if ru {
|
||
"Афиша ближайших выступлений любимых исполнителей"
|
||
} else {
|
||
"Upcoming live shows of your favorite artists"
|
||
},
|
||
TextStyle::regular(14.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 22.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 38.0;
|
||
|
||
if app.concerts.is_empty() {
|
||
let msg = if app.account.is_none() {
|
||
if ru {
|
||
"Войдите в аккаунт Яндекс ID, чтобы видеть персональную афишу концертов."
|
||
} else {
|
||
"Sign in with Yandex ID to see personalized upcoming concerts."
|
||
}
|
||
} else if ru {
|
||
"Ближайшие концерты не найдены или ещё загружаются."
|
||
} else {
|
||
"No upcoming concerts found or still loading."
|
||
};
|
||
ctx.draw_text_wrapped(
|
||
msg,
|
||
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 concerts = app.concerts.clone();
|
||
for (idx, c) in concerts.iter().enumerate() {
|
||
let cr = Rect::from_xywh(x, y, avail_w, 94.0);
|
||
if cr.bottom() >= rect.top() - 40.0 && cr.top() <= rect.bottom() + 40.0 {
|
||
let resp = ctx.interact(WidgetId::from_pair("concert_card", idx), cr);
|
||
ctx.dl().push_rect_bordered(
|
||
cr,
|
||
14.0,
|
||
if resp.hovered {
|
||
pal.surface_hover
|
||
} else {
|
||
pal.surface_secondary
|
||
},
|
||
1.0,
|
||
pal.border_subtle,
|
||
);
|
||
let cov_r = Rect::from_xywh(cr.left() + 14.0, cr.top() + 14.0, 66.0, 66.0);
|
||
draw_cover_art(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
cov_r,
|
||
c.cover_uri.as_deref(),
|
||
&c.id,
|
||
10.0,
|
||
false,
|
||
false,
|
||
);
|
||
|
||
let heading = if c.artist_name.is_empty() {
|
||
c.title.clone()
|
||
} else if c.title.is_empty() || c.title == c.artist_name {
|
||
c.artist_name.clone()
|
||
} else {
|
||
format!("{} · {}", c.artist_name, c.title)
|
||
};
|
||
let text_x = cov_r.right() + 16.0;
|
||
let text_w = (cr.right() - text_x - 136.0).max(100.0);
|
||
ctx.draw_text_ellipsis(
|
||
&heading,
|
||
TextStyle::bold(16.0, pal.text_bright),
|
||
Rect::from_xywh(text_x, cr.top() + 20.0, text_w, 24.0),
|
||
TextAlign::Left,
|
||
);
|
||
let meta: Vec<&str> = [c.date.as_str(), c.city.as_str(), c.place.as_str()]
|
||
.into_iter()
|
||
.filter(|s| !s.is_empty())
|
||
.collect();
|
||
ctx.draw_text_ellipsis(
|
||
&meta.join(" · "),
|
||
TextStyle::regular(13.5, pal.text_secondary),
|
||
Rect::from_xywh(text_x, cr.top() + 50.0, text_w, 20.0),
|
||
TextAlign::Left,
|
||
);
|
||
|
||
if c.afisha_url.is_some() {
|
||
let btn_r = Rect::from_center_size(
|
||
Pos2::new(cr.right() - 68.0, cr.center_y()),
|
||
Vec2::new(108.0, 34.0),
|
||
);
|
||
ctx.dl().push_rect(btn_r, 17.0, pal.yellow);
|
||
ctx.draw_text_ellipsis(
|
||
if ru { "Билеты" } else { "Tickets" },
|
||
TextStyle::bold(13.0, pal.on_yellow),
|
||
btn_r,
|
||
TextAlign::Center,
|
||
);
|
||
}
|
||
if resp.hovered && c.afisha_url.is_some() {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if resp.clicked {
|
||
if let Some(ref url) = c.afisha_url {
|
||
actions.push(AppAction::OpenUrl(url.clone()));
|
||
}
|
||
}
|
||
}
|
||
y += 104.0;
|
||
}
|
||
}
|
||
|
||
y += 20.0;
|
||
let total_h = y - (rect.top() - scroll_y);
|
||
ctx.end_scroll_v(scroll_id, pal, total_h, true);
|
||
}
|
||
|
||
/// Full Yandex Music Chart Page.
|
||
pub fn render_chart(
|
||
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("chart_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;
|
||
|
||
let chart_title = if ru {
|
||
"Чарт Яндекс Музыки"
|
||
} else {
|
||
"Yandex Music Chart"
|
||
};
|
||
ctx.draw_text_ellipsis(
|
||
chart_title,
|
||
TextStyle::headline(34.0, pal.text_bright),
|
||
Rect::from_xywh(x, y, (avail_w - 190.0).max(160.0), 42.0),
|
||
TextAlign::Left,
|
||
);
|
||
ctx.draw_text_ellipsis(
|
||
if ru {
|
||
"Треки, популярные прямо сейчас"
|
||
} else {
|
||
"Tracks trending right now"
|
||
},
|
||
TextStyle::regular(14.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y + 44.0, (avail_w - 190.0).max(160.0), 22.0),
|
||
TextAlign::Left,
|
||
);
|
||
|
||
let chart_playing = app.is_context_playing("chart");
|
||
let (play_resp, _) = yellow_pill_button(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("chart_play_all"),
|
||
Pos2::new(x + avail_w - 168.0, y + 10.0),
|
||
Some(if chart_playing {
|
||
Icon::PauseXxs
|
||
} else {
|
||
Icon::PlayXxs
|
||
}),
|
||
if chart_playing {
|
||
t.pause()
|
||
} else if ru {
|
||
"Слушать чарт"
|
||
} else {
|
||
"Play chart"
|
||
},
|
||
42.0,
|
||
app.landing.chart_tracks.is_empty(),
|
||
);
|
||
if play_resp.clicked && !app.landing.chart_tracks.is_empty() {
|
||
actions.push(AppAction::ToggleContextPlay {
|
||
tracks: app.landing.chart_tracks.clone(),
|
||
context_name: chart_title.into(),
|
||
context_key: "chart".into(),
|
||
is_vibe: false,
|
||
});
|
||
}
|
||
y += 84.0;
|
||
|
||
let tracks = app.landing.chart_tracks.clone();
|
||
let range = visible_row_range(rect, y, TRACK_ROW_HEIGHT, tracks.len(), 2);
|
||
for idx in range {
|
||
let tr = &tracks[idx];
|
||
let row_r = Rect::from_xywh(x, y + idx as f32 * TRACK_ROW_HEIGHT, avail_w, TRACK_ROW_HEIGHT);
|
||
let is_curr = current_track_id.as_deref() == Some(tr.id.as_str());
|
||
match track_row(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair("chart_row", idx),
|
||
row_r,
|
||
tr,
|
||
TrackRowOptions {
|
||
index: Some(idx),
|
||
show_chart_rank: true,
|
||
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.clone(),
|
||
start_index: idx,
|
||
context_name: chart_title.into(),
|
||
context_key: "chart".into(),
|
||
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 => {}
|
||
}
|
||
}
|
||
y += tracks.len() as f32 * TRACK_ROW_HEIGHT + 24.0;
|
||
|
||
let total_h = y - (rect.top() - scroll_y);
|
||
ctx.end_scroll_v(scroll_id, pal, total_h, true);
|
||
}
|
||
|
||
/// Metatags / Mixes Catalog Page (`GET /landing3/metatags`, opened from "Миксы >" on Search).
|
||
pub fn render_metatags(
|
||
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 scroll_id = WidgetId::new("metatags_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;
|
||
|
||
// Back / Forward nav buttons
|
||
y = draw_back_forward_row(ctx, pal, app, x, y, actions);
|
||
|
||
ctx.draw_text_ellipsis(
|
||
t.mixes(),
|
||
TextStyle::headline(34.0, pal.text_bright),
|
||
Rect::from_xywh(x, y, avail_w, 42.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 58.0;
|
||
|
||
const FALLBACK_PALETTE: &[(Color, Color, Color)] = &[
|
||
(Color::rgb(0x6E, 0x52, 0x3C), Color::rgb(0xC8, 0x8A, 0x5A), Color::rgb(0x78, 0x42, 0x22)),
|
||
(Color::rgb(0xA3, 0x90, 0x28), Color::rgb(0xFF, 0xE2, 0x58), Color::rgb(0xF5, 0x9F, 0x2A)),
|
||
(Color::rgb(0x5B, 0xAD, 0xD6), Color::rgb(0xE0, 0x78, 0x52), Color::rgb(0xC8, 0x3A, 0x20)),
|
||
(Color::rgb(0xA3, 0x75, 0x28), Color::rgb(0xFF, 0xE8, 0x52), Color::rgb(0xFF, 0x8A, 0xC8)),
|
||
(Color::rgb(0x93, 0x70, 0x38), Color::rgb(0xB8, 0x9A, 0x58), Color::rgb(0x8E, 0x6E, 0x36)),
|
||
(Color::rgb(0x4F, 0x6C, 0x9B), Color::rgb(0x3F, 0x68, 0xF9), Color::rgb(0x83, 0x41, 0xEF)),
|
||
];
|
||
|
||
if app.metatags.is_empty() {
|
||
let fallback_items: &[(&str, &str, &str)] = &[
|
||
("mood", "Настроение", "Mood"),
|
||
("activity", "Занятия", "Activity"),
|
||
("genres", "Жанры", "Genres"),
|
||
("era", "Эпоха", "Era"),
|
||
("autumn", "Осень", "Autumn"),
|
||
("electronic", "Электроника", "Electronic"),
|
||
("rock", "Рок", "Rock"),
|
||
("pop", "Поп", "Pop"),
|
||
];
|
||
let gap = 24.0;
|
||
let card_sz = 136.0;
|
||
let cols = ((avail_w + gap) / (card_sz + gap)).floor().clamp(2.0, 6.0) as usize;
|
||
for (i, &(id, tru, ten)) in fallback_items.iter().enumerate() {
|
||
let col = i % cols;
|
||
let row = i / cols;
|
||
let (tab_c, c1, c2) = FALLBACK_PALETTE[i % FALLBACK_PALETTE.len()];
|
||
let lbl = if ru { tru } else { ten };
|
||
let cr = Rect::from_xywh(
|
||
x + col as f32 * (card_sz + gap),
|
||
y + row as f32 * (card_sz + 62.0),
|
||
card_sz,
|
||
card_sz + 46.0,
|
||
);
|
||
let resp = stacked_mix_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair("mt_fb", id),
|
||
cr,
|
||
lbl,
|
||
tab_c,
|
||
c1,
|
||
c2,
|
||
None,
|
||
id,
|
||
);
|
||
if resp.clicked {
|
||
actions.push(AppAction::Navigate(Route::Metatag {
|
||
id: id.into(),
|
||
title: lbl.into(),
|
||
}));
|
||
}
|
||
}
|
||
let rows = fallback_items.len().div_ceil(cols);
|
||
y += rows as f32 * (card_sz + 62.0) + 20.0;
|
||
} else {
|
||
let trees = app.metatags.clone();
|
||
let gap = 24.0;
|
||
let card_sz = 136.0;
|
||
let cols = ((avail_w + gap) / (card_sz + gap)).floor().clamp(2.0, 6.0) as usize;
|
||
for (ti, tree) in trees.iter().enumerate() {
|
||
if tree.leaves.is_empty() {
|
||
continue;
|
||
}
|
||
ctx.draw_text_ellipsis(
|
||
&tree.title,
|
||
TextStyle::headline(22.0, pal.text_primary),
|
||
Rect::from_xywh(x, y, avail_w, 28.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 38.0;
|
||
|
||
for (li, leaf) in tree.leaves.iter().enumerate() {
|
||
let col = li % cols;
|
||
let row = li / cols;
|
||
let (fb_tab, c1, c2) = FALLBACK_PALETTE[(ti + li) % FALLBACK_PALETTE.len()];
|
||
let tab_c = leaf
|
||
.color_hex
|
||
.as_deref()
|
||
.and_then(Color::from_hex_str)
|
||
.unwrap_or(fb_tab);
|
||
let cr = Rect::from_xywh(
|
||
x + col as f32 * (card_sz + gap),
|
||
y + row as f32 * (card_sz + 62.0),
|
||
card_w_or(card_sz),
|
||
card_sz + 46.0,
|
||
);
|
||
if cr.bottom() >= rect.top() - 40.0 && cr.top() <= rect.bottom() + 40.0 {
|
||
let resp = stacked_mix_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair("mt_leaf", format!("{}_{}", ti, leaf.id)),
|
||
cr,
|
||
&leaf.title,
|
||
tab_c,
|
||
c1,
|
||
c2,
|
||
leaf.cover_uri.as_deref(),
|
||
&leaf.id,
|
||
);
|
||
if resp.clicked {
|
||
actions.push(AppAction::Navigate(Route::Metatag {
|
||
id: leaf.id.clone(),
|
||
title: leaf.title.clone(),
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
let rows = tree.leaves.len().div_ceil(cols);
|
||
y += rows as f32 * (card_sz + 62.0) + 24.0;
|
||
}
|
||
}
|
||
|
||
let total_h = y - (rect.top() - scroll_y);
|
||
ctx.end_scroll_v(scroll_id, pal, total_h, true);
|
||
}
|
||
|
||
fn card_w_or(v: f32) -> f32 {
|
||
v
|
||
}
|
||
|
||
/// Specific Metatag Detail Page (`GET /metatags/{id}`, opened by clicking any Mix card!).
|
||
pub fn render_metatag_detail(
|
||
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 is_playing = app.is_audio_playing();
|
||
let current_track_id = app.current_track().map(|tr| tr.id.clone());
|
||
|
||
let (route_id, route_title) = match &app.route {
|
||
Route::Metatag { id, title } => (id.clone(), title.clone()),
|
||
_ => (String::new(), t.mixes().into()),
|
||
};
|
||
|
||
let detail = app
|
||
.current_metatag_detail
|
||
.clone()
|
||
.filter(|d| d.id == route_id || route_id.is_empty());
|
||
|
||
let scroll_id = WidgetId::new("metatag_detail_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;
|
||
|
||
// Optional tinted header gradient from metatag color
|
||
if let Some(col) = detail
|
||
.as_ref()
|
||
.and_then(|d| d.color_hex.as_deref())
|
||
.and_then(Color::from_hex_str)
|
||
{
|
||
let grad_col = pal.header_gradient_color(col);
|
||
let grad_r = Rect::from_xywh(
|
||
rect.left() - 25.0,
|
||
rect.top() - 13.0 - scroll_y,
|
||
rect.width() + 50.0,
|
||
240.0,
|
||
);
|
||
ctx.dl().push_gradient_rect(
|
||
grad_r,
|
||
0.0,
|
||
grad_col.with_alpha(if pal.is_dark { 115 } else { 70 }),
|
||
grad_col.with_alpha(0),
|
||
Vec2::new(0.0, 1.0),
|
||
);
|
||
}
|
||
|
||
y = draw_back_forward_row(ctx, pal, app, x, y, actions);
|
||
|
||
let title = detail
|
||
.as_ref()
|
||
.map(|d| d.title.as_str())
|
||
.unwrap_or(route_title.as_str());
|
||
ctx.draw_text_ellipsis(
|
||
title,
|
||
TextStyle::headline(36.0, pal.text_bright),
|
||
Rect::from_xywh(x, y, avail_w, 44.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 48.0;
|
||
|
||
if let Some(ref desc) = detail.as_ref().and_then(|d| d.description.clone()) {
|
||
ctx.draw_text_wrapped(
|
||
desc,
|
||
TextStyle::regular(14.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 40.0),
|
||
Some(2),
|
||
TextAlign::Left,
|
||
);
|
||
y += 42.0;
|
||
}
|
||
|
||
if app.detail_loading && detail.is_none() {
|
||
ctx.draw_text_ellipsis(
|
||
t.loading(),
|
||
TextStyle::medium(14.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 24.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 32.0;
|
||
} else if let Some(d) = detail {
|
||
// Play button if metatag has tracks
|
||
if !d.tracks.is_empty() {
|
||
let ctx_key = format!("metatag:{}", d.id);
|
||
let ctx_playing = app.is_context_playing(&ctx_key);
|
||
let (play_resp, _) = yellow_pill_button(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("mt_det_play"),
|
||
Pos2::new(x, y),
|
||
Some(if ctx_playing {
|
||
Icon::PauseXxs
|
||
} else {
|
||
Icon::PlayXxs
|
||
}),
|
||
if ctx_playing { t.pause() } else { t.listen() },
|
||
40.0,
|
||
false,
|
||
);
|
||
if play_resp.clicked {
|
||
actions.push(AppAction::ToggleContextPlay {
|
||
tracks: d.tracks.clone(),
|
||
context_name: d.title.clone(),
|
||
context_key: ctx_key.clone(),
|
||
is_vibe: false,
|
||
});
|
||
}
|
||
y += 56.0;
|
||
|
||
// Tracks
|
||
ctx.draw_text_ellipsis(
|
||
t.tracks(),
|
||
TextStyle::headline(22.0, pal.text_primary),
|
||
Rect::from_xywh(x, y, avail_w, 28.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 36.0;
|
||
|
||
for (idx, tr) in d.tracks.iter().take(20).enumerate() {
|
||
let row_r = Rect::from_xywh(x, y, avail_w, TRACK_ROW_HEIGHT);
|
||
if row_r.bottom() >= rect.top() - 60.0 && row_r.top() <= rect.bottom() + 60.0 {
|
||
let is_curr = current_track_id.as_deref() == Some(tr.id.as_str());
|
||
match track_row(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair("mt_tr", 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: d.tracks.clone(),
|
||
start_index: idx,
|
||
context_name: d.title.clone(),
|
||
context_key: ctx_key.clone(),
|
||
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 => {}
|
||
}
|
||
}
|
||
y += TRACK_ROW_HEIGHT;
|
||
}
|
||
y += 24.0;
|
||
}
|
||
|
||
// Playlists
|
||
if !d.playlists.is_empty() {
|
||
ctx.draw_text_ellipsis(
|
||
t.playlists(),
|
||
TextStyle::headline(22.0, pal.text_primary),
|
||
Rect::from_xywh(x, y, avail_w, 28.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 38.0;
|
||
let card_w = 164.0;
|
||
let card_h = card_w + 54.0;
|
||
let vp = Rect::from_xywh(x, y, avail_w, card_h);
|
||
let h_id = WidgetId::new("mt_det_pl_scroll");
|
||
let sx = ctx.begin_scroll_h(h_id, vp, 0.0);
|
||
let mut cx = x - sx;
|
||
for pl in &d.playlists {
|
||
let cr = Rect::from_xywh(cx, y, card_w, card_h);
|
||
let m = media_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair("mt_pl", format!("{}_{}", pl.owner_uid, pl.kind)),
|
||
cr,
|
||
&pl.title,
|
||
&pl.owner_name,
|
||
pl.cover_uri.as_deref(),
|
||
&format!("mtpl_{}_{}", pl.owner_uid, pl.kind),
|
||
false,
|
||
false,
|
||
);
|
||
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: pl.owner_name.clone(),
|
||
cover_uri: pl.cover_uri.clone(),
|
||
owner_uid: Some(pl.owner_uid.clone()),
|
||
is_own_playlist: false,
|
||
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 + 16.0;
|
||
}
|
||
ctx.end_scroll_h(h_id, pal, d.playlists.len() as f32 * (card_w + 16.0), false);
|
||
y += card_h + 24.0;
|
||
}
|
||
|
||
// Albums
|
||
if !d.albums.is_empty() {
|
||
ctx.draw_text_ellipsis(
|
||
t.albums(),
|
||
TextStyle::headline(22.0, pal.text_primary),
|
||
Rect::from_xywh(x, y, avail_w, 28.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 38.0;
|
||
let card_w = 164.0;
|
||
let card_h = card_w + 54.0;
|
||
let vp = Rect::from_xywh(x, y, avail_w, card_h);
|
||
let h_id = WidgetId::new("mt_det_alb_scroll");
|
||
let sx = ctx.begin_scroll_h(h_id, vp, 0.0);
|
||
let mut cx = x - sx;
|
||
for alb in &d.albums {
|
||
let cr = Rect::from_xywh(cx, y, card_w, card_h);
|
||
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("mt_alb", &alb.id),
|
||
cr,
|
||
&alb.title,
|
||
sub,
|
||
alb.cover_uri.as_deref(),
|
||
&format!("mtalb_{}", 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: sub.to_string(),
|
||
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.clone(),
|
||
});
|
||
} else if m.clicked {
|
||
actions.push(AppAction::Navigate(Route::Album {
|
||
id: alb.id.clone(),
|
||
title: alb.title.clone(),
|
||
}));
|
||
}
|
||
cx += card_w + 16.0;
|
||
}
|
||
ctx.end_scroll_h(h_id, pal, d.albums.len() as f32 * (card_w + 16.0), false);
|
||
y += card_h + 24.0;
|
||
}
|
||
|
||
// Artists
|
||
if !d.artists.is_empty() {
|
||
ctx.draw_text_ellipsis(
|
||
t.artists(),
|
||
TextStyle::headline(22.0, pal.text_primary),
|
||
Rect::from_xywh(x, y, avail_w, 28.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 38.0;
|
||
let card_w = 152.0;
|
||
let card_h = card_w + 50.0;
|
||
let vp = Rect::from_xywh(x, y, avail_w, card_h);
|
||
let h_id = WidgetId::new("mt_det_art_scroll");
|
||
let sx = ctx.begin_scroll_h(h_id, vp, 0.0);
|
||
let mut cx = x - sx;
|
||
for art in &d.artists {
|
||
let cr = Rect::from_xywh(cx, y, card_w, card_h);
|
||
let m = media_card(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
WidgetId::from_pair("mt_art", &art.id),
|
||
cr,
|
||
&art.name,
|
||
t.artist(),
|
||
art.cover_uri.as_deref(),
|
||
&format!("mtart_{}", 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 + 16.0;
|
||
}
|
||
ctx.end_scroll_h(h_id, pal, d.artists.len() as f32 * (card_w + 16.0), false);
|
||
y += card_h + 24.0;
|
||
}
|
||
} else {
|
||
ctx.draw_text_ellipsis(
|
||
t.search_not_found_title(),
|
||
TextStyle::medium(15.0, pal.text_secondary),
|
||
Rect::from_xywh(x, y, avail_w, 24.0),
|
||
TextAlign::Left,
|
||
);
|
||
y += 32.0;
|
||
}
|
||
|
||
let total_h = y - (rect.top() - scroll_y);
|
||
ctx.end_scroll_v(scroll_id, pal, total_h, true);
|
||
}
|
||
|
||
fn draw_back_forward_row(
|
||
ctx: &mut UiContext,
|
||
pal: &YmPalette,
|
||
app: &AppState,
|
||
x: f32,
|
||
y: f32,
|
||
actions: &mut Vec<AppAction>,
|
||
) -> f32 {
|
||
let can_back = !app.history_back.is_empty();
|
||
let can_fwd = !app.history_forward.is_empty();
|
||
for (offset_x, ic, enabled, is_back) in [
|
||
(0.0_f32, Icon::ArrowLeftXxs, can_back, true),
|
||
(40.0_f32, Icon::ArrowRightXxs, can_fwd, false),
|
||
] {
|
||
let br = Rect::from_xywh(x + offset_x, y, 32.0, 32.0);
|
||
let resp = ctx.interact(WidgetId::from_pair("pk_nav", is_back), br);
|
||
let bg = if enabled && resp.hovered {
|
||
pal.surface_hover
|
||
} else {
|
||
pal.surface_secondary
|
||
};
|
||
ctx.dl().push_circle(br.center(), 16.0, bg);
|
||
ctx.draw_icon(
|
||
ic,
|
||
Rect::from_center_size(br.center(), Vec2::splat(20.0)),
|
||
if enabled {
|
||
pal.text_primary
|
||
} else {
|
||
pal.text_disabled
|
||
},
|
||
);
|
||
if enabled && resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if enabled && resp.clicked {
|
||
actions.push(if is_back {
|
||
AppAction::GoBack
|
||
} else {
|
||
AppAction::GoForward
|
||
});
|
||
}
|
||
}
|
||
y + 46.0
|
||
}
|