first commit
This commit is contained in:
commit
a408df2a76
218 changed files with 52376 additions and 0 deletions
808
src/views/collection.rs
Normal file
808
src/views/collection.rs
Normal file
|
|
@ -0,0 +1,808 @@
|
|||
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::{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};
|
||||
|
||||
/// Exact Yandex Music Desktop 5.129.0 Collection Page (`pages_api_spec.md` §5):
|
||||
/// All 7 original tabs:
|
||||
/// 1. Любимые треки (My Favorites)
|
||||
/// 2. Плейлисты (with "+ Создать плейлист" card/button + Rename & Delete controls!)
|
||||
/// 3. Альбомы (Liked albums grid)
|
||||
/// 4. Исполнители (Liked artists circular grid)
|
||||
/// 5. Подкасты и книги (Bookshelf / Podcasts grid)
|
||||
/// 6. Скачанное (Offline downloaded tracks with play & delete from device)
|
||||
/// 7. История (Listening history)
|
||||
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);
|
||||
|
||||
// `views/mod.rs` already insets `inner_r` by (25, 13, 25, 0)
|
||||
let x = rect.left();
|
||||
let avail_w = (rect.width() - 6.0).max(320.0);
|
||||
let mut y = rect.top() + 8.0 - scroll_y;
|
||||
|
||||
// Page Heading
|
||||
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 += 58.0;
|
||||
|
||||
// Signature "Мне нравится" / "My Favorites" Hero Banner Card (theme-aware!)
|
||||
let hero_r = Rect::from_xywh(x, y, avail_w, 120.0);
|
||||
let hero_resp = ctx.interact(WidgetId::new("col_fav_hero"), hero_r);
|
||||
let hero_bg = if pal.is_dark {
|
||||
if hero_resp.hovered {
|
||||
Color::rgb(0x2A, 0x24, 0x17)
|
||||
} else {
|
||||
Color::rgb(0x22, 0x1D, 0x12)
|
||||
}
|
||||
} else if hero_resp.hovered {
|
||||
Color::rgb(0xFF, 0xF2, 0xBC)
|
||||
} else {
|
||||
Color::rgb(0xFF, 0xF8, 0xD6)
|
||||
};
|
||||
ctx.dl()
|
||||
.push_rect_bordered(hero_r, 16.0, hero_bg, 1.0, pal.border_subtle);
|
||||
|
||||
let cov_r = Rect::from_xywh(hero_r.left() + 18.0, hero_r.center_y() - 42.0, 84.0, 84.0);
|
||||
draw_cover_art(ctx, pal, covers, cov_r, None, "likes", 12.0, false, true);
|
||||
|
||||
let fav_title = t.liked_playlist();
|
||||
ctx.draw_text_ellipsis(
|
||||
fav_title,
|
||||
TextStyle::headline(26.0, pal.text_bright),
|
||||
Rect::from_xywh(cov_r.right() + 20.0, hero_r.top() + 28.0, avail_w - 280.0, 32.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
ctx.draw_text_ellipsis(
|
||||
&t.count_tracks(app.liked_tracks.len()),
|
||||
TextStyle::regular(14.0, pal.text_secondary),
|
||||
Rect::from_xywh(cov_r.right() + 20.0, hero_r.top() + 66.0, avail_w - 280.0, 22.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
|
||||
let likes_playing = app.is_context_playing("likes");
|
||||
let play_btn_label = if likes_playing { t.pause() } else { t.listen() };
|
||||
let play_text_w = ctx
|
||||
.measure_text(play_btn_label, TextStyle::medium(14.0, pal.on_yellow), None)
|
||||
.x;
|
||||
let play_btn_w = (play_text_w + 28.0 + 36.0).max(100.0).ceil();
|
||||
let play_btn_r = Rect::from_xywh(
|
||||
hero_r.right() - play_btn_w - 24.0,
|
||||
hero_r.center_y() - 21.0,
|
||||
play_btn_w,
|
||||
42.0,
|
||||
);
|
||||
let play_resp = crate::engine::widgets::yellow_pill_button_in(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("col_fav_play"),
|
||||
play_btn_r,
|
||||
Some(if likes_playing {
|
||||
Icon::PauseXxs
|
||||
} else {
|
||||
Icon::PlayXxs
|
||||
}),
|
||||
play_btn_label,
|
||||
app.liked_tracks.is_empty(),
|
||||
);
|
||||
if play_resp.clicked && !app.liked_tracks.is_empty() {
|
||||
actions.push(AppAction::ToggleContextPlay {
|
||||
tracks: app.liked_tracks.clone(),
|
||||
context_name: fav_title.into(),
|
||||
context_key: "likes".into(),
|
||||
is_vibe: false,
|
||||
});
|
||||
} else if hero_resp.clicked {
|
||||
actions.push(AppAction::Navigate(Route::LikedTracks));
|
||||
}
|
||||
if hero_resp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
y += 120.0 + 20.0;
|
||||
|
||||
// All 7 Original Collection Tabs (horizontal scrollable pill bar!)
|
||||
let tabs_vp = Rect::from_xywh(x, y, avail_w, 42.0);
|
||||
let tabs_h_id = WidgetId::new("col_tabs_hscroll");
|
||||
let tabs_sx = ctx.begin_scroll_h(tabs_h_id, tabs_vp, 0.0);
|
||||
let mut tx = x - tabs_sx;
|
||||
let all_tabs = [
|
||||
(CollectionTab::Tracks, t.liked_tracks_tab()),
|
||||
(CollectionTab::Playlists, t.playlists()),
|
||||
(CollectionTab::Albums, t.albums()),
|
||||
(CollectionTab::Artists, t.artists()),
|
||||
(CollectionTab::PodcastsAndBooks, t.podcasts_and_books()),
|
||||
(CollectionTab::Downloaded, t.downloaded()),
|
||||
(CollectionTab::History, t.history()),
|
||||
];
|
||||
for (tab_kind, label) in all_tabs {
|
||||
let (resp, r) = secondary_pill_button(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::from_pair("col_tab", tab_kind as u8),
|
||||
Pos2::new(tx, y),
|
||||
None,
|
||||
label,
|
||||
38.0,
|
||||
app.collection_tab == tab_kind,
|
||||
);
|
||||
if resp.clicked {
|
||||
app.collection_tab = tab_kind;
|
||||
}
|
||||
tx = r.right() + 8.0;
|
||||
}
|
||||
let tabs_total_w = (tx + tabs_sx) - x;
|
||||
ctx.end_scroll_h(tabs_h_id, pal, tabs_total_w, false);
|
||||
y += 56.0;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// TAB BODY
|
||||
// -------------------------------------------------------------------------
|
||||
match app.collection_tab {
|
||||
CollectionTab::Tracks => {
|
||||
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, 44.0),
|
||||
Some(2),
|
||||
TextAlign::Left,
|
||||
);
|
||||
y += 48.0;
|
||||
} else {
|
||||
let tracks = app.liked_tracks.clone();
|
||||
y = render_virtual_track_list(
|
||||
ctx,
|
||||
pal,
|
||||
covers,
|
||||
app,
|
||||
shell,
|
||||
rect,
|
||||
x,
|
||||
y,
|
||||
avail_w,
|
||||
&tracks,
|
||||
"col_liked",
|
||||
fav_title,
|
||||
"likes",
|
||||
current_track_id.as_deref(),
|
||||
is_playing,
|
||||
actions,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// Total slots = 1 ("+ Create playlist" card) + user_playlists.len()
|
||||
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", 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,
|
||||
false,
|
||||
);
|
||||
|
||||
// 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 = if !app.liked_albums.is_empty() {
|
||||
app.liked_albums.clone()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
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 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", &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.clone(),
|
||||
});
|
||||
} else if m.clicked {
|
||||
actions.push(AppAction::Navigate(Route::Album {
|
||||
id: alb.id.clone(),
|
||||
title: alb.title.clone(),
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
// Header bar with Play Offline + Clear all downloaded
|
||||
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);
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
1024
src/views/detail.rs
Normal file
1024
src/views/detail.rs
Normal file
File diff suppressed because it is too large
Load diff
753
src/views/for_you.rs
Normal file
753
src/views/for_you.rs
Normal file
|
|
@ -0,0 +1,753 @@
|
|||
use crate::app::state::{AppAction, AppState, CollectionTab, ForYouTab, Route};
|
||||
use crate::covers::CoverCache;
|
||||
use crate::engine::input::WidgetId;
|
||||
use crate::engine::text::{TextAlign, TextStyle};
|
||||
use crate::engine::theme::{YmPalette, TRACK_ROW_HEIGHT};
|
||||
use crate::engine::types::{css_rgba, Color, CornerRadii, CursorKind, Pos2, Rect, Vec2};
|
||||
use crate::engine::widgets::{
|
||||
artist_promo_card, draw_cover_art, media_card, track_row, TrackRowAction, TrackRowOptions,
|
||||
};
|
||||
use crate::engine::UiContext;
|
||||
use crate::icons::Icon;
|
||||
use crate::views::overlays::ShellUiState;
|
||||
|
||||
/// Exact Yandex Music Desktop 5.129.0 "For you and Trends" page (`vibe_wheel_foryou_spec.md` §4):
|
||||
/// - Persistent heading ("Для вас и Тренды" / "For you and Trends") + IN-PLACE switcher tabs ("Для вас" / "Тренды")
|
||||
/// - For You tab:
|
||||
/// * Quick cards: "Мне нравится >" (right 58x58 cover = last liked track `liked_tracks.first()`) &
|
||||
/// "История >" (navigates to `NavigateCollectionTab(CollectionTab::History)`)
|
||||
/// * "Recommended by the artist" (`artist_promo_card` with 80x80 release cover ON TOP of artist photo + localized "Слушать"/"Listen")
|
||||
/// * "Made for you" personal playlists carousel
|
||||
/// * "New releases" albums carousel
|
||||
/// - Trends tab (in-place keeping heading & switcher visible!):
|
||||
/// * Chart tracks (with rank badges & click to play) + clickable heading to full Chart
|
||||
/// * New releases carousel
|
||||
/// * Popular playlists carousel
|
||||
pub fn render_for_you(
|
||||
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("foryou_page_scroll");
|
||||
let scroll_y = ctx.begin_scroll_v(scroll_id, rect, 0.0);
|
||||
|
||||
// `views/mod.rs` already insets `inner_r` by (25, 13, 25, 0) -> rect starts at exact CDP (249, 45)!
|
||||
let x = rect.left();
|
||||
let avail_w = rect.width().max(320.0);
|
||||
let mut y = rect.top() + 8.5 - scroll_y;
|
||||
|
||||
// 0. Persistent Page Heading
|
||||
ctx.draw_text_ellipsis(
|
||||
t.for_you_and_trends(),
|
||||
TextStyle::headline(32.0, pal.text_primary),
|
||||
Rect::from_xywh(x, y, avail_w, 38.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
y += 66.0;
|
||||
|
||||
// 1. In-Place Switcher Tabs ("Для вас" / "Тренды")
|
||||
let for_you_sub: String = {
|
||||
let names: Vec<String> = app
|
||||
.landing
|
||||
.vibe_tracks
|
||||
.iter()
|
||||
.take(2)
|
||||
.map(|tr| tr.artists_string())
|
||||
.collect();
|
||||
if names.is_empty() {
|
||||
if ru {
|
||||
"Персональные рекомендации".into()
|
||||
} else {
|
||||
"Personal picks".into()
|
||||
}
|
||||
} else {
|
||||
names.join(", ")
|
||||
}
|
||||
};
|
||||
let trends_sub: String = {
|
||||
let names: Vec<String> = app
|
||||
.landing
|
||||
.chart_tracks
|
||||
.iter()
|
||||
.take(2)
|
||||
.map(|tr| tr.artists_string())
|
||||
.collect();
|
||||
if names.is_empty() {
|
||||
if ru {
|
||||
"Чарт и новинки".into()
|
||||
} else {
|
||||
"Chart & new hits".into()
|
||||
}
|
||||
} else {
|
||||
names.join(", ")
|
||||
}
|
||||
};
|
||||
let fy_c1 = app
|
||||
.landing
|
||||
.vibe_tracks
|
||||
.first()
|
||||
.and_then(|tr| tr.cover_uri.clone());
|
||||
let fy_c2 = app
|
||||
.landing
|
||||
.vibe_tracks
|
||||
.get(1)
|
||||
.and_then(|tr| tr.cover_uri.clone());
|
||||
let tr_c1 = app
|
||||
.landing
|
||||
.chart_tracks
|
||||
.first()
|
||||
.and_then(|tr| tr.cover_uri.clone());
|
||||
let tr_c2 = app
|
||||
.landing
|
||||
.chart_tracks
|
||||
.get(1)
|
||||
.and_then(|tr| tr.cover_uri.clone());
|
||||
|
||||
let mut tab_x = x;
|
||||
let tabs = [
|
||||
(
|
||||
ForYouTab::ForYou,
|
||||
t.for_you(),
|
||||
for_you_sub.as_str(),
|
||||
Color::rgb(0x6E, 0x7A, 0x86),
|
||||
Color::rgb(0x42, 0x46, 0x4E),
|
||||
fy_c1.as_deref(),
|
||||
fy_c2.as_deref(),
|
||||
),
|
||||
(
|
||||
ForYouTab::Trends,
|
||||
t.trends(),
|
||||
trends_sub.as_str(),
|
||||
Color::rgb(0x52, 0x52, 0x56),
|
||||
Color::rgb(0x98, 0x94, 0x90),
|
||||
tr_c1.as_deref(),
|
||||
tr_c2.as_deref(),
|
||||
),
|
||||
];
|
||||
|
||||
for (tab_kind, title, sub, c1, c2, av1_uri, av2_uri) in tabs {
|
||||
let active = app.for_you_tab == tab_kind;
|
||||
let sub_w = ctx
|
||||
.measure_text(sub, TextStyle::medium(13.0, pal.text_secondary), None)
|
||||
.x
|
||||
.min(220.0);
|
||||
let pill_w = (86.0 + sub_w + 18.0).max(201.0);
|
||||
let pill_r = Rect::from_xywh(tab_x, y, pill_w, 54.0);
|
||||
let resp = ctx.interact(WidgetId::from_pair("fy_tab", tab_kind as u8), pill_r);
|
||||
|
||||
if active || resp.hovered {
|
||||
let bg = if active {
|
||||
pal.surface_hover
|
||||
} else {
|
||||
pal.surface_secondary
|
||||
};
|
||||
ctx.dl().push_rect(pill_r, 27.0, bg);
|
||||
}
|
||||
|
||||
// Overlapping 36x36 circular avatars
|
||||
let a1 = Pos2::new(pill_r.left() + 34.0, pill_r.center_y());
|
||||
let a2 = Pos2::new(pill_r.left() + 60.0, pill_r.center_y());
|
||||
for (pos, uri_opt, fallback) in [(a2, av2_uri, c2), (a1, av1_uri, c1)] {
|
||||
let av_r = Rect::from_center_size(pos, Vec2::splat(36.0));
|
||||
let mut drew = false;
|
||||
if let Some(uri) = uri_opt {
|
||||
if let Some((tex_id, _, _)) = covers.get_or_fetch(uri, 100) {
|
||||
ctx.dl().push_image(av_r, tex_id, 18.0, Color::WHITE);
|
||||
drew = true;
|
||||
}
|
||||
}
|
||||
if !drew {
|
||||
ctx.dl().push_circle(pos, 18.0, fallback);
|
||||
}
|
||||
}
|
||||
|
||||
let tx_l = pill_r.left() + 86.0;
|
||||
let tx_w = (pill_r.right() - tx_l - 14.0).max(40.0);
|
||||
ctx.draw_text_ellipsis(
|
||||
title,
|
||||
TextStyle::bold(14.0, pal.text_primary),
|
||||
Rect::from_xywh(tx_l, pill_r.top() + 8.0, tx_w, 18.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
ctx.draw_text_ellipsis(
|
||||
sub,
|
||||
TextStyle::medium(13.0, pal.text_secondary),
|
||||
Rect::from_xywh(tx_l, pill_r.top() + 28.0, tx_w, 18.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
|
||||
if resp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
if resp.clicked && !active {
|
||||
actions.push(AppAction::SetForYouTab(tab_kind));
|
||||
}
|
||||
|
||||
tab_x = pill_r.right() + 8.0;
|
||||
}
|
||||
y += 54.0 + 41.5;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// IN-PLACE TAB CONTENT
|
||||
// -------------------------------------------------------------------------
|
||||
match app.for_you_tab {
|
||||
ForYouTab::ForYou => {
|
||||
// 2. Two Side-by-Side Quick Cards ("Мне нравится >" & "История >") — exact CDP 480px width, 17.5px gap
|
||||
let card_gap = 17.5;
|
||||
let half_w = ((avail_w.min(977.5) - card_gap) * 0.5).max(260.0);
|
||||
|
||||
// Card A: My Favorites > (right 58x58 mini-cover = last liked track!)
|
||||
let r1 = Rect::from_xywh(x, y, half_w, 82.0);
|
||||
let resp1 = ctx.interact(WidgetId::new("fy_quick_likes"), r1);
|
||||
ctx.dl().push_rect(
|
||||
r1,
|
||||
12.0,
|
||||
if resp1.hovered {
|
||||
pal.surface_hover
|
||||
} else {
|
||||
pal.surface_secondary
|
||||
},
|
||||
);
|
||||
let heart_r = Rect::from_xywh(r1.left() + 12.0, r1.top() + 12.0, 58.0, 58.0);
|
||||
draw_cover_art(ctx, pal, covers, heart_r, None, "likes", 8.0, false, true);
|
||||
|
||||
let fav_title = t.liked_playlist();
|
||||
let fav_tw = ctx
|
||||
.measure_text(fav_title, TextStyle::headline(24.0, pal.text_primary), None)
|
||||
.x
|
||||
.min((r1.width() - 180.0).max(80.0));
|
||||
let fav_ty = r1.top() + 14.0;
|
||||
ctx.draw_text_ellipsis(
|
||||
fav_title,
|
||||
TextStyle::headline(24.0, pal.text_primary),
|
||||
Rect::from_xywh(r1.left() + 82.0, fav_ty, fav_tw + 4.0, 28.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
let arrow_shift = if resp1.hovered { 5.0 } else { 0.0 };
|
||||
ctx.draw_icon(
|
||||
Icon::ArrowRight,
|
||||
Rect::from_center_size(
|
||||
Pos2::new(r1.left() + 82.0 + fav_tw + 14.0 + arrow_shift, fav_ty + 14.0),
|
||||
Vec2::splat(22.0),
|
||||
),
|
||||
pal.text_secondary,
|
||||
);
|
||||
ctx.draw_text_ellipsis(
|
||||
&t.count_tracks(app.liked_tracks.len()),
|
||||
TextStyle::medium(14.0, pal.text_secondary),
|
||||
Rect::from_xywh(r1.left() + 82.0, r1.top() + 42.0, (r1.width() - 160.0).max(60.0), 20.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
// Right 58x58 mini-cover = LAST LIKED TRACK's cover (`liked_tracks.first()`)!
|
||||
let mini1 = Rect::from_xywh(r1.right() - 70.0, r1.top() + 12.0, 58.0, 58.0);
|
||||
let fav_mini_uri = app
|
||||
.liked_tracks
|
||||
.first()
|
||||
.and_then(|tr| tr.cover_uri.clone());
|
||||
draw_cover_art(
|
||||
ctx,
|
||||
pal,
|
||||
covers,
|
||||
mini1,
|
||||
fav_mini_uri.as_deref(),
|
||||
"fav_mini",
|
||||
6.0,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
if resp1.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
if resp1.clicked {
|
||||
actions.push(AppAction::Navigate(Route::LikedTracks));
|
||||
}
|
||||
|
||||
// Card B: History > (navigates to Collection -> History tab!)
|
||||
let r2 = Rect::from_xywh(r1.right() + card_gap, y, half_w, 82.0);
|
||||
let resp2 = ctx.interact(WidgetId::new("fy_quick_history"), r2);
|
||||
ctx.dl().push_rect(
|
||||
r2,
|
||||
12.0,
|
||||
if resp2.hovered {
|
||||
pal.surface_hover
|
||||
} else {
|
||||
pal.surface_secondary
|
||||
},
|
||||
);
|
||||
let hist_box = Rect::from_xywh(r2.left() + 12.0, r2.top() + 12.0, 58.0, 58.0);
|
||||
let hist_box_bg = if pal.is_dark {
|
||||
css_rgba(255, 255, 255, 14)
|
||||
} else {
|
||||
pal.surface_hover
|
||||
};
|
||||
ctx.dl().push_rect(hist_box, 8.0, hist_box_bg);
|
||||
ctx.draw_icon(
|
||||
Icon::History,
|
||||
Rect::from_center_size(hist_box.center(), Vec2::splat(32.0)),
|
||||
pal.text_primary,
|
||||
);
|
||||
let hist_title = t.history();
|
||||
let hist_tw = ctx
|
||||
.measure_text(hist_title, TextStyle::headline(24.0, pal.text_primary), None)
|
||||
.x
|
||||
.min((r2.width() - 180.0).max(80.0));
|
||||
let hist_ty = r2.top() + 14.0;
|
||||
ctx.draw_text_ellipsis(
|
||||
hist_title,
|
||||
TextStyle::headline(24.0, pal.text_primary),
|
||||
Rect::from_xywh(r2.left() + 82.0, hist_ty, hist_tw + 4.0, 28.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
let h_shift = if resp2.hovered { 5.0 } else { 0.0 };
|
||||
ctx.draw_icon(
|
||||
Icon::ArrowRight,
|
||||
Rect::from_center_size(
|
||||
Pos2::new(r2.left() + 82.0 + hist_tw + 14.0 + h_shift, hist_ty + 14.0),
|
||||
Vec2::splat(22.0),
|
||||
),
|
||||
pal.text_secondary,
|
||||
);
|
||||
let hist_sub = if app.play_history.is_empty() {
|
||||
if ru {
|
||||
"Недавно прослушанные треки".into()
|
||||
} else {
|
||||
"Recently played tracks".into()
|
||||
}
|
||||
} else {
|
||||
app.play_history
|
||||
.iter()
|
||||
.take(3)
|
||||
.map(|tr| tr.artists_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
};
|
||||
ctx.draw_text_ellipsis(
|
||||
&hist_sub,
|
||||
TextStyle::medium(14.0, pal.text_secondary),
|
||||
Rect::from_xywh(r2.left() + 82.0, r2.top() + 42.0, (r2.width() - 160.0).max(60.0), 20.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
let mini2 = Rect::from_xywh(r2.right() - 70.0, r2.top() + 12.0, 58.0, 58.0);
|
||||
let hist_mini_uri = app
|
||||
.play_history
|
||||
.first()
|
||||
.and_then(|tr| tr.cover_uri.clone());
|
||||
draw_cover_art(
|
||||
ctx,
|
||||
pal,
|
||||
covers,
|
||||
mini2,
|
||||
hist_mini_uri.as_deref(),
|
||||
"hist_mini",
|
||||
6.0,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
if resp2.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
if resp2.clicked {
|
||||
actions.push(AppAction::NavigateCollectionTab(CollectionTab::History));
|
||||
}
|
||||
y += 82.0 + 35.0;
|
||||
|
||||
// 3. "Recommended by the Artist" / Trending Promo Cards (`artist_promo_card`)
|
||||
if !app.landing.chart_tracks.is_empty() {
|
||||
ctx.draw_text_ellipsis(
|
||||
t.recommended_by_artist(),
|
||||
TextStyle::headline(24.0, pal.text_primary),
|
||||
Rect::from_xywh(x, y, avail_w, 30.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
y += 47.0;
|
||||
|
||||
let cols = 3usize;
|
||||
let promo_gap = 16.0;
|
||||
let promo_w = ((avail_w - promo_gap * (cols as f32 - 1.0)) / cols as f32).max(210.0);
|
||||
let banner_h = 215.0;
|
||||
let card_h = banner_h + 50.0;
|
||||
|
||||
let chart_tracks = app.landing.chart_tracks.clone();
|
||||
for (i, tr) in chart_tracks.iter().take(3).enumerate() {
|
||||
let cx = x + i as f32 * (promo_w + promo_gap);
|
||||
let card_r = Rect::from_xywh(cx, y, promo_w, card_h);
|
||||
let distinct_artist_photo = tr
|
||||
.artists
|
||||
.first()
|
||||
.and_then(|a| a.cover_uri.as_deref());
|
||||
let artist_photo = distinct_artist_photo.or(tr.cover_uri.as_deref());
|
||||
// Always render 80x80 release cover in bottom-left even when artist photo is missing!
|
||||
let album_cov = tr.cover_uri.as_deref();
|
||||
let tr_playing =
|
||||
is_playing && current_track_id.as_deref() == Some(tr.id.as_str());
|
||||
let res = artist_promo_card(
|
||||
ctx,
|
||||
pal,
|
||||
covers,
|
||||
WidgetId::from_pair("fy_promo", &tr.id),
|
||||
card_r,
|
||||
banner_h,
|
||||
&tr.title,
|
||||
&tr.artists_string(),
|
||||
t.listen(),
|
||||
artist_photo,
|
||||
album_cov,
|
||||
tr.is_explicit,
|
||||
tr_playing,
|
||||
&format!("promo_{}", tr.id),
|
||||
);
|
||||
if res.listen_clicked {
|
||||
if tr_playing {
|
||||
actions.push(AppAction::TogglePlay);
|
||||
} else {
|
||||
actions.push(AppAction::PlayTracks {
|
||||
tracks: chart_tracks.clone(),
|
||||
start_index: i,
|
||||
context_name: t.chart().into(),
|
||||
context_key: "chart".into(),
|
||||
is_vibe: false,
|
||||
});
|
||||
}
|
||||
} else if res.card_clicked {
|
||||
if let Some(ref aid) = tr.album_id {
|
||||
actions.push(AppAction::Navigate(Route::Album {
|
||||
id: aid.clone(),
|
||||
title: tr
|
||||
.album_title
|
||||
.clone()
|
||||
.unwrap_or_else(|| tr.title.clone()),
|
||||
}));
|
||||
} else {
|
||||
actions.push(AppAction::PlayTracks {
|
||||
tracks: chart_tracks.clone(),
|
||||
start_index: i,
|
||||
context_name: t.chart().into(),
|
||||
context_key: "chart".into(),
|
||||
is_vibe: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
y += card_h + 30.8;
|
||||
}
|
||||
|
||||
// 4. "Made for you" Personal AI Playlists
|
||||
if !app.landing.personal_playlists.is_empty() {
|
||||
ctx.draw_text_ellipsis(
|
||||
t.made_for_you(),
|
||||
TextStyle::headline(24.0, pal.text_primary),
|
||||
Rect::from_xywh(x, y, avail_w, 30.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
y += 40.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("foryou_personal_scroll");
|
||||
let scroll_x = ctx.begin_scroll_h(h_id, row_vp, 0.0);
|
||||
|
||||
let playlists = app.landing.personal_playlists.clone();
|
||||
let mut cx = x - scroll_x;
|
||||
for pl in &playlists {
|
||||
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 = pl.description.as_deref().unwrap_or(t.playlist());
|
||||
let m = media_card(
|
||||
ctx,
|
||||
pal,
|
||||
covers,
|
||||
WidgetId::from_pair("fy_pl", format!("{}_{}", pl.owner_uid, pl.kind)),
|
||||
cr,
|
||||
&pl.title,
|
||||
sub,
|
||||
pl.cover_uri.as_deref(),
|
||||
&format!("pl_{}_{}", pl.owner_uid, pl.kind),
|
||||
false,
|
||||
false,
|
||||
);
|
||||
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;
|
||||
}
|
||||
let total_w = (playlists.len() as f32) * (card_w + 16.0);
|
||||
ctx.end_scroll_h(h_id, pal, total_w, false);
|
||||
y += card_h + 26.0;
|
||||
}
|
||||
|
||||
// 5. "New Releases"
|
||||
if !app.landing.new_releases.is_empty() {
|
||||
y = render_new_releases_carousel(ctx, pal, covers, app, x, y, avail_w, "fy_rel", actions);
|
||||
}
|
||||
}
|
||||
|
||||
ForYouTab::Trends => {
|
||||
// IN-PLACE TRENDS TAB: Chart tracks + New releases + Popular playlists!
|
||||
// 1. Chart Tracks Section (with clickable "Чарт >" heading opening full Chart)
|
||||
if !app.landing.chart_tracks.is_empty() {
|
||||
let head_txt = t.chart();
|
||||
let head_w = ctx
|
||||
.measure_text(head_txt, TextStyle::headline(24.0, pal.text_primary), None)
|
||||
.x
|
||||
+ 32.0;
|
||||
let head_r = Rect::from_xywh(x, y, head_w, 30.0);
|
||||
let head_resp = ctx.interact(WidgetId::new("trends_chart_heading"), head_r);
|
||||
ctx.draw_text_ellipsis(
|
||||
head_txt,
|
||||
TextStyle::headline(
|
||||
24.0,
|
||||
if head_resp.hovered {
|
||||
pal.text_bright
|
||||
} else {
|
||||
pal.text_primary
|
||||
},
|
||||
),
|
||||
head_r,
|
||||
TextAlign::Left,
|
||||
);
|
||||
ctx.draw_icon(
|
||||
Icon::ArrowRight,
|
||||
Rect::from_center_size(
|
||||
Pos2::new(head_r.right() - 12.0, head_r.center_y()),
|
||||
Vec2::splat(22.0),
|
||||
),
|
||||
pal.text_secondary,
|
||||
);
|
||||
if head_resp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
if head_resp.clicked {
|
||||
actions.push(AppAction::Navigate(Route::Chart));
|
||||
}
|
||||
y += 40.0;
|
||||
|
||||
let chart_tracks = app.landing.chart_tracks.clone();
|
||||
let limit = chart_tracks.len().min(10);
|
||||
for (idx, tr) in chart_tracks.iter().take(limit).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("trends_chart_row", &tr.id),
|
||||
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: chart_tracks.clone(),
|
||||
start_index: idx,
|
||||
context_name: t.chart().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 += TRACK_ROW_HEIGHT;
|
||||
}
|
||||
y += 28.0;
|
||||
}
|
||||
|
||||
// 2. New Releases Carousel
|
||||
if !app.landing.new_releases.is_empty() {
|
||||
y = render_new_releases_carousel(
|
||||
ctx,
|
||||
pal,
|
||||
covers,
|
||||
app,
|
||||
x,
|
||||
y,
|
||||
avail_w,
|
||||
"trends_rel",
|
||||
actions,
|
||||
);
|
||||
}
|
||||
|
||||
// 3. Popular Playlists Carousel
|
||||
if !app.landing.popular_playlists.is_empty() {
|
||||
ctx.draw_text_ellipsis(
|
||||
t.popular_playlists(),
|
||||
TextStyle::headline(24.0, pal.text_primary),
|
||||
Rect::from_xywh(x, y, avail_w, 30.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
y += 40.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("trends_pop_pl_scroll");
|
||||
let scroll_x = ctx.begin_scroll_h(h_id, row_vp, 0.0);
|
||||
|
||||
let playlists = app.landing.popular_playlists.clone();
|
||||
let mut cx = x - scroll_x;
|
||||
for pl in &playlists {
|
||||
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 m = media_card(
|
||||
ctx,
|
||||
pal,
|
||||
covers,
|
||||
WidgetId::from_pair("tr_pl", format!("{}_{}", pl.owner_uid, pl.kind)),
|
||||
cr,
|
||||
&pl.title,
|
||||
&pl.owner_name,
|
||||
pl.cover_uri.as_deref(),
|
||||
&format!("trpl_{}_{}", pl.owner_uid, pl.kind),
|
||||
false,
|
||||
false,
|
||||
);
|
||||
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;
|
||||
}
|
||||
let total_w = (playlists.len() as f32) * (card_w + 16.0);
|
||||
ctx.end_scroll_h(h_id, pal, total_w, false);
|
||||
y += card_h + 24.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
y += 20.0;
|
||||
let _ = CornerRadii::ZERO;
|
||||
let total_h = y - (rect.top() - scroll_y);
|
||||
ctx.end_scroll_v(scroll_id, pal, total_h, true);
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn render_new_releases_carousel(
|
||||
ctx: &mut UiContext,
|
||||
pal: &YmPalette,
|
||||
covers: &mut CoverCache,
|
||||
app: &AppState,
|
||||
x: f32,
|
||||
mut y: f32,
|
||||
avail_w: f32,
|
||||
salt: &str,
|
||||
actions: &mut Vec<AppAction>,
|
||||
) -> f32 {
|
||||
let t = app.i18n();
|
||||
ctx.draw_text_ellipsis(
|
||||
t.new_releases(),
|
||||
TextStyle::headline(24.0, pal.text_primary),
|
||||
Rect::from_xywh(x, y, avail_w, 30.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
y += 40.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(salt);
|
||||
let scroll_x = ctx.begin_scroll_h(h_id, row_vp, 0.0);
|
||||
|
||||
let releases = app.landing.new_releases.clone();
|
||||
let mut cx = x - scroll_x;
|
||||
for alb in &releases {
|
||||
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 art = alb
|
||||
.artists
|
||||
.first()
|
||||
.map(|a| a.name.as_str())
|
||||
.unwrap_or(t.album());
|
||||
let m = media_card(
|
||||
ctx,
|
||||
pal,
|
||||
covers,
|
||||
WidgetId::from_pair(salt, &alb.id),
|
||||
cr,
|
||||
&alb.title,
|
||||
art,
|
||||
alb.cover_uri.as_deref(),
|
||||
&format!("alb_{}", alb.id),
|
||||
false,
|
||||
false,
|
||||
);
|
||||
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;
|
||||
}
|
||||
let total_w = (releases.len() as f32) * (card_w + 16.0);
|
||||
ctx.end_scroll_h(h_id, pal, total_w, false);
|
||||
y + card_h + 26.0
|
||||
}
|
||||
673
src/views/mod.rs
Normal file
673
src/views/mod.rs
Normal file
|
|
@ -0,0 +1,673 @@
|
|||
pub mod collection;
|
||||
pub mod detail;
|
||||
pub mod for_you;
|
||||
pub mod my_vibe;
|
||||
pub mod overlays;
|
||||
pub mod player_bar;
|
||||
pub mod podcasts_kids;
|
||||
pub mod search;
|
||||
pub mod settings;
|
||||
pub mod sidebar;
|
||||
pub mod titlebar;
|
||||
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::app::{AppAction, AppState, RightDrawerTab, Route, WindowCommand};
|
||||
use crate::covers::CoverCache;
|
||||
use crate::engine::{
|
||||
copy_to_clipboard, Color, FrameOutput, Key, Pos2, Rect, UiContext, Vec2, WidgetId, YmPalette,
|
||||
CONTENT_RADIUS, LAYOUT_GAP, NAVBAR_COLLAPSED_WIDTH, NAVBAR_FULL_WIDTH, PLAYER_BAR_HEIGHT,
|
||||
TITLEBAR_HEIGHT,
|
||||
};
|
||||
use crate::vulkan::vibe_renderer::VibePushConstants;
|
||||
|
||||
use overlays::{
|
||||
render_delete_playlist_confirm_modal, render_entity_context_menu, render_eq_popover,
|
||||
render_fullscreen_player, render_login_modal, render_playlist_modal, render_right_drawer,
|
||||
render_toast, render_track_context_menu, render_track_detail_modal, render_vibe_settings_modal,
|
||||
ShellUiState, SplashPlayer,
|
||||
};
|
||||
use player_bar::render_player_bar;
|
||||
use sidebar::render_sidebar;
|
||||
use titlebar::render_titlebar;
|
||||
|
||||
/// Top-level pure-Rust Application Shell combining `AppState`, `UiContext`, `CoverCache`,
|
||||
/// `YmPalette`, `ShellUiState`, and the theme-aware `SplashPlayer`.
|
||||
pub struct YandexMusicShell {
|
||||
pub app: AppState,
|
||||
pub ui: UiContext,
|
||||
pub covers: CoverCache,
|
||||
pub palette: YmPalette,
|
||||
pub shell: ShellUiState,
|
||||
pub splash: Option<SplashPlayer>,
|
||||
start_instant: Instant,
|
||||
}
|
||||
|
||||
impl YandexMusicShell {
|
||||
pub fn new(runtime: tokio::runtime::Handle, gpu_name: String) -> Self {
|
||||
let app = AppState::new(runtime.clone(), gpu_name);
|
||||
let palette = YmPalette::from_mode(app.config.theme);
|
||||
let covers = CoverCache::new(app.config.max_cover_cache, runtime);
|
||||
let ui = UiContext::new();
|
||||
|
||||
let skip_splash = std::env::args().any(|a| a == "--no-splash" || a.starts_with("--page="));
|
||||
let splash = if skip_splash {
|
||||
None
|
||||
} else {
|
||||
Some(SplashPlayer::spawn(palette.is_dark))
|
||||
};
|
||||
|
||||
Self {
|
||||
app,
|
||||
ui,
|
||||
covers,
|
||||
palette,
|
||||
shell: ShellUiState::default(),
|
||||
splash,
|
||||
start_instant: Instant::now(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Deterministic offline shell constructor for headless visual parity tests (zero splash).
|
||||
pub fn new_visual_test(app: AppState, covers: CoverCache) -> Self {
|
||||
let palette = YmPalette::from_mode(app.config.theme);
|
||||
Self {
|
||||
app,
|
||||
ui: UiContext::new(),
|
||||
covers,
|
||||
palette,
|
||||
shell: ShellUiState::default(),
|
||||
splash: None,
|
||||
start_instant: Instant::now(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sync_palette(&mut self) {
|
||||
if self.app.theme_dirty {
|
||||
self.palette = YmPalette::from_mode(self.app.config.theme);
|
||||
self.app.theme_dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn window_title(&self) -> &'static str {
|
||||
self.app.i18n().app_name()
|
||||
}
|
||||
|
||||
pub fn is_dark(&self) -> bool {
|
||||
self.palette.is_dark
|
||||
}
|
||||
|
||||
pub fn elapsed_secs(&self) -> f64 {
|
||||
self.start_instant.elapsed().as_secs_f64()
|
||||
}
|
||||
|
||||
pub fn needs_continuous_repaint(&self) -> bool {
|
||||
self.splash.is_some() || self.app.needs_continuous_repaint()
|
||||
}
|
||||
|
||||
pub fn continuous_repaint_interval(&self, window_focused: bool) -> Option<std::time::Duration> {
|
||||
if self.splash.is_some() {
|
||||
return Some(std::time::Duration::from_millis(16));
|
||||
}
|
||||
self.app.continuous_repaint_interval(window_focused)
|
||||
}
|
||||
|
||||
/// Lightweight CPU-only background poll for idle/minimized/hidden states.
|
||||
/// Returns `true` if new API data, decoded covers, or expired toasts require a GPU redraw.
|
||||
pub fn poll_background_events(&mut self) -> bool {
|
||||
let mut dirty = self.app.poll_async_events();
|
||||
if self.app.take_clear_cover_cache_requested() {
|
||||
self.covers.clear(&mut self.ui.textures);
|
||||
dirty = true;
|
||||
}
|
||||
if self.app.take_cover_cache_capacity_dirty() {
|
||||
self.covers.set_capacity(self.app.config.max_cover_cache);
|
||||
}
|
||||
if self.covers.poll_uploads(&mut self.ui.textures) {
|
||||
dirty = true;
|
||||
}
|
||||
if self.app.toast.is_some() && self.app.current_toast().is_none() {
|
||||
dirty = true;
|
||||
}
|
||||
dirty
|
||||
}
|
||||
|
||||
pub fn handle_winit_event(&mut self, event: &winit::event::WindowEvent) -> bool {
|
||||
self.ui.input.handle_winit_event(event)
|
||||
}
|
||||
|
||||
fn current_cover_fallback_rgb(&mut self) -> Option<[u8; 3]> {
|
||||
let uri = self
|
||||
.app
|
||||
.current_track()
|
||||
.and_then(|t| t.cover_uri.as_deref())
|
||||
.map(String::from)?;
|
||||
self.covers
|
||||
.get_or_fetch(&uri, 100)
|
||||
.map(|(_, dom, _)| [dom.r, dom.g, dom.b])
|
||||
}
|
||||
|
||||
pub fn vibe_push_constants(&mut self) -> Option<VibePushConstants> {
|
||||
let fallback_rgb = self.current_cover_fallback_rgb();
|
||||
self.app
|
||||
.vibe_push_constants(self.palette.is_dark, fallback_rgb)
|
||||
}
|
||||
|
||||
/// Render one complete UI frame into a `FrameOutput` (`DisplayList` + `TextureUpload`s + cursor).
|
||||
pub fn render_frame(
|
||||
&mut self,
|
||||
screen_size: Vec2,
|
||||
scale_factor: f32,
|
||||
time: f64,
|
||||
is_maximized: bool,
|
||||
) -> (FrameOutput, WindowCommand) {
|
||||
self.sync_palette();
|
||||
self.app.poll_async_events();
|
||||
|
||||
if self.app.take_clear_cover_cache_requested() {
|
||||
self.covers.clear(&mut self.ui.textures);
|
||||
}
|
||||
if self.app.take_cover_cache_capacity_dirty() {
|
||||
self.covers.set_capacity(self.app.config.max_cover_cache);
|
||||
}
|
||||
let covers_arrived = self.covers.poll_uploads(&mut self.ui.textures);
|
||||
|
||||
let dt = self.app.last_vibe_tick.elapsed().as_secs_f32();
|
||||
self.app.last_vibe_tick = Instant::now();
|
||||
if self.app.fixed_vibe_time.is_none()
|
||||
&& (self.app.has_active_vibe_surface()
|
||||
|| self.app.smooth_playing > 0.001
|
||||
|| self.app.is_audio_playing())
|
||||
{
|
||||
let fallback_rgb = if self.app.has_active_vibe_surface() {
|
||||
self.current_cover_fallback_rgb()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
self.app.tick_vibe_animation(dt, fallback_rgb);
|
||||
}
|
||||
|
||||
self.ui.begin_frame(screen_size, scale_factor, time);
|
||||
if covers_arrived {
|
||||
self.ui.request_repaint();
|
||||
}
|
||||
|
||||
let mut actions: Vec<AppAction> = Vec::with_capacity(8);
|
||||
|
||||
// Global keyboard shortcuts (skipped whenever a text input has focus!)
|
||||
self.collect_keyboard_shortcuts(&mut actions);
|
||||
|
||||
let pal = self.palette;
|
||||
let screen = self.ui.screen_rect();
|
||||
let is_my_vibe_page = matches!(self.app.route, Route::MyVibe);
|
||||
|
||||
// 1. Left Sidebar (full-height, smooth 224px <-> 72px collapse animation)
|
||||
let collapse_t = self.ui.animate_bool(
|
||||
WidgetId::new("ym_sidebar_collapse_anim"),
|
||||
self.app.config.sidebar_collapsed,
|
||||
0.16,
|
||||
);
|
||||
let nav_w = (NAVBAR_FULL_WIDTH * (1.0 - collapse_t)
|
||||
+ NAVBAR_COLLAPSED_WIDTH * collapse_t)
|
||||
.round();
|
||||
let sidebar_rect = Rect::from_xywh(
|
||||
screen.left(),
|
||||
screen.top() + TITLEBAR_HEIGHT,
|
||||
nav_w,
|
||||
(screen.height() - TITLEBAR_HEIGHT).max(0.0),
|
||||
);
|
||||
render_sidebar(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&self.app,
|
||||
&mut self.shell,
|
||||
sidebar_rect,
|
||||
collapse_t,
|
||||
&mut actions,
|
||||
);
|
||||
|
||||
// 2. Bottom PlayerBar (80px height, 12px bottom & right margins; hidden on My Vibe)
|
||||
let player_bar_rect = Rect::from_xywh(
|
||||
nav_w,
|
||||
(screen.bottom() - PLAYER_BAR_HEIGHT - 12.0).max(TITLEBAR_HEIGHT),
|
||||
(screen.width() - nav_w - LAYOUT_GAP).max(200.0),
|
||||
PLAYER_BAR_HEIGHT,
|
||||
);
|
||||
if !is_my_vibe_page {
|
||||
render_player_bar(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&self.app,
|
||||
&mut self.shell,
|
||||
player_bar_rect,
|
||||
&mut actions,
|
||||
);
|
||||
}
|
||||
|
||||
// 3. Optional Right Slide-Over Drawer (Queue / Sync Lyrics; hidden when Fullscreen is open)
|
||||
let show_side_drawer =
|
||||
self.app.right_drawer != RightDrawerTab::None && !self.app.fullscreen_open;
|
||||
let content_bottom = if is_my_vibe_page {
|
||||
screen.bottom()
|
||||
} else {
|
||||
(player_bar_rect.top() - LAYOUT_GAP).max(TITLEBAR_HEIGHT + 40.0)
|
||||
};
|
||||
let drawer_w = 332.0;
|
||||
let content_top = screen.top() + TITLEBAR_HEIGHT + 1.0;
|
||||
let drawer_rect = Rect::from_xywh(
|
||||
screen.right() - drawer_w - LAYOUT_GAP,
|
||||
content_top,
|
||||
drawer_w,
|
||||
(content_bottom - content_top).max(40.0),
|
||||
);
|
||||
if show_side_drawer {
|
||||
render_right_drawer(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&self.app,
|
||||
&mut self.shell,
|
||||
drawer_rect,
|
||||
&mut actions,
|
||||
);
|
||||
}
|
||||
|
||||
// 4. Main Content Area (Full-bleed on My Vibe; Rounded 16px `pal.bg_content` card on all other pages!)
|
||||
if is_my_vibe_page {
|
||||
let vibe_rect = Rect::from_xywh(
|
||||
nav_w,
|
||||
screen.top(),
|
||||
(screen.width() - nav_w - if show_side_drawer { drawer_w + LAYOUT_GAP * 2.0 } else { 0.0 })
|
||||
.max(100.0),
|
||||
screen.height(),
|
||||
);
|
||||
my_vibe::render_my_vibe(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&mut self.app,
|
||||
&mut self.shell,
|
||||
vibe_rect,
|
||||
&mut actions,
|
||||
);
|
||||
} else {
|
||||
let content_right = if show_side_drawer {
|
||||
drawer_rect.left() - LAYOUT_GAP
|
||||
} else {
|
||||
screen.right() - LAYOUT_GAP
|
||||
};
|
||||
let outer_r = Rect::from_min_max(
|
||||
Pos2::new(nav_w, content_top),
|
||||
Pos2::new(content_right.max(nav_w + 120.0), content_bottom),
|
||||
);
|
||||
|
||||
// Base rounded content card
|
||||
self.ui.dl().push_rect(outer_r, CONTENT_RADIUS, pal.bg_content);
|
||||
|
||||
// Edge-to-edge top atmospheric gradient wash on Detail pages (clipped cleanly by SDF rounded rect!)
|
||||
let is_detail_page = matches!(
|
||||
self.app.route,
|
||||
Route::LikedTracks
|
||||
| Route::Playlist { .. }
|
||||
| Route::Album { .. }
|
||||
| Route::Artist { .. }
|
||||
);
|
||||
if is_detail_page {
|
||||
let wash_h = 340.0f32.min(outer_r.height());
|
||||
let wash_r = Rect::from_xywh(outer_r.left(), outer_r.top(), outer_r.width(), wash_h);
|
||||
let wash_top = if pal.is_dark {
|
||||
Color::rgb(61, 61, 61)
|
||||
} else {
|
||||
Color::rgb(235, 235, 235)
|
||||
};
|
||||
self.ui.push_clip(outer_r, CONTENT_RADIUS);
|
||||
self.ui.dl().push_gradient_rect(
|
||||
wash_r,
|
||||
0.0,
|
||||
wash_top,
|
||||
pal.bg_content,
|
||||
Vec2::new(0.0, 1.0),
|
||||
);
|
||||
self.ui.pop_clip();
|
||||
}
|
||||
|
||||
// 1px subtle border
|
||||
self.ui.dl().push_rect_bordered(
|
||||
outer_r,
|
||||
CONTENT_RADIUS,
|
||||
Color::TRANSPARENT,
|
||||
1.0,
|
||||
pal.border_subtle,
|
||||
);
|
||||
|
||||
// Exact inner content rect (+25px horizontal, +12px top so inner y stays 45.0 with +1px card_top)
|
||||
let inner_r = outer_r.inset(25.0, 12.0, 25.0, 0.0);
|
||||
self.ui.push_clip(outer_r, CONTENT_RADIUS);
|
||||
match self.app.route.clone() {
|
||||
Route::MyVibe => {}
|
||||
Route::ForYou => for_you::render_for_you(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&mut self.app,
|
||||
&mut self.shell,
|
||||
inner_r,
|
||||
&mut actions,
|
||||
),
|
||||
Route::Search => search::render_search(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&mut self.app,
|
||||
&mut self.shell,
|
||||
inner_r,
|
||||
&mut actions,
|
||||
),
|
||||
Route::Collection => collection::render_collection(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&mut self.app,
|
||||
&mut self.shell,
|
||||
inner_r,
|
||||
&mut actions,
|
||||
),
|
||||
Route::LikedTracks
|
||||
| Route::Playlist { .. }
|
||||
| Route::Album { .. }
|
||||
| Route::Artist { .. } => detail::render_detail(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&mut self.app,
|
||||
&mut self.shell,
|
||||
inner_r,
|
||||
&mut actions,
|
||||
),
|
||||
Route::Podcasts => podcasts_kids::render_podcasts(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&mut self.app,
|
||||
&mut self.shell,
|
||||
inner_r,
|
||||
&mut actions,
|
||||
),
|
||||
Route::Kids => podcasts_kids::render_kids(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&mut self.app,
|
||||
&mut self.shell,
|
||||
inner_r,
|
||||
&mut actions,
|
||||
),
|
||||
Route::Concerts => podcasts_kids::render_concerts(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&mut self.app,
|
||||
&mut self.shell,
|
||||
inner_r,
|
||||
&mut actions,
|
||||
),
|
||||
Route::Chart => podcasts_kids::render_chart(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&mut self.app,
|
||||
&mut self.shell,
|
||||
inner_r,
|
||||
&mut actions,
|
||||
),
|
||||
Route::Metatags => podcasts_kids::render_metatags(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&mut self.app,
|
||||
&mut self.shell,
|
||||
inner_r,
|
||||
&mut actions,
|
||||
),
|
||||
Route::Metatag { .. } => podcasts_kids::render_metatag_detail(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&mut self.app,
|
||||
&mut self.shell,
|
||||
inner_r,
|
||||
&mut actions,
|
||||
),
|
||||
Route::Settings => settings::render_settings(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&mut self.app,
|
||||
&mut self.shell,
|
||||
inner_r,
|
||||
&mut actions,
|
||||
),
|
||||
}
|
||||
self.ui.pop_clip();
|
||||
}
|
||||
|
||||
// 5. FullscreenPlayerDesktop (ZLayer::Drawer — sits below Popovers/Modals/Titlebar!)
|
||||
if self.app.fullscreen_open {
|
||||
render_fullscreen_player(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&mut self.covers,
|
||||
&self.app,
|
||||
&mut self.shell,
|
||||
&mut actions,
|
||||
);
|
||||
}
|
||||
|
||||
// 6. Floating Popovers & Context Menus (ZLayer::Popover)
|
||||
if self.app.eq_popover_open {
|
||||
render_eq_popover(&mut self.ui, &pal, &self.app, &mut actions);
|
||||
}
|
||||
render_track_context_menu(&mut self.ui, &pal, &self.app, &mut self.shell, &mut actions);
|
||||
render_entity_context_menu(&mut self.ui, &pal, &self.app, &mut self.shell, &mut actions);
|
||||
|
||||
// 7. Modals (ZLayer::Modal)
|
||||
if self.app.vibe_modal_open {
|
||||
render_vibe_settings_modal(&mut self.ui, &pal, &self.app, &mut actions);
|
||||
}
|
||||
render_playlist_modal(&mut self.ui, &pal, &mut self.app, &mut actions);
|
||||
render_delete_playlist_confirm_modal(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&self.app,
|
||||
&mut self.shell,
|
||||
&mut actions,
|
||||
);
|
||||
if self.app.login_modal_open {
|
||||
render_login_modal(&mut self.ui, &pal, &mut self.app, &mut actions);
|
||||
}
|
||||
if self.app.track_detail_modal.is_some() {
|
||||
render_track_detail_modal(&mut self.ui, &pal, &mut self.covers, &self.app, &mut actions);
|
||||
}
|
||||
|
||||
// 8. Transparent 32px Floating TitleBar (ZLayer::Titlebar)
|
||||
let win_cmd = render_titlebar(
|
||||
&mut self.ui,
|
||||
&pal,
|
||||
&self.app,
|
||||
is_maximized,
|
||||
self.app.fullscreen_open,
|
||||
);
|
||||
|
||||
// 9. Floating Toast (when splash is done)
|
||||
if self.splash.is_none() {
|
||||
if let Some(msg) = self.app.current_toast().map(String::from) {
|
||||
render_toast(&mut self.ui, &pal, &msg);
|
||||
}
|
||||
}
|
||||
|
||||
// 10. Theme-Aware Streaming Animated Splash Screen (`splash_dark.webp` / `splash_light.webp`)
|
||||
if let Some(ref mut sp) = self.splash {
|
||||
if sp.render(&mut self.ui) {
|
||||
self.splash = None;
|
||||
}
|
||||
}
|
||||
|
||||
// Dispatch all actions emitted during this frame
|
||||
for act in actions {
|
||||
self.app.dispatch(act);
|
||||
}
|
||||
|
||||
// Flush any clipboard write requested by Share > Copy link / HTML code
|
||||
if let Some(clip_text) = self.app.take_pending_clipboard_text() {
|
||||
let _ = copy_to_clipboard(&clip_text);
|
||||
}
|
||||
|
||||
// Refresh palette immediately if theme changed this frame
|
||||
self.sync_palette();
|
||||
|
||||
let output = self.ui.end_frame(&self.palette);
|
||||
(output, win_cmd)
|
||||
}
|
||||
|
||||
/// Exact Yandex Music Desktop 5.129.0 global keyboard shortcuts (disabled while typing in a text input).
|
||||
fn collect_keyboard_shortcuts(&mut self, actions: &mut Vec<AppAction>) {
|
||||
// OS Media keys always work regardless of text focus
|
||||
if self.ui.input.key_pressed(Key::MediaPlayPause) {
|
||||
actions.push(AppAction::TogglePlay);
|
||||
}
|
||||
if self.ui.input.key_pressed(Key::MediaNext) {
|
||||
actions.push(AppAction::Next);
|
||||
}
|
||||
if self.ui.input.key_pressed(Key::MediaPrev) {
|
||||
actions.push(AppAction::Prev);
|
||||
}
|
||||
if self.ui.input.key_pressed(Key::MediaStop) {
|
||||
actions.push(AppAction::Stop);
|
||||
}
|
||||
|
||||
if self.ui.input.key_pressed(Key::Escape) {
|
||||
self.shell.close_all_menus();
|
||||
self.shell.confirm_delete_playlist = None;
|
||||
actions.push(AppAction::DismissOverlays);
|
||||
}
|
||||
|
||||
if self.ui.input.has_text_focus() {
|
||||
return;
|
||||
}
|
||||
|
||||
let inp = &self.ui.input;
|
||||
let key_any = |chars: &[char]| -> bool {
|
||||
chars.iter().any(|&c| {
|
||||
inp.key_pressed_no_mods(Key::Char(c))
|
||||
|| c.to_uppercase()
|
||||
.next()
|
||||
.map_or(false, |u| inp.key_pressed_no_mods(Key::Char(u)))
|
||||
})
|
||||
};
|
||||
let ctrl_any = |chars: &[char]| -> bool {
|
||||
inp.key_events.iter().any(|e| {
|
||||
e.modifiers.command()
|
||||
&& !e.modifiers.shift
|
||||
&& !e.modifiers.alt
|
||||
&& matches!(e.key, Key::Char(c) if chars.iter().any(|&t| {
|
||||
c == t || c.to_lowercase().next() == Some(t)
|
||||
}))
|
||||
})
|
||||
};
|
||||
|
||||
// K / л / Space -> Play / Pause
|
||||
if inp.key_pressed_no_mods(Key::Space) || key_any(&['k', 'л']) {
|
||||
actions.push(AppAction::TogglePlay);
|
||||
}
|
||||
|
||||
// M / ь -> Mute
|
||||
if key_any(&['m', 'ь']) {
|
||||
actions.push(AppAction::ToggleMute);
|
||||
}
|
||||
|
||||
// Volume ±5%
|
||||
if inp.key_pressed_no_mods(Key::ArrowUp) {
|
||||
actions.push(AppAction::SetVolume((self.app.config.volume + 0.05).clamp(0.0, 1.0)));
|
||||
}
|
||||
if inp.key_pressed_no_mods(Key::ArrowDown) {
|
||||
actions.push(AppAction::SetVolume((self.app.config.volume - 0.05).clamp(0.0, 1.0)));
|
||||
}
|
||||
|
||||
// Seek ±2s (ArrowLeft / J / о, ArrowRight / L / д)
|
||||
if inp.key_pressed_no_mods(Key::ArrowRight) || key_any(&['l', 'д']) {
|
||||
let target = (self.app.position_ms() + 2000).min(self.app.duration_ms());
|
||||
actions.push(AppAction::SeekMs(target));
|
||||
}
|
||||
if inp.key_pressed_no_mods(Key::ArrowLeft) || key_any(&['j', 'о']) {
|
||||
let target = self.app.position_ms().saturating_sub(2000);
|
||||
actions.push(AppAction::SeekMs(target));
|
||||
}
|
||||
|
||||
// Next / Prev (N/т, P/з or Ctrl+ArrowRight/Left)
|
||||
let ctrl_right = inp
|
||||
.key_events
|
||||
.iter()
|
||||
.any(|e| e.key == Key::ArrowRight && e.modifiers.command());
|
||||
let ctrl_left = inp
|
||||
.key_events
|
||||
.iter()
|
||||
.any(|e| e.key == Key::ArrowLeft && e.modifiers.command());
|
||||
if ctrl_right || key_any(&['n', 'т']) {
|
||||
actions.push(AppAction::Next);
|
||||
}
|
||||
if ctrl_left || key_any(&['p', 'з']) {
|
||||
actions.push(AppAction::Prev);
|
||||
}
|
||||
|
||||
// Like (F / а) & Dislike (D / в)
|
||||
if key_any(&['f', 'а']) {
|
||||
if let Some(tr) = self.app.current_track().cloned() {
|
||||
actions.push(AppAction::ToggleLike(tr));
|
||||
}
|
||||
}
|
||||
if key_any(&['d', 'в']) {
|
||||
if let Some(tr) = self.app.current_track().cloned() {
|
||||
actions.push(AppAction::ToggleDislike(tr));
|
||||
}
|
||||
}
|
||||
|
||||
// Repeat (R / к), Shuffle (S / ы), Fullscreen (W / ц)
|
||||
if key_any(&['r', 'к']) {
|
||||
actions.push(AppAction::CycleRepeat);
|
||||
}
|
||||
if key_any(&['s', 'ы']) {
|
||||
actions.push(AppAction::ToggleShuffle);
|
||||
}
|
||||
if key_any(&['w', 'ц']) {
|
||||
actions.push(AppAction::ToggleFullscreen);
|
||||
}
|
||||
|
||||
// Ctrl+F / Ctrl+а -> Search, Ctrl+L / Ctrl+д -> Lyrics, Alt+Left/Right -> Nav History
|
||||
if ctrl_any(&['f', 'а']) {
|
||||
actions.push(AppAction::Navigate(Route::Search));
|
||||
}
|
||||
if ctrl_any(&['l', 'д']) {
|
||||
if self.app.fullscreen_open && self.app.fullscreen_lyrics_open {
|
||||
actions.push(AppAction::ToggleFullscreenLyrics);
|
||||
} else {
|
||||
actions.push(AppAction::OpenFullscreenSyncLyrics);
|
||||
}
|
||||
}
|
||||
let alt_left = inp
|
||||
.key_events
|
||||
.iter()
|
||||
.any(|e| e.key == Key::ArrowLeft && e.modifiers.alt);
|
||||
let alt_right = inp
|
||||
.key_events
|
||||
.iter()
|
||||
.any(|e| e.key == Key::ArrowRight && e.modifiers.alt);
|
||||
if alt_left {
|
||||
actions.push(AppAction::GoBack);
|
||||
}
|
||||
if alt_right {
|
||||
actions.push(AppAction::GoForward);
|
||||
}
|
||||
}
|
||||
}
|
||||
1938
src/views/my_vibe.rs
Normal file
1938
src/views/my_vibe.rs
Normal file
File diff suppressed because it is too large
Load diff
3774
src/views/overlays.rs
Normal file
3774
src/views/overlays.rs
Normal file
File diff suppressed because it is too large
Load diff
673
src/views/player_bar.rs
Normal file
673
src/views/player_bar.rs
Normal file
|
|
@ -0,0 +1,673 @@
|
|||
use crate::api::models::format_ms;
|
||||
use crate::app::{AppAction, AppState, RepeatMode, Route};
|
||||
use crate::covers::CoverCache;
|
||||
use crate::engine::widgets::{draw_cover_art, separated_artists, ym_volume_capsule};
|
||||
use crate::engine::{
|
||||
css_rgba, Color, CursorKind, Pos2, Rect, RichSpan, TextAlign, TextStyle, UiContext, Vec2,
|
||||
WidgetId, YmPalette, ZLayer,
|
||||
};
|
||||
use crate::icons::Icon;
|
||||
use crate::views::overlays::ShellUiState;
|
||||
|
||||
/// Exact Yandex Music Desktop 5.129.0 Bottom PlayerBar (`PlayerBarDesktopWithBackgroundProgressBar`):
|
||||
/// - Exact 80px height, `hsl(h, s%, 20%)` track-derived bg (or `pal.bg_player`) in BOTH themes
|
||||
/// - Subtle played split fill + hover top 4px yellow progress bar + 12px thumb + timecode pills
|
||||
/// - Clickable cover (hover scrim + Fullscreen), clickable title (opens album),
|
||||
/// individually clickable multi-artists (`SeparatedArtists`), full `•••` TrackContextMenu
|
||||
/// - Disabled visual states: Shuffle muted (`hsla(0,0%,100%,.08)`) & non-clickable when `is_vibe_active`;
|
||||
/// Lyrics muted (`#4D4D4D`) & non-clickable when `!track.has_lyrics`
|
||||
/// - Right-side `44×216` vertical hover volume popover with real Kawase blur & 1% wheel step
|
||||
pub fn render_player_bar(
|
||||
ctx: &mut UiContext,
|
||||
pal: &YmPalette,
|
||||
covers: &mut CoverCache,
|
||||
app: &AppState,
|
||||
shell: &mut ShellUiState,
|
||||
rect: Rect,
|
||||
actions: &mut Vec<AppAction>,
|
||||
) {
|
||||
let i18n = app.i18n();
|
||||
let current_track = app.current_track();
|
||||
let is_playing = app.is_audio_playing();
|
||||
let is_buffering = app.is_buffering();
|
||||
let position_ms = app.position_ms();
|
||||
let duration_ms = app.duration_ms();
|
||||
let volume = app.config.volume;
|
||||
let muted = app.config.muted;
|
||||
let is_vibe_active = app.is_vibe_active;
|
||||
|
||||
let is_liked = current_track.map_or(false, |t| app.liked_ids.contains(&t.id));
|
||||
let is_disliked = current_track.map_or(false, |t| app.disliked_ids.contains(&t.id));
|
||||
let has_lyrics = current_track.map_or(false, |t| {
|
||||
t.has_lyrics
|
||||
|| app
|
||||
.current_lyrics
|
||||
.as_ref()
|
||||
.map_or(false, |l| l.track_id == t.id && !l.lines.is_empty())
|
||||
});
|
||||
|
||||
let progress = if duration_ms > 0 {
|
||||
(position_ms as f32 / duration_ms as f32).clamp(0.0, 1.0)
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
// 1. Exact 5.129.0 `--player-average-color-background`: `hsl(h, s%, 20%)` in BOTH dark & light themes!
|
||||
// Falls back to `pal.bg_player` (`#141414` dark / `#999999` light) when idle.
|
||||
let track_rgb = current_track.and_then(|tr| {
|
||||
tr.derived_average_hex
|
||||
.as_deref()
|
||||
.and_then(Color::from_hex_str)
|
||||
.or_else(|| tr.derived_accent_hex.as_deref().and_then(Color::from_hex_str))
|
||||
.or_else(|| {
|
||||
tr.cover_uri
|
||||
.as_deref()
|
||||
.and_then(|u| covers.get_or_fetch(u, 100))
|
||||
.map(|(_, dom, _)| dom)
|
||||
})
|
||||
});
|
||||
let base_bg = pal.player_bar_bg(track_rgb);
|
||||
|
||||
// Player bar controls always sit on a dark/mid-grey surface (`hsl(..., 20%)`, `#141414`, or `#999`),
|
||||
// so foreground uses official `--ym-controls-color-secondary-text-*` tokens (light/white in both themes).
|
||||
let fg_bright = Color::WHITE;
|
||||
let fg_muted = css_rgba(255, 255, 255, 148);
|
||||
let fg_disabled_shuffle = if pal.is_dark {
|
||||
css_rgba(255, 255, 255, 20) // hsla(0,0%,100%,.08)
|
||||
} else {
|
||||
css_rgba(255, 255, 255, 26) // hsla(0,0%,100%,.10)
|
||||
};
|
||||
let fg_disabled_lyrics = if pal.is_dark {
|
||||
Color::rgb(0x4D, 0x4D, 0x4D)
|
||||
} else {
|
||||
css_rgba(255, 255, 255, 72)
|
||||
};
|
||||
let btn_hover_bg = css_rgba(255, 255, 255, 31);
|
||||
|
||||
ctx.dl().push_rect(rect, 12.0, base_bg);
|
||||
|
||||
// 2. Top-edge 4px yellow progress bar + 12px thumb + hover timecode pills
|
||||
let bar_hover_zone = rect.expand2(Vec2::new(0.0, 6.0));
|
||||
let bar_hovered = ctx.is_hovered(bar_hover_zone);
|
||||
let scrub_zone = Rect::from_min_max(
|
||||
Pos2::new(rect.left() + 8.0, rect.top() - 6.0),
|
||||
Pos2::new(rect.right() - 8.0, rect.top() + 12.0),
|
||||
);
|
||||
let scrub_resp = ctx.interact(WidgetId::new("pb_top_scrub"), scrub_zone);
|
||||
|
||||
// Smooth drag seeking: preview drag position locally and dispatch SeekFraction ONLY on release/click!
|
||||
if scrub_resp.pressed || scrub_resp.dragged {
|
||||
if let Some(pos) = ctx.input.pointer_pos {
|
||||
let frac = ((pos.x - scrub_zone.left()) / scrub_zone.width().max(1.0)).clamp(0.0, 1.0);
|
||||
shell.pb_scrub_frac = Some(frac);
|
||||
}
|
||||
}
|
||||
if let Some(frac) = shell.pb_scrub_frac {
|
||||
if !ctx.input.left_down || scrub_resp.drag_stopped || scrub_resp.clicked {
|
||||
let commit_frac = ctx
|
||||
.input
|
||||
.pointer_pos
|
||||
.map(|pos| ((pos.x - scrub_zone.left()) / scrub_zone.width().max(1.0)).clamp(0.0, 1.0))
|
||||
.unwrap_or(frac);
|
||||
actions.push(AppAction::SeekFraction(commit_frac));
|
||||
shell.pb_scrub_frac = None;
|
||||
}
|
||||
} else if scrub_resp.clicked {
|
||||
if let Some(pos) = ctx.input.pointer_pos {
|
||||
let frac = ((pos.x - scrub_zone.left()) / scrub_zone.width().max(1.0)).clamp(0.0, 1.0);
|
||||
actions.push(AppAction::SeekFraction(frac));
|
||||
}
|
||||
}
|
||||
|
||||
let display_progress = shell.pb_scrub_frac.unwrap_or(progress);
|
||||
|
||||
// Subtle played split overlay clipped to left progress fraction (exact 5.129.0 `rgba(255,255,255,0.051)`)
|
||||
let prog_x = rect.left() + rect.width() * display_progress;
|
||||
if display_progress > 0.002 {
|
||||
let clip_played = Rect::from_min_max(rect.min(), Pos2::new(prog_x, rect.bottom()));
|
||||
ctx.dl().push_clip(clip_played, 0.0);
|
||||
ctx.dl().push_rect(rect, 12.0, css_rgba(255, 255, 255, 13));
|
||||
ctx.dl().pop_clip();
|
||||
}
|
||||
ctx.dl()
|
||||
.push_rect_bordered(rect, 12.0, Color::TRANSPARENT, 1.0, pal.border_subtle);
|
||||
|
||||
let scrub_active =
|
||||
scrub_resp.hovered || scrub_resp.pressed || scrub_resp.dragged || shell.pb_scrub_frac.is_some();
|
||||
let hover_t = ctx.animate_bool(WidgetId::new("pb_scrub_hover_anim"), bar_hovered || scrub_active, 0.15);
|
||||
|
||||
if hover_t > 0.01 {
|
||||
let display_frac = display_progress;
|
||||
|
||||
ctx.with_layer(ZLayer::Popover, |ctx| {
|
||||
let bar_y = rect.top() + 2.0;
|
||||
let bar_r = Rect::from_min_max(
|
||||
Pos2::new(scrub_zone.left(), bar_y - 2.0),
|
||||
Pos2::new(scrub_zone.right(), bar_y + 2.0),
|
||||
);
|
||||
ctx.dl()
|
||||
.push_rect(bar_r, 2.0, css_rgba(255, 255, 255, (38.0 * hover_t).round() as u8));
|
||||
|
||||
let fill_x = scrub_zone.left() + scrub_zone.width() * display_frac;
|
||||
let fill_r = Rect::from_min_max(bar_r.min(), Pos2::new(fill_x, bar_r.bottom()));
|
||||
let yellow_a = pal.yellow.with_alpha_f32(hover_t);
|
||||
ctx.dl().push_rect(fill_r, 2.0, yellow_a);
|
||||
|
||||
// Exact 12px circular yellow thumb (`radius = 6px`)
|
||||
ctx.dl()
|
||||
.push_circle(Pos2::new(fill_x, bar_y), 6.0 * hover_t, yellow_a);
|
||||
|
||||
// Left & right timecode pills
|
||||
let cur_ms = (display_frac * duration_ms as f32) as u64;
|
||||
let tc_bg = css_rgba(20, 20, 20, (215.0 * hover_t).round() as u8);
|
||||
let tc_fg = Color::rgb(0xE6, 0xE6, 0xE6).with_alpha_f32(hover_t);
|
||||
|
||||
let left_tc_r = Rect::from_xywh(rect.left() + 8.0, rect.top() - 24.0, 44.0, 18.0);
|
||||
ctx.dl().push_rect(left_tc_r, 9.0, tc_bg);
|
||||
ctx.draw_text_ellipsis(
|
||||
&format_ms(cur_ms),
|
||||
TextStyle::medium(11.0, tc_fg),
|
||||
left_tc_r,
|
||||
TextAlign::Center,
|
||||
);
|
||||
|
||||
let right_tc_r = Rect::from_xywh(rect.right() - 52.0, rect.top() - 24.0, 44.0, 18.0);
|
||||
ctx.dl().push_rect(right_tc_r, 9.0, tc_bg);
|
||||
ctx.draw_text_ellipsis(
|
||||
&format_ms(duration_ms),
|
||||
TextStyle::medium(11.0, tc_fg),
|
||||
right_tc_r,
|
||||
TextAlign::Center,
|
||||
);
|
||||
|
||||
// Hover seek cursor timecode tooltip
|
||||
if scrub_active {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
if let Some(pos) = ctx.input.pointer_pos {
|
||||
let frac = ((pos.x - scrub_zone.left()) / scrub_zone.width().max(1.0)).clamp(0.0, 1.0);
|
||||
let hover_ms = (frac * duration_ms as f32) as u64;
|
||||
let tip_x = pos.x.clamp(rect.left() + 78.0, (rect.right() - 78.0).max(rect.left() + 78.0));
|
||||
let tip_r = Rect::from_center_size(Pos2::new(tip_x, rect.top() - 18.0), Vec2::new(50.0, 22.0));
|
||||
ctx.dl().push_rect(tip_r, 11.0, css_rgba(20, 20, 20, 230));
|
||||
ctx.draw_text_ellipsis(
|
||||
&format_ms(hover_ms),
|
||||
TextStyle::medium(12.0, Color::WHITE),
|
||||
tip_r,
|
||||
TextAlign::Center,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let cy = rect.center_y();
|
||||
let cx = rect.center_x() - 12.0;
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
// LEFT: 64×64 Cover + Clickable Title + Explicit + `•••` TrackContextMenu + SeparatedArtists
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
let left_max_x = (cx - 182.0).max(rect.left() + 140.0);
|
||||
if let Some(track) = current_track {
|
||||
let cover_rect = Rect::from_xywh(rect.left() + 8.0, cy - 32.0, 64.0, 64.0);
|
||||
draw_cover_art(
|
||||
ctx,
|
||||
pal,
|
||||
covers,
|
||||
cover_rect,
|
||||
track.cover_uri.as_deref(),
|
||||
&track.id,
|
||||
6.0,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
let cov_resp = ctx.interact(WidgetId::new("pb_cover"), cover_rect);
|
||||
if cov_resp.hovered {
|
||||
ctx.dl().push_rect(cover_rect, 6.0, css_rgba(0, 0, 0, 128));
|
||||
ctx.dl()
|
||||
.push_circle(cover_rect.center(), 22.0, css_rgba(26, 26, 26, 230));
|
||||
ctx.draw_icon(
|
||||
Icon::Fullscreen,
|
||||
Rect::from_center_size(cover_rect.center(), Vec2::splat(24.0)),
|
||||
Color::WHITE,
|
||||
);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(cover_rect, i18n.fullscreen_player());
|
||||
}
|
||||
if cov_resp.clicked {
|
||||
actions.push(AppAction::SetFullscreen(true));
|
||||
}
|
||||
|
||||
let info_x = cover_rect.right() + 10.0;
|
||||
let info_w = (left_max_x - info_x - 50.0).max(70.0);
|
||||
|
||||
// Title + optional version
|
||||
let version_str = track
|
||||
.version
|
||||
.as_deref()
|
||||
.filter(|v| !v.is_empty())
|
||||
.map(|v| format!(" {}", v));
|
||||
let full_text = match &version_str {
|
||||
Some(vs) => format!("{}{}", track.title, vs),
|
||||
None => track.title.clone(),
|
||||
};
|
||||
let measured_w = ctx
|
||||
.measure_text(&full_text, TextStyle::bold(14.0, fg_bright), None)
|
||||
.x
|
||||
.min(info_w);
|
||||
let title_r = Rect::from_xywh(info_x, cy - 19.0, measured_w.max(20.0), 20.0);
|
||||
let title_resp = ctx.interact(WidgetId::new("pb_title_click"), title_r);
|
||||
|
||||
let mut spans = vec![RichSpan::new(&track.title, TextStyle::bold(14.0, fg_bright))];
|
||||
if let Some(ref vs) = version_str {
|
||||
spans.push(RichSpan::new(vs, TextStyle::medium(14.0, fg_muted)));
|
||||
}
|
||||
ctx.draw_rich_text(
|
||||
&spans,
|
||||
Rect::from_xywh(info_x, cy - 19.0, info_w, 20.0),
|
||||
Some(1),
|
||||
TextAlign::Left,
|
||||
);
|
||||
if title_resp.hovered && track.album_id.is_some() {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.dl().push_rect(
|
||||
Rect::from_xywh(title_r.left(), title_r.bottom() - 2.0, title_r.width(), 1.0),
|
||||
0.0,
|
||||
fg_bright.scale_alpha(0.75),
|
||||
);
|
||||
}
|
||||
if title_resp.clicked {
|
||||
if let Some(ref aid) = track.album_id {
|
||||
actions.push(AppAction::Navigate(Route::Album {
|
||||
id: aid.clone(),
|
||||
title: track
|
||||
.album_title
|
||||
.clone()
|
||||
.unwrap_or_else(|| i18n.album().to_string()),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
let mut after_title_x = info_x + measured_w + 4.0;
|
||||
if track.is_explicit && after_title_x + 18.0 < left_max_x - 24.0 {
|
||||
ctx.draw_icon(
|
||||
Icon::Explicit,
|
||||
Rect::from_center_size(Pos2::new(after_title_x + 9.0, cy - 10.0), Vec2::splat(18.0)),
|
||||
fg_muted,
|
||||
);
|
||||
after_title_x += 22.0;
|
||||
}
|
||||
|
||||
// `•••` button opens the full reusable `TrackContextMenu` (player bar mode!)
|
||||
let more_pos = Pos2::new((after_title_x + 16.0).min(left_max_x - 24.0), cy - 10.0);
|
||||
let more_r = Rect::from_center_size(more_pos, Vec2::splat(24.0));
|
||||
let more_resp = ctx.interact(WidgetId::new("pb_more_btn"), more_r);
|
||||
let more_open = shell
|
||||
.track_menu
|
||||
.as_ref()
|
||||
.map_or(false, |m| m.from_player_bar && m.track.id == track.id);
|
||||
if more_resp.hovered || more_open {
|
||||
ctx.dl().push_circle(more_pos, 12.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
ctx.draw_icon(
|
||||
Icon::MoreXxs,
|
||||
Rect::from_center_size(more_pos, Vec2::splat(20.0)),
|
||||
if more_resp.hovered || more_open {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if more_resp.clicked {
|
||||
if more_open {
|
||||
shell.track_menu = None;
|
||||
} else {
|
||||
shell.open_track_menu_player_bar(track.clone(), Pos2::new(more_pos.x, rect.top() - 8.0));
|
||||
}
|
||||
}
|
||||
|
||||
// Individually clickable multi-artists (`SeparatedArtists`)!
|
||||
let artist_r = Rect::from_xywh(info_x, cy + 2.0, info_w, 20.0);
|
||||
if let Some((aid, aname)) = separated_artists(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("pb_artists"),
|
||||
artist_r,
|
||||
&track.artists,
|
||||
14.0,
|
||||
fg_muted,
|
||||
fg_bright,
|
||||
TextAlign::Left,
|
||||
) {
|
||||
actions.push(AppAction::Navigate(Route::Artist { id: aid, name: aname }));
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
// CENTER: [Dislike] [Shuffle] [Prev] [40px Yellow Play] [Next] [Repeat] [Like]
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
|
||||
// Dislike
|
||||
let dis_r = Rect::from_center_size(Pos2::new(cx - 154.0, cy), Vec2::splat(40.0));
|
||||
let dis_resp = ctx.interact(WidgetId::new("pb_dis"), dis_r);
|
||||
if dis_resp.hovered {
|
||||
ctx.dl().push_circle(dis_r.center(), 18.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(dis_r, i18n.dislike());
|
||||
}
|
||||
ctx.draw_icon(
|
||||
if is_disliked { Icon::Disliked } else { Icon::Dislike },
|
||||
Rect::from_center_size(dis_r.center(), Vec2::splat(24.0)),
|
||||
if is_disliked || dis_resp.hovered {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if dis_resp.clicked {
|
||||
if let Some(tr) = current_track {
|
||||
actions.push(AppAction::ToggleDislike(tr.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
// Shuffle — DISABLED & non-clickable when `is_vibe_active` (exact `hsla(0,0%,100%,.08)`)!
|
||||
let shuf_r = Rect::from_center_size(Pos2::new(cx - 100.0, cy), Vec2::splat(32.0));
|
||||
if is_vibe_active {
|
||||
ctx.draw_icon(
|
||||
Icon::Shuffle,
|
||||
Rect::from_center_size(shuf_r.center(), Vec2::splat(24.0)),
|
||||
fg_disabled_shuffle,
|
||||
);
|
||||
} else {
|
||||
let shuf_resp = ctx.interact(WidgetId::new("pb_shuf"), shuf_r);
|
||||
if shuf_resp.hovered {
|
||||
ctx.dl().push_circle(shuf_r.center(), 16.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(shuf_r, i18n.shuffle());
|
||||
}
|
||||
ctx.draw_icon(
|
||||
Icon::Shuffle,
|
||||
Rect::from_center_size(shuf_r.center(), Vec2::splat(24.0)),
|
||||
if app.shuffle {
|
||||
pal.yellow
|
||||
} else if shuf_resp.hovered {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if shuf_resp.clicked {
|
||||
actions.push(AppAction::ToggleShuffle);
|
||||
}
|
||||
}
|
||||
|
||||
// Previous
|
||||
let prev_r = Rect::from_center_size(Pos2::new(cx - 46.0, cy), Vec2::splat(40.0));
|
||||
let prev_resp = ctx.interact(WidgetId::new("pb_prev"), prev_r);
|
||||
if prev_resp.hovered {
|
||||
ctx.dl().push_circle(prev_r.center(), 18.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
ctx.draw_icon(
|
||||
Icon::PreviousXxs,
|
||||
Rect::from_center_size(prev_r.center(), Vec2::splat(20.0)),
|
||||
if prev_resp.hovered { fg_bright } else { fg_muted },
|
||||
);
|
||||
if prev_resp.clicked {
|
||||
actions.push(AppAction::Prev);
|
||||
}
|
||||
|
||||
// 40px Yellow circular Play / Pause button
|
||||
let play_r = Rect::from_center_size(Pos2::new(cx, cy), Vec2::splat(40.0));
|
||||
let play_resp = ctx.interact(WidgetId::new("pb_play"), play_r);
|
||||
let play_col = if play_resp.hovered {
|
||||
pal.yellow_hover
|
||||
} else {
|
||||
pal.yellow
|
||||
};
|
||||
if is_buffering {
|
||||
ctx.dl().push_circle(play_r.center(), 20.0, play_col);
|
||||
ctx.draw_text_ellipsis("···", TextStyle::medium(15.0, pal.on_yellow), play_r, TextAlign::Center);
|
||||
} else {
|
||||
let sz = if play_resp.hovered { 42.0 } else { 40.0 };
|
||||
ctx.draw_icon(
|
||||
if is_playing {
|
||||
Icon::PauseFilled
|
||||
} else {
|
||||
Icon::PlayFilled
|
||||
},
|
||||
Rect::from_center_size(play_r.center(), Vec2::splat(sz)),
|
||||
play_col,
|
||||
);
|
||||
}
|
||||
if play_resp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
if play_resp.clicked {
|
||||
actions.push(AppAction::TogglePlay);
|
||||
}
|
||||
|
||||
// Next
|
||||
let next_r = Rect::from_center_size(Pos2::new(cx + 46.0, cy), Vec2::splat(40.0));
|
||||
let next_resp = ctx.interact(WidgetId::new("pb_next"), next_r);
|
||||
if next_resp.hovered {
|
||||
ctx.dl().push_circle(next_r.center(), 18.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
ctx.draw_icon(
|
||||
Icon::NextXxs,
|
||||
Rect::from_center_size(next_r.center(), Vec2::splat(20.0)),
|
||||
if next_resp.hovered { fg_bright } else { fg_muted },
|
||||
);
|
||||
if next_resp.clicked {
|
||||
actions.push(AppAction::Next);
|
||||
}
|
||||
|
||||
// Repeat
|
||||
let rep_r = Rect::from_center_size(Pos2::new(cx + 100.0, cy), Vec2::splat(32.0));
|
||||
let rep_resp = ctx.interact(WidgetId::new("pb_rep"), rep_r);
|
||||
if rep_resp.hovered {
|
||||
ctx.dl().push_circle(rep_r.center(), 16.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(rep_r, i18n.repeat());
|
||||
}
|
||||
ctx.draw_icon(
|
||||
if app.repeat == RepeatMode::One {
|
||||
Icon::RepeatOne
|
||||
} else {
|
||||
Icon::Repeat
|
||||
},
|
||||
Rect::from_center_size(rep_r.center(), Vec2::splat(24.0)),
|
||||
if app.repeat != RepeatMode::Off {
|
||||
pal.yellow
|
||||
} else if rep_resp.hovered {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if rep_resp.clicked {
|
||||
actions.push(AppAction::CycleRepeat);
|
||||
}
|
||||
|
||||
// Like
|
||||
let like_r = Rect::from_center_size(Pos2::new(cx + 154.0, cy), Vec2::splat(40.0));
|
||||
let like_resp = ctx.interact(WidgetId::new("pb_like"), like_r);
|
||||
if like_resp.hovered {
|
||||
ctx.dl().push_circle(like_r.center(), 18.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(like_r, i18n.like());
|
||||
}
|
||||
ctx.draw_icon(
|
||||
if is_liked { Icon::Liked } else { Icon::Like },
|
||||
Rect::from_center_size(like_r.center(), Vec2::splat(24.0)),
|
||||
if is_liked {
|
||||
pal.accent_coral
|
||||
} else if like_resp.hovered {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if like_resp.clicked {
|
||||
if let Some(tr) = current_track {
|
||||
actions.push(AppAction::ToggleLike(tr.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
// RIGHT: [Lyrics] [Queue] [EQ] [Volume + 44×216 Kawase Popover]
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
let vol_icon_x = rect.right() - 35.0;
|
||||
|
||||
// 1. Lyrics button (disabled muted when `!has_lyrics`!)
|
||||
let lyr_x = vol_icon_x - 135.0;
|
||||
if lyr_x >= cx + 184.0 {
|
||||
let br = Rect::from_center_size(Pos2::new(lyr_x, cy), Vec2::splat(36.0));
|
||||
if !has_lyrics {
|
||||
ctx.draw_icon(
|
||||
Icon::Lyrics,
|
||||
Rect::from_center_size(br.center(), Vec2::splat(24.0)),
|
||||
fg_disabled_lyrics,
|
||||
);
|
||||
} else {
|
||||
let bresp = ctx.interact(WidgetId::new("pb_r_lyr"), br);
|
||||
let active = app.fullscreen_open && app.fullscreen_lyrics_open;
|
||||
let ic_sz = if bresp.hovered { 25.2 } else { 24.0 };
|
||||
if bresp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(br, i18n.lyrics());
|
||||
}
|
||||
ctx.draw_icon(
|
||||
Icon::Lyrics,
|
||||
Rect::from_center_size(br.center(), Vec2::splat(ic_sz)),
|
||||
if active {
|
||||
pal.yellow
|
||||
} else if bresp.hovered {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if bresp.clicked {
|
||||
actions.push(AppAction::OpenFullscreenSyncLyrics);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Queue button
|
||||
let que_x = vol_icon_x - 90.0;
|
||||
if que_x >= cx + 184.0 {
|
||||
let br = Rect::from_center_size(Pos2::new(que_x, cy), Vec2::splat(36.0));
|
||||
let bresp = ctx.interact(WidgetId::new("pb_r_que"), br);
|
||||
let active = app.fullscreen_open && app.fullscreen_queue_open;
|
||||
let ic_sz = if bresp.hovered { 25.2 } else { 24.0 };
|
||||
if bresp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(br, i18n.queue());
|
||||
}
|
||||
ctx.draw_icon(
|
||||
Icon::Queue,
|
||||
Rect::from_center_size(br.center(), Vec2::splat(ic_sz)),
|
||||
if active {
|
||||
pal.yellow
|
||||
} else if bresp.hovered {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if bresp.clicked {
|
||||
actions.push(AppAction::OpenFullscreenQueue);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. EQ / Sound Settings button
|
||||
let eq_x = vol_icon_x - 45.0;
|
||||
if eq_x >= cx + 184.0 {
|
||||
let br = Rect::from_center_size(Pos2::new(eq_x, cy), Vec2::splat(36.0));
|
||||
let bresp = ctx.interact(WidgetId::new("pb_r_eq"), br);
|
||||
let ic_sz = if bresp.hovered { 25.2 } else { 24.0 };
|
||||
if bresp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(br, i18n.sound_settings());
|
||||
}
|
||||
ctx.draw_icon(
|
||||
Icon::Settings,
|
||||
Rect::from_center_size(br.center(), Vec2::splat(ic_sz)),
|
||||
if app.eq_popover_open {
|
||||
pal.yellow
|
||||
} else if bresp.hovered {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if bresp.clicked {
|
||||
actions.push(AppAction::SetEqPopoverOpen(!app.eq_popover_open));
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Volume button + Exact 44×216 Vertical Hover Popover (Kawase Blur + 1% wheel step)
|
||||
if vol_icon_x >= cx + 184.0 {
|
||||
let vol_btn_r = Rect::from_center_size(Pos2::new(vol_icon_x, cy), Vec2::splat(38.0));
|
||||
let vol_resp = ctx.interact(WidgetId::new("pb_r_vol"), vol_btn_r);
|
||||
let vol_ic = if muted || volume < 0.01 {
|
||||
Icon::VolumeOff
|
||||
} else {
|
||||
Icon::Volume
|
||||
};
|
||||
let ic_sz = if vol_resp.hovered { 25.2 } else { 24.0 };
|
||||
if vol_resp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
ctx.draw_icon(
|
||||
vol_ic,
|
||||
Rect::from_center_size(vol_btn_r.center(), Vec2::splat(ic_sz)),
|
||||
if vol_resp.hovered { fg_bright } else { fg_muted },
|
||||
);
|
||||
if vol_resp.clicked {
|
||||
actions.push(AppAction::ToggleMute);
|
||||
}
|
||||
|
||||
let pop_w = 44.0;
|
||||
let pop_h = 216.0;
|
||||
let pop_rect = Rect::from_xywh(
|
||||
(vol_icon_x - pop_w * 0.5).clamp(8.0, (ctx.screen_rect().right() - pop_w - 8.0).max(8.0)),
|
||||
(rect.top() - pop_h - 4.0).max(36.0),
|
||||
pop_w,
|
||||
pop_h,
|
||||
);
|
||||
let bridge = vol_btn_r.union(pop_rect);
|
||||
let pointer_in_bridge = ctx.input.pointer_pos.map_or(false, |p| bridge.contains(p));
|
||||
let vol_dragging = ctx.input.active_id == Some(WidgetId::new("pb_vol_vslider"));
|
||||
let show_popover = pointer_in_bridge || vol_dragging;
|
||||
shell.pb_vol_hovered = show_popover;
|
||||
|
||||
if show_popover {
|
||||
// Exact 1% (0.01) wheel step per notch
|
||||
let wy = ctx.input.wheel_delta.y;
|
||||
if wy.abs() > 0.1 {
|
||||
let delta = if wy > 0.0 { 0.01 } else { -0.01 };
|
||||
let next = ((volume + delta) * 100.0).round() / 100.0;
|
||||
actions.push(AppAction::SetVolume(next.clamp(0.0, 1.0)));
|
||||
}
|
||||
|
||||
ctx.with_layer(ZLayer::Popover, |ctx| {
|
||||
let cur_v = if muted { 0.0 } else { volume };
|
||||
let sresp = ym_volume_capsule(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("pb_vol_vslider"),
|
||||
pop_rect,
|
||||
cur_v,
|
||||
false,
|
||||
pal.yellow,
|
||||
);
|
||||
if let Some(new_v) = sresp.value {
|
||||
actions.push(AppAction::SetVolume(new_v));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
1355
src/views/podcasts_kids.rs
Normal file
1355
src/views/podcasts_kids.rs
Normal file
File diff suppressed because it is too large
Load diff
1360
src/views/search.rs
Normal file
1360
src/views/search.rs
Normal file
File diff suppressed because it is too large
Load diff
769
src/views/settings.rs
Normal file
769
src/views/settings.rs
Normal file
|
|
@ -0,0 +1,769 @@
|
|||
use crate::app::i18n::APP_VERSION;
|
||||
use crate::app::state::{AppAction, AppState};
|
||||
use crate::audio::dsp::{EQ_LABELS, EQ_PRESETS};
|
||||
use crate::config::{AudioQuality, Language, ThemeMode};
|
||||
use crate::covers::CoverCache;
|
||||
use crate::engine::input::WidgetId;
|
||||
use crate::engine::text::{TextAlign, TextStyle};
|
||||
use crate::engine::theme::YmPalette;
|
||||
use crate::engine::types::{CursorKind, Pos2, Rect};
|
||||
use crate::engine::widgets::{
|
||||
secondary_pill_button, text_input_widget, yellow_pill_button, ym_slider, ym_vertical_slider,
|
||||
TextInputOptions,
|
||||
};
|
||||
use crate::engine::UiContext;
|
||||
use crate::icons::Icon;
|
||||
use crate::views::overlays::ShellUiState;
|
||||
|
||||
/// Authentic Yandex Music Desktop 5.129.0 Settings Page:
|
||||
/// - Account (Yandex ID / OAuth)
|
||||
/// - Appearance & Language (3-way System / Dark / Light theme selector + RU/EN + Close to tray)
|
||||
/// - Sound (Audio quality, Loudness normalization, Crossfade)
|
||||
/// - 10-band Equalizer (Enable, Presets, 10 vertical band sliders)
|
||||
/// - Recommendations & Content (Less AI, Show Kids section)
|
||||
/// - Keyboard shortcuts
|
||||
/// - About 5.129.0 (Update check & Clear cover cache)
|
||||
/// 100% `YmPalette` theme-aware & 100% localized RU/EN!
|
||||
pub fn render_settings(
|
||||
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("settings_scroll");
|
||||
let scroll_y = ctx.begin_scroll_v(scroll_id, rect, 0.0);
|
||||
|
||||
// `views/mod.rs` already insets `inner_r` by (25, 13, 25, 0)
|
||||
let content_x = rect.left();
|
||||
let content_w = (rect.width() - 8.0).clamp(320.0, 960.0);
|
||||
let mut y = rect.top() + 8.0 - scroll_y;
|
||||
|
||||
// Page Heading
|
||||
ctx.draw_text_ellipsis(
|
||||
t.settings(),
|
||||
TextStyle::headline(34.0, pal.text_bright),
|
||||
Rect::from_xywh(content_x, y, content_w, 42.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
y += 58.0;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 1. Account (Yandex ID)
|
||||
// -------------------------------------------------------------------------
|
||||
let acc_h = if app.account.is_some() { 112.0 } else { 196.0 };
|
||||
let acc_inner = draw_settings_card(
|
||||
ctx,
|
||||
pal,
|
||||
Rect::from_xywh(content_x, y, content_w, acc_h),
|
||||
if ru {
|
||||
"Аккаунт Яндекс ID"
|
||||
} else {
|
||||
"Yandex ID Account"
|
||||
},
|
||||
);
|
||||
if let Some(ref acc) = app.account {
|
||||
let sign_out_lbl = t.sign_out();
|
||||
let measured_w = ctx
|
||||
.measure_text(sign_out_lbl, TextStyle::bold(14.0, pal.text_primary), None)
|
||||
.x;
|
||||
let btn_w = (measured_w + 54.0).max(112.0).ceil();
|
||||
let text_w = (acc_inner.width() - btn_w - 16.0).max(120.0);
|
||||
let row_y = acc_inner.top();
|
||||
ctx.draw_text_ellipsis(
|
||||
&acc.display_name,
|
||||
TextStyle::bold(16.0, pal.text_bright),
|
||||
Rect::from_xywh(acc_inner.left(), row_y, text_w, 22.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
let plan = if acc.has_plus {
|
||||
if ru {
|
||||
"Яндекс Плюс активен"
|
||||
} else {
|
||||
"Yandex Plus active"
|
||||
}
|
||||
} else if ru {
|
||||
"Базовый тариф"
|
||||
} else {
|
||||
"Free plan"
|
||||
};
|
||||
let meta = format!("@{} · UID {} · {}", acc.login, acc.uid, plan);
|
||||
ctx.draw_text_ellipsis(
|
||||
&meta,
|
||||
TextStyle::regular(13.0, pal.text_secondary),
|
||||
Rect::from_xywh(acc_inner.left(), row_y + 24.0, text_w, 20.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
let logout_r = Rect::from_xywh(acc_inner.right() - btn_w, row_y + 4.0, btn_w, 38.0);
|
||||
let resp = crate::engine::widgets::secondary_pill_button_in(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("set_logout"),
|
||||
logout_r,
|
||||
Some(Icon::ProfileLogoutXxs),
|
||||
sign_out_lbl,
|
||||
false,
|
||||
);
|
||||
if resp.clicked {
|
||||
actions.push(AppAction::Logout);
|
||||
}
|
||||
} else {
|
||||
let mut cy = acc_inner.top();
|
||||
ctx.draw_text_wrapped(
|
||||
if ru {
|
||||
"Войдите через Яндекс ID, чтобы слушать свою коллекцию, «Мою волну» и Lossless FLAC."
|
||||
} else {
|
||||
"Sign in with Yandex ID to access your collection, My Vibe, and Lossless FLAC."
|
||||
},
|
||||
TextStyle::regular(13.5, pal.text_secondary),
|
||||
Rect::from_xywh(acc_inner.left(), cy, acc_inner.width(), 36.0),
|
||||
Some(2),
|
||||
TextAlign::Left,
|
||||
);
|
||||
cy += 36.0;
|
||||
|
||||
let (oauth_resp, _) = yellow_pill_button(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("set_oauth_btn"),
|
||||
Pos2::new(acc_inner.left(), cy),
|
||||
Some(Icon::Plus),
|
||||
if ru {
|
||||
"Войти через Яндекс ID"
|
||||
} else {
|
||||
"Sign in with Yandex ID"
|
||||
},
|
||||
38.0,
|
||||
false,
|
||||
);
|
||||
if oauth_resp.clicked {
|
||||
actions.push(AppAction::OpenOAuthBrowser);
|
||||
}
|
||||
cy += 50.0;
|
||||
|
||||
let input_w = (acc_inner.width() - 130.0).clamp(180.0, 420.0);
|
||||
let input_r = Rect::from_xywh(acc_inner.left(), cy, input_w, 38.0);
|
||||
let mut token_copy = app.token_input.clone();
|
||||
let ti = text_input_widget(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("set_token_input"),
|
||||
input_r,
|
||||
&mut token_copy,
|
||||
TextInputOptions {
|
||||
placeholder: if ru {
|
||||
"Вставьте OAuth-токен (y0_...) или URL"
|
||||
} else {
|
||||
"Paste OAuth token (y0_...) or redirect URL"
|
||||
},
|
||||
leading_icon: None,
|
||||
show_clear_button: true,
|
||||
hide_placeholder_when_unfocused: false,
|
||||
transparent_bg: false,
|
||||
font_size: 13.5,
|
||||
pill: true,
|
||||
},
|
||||
);
|
||||
if ti.changed {
|
||||
app.token_input = token_copy.clone();
|
||||
}
|
||||
let (sub_resp, _) = secondary_pill_button(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("set_token_submit"),
|
||||
Pos2::new(input_r.right() + 10.0, cy),
|
||||
Some(Icon::CheckXxs),
|
||||
t.log_in(),
|
||||
38.0,
|
||||
!token_copy.trim().is_empty(),
|
||||
);
|
||||
if (sub_resp.clicked || ti.submitted) && !token_copy.trim().is_empty() {
|
||||
actions.push(AppAction::SubmitOAuthToken(token_copy));
|
||||
}
|
||||
}
|
||||
y += acc_h + 14.0;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 2. Appearance & Language (3-way System / Dark / Light + RU/EN + Tray)
|
||||
// -------------------------------------------------------------------------
|
||||
let app_h = 204.0;
|
||||
let app_inner = draw_settings_card(
|
||||
ctx,
|
||||
pal,
|
||||
Rect::from_xywh(content_x, y, content_w, app_h),
|
||||
if ru {
|
||||
"Оформление и интерфейс"
|
||||
} else {
|
||||
"Appearance & Language"
|
||||
},
|
||||
);
|
||||
{
|
||||
let mut cy = app_inner.top();
|
||||
ctx.draw_text_ellipsis(
|
||||
t.appearance(),
|
||||
TextStyle::medium(13.0, pal.text_secondary),
|
||||
Rect::from_xywh(app_inner.left(), cy, app_inner.width(), 18.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
cy += 24.0;
|
||||
|
||||
let mut tx = app_inner.left();
|
||||
for (mode, icon, label) in [
|
||||
(ThemeMode::System, Icon::ThemeSystemXxs, t.theme_system()),
|
||||
(ThemeMode::Dark, Icon::ThemeDarkXxs, t.theme_dark()),
|
||||
(ThemeMode::Light, Icon::ThemeLightXxs, t.theme_light()),
|
||||
] {
|
||||
let (resp, r) = secondary_pill_button(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::from_pair("set_theme", mode as u8),
|
||||
Pos2::new(tx, cy),
|
||||
Some(icon),
|
||||
label,
|
||||
38.0,
|
||||
app.config.theme == mode,
|
||||
);
|
||||
if resp.clicked {
|
||||
actions.push(AppAction::SetTheme(mode));
|
||||
}
|
||||
tx = r.right() + 10.0;
|
||||
}
|
||||
cy += 50.0;
|
||||
|
||||
// Language selector
|
||||
let mut lx = app_inner.left();
|
||||
for (lang, label) in [(Language::Ru, "Русский"), (Language::En, "English")] {
|
||||
let (resp, r) = secondary_pill_button(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::from_pair("set_lang", lang as u8),
|
||||
Pos2::new(lx, cy),
|
||||
Some(Icon::ProfileGlobeXxs),
|
||||
label,
|
||||
36.0,
|
||||
app.config.language == lang,
|
||||
);
|
||||
if resp.clicked {
|
||||
actions.push(AppAction::SetLanguage(lang));
|
||||
}
|
||||
lx = r.right() + 10.0;
|
||||
}
|
||||
cy += 48.0;
|
||||
|
||||
// Close to tray toggle
|
||||
if let Some(next) = settings_toggle_row(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("set_close_to_tray"),
|
||||
Rect::from_xywh(app_inner.left(), cy, app_inner.width(), 32.0),
|
||||
if ru {
|
||||
"Сворачивать в системный трей при закрытии окна"
|
||||
} else {
|
||||
"Minimize to system tray on close"
|
||||
},
|
||||
app.config.close_to_tray,
|
||||
) {
|
||||
actions.push(AppAction::SetCloseToTray(next));
|
||||
}
|
||||
}
|
||||
y += app_h + 14.0;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 3. Sound (Audio quality, Loudness normalization, Crossfade)
|
||||
// -------------------------------------------------------------------------
|
||||
let sound_inner_w = (content_w - 36.0).max(100.0);
|
||||
let mut q_rows = 1usize;
|
||||
let mut sim_qx = 0.0_f32;
|
||||
for q in [
|
||||
AudioQuality::Lossless,
|
||||
AudioQuality::High,
|
||||
AudioQuality::Standard,
|
||||
] {
|
||||
let lbl = q.label_for(app.config.language);
|
||||
let btn_w = (ctx
|
||||
.measure_text(lbl, TextStyle::bold(14.0, pal.text_primary), None)
|
||||
.x
|
||||
+ 36.0)
|
||||
.min(260.0);
|
||||
if sim_qx + btn_w > sound_inner_w && sim_qx > 0.0 {
|
||||
q_rows += 1;
|
||||
sim_qx = 0.0;
|
||||
}
|
||||
sim_qx += btn_w + 8.0;
|
||||
}
|
||||
let sound_h = 196.0 + (q_rows.saturating_sub(1) as f32) * 44.0;
|
||||
let sound_inner = draw_settings_card(
|
||||
ctx,
|
||||
pal,
|
||||
Rect::from_xywh(content_x, y, content_w, sound_h),
|
||||
if ru { "Звук" } else { "Sound" },
|
||||
);
|
||||
{
|
||||
let mut cy = sound_inner.top();
|
||||
ctx.draw_text_ellipsis(
|
||||
if ru {
|
||||
"Качество звука"
|
||||
} else {
|
||||
"Audio quality"
|
||||
},
|
||||
TextStyle::medium(13.0, pal.text_secondary),
|
||||
Rect::from_xywh(sound_inner.left(), cy, sound_inner.width(), 18.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
cy += 24.0;
|
||||
|
||||
let mut qx = sound_inner.left();
|
||||
for q in [
|
||||
AudioQuality::Lossless,
|
||||
AudioQuality::High,
|
||||
AudioQuality::Standard,
|
||||
] {
|
||||
let lbl = q.label_for(app.config.language);
|
||||
let measured = ctx
|
||||
.measure_text(lbl, TextStyle::bold(14.0, pal.text_primary), None)
|
||||
.x
|
||||
+ 36.0;
|
||||
let btn_w = measured.min(260.0);
|
||||
if qx + btn_w > sound_inner.right() && qx > sound_inner.left() {
|
||||
qx = sound_inner.left();
|
||||
cy += 44.0;
|
||||
}
|
||||
let r = Rect::from_xywh(qx, cy, btn_w, 38.0);
|
||||
let resp = crate::engine::widgets::secondary_pill_button_in(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::from_pair("set_quality", q as u8),
|
||||
r,
|
||||
None,
|
||||
lbl,
|
||||
app.config.audio_quality == q,
|
||||
);
|
||||
if resp.clicked {
|
||||
actions.push(AppAction::SetAudioQuality(q));
|
||||
}
|
||||
qx = r.right() + 8.0;
|
||||
}
|
||||
cy += 50.0;
|
||||
|
||||
if let Some(next) = settings_toggle_row(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("set_loudness"),
|
||||
Rect::from_xywh(sound_inner.left(), cy, sound_inner.width(), 32.0),
|
||||
if ru {
|
||||
"Выравнивание громкости (EBU R128)"
|
||||
} else {
|
||||
"Loudness normalization (EBU R128)"
|
||||
},
|
||||
app.config.normalize_loudness,
|
||||
) {
|
||||
actions.push(AppAction::SetNormalizeLoudness(next));
|
||||
}
|
||||
cy += 40.0;
|
||||
|
||||
let cf_label = if ru {
|
||||
format!("Плавные переходы между треками: {:.0} с", app.config.crossfade_secs)
|
||||
} else {
|
||||
format!("Crossfade between tracks: {:.0} s", app.config.crossfade_secs)
|
||||
};
|
||||
ctx.draw_text_ellipsis(
|
||||
&cf_label,
|
||||
TextStyle::regular(14.0, pal.text_primary),
|
||||
Rect::from_xywh(sound_inner.left(), cy, 310.0, 26.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
let slider_r = Rect::from_xywh(
|
||||
sound_inner.left() + 320.0,
|
||||
cy,
|
||||
(sound_inner.width() - 330.0).clamp(120.0, 280.0),
|
||||
26.0,
|
||||
);
|
||||
let sr = ym_slider(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("set_crossfade_slider"),
|
||||
slider_r,
|
||||
(app.config.crossfade_secs / 12.0).clamp(0.0, 1.0),
|
||||
0.0,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
if let Some(v) = sr.value {
|
||||
let secs = (v * 12.0).round();
|
||||
if (secs - app.config.crossfade_secs).abs() >= 0.5 {
|
||||
actions.push(AppAction::SetCrossfadeSecs(secs));
|
||||
}
|
||||
}
|
||||
}
|
||||
y += sound_h + 14.0;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 4. 10-Band Equalizer (dynamic height so wrapped EQ presets never clip or break)
|
||||
// -------------------------------------------------------------------------
|
||||
let eq_inner_w = (content_w - 36.0).max(100.0);
|
||||
let mut eq_preset_rows = 1usize;
|
||||
let mut sim_px = 0.0_f32;
|
||||
for preset in EQ_PRESETS.iter() {
|
||||
let pw = (ctx
|
||||
.measure_text(preset.name, TextStyle::bold(14.0, pal.text_primary), None)
|
||||
.x
|
||||
+ 32.0)
|
||||
.max(54.0);
|
||||
if sim_px + pw > eq_inner_w && sim_px > 0.0 {
|
||||
eq_preset_rows += 1;
|
||||
sim_px = 0.0;
|
||||
}
|
||||
sim_px += pw + 6.0;
|
||||
}
|
||||
let eq_h = 266.0 + (eq_preset_rows.saturating_sub(1) as f32) * 38.0;
|
||||
let eq_inner = draw_settings_card(
|
||||
ctx,
|
||||
pal,
|
||||
Rect::from_xywh(content_x, y, content_w, eq_h),
|
||||
if ru { "Эквалайзер" } else { "Equalizer" },
|
||||
);
|
||||
{
|
||||
let mut enabled = app.config.eq_enabled;
|
||||
let mut bands = app.config.eq_bands_db;
|
||||
let mut changed = false;
|
||||
let mut cy = eq_inner.top();
|
||||
|
||||
if let Some(next) = settings_toggle_row(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("set_eq_enable"),
|
||||
Rect::from_xywh(eq_inner.left(), cy, eq_inner.width(), 30.0),
|
||||
if ru {
|
||||
"Включить 10-полосный эквалайзер"
|
||||
} else {
|
||||
"Enable 10-band equalizer"
|
||||
},
|
||||
enabled,
|
||||
) {
|
||||
enabled = next;
|
||||
changed = true;
|
||||
}
|
||||
cy += 38.0;
|
||||
|
||||
// Presets rows (wrap cleanly across multiple lines — NO truncation!)
|
||||
let mut px = eq_inner.left();
|
||||
for (idx, preset) in EQ_PRESETS.iter().enumerate() {
|
||||
let pw = (ctx
|
||||
.measure_text(preset.name, TextStyle::bold(14.0, pal.text_primary), None)
|
||||
.x
|
||||
+ 32.0)
|
||||
.max(54.0);
|
||||
if px + pw > eq_inner.right() && px > eq_inner.left() {
|
||||
px = eq_inner.left();
|
||||
cy += 38.0;
|
||||
}
|
||||
let is_match = enabled
|
||||
&& bands
|
||||
.iter()
|
||||
.zip(preset.gains.iter())
|
||||
.all(|(a, b)| (a - b).abs() < 0.2);
|
||||
let r = Rect::from_xywh(px, cy, pw, 30.0);
|
||||
let resp = crate::engine::widgets::secondary_pill_button_in(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::from_pair("set_eq_preset", idx),
|
||||
r,
|
||||
None,
|
||||
preset.name,
|
||||
is_match,
|
||||
);
|
||||
if resp.clicked {
|
||||
enabled = true;
|
||||
bands = preset.gains;
|
||||
changed = true;
|
||||
}
|
||||
px = r.right() + 6.0;
|
||||
}
|
||||
cy += 42.0;
|
||||
|
||||
// 10 vertical band sliders
|
||||
let col_w = (eq_inner.width() / 10.0).min(64.0);
|
||||
for i in 0..10 {
|
||||
let bx = eq_inner.left() + i as f32 * col_w;
|
||||
ctx.draw_text_ellipsis(
|
||||
&format!("{:+.0}", bands[i]),
|
||||
TextStyle::regular(11.5, pal.text_secondary),
|
||||
Rect::from_xywh(bx, cy, col_w, 16.0),
|
||||
TextAlign::Center,
|
||||
);
|
||||
let sl_r = Rect::from_xywh(bx + col_w * 0.5 - 14.0, cy + 20.0, 28.0, 96.0);
|
||||
let norm = ((bands[i] + 12.0) / 24.0).clamp(0.0, 1.0);
|
||||
let sr = ym_vertical_slider(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::from_pair("set_eq_band", i),
|
||||
sl_r,
|
||||
norm,
|
||||
false,
|
||||
if enabled { pal.yellow } else { pal.text_primary },
|
||||
);
|
||||
if let Some(v) = sr.value {
|
||||
let db = ((v * 24.0) - 12.0).round().clamp(-12.0, 12.0);
|
||||
if (db - bands[i]).abs() >= 0.5 {
|
||||
bands[i] = db;
|
||||
enabled = true;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
ctx.draw_text_ellipsis(
|
||||
EQ_LABELS[i],
|
||||
TextStyle::bold(11.5, pal.text_primary),
|
||||
Rect::from_xywh(bx, cy + 120.0, col_w, 16.0),
|
||||
TextAlign::Center,
|
||||
);
|
||||
}
|
||||
|
||||
if changed {
|
||||
actions.push(AppAction::UpdateEq { enabled, bands });
|
||||
}
|
||||
}
|
||||
y += eq_h + 14.0;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 5. Recommendations & Content (Less AI, Kids toggle)
|
||||
// -------------------------------------------------------------------------
|
||||
let rec_h = 132.0;
|
||||
let rec_inner = draw_settings_card(
|
||||
ctx,
|
||||
pal,
|
||||
Rect::from_xywh(content_x, y, content_w, rec_h),
|
||||
if ru {
|
||||
"Рекомендации и разделы"
|
||||
} else {
|
||||
"Recommendations & Content"
|
||||
},
|
||||
);
|
||||
{
|
||||
let mut cy = rec_inner.top();
|
||||
if let Some(next) = settings_toggle_row(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("set_ai_red"),
|
||||
Rect::from_xywh(rec_inner.left(), cy, rec_inner.width(), 32.0),
|
||||
if ru {
|
||||
"Меньше ИИ — реже показывать музыку, созданную с помощью ИИ"
|
||||
} else {
|
||||
"Less AI — reduce AI-generated music in recommendations"
|
||||
},
|
||||
app.config.ai_content_reduction,
|
||||
) {
|
||||
actions.push(AppAction::SetAiContentReduction(next));
|
||||
}
|
||||
cy += 40.0;
|
||||
if let Some(next) = settings_toggle_row(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("set_child_mode"),
|
||||
Rect::from_xywh(rec_inner.left(), cy, rec_inner.width(), 32.0),
|
||||
if ru {
|
||||
"Показывать раздел «Детям»"
|
||||
} else {
|
||||
"Show «For Kids» section"
|
||||
},
|
||||
app.config.child_mode,
|
||||
) {
|
||||
actions.push(AppAction::SetChildMode(next));
|
||||
}
|
||||
}
|
||||
y += rec_h + 14.0;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 6. Keyboard Shortcuts
|
||||
// -------------------------------------------------------------------------
|
||||
let shortcuts: &[(&str, &str, &str)] = &[
|
||||
("Space / K", "Пауза / Воспроизведение", "Play / Pause"),
|
||||
("N / P", "Следующий / Предыдущий трек", "Next / Previous track"),
|
||||
("← / → (J / L)", "Перемотка ±2 сек", "Seek ±2 sec"),
|
||||
("↑ / ↓", "Громкость ±5%", "Volume ±5%"),
|
||||
("M", "Выключить / включить звук", "Mute / Unmute"),
|
||||
("F / D", "Нравится / Не нравится", "Like / Dislike"),
|
||||
("R / S", "Повтор / Перемешать", "Repeat / Shuffle"),
|
||||
("W", "Полноэкранный плеер", "Fullscreen player"),
|
||||
("Ctrl + F / Ctrl + L", "Поиск / Текст песни", "Search / Lyrics"),
|
||||
];
|
||||
let sc_h = 62.0 + shortcuts.len() as f32 * 26.0;
|
||||
let sc_inner = draw_settings_card(
|
||||
ctx,
|
||||
pal,
|
||||
Rect::from_xywh(content_x, y, content_w, sc_h),
|
||||
if ru {
|
||||
"Горячие клавиши"
|
||||
} else {
|
||||
"Keyboard shortcuts"
|
||||
},
|
||||
);
|
||||
{
|
||||
let mut cy = sc_inner.top();
|
||||
for (keys, desc_ru, desc_en) in shortcuts {
|
||||
ctx.draw_text_ellipsis(
|
||||
keys,
|
||||
TextStyle::bold(13.0, pal.text_bright),
|
||||
Rect::from_xywh(sc_inner.left(), cy, 175.0, 22.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
ctx.draw_text_ellipsis(
|
||||
if ru { *desc_ru } else { *desc_en },
|
||||
TextStyle::regular(13.0, pal.text_secondary),
|
||||
Rect::from_xywh(sc_inner.left() + 185.0, cy, sc_inner.width() - 185.0, 22.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
cy += 26.0;
|
||||
}
|
||||
}
|
||||
y += sc_h + 14.0;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 7. About 5.129.0 & Cache
|
||||
// -------------------------------------------------------------------------
|
||||
let about_h = 148.0;
|
||||
let about_inner = draw_settings_card(
|
||||
ctx,
|
||||
pal,
|
||||
Rect::from_xywh(content_x, y, content_w, about_h),
|
||||
if ru { "О приложении" } else { "About" },
|
||||
);
|
||||
{
|
||||
let mut cy = about_inner.top();
|
||||
let ver_str = if ru {
|
||||
format!("Яндекс Музыка · Версия {}", APP_VERSION)
|
||||
} else {
|
||||
format!("Yandex Music · Version {}", APP_VERSION)
|
||||
};
|
||||
ctx.draw_text_ellipsis(
|
||||
&ver_str,
|
||||
TextStyle::medium(14.0, pal.text_primary),
|
||||
Rect::from_xywh(about_inner.left(), cy, about_inner.width(), 22.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
cy += 24.0;
|
||||
let cache_str = if ru {
|
||||
format!("© Яндекс · Кэш обложек: {} шт.", covers.len())
|
||||
} else {
|
||||
format!("© Yandex · Cover cache: {} items", covers.len())
|
||||
};
|
||||
ctx.draw_text_ellipsis(
|
||||
&cache_str,
|
||||
TextStyle::regular(12.5, pal.text_secondary),
|
||||
Rect::from_xywh(about_inner.left(), cy, about_inner.width(), 20.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
cy += 28.0;
|
||||
|
||||
let (upd_resp, upd_r) = secondary_pill_button(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("set_check_updates"),
|
||||
Pos2::new(about_inner.left(), cy),
|
||||
None,
|
||||
if ru {
|
||||
"Проверить обновления"
|
||||
} else {
|
||||
"Check for updates"
|
||||
},
|
||||
36.0,
|
||||
false,
|
||||
);
|
||||
if upd_resp.clicked {
|
||||
actions.push(AppAction::CheckForUpdates);
|
||||
}
|
||||
let (clr_resp, _) = secondary_pill_button(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("set_clear_cache"),
|
||||
Pos2::new(upd_r.right() + 10.0, cy),
|
||||
None,
|
||||
if ru {
|
||||
"Очистить кэш обложек"
|
||||
} else {
|
||||
"Clear cover cache"
|
||||
},
|
||||
36.0,
|
||||
false,
|
||||
);
|
||||
if clr_resp.clicked {
|
||||
actions.push(AppAction::ClearCoverCache);
|
||||
}
|
||||
}
|
||||
y += about_h + 28.0;
|
||||
|
||||
let total_content_h = y - (rect.top() - scroll_y);
|
||||
ctx.end_scroll_v(scroll_id, pal, total_content_h, true);
|
||||
}
|
||||
|
||||
/// Renders a theme-aware settings section card and returns its inner body `Rect` below the heading.
|
||||
fn draw_settings_card(ctx: &mut UiContext, pal: &YmPalette, rect: Rect, heading: &str) -> Rect {
|
||||
ctx.dl()
|
||||
.push_rect_bordered(rect, 14.0, pal.surface_secondary, 1.0, pal.border_subtle);
|
||||
let inner_x = rect.left() + 18.0;
|
||||
let inner_w = (rect.width() - 36.0).max(100.0);
|
||||
ctx.draw_text_ellipsis(
|
||||
heading,
|
||||
TextStyle::bold(16.0, pal.text_bright),
|
||||
Rect::from_xywh(inner_x, rect.top() + 16.0, inner_w, 22.0),
|
||||
TextAlign::Left,
|
||||
);
|
||||
Rect::from_xywh(
|
||||
inner_x,
|
||||
rect.top() + 46.0,
|
||||
inner_w,
|
||||
(rect.height() - 62.0).max(0.0),
|
||||
)
|
||||
}
|
||||
|
||||
/// Interactive pill toggle switch row (100% theme-aware). Returns `Some(new_val)` when toggled.
|
||||
fn settings_toggle_row(
|
||||
ctx: &mut UiContext,
|
||||
pal: &YmPalette,
|
||||
id: WidgetId,
|
||||
rect: Rect,
|
||||
label: &str,
|
||||
checked: bool,
|
||||
) -> Option<bool> {
|
||||
let resp = ctx.interact(id, rect);
|
||||
let anim = ctx.animate_bool(id.with("tog"), checked, 0.18);
|
||||
|
||||
ctx.draw_text_ellipsis(
|
||||
label,
|
||||
TextStyle::regular(14.0, pal.text_primary),
|
||||
Rect::from_xywh(rect.left(), rect.top(), (rect.width() - 56.0).max(40.0), rect.height()),
|
||||
TextAlign::Left,
|
||||
);
|
||||
|
||||
let sw_w = 42.0;
|
||||
let sw_h = 24.0;
|
||||
let sw_r = Rect::from_xywh(
|
||||
rect.right() - sw_w,
|
||||
rect.center_y() - sw_h * 0.5,
|
||||
sw_w,
|
||||
sw_h,
|
||||
);
|
||||
let track_col = pal.border_control.lerp(pal.yellow, anim);
|
||||
ctx.dl().push_rect(sw_r, sw_h * 0.5, track_col);
|
||||
|
||||
let knob_x = sw_r.left() + 12.0 + anim * (sw_w - 24.0);
|
||||
let knob_col = if anim > 0.5 {
|
||||
pal.on_yellow
|
||||
} else {
|
||||
pal.text_bright
|
||||
};
|
||||
ctx.dl()
|
||||
.push_circle(Pos2::new(knob_x, sw_r.center_y()), 8.5, knob_col);
|
||||
|
||||
if resp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
if resp.clicked {
|
||||
Some(!checked)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
1001
src/views/sidebar.rs
Normal file
1001
src/views/sidebar.rs
Normal file
File diff suppressed because it is too large
Load diff
162
src/views/titlebar.rs
Normal file
162
src/views/titlebar.rs
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
use crate::app::{AppState, WindowCommand};
|
||||
use crate::engine::{
|
||||
css_rgba, Color, CornerRadii, CursorKind, Pos2, Rect, TextAlign, TextStyle, UiContext, Vec2,
|
||||
WidgetId, YmPalette, ZLayer, TITLEBAR_BTN_WIDTH, TITLEBAR_HEIGHT,
|
||||
};
|
||||
|
||||
/// Exact Yandex Music Desktop 5.129.0 floating transparent 32px TitleBar (`TitleBar_root__QjdOZ`):
|
||||
/// - Floats over My Vibe full-bleed canvas AND FullscreenPlayer on `ZLayer::Titlebar`
|
||||
/// - Drag region + double-click to toggle maximize
|
||||
/// - 46×32 caption buttons: Minimize (10×1 pill), Maximize (10×10 rounded square when unmaximized,
|
||||
/// crisp Windows 11 Restore double-square when `is_maximized == true`), Close (`#F23F42` hover)
|
||||
pub fn render_titlebar(
|
||||
ctx: &mut UiContext,
|
||||
pal: &YmPalette,
|
||||
app: &AppState,
|
||||
is_maximized: bool,
|
||||
with_secondary_color: bool,
|
||||
) -> WindowCommand {
|
||||
let mut cmd = WindowCommand::None;
|
||||
let screen = ctx.screen_rect();
|
||||
let i18n = app.i18n();
|
||||
|
||||
ctx.with_layer(ZLayer::Titlebar, |ctx| {
|
||||
let rect = Rect::from_xywh(screen.x, screen.y, screen.w, TITLEBAR_HEIGHT);
|
||||
let close_r = Rect::from_xywh(
|
||||
rect.right() - TITLEBAR_BTN_WIDTH,
|
||||
rect.top(),
|
||||
TITLEBAR_BTN_WIDTH,
|
||||
TITLEBAR_HEIGHT,
|
||||
);
|
||||
let max_r = Rect::from_xywh(
|
||||
close_r.left() - TITLEBAR_BTN_WIDTH,
|
||||
rect.top(),
|
||||
TITLEBAR_BTN_WIDTH,
|
||||
TITLEBAR_HEIGHT,
|
||||
);
|
||||
let min_r = Rect::from_xywh(
|
||||
max_r.left() - TITLEBAR_BTN_WIDTH,
|
||||
rect.top(),
|
||||
TITLEBAR_BTN_WIDTH,
|
||||
TITLEBAR_HEIGHT,
|
||||
);
|
||||
let drag_r = Rect::from_xywh(
|
||||
rect.left(),
|
||||
rect.top(),
|
||||
(min_r.left() - rect.left()).max(0.0),
|
||||
TITLEBAR_HEIGHT,
|
||||
);
|
||||
|
||||
// Block pointer hit-testing underneath the 32px titlebar overlay
|
||||
ctx.register_blocker(rect);
|
||||
|
||||
// Drag + double-click maximize region
|
||||
let drag_resp = ctx.interact(WidgetId::new("ym_tb_drag"), drag_r);
|
||||
if drag_resp.double_clicked {
|
||||
cmd = WindowCommand::ToggleMaximize;
|
||||
} else if drag_resp.drag_started {
|
||||
cmd = WindowCommand::DragWindow;
|
||||
}
|
||||
|
||||
// Optional lightweight Vulkan Perf HUD in the titlebar center
|
||||
if app.config.show_perf_hud && drag_r.width() > 360.0 {
|
||||
let hud = format!(
|
||||
"RAM {:.1} MB · VRAM {:.1} MB · {:.0} FPS · Vulkan",
|
||||
app.perf.working_set_mb, app.perf.vram_mb, app.perf.fps
|
||||
);
|
||||
let hud_col = if with_secondary_color {
|
||||
css_rgba(255, 255, 255, 110)
|
||||
} else {
|
||||
pal.text_disabled
|
||||
};
|
||||
ctx.draw_text_ellipsis(&hud, TextStyle::regular(10.5, hud_col), drag_r, TextAlign::Center);
|
||||
}
|
||||
|
||||
let icon_col = if with_secondary_color {
|
||||
Color::rgb(0xE6, 0xE6, 0xE6)
|
||||
} else {
|
||||
pal.text_primary
|
||||
};
|
||||
let btn_hover_bg = if with_secondary_color {
|
||||
css_rgba(255, 255, 255, 24)
|
||||
} else {
|
||||
pal.surface_hover
|
||||
};
|
||||
|
||||
// 1. Minimize (`windows-menu.roll-up`)
|
||||
let min_resp = ctx.interact(WidgetId::new("ym_tb_min"), min_r);
|
||||
if min_resp.hovered {
|
||||
ctx.dl().push_rect(min_r, 0.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(min_r, i18n.roll_up());
|
||||
}
|
||||
let mc = min_r.center();
|
||||
ctx.dl().push_rect(
|
||||
Rect::from_center_size(Pos2::new(mc.x.round(), mc.y.round()), Vec2::new(10.0, 1.0)),
|
||||
0.5,
|
||||
icon_col,
|
||||
);
|
||||
if min_resp.clicked {
|
||||
cmd = WindowCommand::Minimize;
|
||||
}
|
||||
|
||||
// 2. Maximize / Windows 11 Restore double-square (`windows-menu.unwrap`)
|
||||
let max_resp = ctx.interact(WidgetId::new("ym_tb_max"), max_r);
|
||||
if max_resp.hovered {
|
||||
ctx.dl().push_rect(max_r, 0.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(max_r, i18n.unwrap());
|
||||
}
|
||||
let xc = Pos2::new(max_r.center_x().round(), max_r.center_y().round());
|
||||
if is_maximized {
|
||||
// Crisp Windows 11 Restore double-square:
|
||||
// Front 8×8 rounded hollow square at bottom-left + rear 8×8 shifted (+2, -2) top-right
|
||||
let front = Rect::from_xywh(xc.x - 5.0, xc.y - 3.0, 8.0, 8.0);
|
||||
let rear = Rect::from_xywh(xc.x - 3.0, xc.y - 5.0, 8.0, 8.0);
|
||||
|
||||
// Clip rear square to top & right exposed strips so it never overlaps front interior
|
||||
let top_strip = Rect::from_xywh(rear.left() - 1.0, rear.top() - 1.0, rear.width() + 2.0, front.top() - rear.top() + 1.0);
|
||||
ctx.dl().push_clip(top_strip, 0.0);
|
||||
ctx.dl().push_rect_bordered(rear, CornerRadii::same(1.5), Color::TRANSPARENT, 1.0, icon_col);
|
||||
ctx.dl().pop_clip();
|
||||
|
||||
let right_strip = Rect::from_xywh(front.right(), rear.top() - 1.0, rear.right() - front.right() + 1.0, rear.height() + 2.0);
|
||||
ctx.dl().push_clip(right_strip, 0.0);
|
||||
ctx.dl().push_rect_bordered(rear, CornerRadii::same(1.5), Color::TRANSPARENT, 1.0, icon_col);
|
||||
ctx.dl().pop_clip();
|
||||
|
||||
// Front 8×8 rounded square on top
|
||||
ctx.dl().push_rect_bordered(front, CornerRadii::same(1.5), Color::TRANSPARENT, 1.0, icon_col);
|
||||
} else {
|
||||
// Exact 10×10 rounded-corner hollow square (`rx ≈ 1.5px`, `1px` stroke)
|
||||
let sq = Rect::from_center_size(xc, Vec2::splat(10.0));
|
||||
ctx.dl().push_rect_bordered(sq, CornerRadii::same(1.5), Color::TRANSPARENT, 1.0, icon_col);
|
||||
}
|
||||
if max_resp.clicked {
|
||||
cmd = WindowCommand::ToggleMaximize;
|
||||
}
|
||||
|
||||
// 3. Close (`windows-menu.close`, exact `#F23F42` hover in BOTH themes)
|
||||
let close_resp = ctx.interact(WidgetId::new("ym_tb_close"), close_r);
|
||||
if close_resp.hovered {
|
||||
ctx.dl().push_rect(close_r, 0.0, pal.close_red);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(close_r, i18n.close());
|
||||
}
|
||||
let cc = Pos2::new(close_r.center_x().round(), close_r.center_y().round());
|
||||
let cc_col = if close_resp.hovered {
|
||||
Color::WHITE
|
||||
} else {
|
||||
icon_col
|
||||
};
|
||||
ctx.dl()
|
||||
.push_line(Pos2::new(cc.x - 4.8, cc.y - 4.8), Pos2::new(cc.x + 4.8, cc.y + 4.8), 1.1, cc_col);
|
||||
ctx.dl()
|
||||
.push_line(Pos2::new(cc.x + 4.8, cc.y - 4.8), Pos2::new(cc.x - 4.8, cc.y + 4.8), 1.1, cc_col);
|
||||
if close_resp.clicked {
|
||||
cmd = WindowCommand::Close;
|
||||
}
|
||||
});
|
||||
|
||||
cmd
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue