use std::time::Instant; use crossbeam_channel::Receiver; use crate::api::models::{format_ms, Track, TrackLyrics}; use crate::app::{AppAction, AppState, PlaylistModalState, RepeatMode, RightDrawerTab, Route}; use crate::audio::dsp::{EQ_LABELS, EQ_PRESETS}; use crate::covers::CoverCache; use crate::engine::textures::{premultiply_rgba_srgb, TextureRegistry}; use crate::engine::widgets::{ draw_cover_art, icon_button, secondary_pill_button, separated_artists, text_input_widget, yellow_pill_button, ym_menu_frame, ym_menu_item, ym_menu_item_ex, ym_vertical_slider, ym_volume_capsule, TextInputOptions, }; use crate::engine::{ css_rgba, Color, CornerRadii, CursorKind, Pos2, Rect, TextAlign, TextStyle, TextureId, UiContext, Vec2, WidgetId, YmPalette, ZLayer, PLAYER_BAR_HEIGHT, }; use crate::icons::Icon; // ============================================================================= // Shared Shell UI State (Popovers, Context Menus, Drag-and-Drop, Fullscreen Split) // ============================================================================= #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum TrackSubmenu { AddToPlaylist, Share, Artists, } #[derive(Debug, Clone)] pub struct TrackContextMenuState { pub track: Track, pub anchor: Pos2, pub from_player_bar: bool, pub from_queue_index: Option, pub from_playlist: Option<(String, String, usize)>, pub is_fullscreen: bool, pub open_submenu: Option, } #[derive(Debug, Clone)] pub struct EntityContextMenuState { pub kind: String, // "playlist" | "album" | "artist" | "likes" | "wave" pub id: String, pub title: String, pub subtitle: String, pub cover_uri: Option, pub owner_uid: Option, pub is_own_playlist: bool, pub tracks: Vec, pub anchor: Pos2, pub share_url: String, } #[derive(Debug, Clone, Copy)] pub struct QueueDragState { pub from_index: usize, pub hover_index: usize, } #[derive(Default)] pub struct ShellUiState { pub track_menu: Option, pub entity_menu: Option, pub entity_share_submenu_open: bool, pub sidebar_profile_open: bool, pub sidebar_appearance_open: bool, pub sidebar_lang_open: bool, pub sidebar_pin_menu: Option<(usize, Pos2)>, pub vibe_menu_open: bool, pub vibe_vol_open: bool, pub podcast_filter_tab: u8, pub pb_vol_hovered: bool, pub pb_scrub_frac: Option, pub fs_scrub_frac: Option, pub vibe_scrub_frac: Option, pub confirm_delete_playlist: Option<(u64, String, String)>, pub queue_drag: Option, pub fs_lyrics_scroll_y: f32, pub fs_lyrics_manual_until: f64, pub fs_lyrics_upper_until: f64, pub fs_lyrics_last_mouse: Option, pub fs_lyrics_track_id: String, } impl ShellUiState { pub fn open_track_menu(&mut self, track: Track, anchor: Pos2) { self.close_all_menus(); self.track_menu = Some(TrackContextMenuState { track, anchor, from_player_bar: false, from_queue_index: None, from_playlist: None, is_fullscreen: false, open_submenu: None, }); } pub fn open_track_menu_player_bar(&mut self, track: Track, anchor: Pos2) { self.close_all_menus(); self.track_menu = Some(TrackContextMenuState { track, anchor, from_player_bar: true, from_queue_index: None, from_playlist: None, is_fullscreen: false, open_submenu: None, }); } pub fn open_track_menu_in_queue(&mut self, track: Track, queue_idx: usize, anchor: Pos2) { self.close_all_menus(); self.track_menu = Some(TrackContextMenuState { track, anchor, from_player_bar: false, from_queue_index: Some(queue_idx), from_playlist: None, is_fullscreen: false, open_submenu: None, }); } pub fn open_track_menu_in_playlist( &mut self, track: Track, owner_uid: String, kind: String, index: usize, anchor: Pos2, ) { self.close_all_menus(); self.track_menu = Some(TrackContextMenuState { track, anchor, from_player_bar: false, from_queue_index: None, from_playlist: Some((owner_uid, kind, index)), is_fullscreen: false, open_submenu: None, }); } pub fn open_track_menu_fullscreen(&mut self, track: Track, anchor: Pos2) { self.close_all_menus(); self.track_menu = Some(TrackContextMenuState { track, anchor, from_player_bar: false, from_queue_index: None, from_playlist: None, is_fullscreen: true, open_submenu: None, }); } pub fn open_entity_menu(&mut self, menu: EntityContextMenuState) { self.close_all_menus(); self.entity_menu = Some(menu); } pub fn is_track_menu_open(&self, track_id: &str) -> bool { self.track_menu .as_ref() .map_or(false, |m| m.track.id == track_id) } pub fn close_all_menus(&mut self) { self.track_menu = None; self.entity_menu = None; self.entity_share_submenu_open = false; self.sidebar_profile_open = false; self.sidebar_appearance_open = false; self.sidebar_lang_open = false; self.sidebar_pin_menu = None; self.vibe_menu_open = false; self.vibe_vol_open = false; } } // ============================================================================= // 1. Right Slide-Over Drawer (Play Queue with Drag-and-Drop + Karaoke Lyrics) // ============================================================================= pub fn render_right_drawer( ctx: &mut UiContext, pal: &YmPalette, covers: &mut CoverCache, app: &AppState, shell: &mut ShellUiState, rect: Rect, actions: &mut Vec, ) { let i18n = app.i18n(); let ru = i18n.is_ru(); let tab = app.right_drawer; ctx.with_layer(ZLayer::Drawer, |ctx| { ctx.register_blocker(rect); ctx.dl() .push_rect_bordered(rect, 16.0, pal.bg_content, 1.0, pal.border_subtle); let inner = rect.shrink(16.0); // Header bar let heading = match tab { RightDrawerTab::Queue => i18n.queue(), RightDrawerTab::Lyrics => i18n.lyrics(), RightDrawerTab::None => "", }; ctx.draw_text_ellipsis( heading, TextStyle::headline(20.0, pal.text_bright), Rect::from_xywh(inner.left(), inner.top(), (inner.width() - 110.0).max(60.0), 28.0), TextAlign::Left, ); let close_r = Rect::from_xywh(inner.right() - 28.0, inner.top(), 28.0, 28.0); if icon_button( ctx, WidgetId::new("drawer_close_btn"), close_r, Icon::Close, 14.0, pal.text_secondary, pal.text_bright, pal.surface_hover, false, i18n.close(), ) .clicked { actions.push(AppAction::CloseRightDrawer); } if tab == RightDrawerTab::Queue && !app.queue.is_empty() { let clr_lbl = i18n.clear(); let clr_w = ctx .measure_text(clr_lbl, TextStyle::medium(12.5, pal.text_secondary), None) .x + 12.0; let clr_r = Rect::from_xywh(close_r.left() - clr_w - 6.0, inner.top() + 2.0, clr_w, 24.0); let clr_resp = ctx.interact(WidgetId::new("drawer_clear_queue"), clr_r); if clr_resp.hovered { ctx.set_cursor(CursorKind::Pointer); } ctx.draw_text_ellipsis( clr_lbl, TextStyle::medium( 12.5, if clr_resp.hovered { pal.text_primary } else { pal.text_secondary }, ), clr_r, TextAlign::Center, ); if clr_resp.clicked { actions.push(AppAction::ClearQueue); } } let content_top = inner.top() + 38.0; let content_rect = Rect::from_min_max( Pos2::new(inner.left(), content_top), Pos2::new(inner.right(), inner.bottom()), ); match tab { RightDrawerTab::Queue => { let sub = if ru { format!("Сейчас играет · {}", app.context_name) } else { format!("Now playing · {}", app.context_name) }; ctx.draw_text_ellipsis( &sub, TextStyle::regular(12.5, pal.text_secondary), Rect::from_xywh(content_rect.left(), content_rect.top(), content_rect.width(), 18.0), TextAlign::Left, ); let list_rect = Rect::from_min_max( Pos2::new(content_rect.left(), content_rect.top() + 24.0), content_rect.max(), ); render_queue_list_dnd( ctx, pal, covers, app, shell, list_rect, false, WidgetId::new("drawer_queue_scroll"), actions, ); } RightDrawerTab::Lyrics => { if let Some(ref lyr) = app.current_lyrics { render_drawer_lyrics(ctx, pal, lyr, app.position_ms(), content_rect, ru, actions); } else { let empty_msg = if ru { "Выберите трек, чтобы увидеть текст песни" } else { "Select a track to see lyrics" }; ctx.draw_text_wrapped( empty_msg, TextStyle::regular(14.0, pal.text_secondary), Rect::from_center_size( content_rect.center(), Vec2::new(content_rect.width() - 16.0, 48.0), ), Some(3), TextAlign::Center, ); } } RightDrawerTab::None => {} } }); } /// Interactive Queue Track List with full Drag-and-Drop Reorder, Remove, Jump, and Right-Click Menu. /// Reused by both Right Drawer (`on_dark_backdrop = false`) and Fullscreen 50/50 Queue split (`on_dark_backdrop = true`). #[allow(clippy::too_many_arguments)] fn render_queue_list_dnd( ctx: &mut UiContext, pal: &YmPalette, covers: &mut CoverCache, app: &AppState, shell: &mut ShellUiState, list_rect: Rect, on_dark_backdrop: bool, scroll_id: WidgetId, actions: &mut Vec, ) { let fg_primary = if on_dark_backdrop { Color::rgb(0xE6, 0xE6, 0xE6) } else { pal.text_primary }; let fg_secondary = if on_dark_backdrop { css_rgba(255, 255, 255, 140) } else { pal.text_secondary }; let active_bg = if on_dark_backdrop { css_rgba(255, 255, 255, 28) } else { pal.surface_list_active }; let hover_bg = if on_dark_backdrop { css_rgba(255, 255, 255, 18) } else { pal.surface_secondary }; let row_h = 52.0; let scroll_y = ctx.begin_scroll_v(scroll_id, list_rect, 8.0); let total_h = app.queue.len() as f32 * row_h; // Update active drag target index from pointer Y if let Some(ref mut drag) = shell.queue_drag { if let Some(pos) = ctx.input.pointer_pos { let rel_y = pos.y - list_rect.top() + scroll_y; let max_idx = app.queue.len().saturating_sub(1); drag.hover_index = ((rel_y / row_h).floor().max(0.0) as usize).min(max_idx); } ctx.set_cursor(CursorKind::Grabbing); } let row_range = crate::engine::visible_row_range( list_rect, list_rect.top() - scroll_y, row_h, app.queue.len(), 2, ); for idx in row_range { let tr = &app.queue[idx]; let y = list_rect.top() + idx as f32 * row_h - scroll_y; let r = Rect::from_xywh(list_rect.left(), y, list_rect.width(), row_h - 2.0); let is_curr = idx == app.queue_index; let is_dragged_row = shell.queue_drag.map_or(false, |d| d.from_index == idx); let row_id = scroll_id.with(("q_row", idx)); let resp = ctx.interact(row_id, r); if is_dragged_row { ctx.dl() .push_rect_bordered(r, 8.0, active_bg, 1.0, pal.yellow); } else if is_curr { ctx.dl().push_rect(r, 8.0, active_bg); } else if resp.hovered { ctx.dl().push_rect(r, 8.0, hover_bg); } // Cover art let cov = Rect::from_center_size(Pos2::new(r.left() + 24.0, r.center_y()), Vec2::splat(36.0)); draw_cover_art( ctx, pal, covers, cov, tr.cover_uri.as_deref(), &tr.id, 6.0, false, false, ); let tx = cov.right() + 10.0; let tw = (r.right() - tx - 32.0).max(50.0); let title_col = if is_curr { if pal.is_dark || on_dark_backdrop { pal.yellow } else { pal.outline_selected } } else { fg_primary }; ctx.draw_text_ellipsis( &tr.title, TextStyle::medium(13.0, title_col), Rect::from_xywh(tx, r.top() + 7.0, tw, 18.0), TextAlign::Left, ); ctx.draw_text_ellipsis( &tr.artists_string(), TextStyle::regular(12.0, fg_secondary), Rect::from_xywh(tx, r.top() + 26.0, tw, 16.0), TextAlign::Left, ); // Hover remove button (`×`) let mut rm_clicked = false; let rm_r = Rect::from_center_size(Pos2::new(r.right() - 14.0, r.center_y()), Vec2::splat(24.0)); let rm_resp = ctx.interact(scroll_id.with(("q_rm", idx)), rm_r); if (resp.hovered || rm_resp.hovered) && shell.queue_drag.is_none() { if rm_resp.hovered { ctx.dl().push_circle(rm_r.center(), 11.0, hover_bg); } ctx.draw_icon( Icon::Close, Rect::from_center_size(rm_r.center(), Vec2::splat(12.0)), if rm_resp.hovered { fg_primary } else { fg_secondary }, ); if rm_resp.clicked { rm_clicked = true; actions.push(AppAction::RemoveQueueAt(idx)); } } // Drag-and-drop initiation if resp.drag_started && !rm_clicked { shell.queue_drag = Some(QueueDragState { from_index: idx, hover_index: idx, }); } // Right-click opens full TrackContextMenu (with "Remove from queue"!) if resp.right_clicked { let anchor = ctx.input.pointer_pos.unwrap_or(r.center()); shell.open_track_menu_in_queue(tr.clone(), idx, anchor); } else if resp.clicked && !rm_clicked && shell.queue_drag.is_none() { actions.push(AppAction::JumpQueue(idx)); } if resp.hovered && shell.queue_drag.is_none() { ctx.set_cursor(CursorKind::Pointer); } } // Crisp yellow drop-target insertion bar while dragging if let Some(drag) = shell.queue_drag { if drag.from_index != drag.hover_index { let line_idx = if drag.hover_index > drag.from_index { drag.hover_index + 1 } else { drag.hover_index }; let line_y = list_rect.top() + line_idx as f32 * row_h - scroll_y - 1.0; ctx.dl().push_rect( Rect::from_xywh(list_rect.left() + 6.0, line_y, (list_rect.width() - 12.0).max(0.0), 2.5), 1.25, pal.yellow, ); } if ctx.input.left_released || !ctx.input.left_down { if drag.from_index != drag.hover_index { actions.push(AppAction::MoveQueue { from: drag.from_index, to: drag.hover_index, }); } shell.queue_drag = None; } } ctx.end_scroll_v(scroll_id, pal, total_h, true); } fn render_drawer_lyrics( ctx: &mut UiContext, pal: &YmPalette, lyr: &TrackLyrics, position_ms: u64, rect: Rect, ru: bool, actions: &mut Vec, ) { let active_idx = if lyr.is_synced { lyr.lines .iter() .rposition(|l| l.time_ms <= position_ms) .unwrap_or(0) } else { usize::MAX }; let scroll_id = WidgetId::new("drawer_lyrics_scroll"); let scroll_y = ctx.begin_scroll_v(scroll_id, rect, 8.0); let mut cur_y = rect.top() - scroll_y; let line_w = (rect.width() - 12.0).max(80.0); for (i, line) in lyr.lines.iter().enumerate() { let is_active = i == active_idx; let is_next = lyr.is_synced && active_idx != usize::MAX && i == active_idx + 1; let font_sz = if is_active { 22.0 } else { 18.0 }; let alpha = if !lyr.is_synced || is_active { 1.0 } else if is_next { 0.40 } else { 0.22 }; let col = pal.text_bright.with_alpha_f32(alpha); let txt = if line.text.trim().is_empty() { "• • •" } else { line.text.as_str() }; let sz = ctx.measure_text(txt, TextStyle::bold(font_sz, col), Some(line_w)); let h = sz.y.max(font_sz * 1.3); let lr = Rect::from_xywh(rect.left() + 6.0, cur_y, line_w, h); if lr.bottom() >= rect.top() - 40.0 && lr.top() <= rect.bottom() + 40.0 { let resp = ctx.interact(scroll_id.with(("lyr_ln", i)), lr); let draw_col = if resp.hovered && lyr.is_synced { pal.text_bright } else { col }; ctx.draw_text_wrapped(txt, TextStyle::bold(font_sz, draw_col), lr, None, TextAlign::Center); if resp.hovered && lyr.is_synced { ctx.set_cursor(CursorKind::Pointer); } if resp.clicked && lyr.is_synced { actions.push(AppAction::SeekMs(line.time_ms)); } } cur_y += h + 16.0; } if let Some(ref w) = lyr.writers { cur_y += 12.0; let footer = if ru { format!("Авторы: {}", w) } else { format!("Writers: {}", w) }; let fr = Rect::from_xywh(rect.left() + 6.0, cur_y, line_w, 36.0); ctx.draw_text_wrapped( &footer, TextStyle::regular(13.0, pal.text_secondary), fr, Some(2), TextAlign::Center, ); cur_y += 40.0; } let total_h = (cur_y - (rect.top() - scroll_y)).max(0.0); ctx.end_scroll_v(scroll_id, pal, total_h, true); } // ============================================================================= // 2. FullscreenPlayerDesktop & 50/50 Animated SyncLyrics / Queue Split // ============================================================================= pub fn render_fullscreen_player( ctx: &mut UiContext, pal: &YmPalette, covers: &mut CoverCache, app: &AppState, shell: &mut ShellUiState, actions: &mut Vec, ) { let screen = ctx.screen_rect(); let i18n = app.i18n(); let ru = i18n.is_ru(); let track = app.current_track(); let is_playing = app.is_audio_playing(); let position_ms = app.position_ms(); let duration_ms = app.duration_ms(); let is_vibe_active = app.is_vibe_active; let is_liked = track.map_or(false, |t| app.liked_ids.contains(&t.id)); // Exact `--player-average-color-background: hsl(h, s%, 20%)` let track_rgb = 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 bg_color = match track_rgb { Some(c) => { let (h, s, _) = c.to_hsl(); Color::from_hsl(h, s, 0.20) } None => Color::rgb(0x2E, 0x2A, 0x2C), }; // Fullscreen renders on ZLayer::Drawer so Popover (TrackContextMenu) & Modal & Titlebar sit cleanly above! ctx.with_layer(ZLayer::Drawer, |ctx| { ctx.register_blocker(screen); ctx.dl().push_rect(screen, 0.0, bg_color); // Render track player + 50/50 split BEFORE top-right `v` collapse button so // SyncLyrics top gradient fade mask never slices over `FullscreenPlayerDesktop_closeButton`! if let Some(tr) = track { // Mutually exclusive right split modes (SyncLyrics OR PlayQueue) WITHOUT closing fullscreen! let is_split = app.fullscreen_lyrics_open || app.fullscreen_queue_open; let split_t = ctx.animate_bool(WidgetId::new("fs_split_t"), is_split, 0.35); // Cover geometry: 400 / 384 / 336 responsive square let base_cov = if screen.width() > 1060.0 { 400.0f32 } else if screen.width() > 960.0 { 384.0 } else { 336.0 }; let max_pane_w = screen.width() * (1.0 - 0.50 * split_t) - 64.0; let cov_sz = base_cov .min(screen.height() - 240.0) .min(max_pane_w) .max(220.0); let cx_center = screen.center_x(); let cx_left = screen.left() + screen.width() * 0.25; let cx = cx_center + (cx_left - cx_center) * split_t; // Center the entire (poster + 110px info) block symmetrically around `screen.center_y()` let cov_cy = screen.center_y() - 55.0; let cov_r = Rect::from_center_size(Pos2::new(cx, cov_cy), Vec2::splat(cov_sz)); // Soft cover elevation shadow ctx.dl().push_shadow( cov_r, 8.0, 24.0, 2.0, Vec2::new(0.0, 10.0), css_rgba(0, 0, 0, 110), ); draw_cover_art( ctx, pal, covers, cov_r, tr.cover_uri.as_deref(), &tr.id, 8.0, false, false, ); // Hover 3×3 Controls overlay (stays visible while fullscreen TrackContextMenu is open!) let fs_menu_open = shell.track_menu.as_ref().map_or(false, |m| m.is_fullscreen); let cov_hovered = ctx.is_hovered(cov_r) || fs_menu_open; let hover_t = ctx.animate_bool(WidgetId::new("fs_cov_hover_t"), cov_hovered, 0.28); if hover_t > 0.005 { // Scrim `rgba(0,0,0,0.5)` ctx.dl() .push_rect(cov_r, 8.0, css_rgba(0, 0, 0, (128.0 * hover_t).round() as u8)); let draw_ov_circle = |ctx: &mut UiContext, center: Pos2, diam: f32, id: &str, ic: Icon, ic_sz: f32, tint: Color, tooltip: &str| -> bool { let r = Rect::from_center_size(center, Vec2::splat(diam)); let resp = ctx.interact(WidgetId::new(id), r); let draw_diam = if resp.hovered { diam * 1.05 } else { diam }; let bg = if resp.hovered { css_rgba(51, 51, 51, (230.0 * hover_t).round() as u8) } else { css_rgba(26, 26, 26, (230.0 * hover_t).round() as u8) }; ctx.dl().push_circle(center, draw_diam * 0.5, bg); ctx.draw_icon( ic, Rect::from_center_size(center, Vec2::splat(ic_sz)), tint.scale_alpha(hover_t), ); if resp.hovered { ctx.set_cursor(CursorKind::Pointer); if !tooltip.is_empty() { ctx.show_tooltip(r, tooltip); } } resp.clicked }; let corner_inset = 16.0 + 26.0; let is_disliked = app.disliked_ids.contains(&tr.id); // Row 1, Col 1 (Top-Left): Dislike if draw_ov_circle( ctx, Pos2::new(cov_r.left() + corner_inset, cov_r.top() + corner_inset), 52.0, "fs_ov_dislike", if is_disliked { Icon::Disliked } else { Icon::Dislike }, 30.0, if is_disliked { pal.accent_coral } else { Color::WHITE }, i18n.dislike(), ) { actions.push(AppAction::ToggleDislike(tr.clone())); } // Row 1, Col 3 (Top-Right): Queue split toggle (`PlayQueueButton`) if draw_ov_circle( ctx, Pos2::new(cov_r.right() - corner_inset, cov_r.top() + corner_inset), 52.0, "fs_ov_queue", Icon::Queue, 30.0, if app.fullscreen_queue_open { pal.yellow } else { Color::WHITE }, i18n.queue(), ) { actions.push(AppAction::ToggleFullscreenQueue); } // Row 3, Col 1 (Bottom-Left): `•••` opens TrackContextMenu (NOT Queue!) let more_center = Pos2::new(cov_r.left() + corner_inset, cov_r.bottom() - corner_inset); if draw_ov_circle( ctx, more_center, 52.0, "fs_ov_more", Icon::More, 30.0, if fs_menu_open { pal.yellow } else { Color::WHITE }, "", ) { if fs_menu_open { shell.track_menu = None; } else { shell.open_track_menu_fullscreen( tr.clone(), Pos2::new(more_center.x - 16.0, more_center.y - 26.0), ); } } // Row 3, Col 2 (Bottom-Center): SyncLyrics toggles 50/50 split WITHOUT closing fullscreen! let has_lyrics = tr.has_lyrics || app .current_lyrics .as_ref() .map_or(false, |l| l.track_id == tr.id && !l.lines.is_empty()); if has_lyrics || app.fullscreen_lyrics_open { if draw_ov_circle( ctx, Pos2::new(cov_r.center_x(), cov_r.bottom() - corner_inset), 52.0, "fs_ov_lyrics", Icon::Lyrics, 30.0, if app.fullscreen_lyrics_open { pal.yellow } else { Color::WHITE }, i18n.lyrics(), ) { actions.push(AppAction::ToggleFullscreenLyrics); } } // Row 3, Col 3 (Bottom-Right): Like if draw_ov_circle( ctx, Pos2::new(cov_r.right() - corner_inset, cov_r.bottom() - corner_inset), 52.0, "fs_ov_like", if is_liked { Icon::Liked } else { Icon::Like }, 30.0, if is_liked { pal.accent_coral } else { Color::WHITE }, i18n.like(), ) { actions.push(AppAction::ToggleLike(tr.clone())); } // Row 2, Col 1–3 (Center Transport): Play/Pause + Prev/Next (+ Shuffle/Repeat ONLY when !is_vibe_active!) let play_r = Rect::from_center_size(cov_r.center(), Vec2::splat(64.0)); let play_resp = ctx.interact(WidgetId::new("fs_play"), play_r); let play_rad = if play_resp.hovered { 33.6 } else { 32.0 }; let play_bg = if play_resp.hovered { pal.yellow_hover } else { pal.yellow }; ctx.dl() .push_circle(play_r.center(), play_rad, play_bg.scale_alpha(hover_t)); ctx.draw_icon( if is_playing { Icon::PauseLarge } else { Icon::PlayLarge }, Rect::from_center_size(play_r.center(), Vec2::splat(30.0)), pal.on_yellow.scale_alpha(hover_t), ); if play_resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if play_resp.clicked { actions.push(AppAction::TogglePlay); } if draw_ov_circle( ctx, Pos2::new(cx - 64.0, cov_cy), 44.0, "fs_prev", Icon::PreviousXxs, 22.0, Color::WHITE, "", ) { actions.push(AppAction::Prev); } if draw_ov_circle( ctx, Pos2::new(cx + 64.0, cov_cy), 44.0, "fs_next", Icon::NextXxs, 22.0, Color::WHITE, "", ) { actions.push(AppAction::Next); } // Shuffle hidden when `is_vibe_active`; Repeat stays visible & interactive (`Off <-> One` in Vibe)! if !is_vibe_active { if draw_ov_circle( ctx, Pos2::new(cx - 114.0, cov_cy), 36.0, "fs_shuf", Icon::Shuffle, 18.0, if app.shuffle { pal.yellow } else { css_rgba(255, 255, 255, 190) }, i18n.shuffle(), ) { actions.push(AppAction::ToggleShuffle); } } if draw_ov_circle( ctx, Pos2::new(cx + 114.0, cov_cy), 36.0, "fs_rep", if app.repeat == RepeatMode::One { Icon::RepeatOne } else { Icon::Repeat }, 18.0, if app.repeat != RepeatMode::Off { pal.yellow } else { css_rgba(255, 255, 255, 190) }, i18n.repeat(), ) { actions.push(AppAction::CycleRepeat); } } // Below Cover: Clickable Track Title + Explicit + Individually Clickable Artists let title_y = cov_r.bottom() + 24.0; let meta_w = cov_sz.max(320.0); let full_title = tr.full_title(); let measured_tw = ctx .measure_text(&full_title, TextStyle::bold(16.0, Color::WHITE), None) .x .min(meta_w - if tr.is_explicit { 24.0 } else { 0.0 }); let title_r = Rect::from_center_size(Pos2::new(cx, title_y + 10.0), Vec2::new(measured_tw.max(24.0), 22.0)); let title_resp = ctx.interact(WidgetId::new("fs_title_link"), title_r); ctx.draw_text_ellipsis( &full_title, TextStyle::bold(16.0, Color::WHITE), Rect::from_center_size(Pos2::new(cx, title_y + 10.0), Vec2::new(meta_w - 24.0, 22.0)), TextAlign::Center, ); if title_resp.hovered && tr.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, css_rgba(255, 255, 255, 180), ); } if title_resp.clicked { if let Some(ref aid) = tr.album_id { actions.push(AppAction::SetFullscreen(false)); actions.push(AppAction::Navigate(Route::Album { id: aid.clone(), title: tr .album_title .clone() .unwrap_or_else(|| i18n.album().to_string()), })); } } if tr.is_explicit { ctx.draw_icon( Icon::Explicit, Rect::from_center_size( Pos2::new(cx + measured_tw * 0.5 + 12.0, title_y + 10.0), Vec2::splat(16.0), ), css_rgba(255, 255, 255, 165), ); } // Individually clickable artists below title (`SeparatedArtists`)! let art_r = Rect::from_xywh(cx - meta_w * 0.5, title_y + 26.0, meta_w, 22.0); if let Some((aid, aname)) = separated_artists( ctx, pal, WidgetId::new("fs_artists"), art_r, &tr.artists, 14.0, css_rgba(255, 255, 255, 165), Color::WHITE, TextAlign::Center, ) { actions.push(AppAction::SetFullscreen(false)); actions.push(AppAction::Navigate(Route::Artist { id: aid, name: aname })); } // Progress bar (`ChangeTimecode`: 4px `#E6E6E6` fill/thumb + hover timecodes + smooth drag seek) let bar_y = cov_r.bottom() + 86.0; let bar_hit = Rect::from_center_size(Pos2::new(cx, bar_y), Vec2::new(cov_sz, 22.0)); let bar_resp = ctx.interact(WidgetId::new("fs_progress"), bar_hit); let bar_r = Rect::from_center_size(Pos2::new(cx, bar_y), Vec2::new(cov_sz, 4.0)); let progress = if duration_ms > 0 { (position_ms as f32 / duration_ms as f32).clamp(0.0, 1.0) } else { 0.0 }; if bar_resp.pressed || bar_resp.dragged { if let Some(pos) = ctx.input.pointer_pos { let frac = ((pos.x - bar_r.left()) / bar_r.width().max(1.0)).clamp(0.0, 1.0); shell.fs_scrub_frac = Some(frac); } } if let Some(frac) = shell.fs_scrub_frac { if !ctx.input.left_down || bar_resp.drag_stopped || bar_resp.clicked { let commit_frac = ctx .input .pointer_pos .map(|pos| ((pos.x - bar_r.left()) / bar_r.width().max(1.0)).clamp(0.0, 1.0)) .unwrap_or(frac); if duration_ms > 0 { actions.push(AppAction::SeekFraction(commit_frac)); } shell.fs_scrub_frac = None; } } else if bar_resp.clicked && duration_ms > 0 { if let Some(pos) = ctx.input.pointer_pos { let frac = ((pos.x - bar_r.left()) / bar_r.width().max(1.0)).clamp(0.0, 1.0); actions.push(AppAction::SeekFraction(frac)); } } let display_progress = shell.fs_scrub_frac.unwrap_or(progress); let display_pos_ms = (display_progress * duration_ms as f32) as u64; ctx.dl().push_rect(bar_r, 2.0, css_rgba(255, 255, 255, 28)); let fill_x = bar_r.left() + bar_r.width() * display_progress; let fill_col = Color::rgb(0xE6, 0xE6, 0xE6); ctx.dl().push_rect( Rect::from_min_max(bar_r.min(), Pos2::new(fill_x, bar_r.bottom())), 2.0, fill_col, ); let bar_active = bar_resp.hovered || bar_resp.pressed || bar_resp.dragged || shell.fs_scrub_frac.is_some(); let tc_t = ctx.animate_bool(WidgetId::new("fs_bar_tc_t"), bar_active, 0.18); if tc_t > 0.01 { let tc_col = Color::rgb(0xE6, 0xE6, 0xE6).with_alpha_f32(0.85 * tc_t); ctx.draw_text_ellipsis( &format_ms(display_pos_ms), TextStyle::medium(12.0, tc_col), Rect::from_xywh(bar_r.left(), bar_y + 8.0, 52.0, 16.0), TextAlign::Left, ); ctx.draw_text_ellipsis( &format_ms(duration_ms), TextStyle::medium(12.0, tc_col), Rect::from_xywh(bar_r.right() - 52.0, bar_y + 8.0, 52.0, 16.0), TextAlign::Right, ); } if bar_active { ctx.set_cursor(CursorKind::Pointer); ctx.dl().push_circle(Pos2::new(fill_x, bar_y), 6.0, fill_col); } // Right-Half 50/50 Animated Pane (`FullscreenPlayerDesktopContent_additionalContent`): SyncLyrics OR PlayQueue! if split_t > 0.02 { let indent = if screen.width() > 1060.0 { 44.0 } else if screen.width() > 960.0 { 20.0 } else { 10.0 }; let right_left = screen.left() + screen.width() * 0.50 - indent; let right_right = (right_left + screen.width() * 0.50).min(screen.right()); let right_bottom = screen.bottom() - (screen.height() * 0.09).max(56.0); if app.fullscreen_queue_open { let right_rect = Rect::from_min_max( Pos2::new(right_left, screen.top() + 56.0), Pos2::new((right_right - 48.0).max(right_left + 120.0), right_bottom), ); ctx.draw_text_ellipsis( i18n.queue(), TextStyle::headline(22.0, Color::WHITE.with_alpha_f32(split_t)), Rect::from_xywh(right_rect.left(), right_rect.top(), right_rect.width(), 30.0), TextAlign::Left, ); let q_rect = Rect::from_min_max( Pos2::new(right_rect.left(), right_rect.top() + 38.0), right_rect.max(), ); render_queue_list_dnd( ctx, pal, covers, app, shell, q_rect, true, WidgetId::new("fs_queue_scroll"), actions, ); } else { let lyr_rect = Rect::from_min_max( Pos2::new(right_left, screen.top() + 32.0), Pos2::new(right_right, right_bottom), ); render_fullscreen_sync_lyrics( ctx, app.current_lyrics.as_ref(), tr, position_ms, is_playing, lyr_rect, bg_color, split_t, ru, shell, actions, ); } } } // end `if let Some(tr) = track` // Top-right circular `v` collapse button (`FullscreenPlayerDesktop_closeButton`, z-index: header) let close_r = Rect::from_center_size( Pos2::new(screen.right() - 44.0, screen.top() + 56.0), Vec2::splat(40.0), ); let close_resp = ctx.interact(WidgetId::new("fs_close"), close_r); ctx.dl().push_circle( close_r.center(), if close_resp.hovered { 21.0 } else { 20.0 }, if close_resp.hovered { css_rgba(255, 255, 255, 36) } else { css_rgba(255, 255, 255, 22) }, ); ctx.draw_icon( Icon::ArrowDown, Rect::from_center_size(close_r.center(), Vec2::splat(24.0)), Color::WHITE, ); if close_resp.hovered { ctx.set_cursor(CursorKind::Pointer); ctx.show_tooltip(close_r, i18n.close()); } if close_resp.clicked { actions.push(AppAction::SetFullscreen(false)); } if track.is_none() { return; } // Bottom-right Volume / Mute button anchored cleanly at bottom-right aligned with top-right `v`! let vol_center = Pos2::new(screen.right() - 44.0, screen.bottom() - 40.0); let vol_btn_r = Rect::from_center_size(vol_center, Vec2::splat(40.0)); let vol_resp = ctx.interact(WidgetId::new("fs_vol_btn"), vol_btn_r); let vol_val = app.config.volume; let muted = app.config.muted; ctx.dl().push_circle( vol_center, if vol_resp.hovered { 21.0 } else { 20.0 }, if vol_resp.hovered { css_rgba(255, 255, 255, 36) } else { css_rgba(255, 255, 255, 22) }, ); ctx.draw_icon( if muted || vol_val < 0.01 { Icon::VolumeOff } else { Icon::Volume }, Rect::from_center_size(vol_center, Vec2::splat(22.0)), Color::WHITE, ); if vol_resp.hovered { ctx.set_cursor(CursorKind::Pointer); ctx.show_tooltip(vol_btn_r, i18n.volume()); } 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_center.x - pop_w * 0.5, (vol_btn_r.top() - pop_h - 8.0).max(40.0), pop_w, pop_h, ); let bridge = vol_btn_r.union(pop_rect); let fs_vol_active = ctx.input.pointer_pos.map_or(false, |p| bridge.contains(p)) || ctx.input.active_id == Some(WidgetId::new("fs_vol_vslider")); if fs_vol_active { 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 = ((vol_val + 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 { vol_val }; let sresp = ym_volume_capsule( ctx, pal, WidgetId::new("fs_vol_vslider"), pop_rect, cur_v, true, Color::WHITE, ); if let Some(new_v) = sresp.value { actions.push(AppAction::SetVolume(new_v)); } }); } }); } /// 1-to-1 Official `SyncLyrics` (`83ceed5f9f3f6e01.css` + `9631.422e0bf38581fe75.js`): /// - `40vh` active anchor, `32px` Swiper spacing, `base_sz` `(2.5vw clamped 32..48px)`, `scale(1.2)` active line /// - `INTRO` 4 staggered pulsing dots + `PREPARE` `3/2/1` countdown slot above line 0 /// - `withVisibleUpperLyrics` (3s on mouse move) & `withVisibleScrolledLyrics` (3s on wheel scroll) /// - Exact opacity ladder (`1.0` active, `0.30` next, `0.10` upcoming / upper-visible, `0.0` hidden past) /// - Official `SyncLyricsFooter` (`Авторы:` / `Writers:` + `Источник:` / `Source:`) + `80px` top/bottom fades #[allow(clippy::too_many_arguments)] fn render_fullscreen_sync_lyrics( ctx: &mut UiContext, lyrics: Option<&TrackLyrics>, track: &Track, position_ms: u64, is_playing: bool, lyr_rect: Rect, bg_color: Color, split_t: f32, ru: bool, shell: &mut ShellUiState, actions: &mut Vec, ) { if shell.fs_lyrics_track_id != track.id { shell.fs_lyrics_track_id = track.id.clone(); shell.fs_lyrics_scroll_y = 0.0; shell.fs_lyrics_manual_until = 0.0; shell.fs_lyrics_upper_until = 0.0; shell.fs_lyrics_last_mouse = None; } let Some(lyr) = lyrics.filter(|l| !l.lines.is_empty()) else { let msg = if ru { "Для этого трека текст пока недоступен" } else { "Lyrics are not available for this track" }; ctx.draw_text_ellipsis( msg, TextStyle::medium(18.0, css_rgba(255, 255, 255, (155.0 * split_t).round() as u8)), lyr_rect, TextAlign::Center, ); return; }; let screen = ctx.screen_rect(); let screen_w = screen.width(); let base_sz = (screen_w * 0.025).clamp(32.0, 48.0).round(); let active_sz = (base_sz * 1.2).round(); let base_lh = (base_sz * 1.25).round(); let active_lh = (active_sz * 1.25).round(); let max_line_w = (lyr_rect.width() * 0.80).max(200.0); let line_gap = 32.0f32; // exact Swiper `spaceBetween: 32` // Exact `--sync-lyrics-scroller-inset-top-vh: 40vh` anchor let anchor_y = (screen.top() + screen.height() * 0.40) .clamp(lyr_rect.top() + 48.0, lyr_rect.bottom() - 80.0); // Exact state machine: INTRO / PREPARE / PLAYING let start_ms = lyr.lines.first().map_or(0, |l| l.time_ms); let is_prepare = lyr.is_synced && start_ms >= 3000 && position_ms < start_ms && (start_ms - position_ms) <= 3000; let is_intro = lyr.is_synced && start_ms > 0 && position_ms < start_ms && !is_prepare; let active_idx: Option = if lyr.is_synced && !is_intro && !is_prepare { lyr.lines.iter().rposition(|l| l.time_ms <= position_ms) } else { None }; // Pre-measure every line at fixed `base_sz` / `base_lh` (zero wrap-jumping during `scale(1.2)`) let measure_style = TextStyle::headline(base_sz, Color::WHITE).with_line_height(base_lh); let mut line_heights = Vec::with_capacity(lyr.lines.len()); let mut line_y = Vec::with_capacity(lyr.lines.len()); let mut cur_y = 0.0f32; for line in &lyr.lines { let txt = if line.text.trim().is_empty() { "• • •" } else { line.text.as_str() }; let measured = ctx.measure_text(txt, measure_style, Some(max_line_w)); let h = measured.y.max(base_lh); line_y.push(cur_y + h * 0.5); line_heights.push(h); cur_y += h + line_gap; } let total_h = cur_y; let counter_y = -(line_gap + 22.0); let min_scroll = if is_intro || is_prepare { counter_y } else { 0.0 }; let now_t = ctx.input.time; let dt = ctx.input.dt; // Mouse movement (`> 2px`) reveals past upper lines for 3s (`withVisibleUpperLyrics`) if let Some(pos) = ctx.input.pointer_pos { if let Some(prev) = shell.fs_lyrics_last_mouse { if pos.distance(prev) > 2.0 { shell.fs_lyrics_upper_until = now_t + 3.0; shell.fs_lyrics_last_mouse = Some(pos); } } else { shell.fs_lyrics_last_mouse = Some(pos); } } // Wheel scroll enters manual browse mode for 3s (`withVisibleScrolledLyrics`) let wheel_dy = if ctx.is_hovered(lyr_rect) { ctx.input.wheel_delta.y } else { 0.0 }; if wheel_dy.abs() > 0.25 { shell.fs_lyrics_scroll_y = (shell.fs_lyrics_scroll_y - wheel_dy).clamp(min_scroll, total_h.max(0.0)); shell.fs_lyrics_manual_until = now_t + 3.0; } else if lyr.is_synced && now_t >= shell.fs_lyrics_manual_until { let target_y = if is_intro || is_prepare { counter_y } else if let Some(act) = active_idx { line_y[act] } else { 0.0 }; let alpha = 1.0 - (-dt * 7.5).exp(); shell.fs_lyrics_scroll_y += (target_y - shell.fs_lyrics_scroll_y) * alpha; if (target_y - shell.fs_lyrics_scroll_y).abs() > 0.4 { ctx.request_repaint(); } } let manual_scrolled = now_t < shell.fs_lyrics_manual_until; let upper_visible = now_t < shell.fs_lyrics_upper_until; let lyr_cx = lyr_rect.center_x(); ctx.push_clip(lyr_rect, 0.0); // Counter / Loader slot above line 0 (`INTRO`: 4 staggered pulsing dots; `PREPARE`: "3"/"2"/"1") if is_intro || is_prepare { let cy_screen = anchor_y + (counter_y - shell.fs_lyrics_scroll_y); if cy_screen >= lyr_rect.top() - 40.0 && cy_screen <= lyr_rect.bottom() + 40.0 { if is_prepare { let rem_ms = start_ms.saturating_sub(position_ms); let digit = ((rem_ms.saturating_sub(1)) / 1000 + 1).clamp(1, 3); ctx.draw_text_ellipsis( &digit.to_string(), TextStyle::headline(base_sz, Color::WHITE.with_alpha_f32(0.50 * split_t)), Rect::from_center_size(Pos2::new(lyr_cx, cy_screen), Vec2::new(80.0, base_lh)), TextAlign::Center, ); } else { let spacing = 20.0f32; let start_x = lyr_cx - spacing * 1.5; for k in 0..4 { let (dy, dot_a) = if is_playing { let phase = (now_t as f32 * 4.2 - k as f32 * 0.55).sin(); (-phase.max(0.0) * 6.0, (0.30 + 0.55 * (phase * 0.5 + 0.5)) * split_t) } else { (0.0, 0.35 * split_t) }; ctx.dl().push_circle( Pos2::new(start_x + k as f32 * spacing, cy_screen + dy), 5.5, Color::WHITE.with_alpha_f32(dot_a), ); } if is_playing { ctx.request_repaint(); } } } } for (i, line) in lyr.lines.iter().enumerate() { let y_screen = anchor_y + (line_y[i] - shell.fs_lyrics_scroll_y); let h = line_heights[i]; let is_active = !manual_scrolled && active_idx == Some(i); let target_op: f32 = if !lyr.is_synced || manual_scrolled { 1.0 } else if is_intro || is_prepare { if i == 0 { 0.30 } else { 0.10 } } else if let Some(act) = active_idx { if i == act { 1.0 } else if i == act + 1 { 0.30 } else if i > act + 1 { 0.10 } else if upper_visible { 0.10 } else { 0.0 } } else { 0.10 }; let op_t = ctx.animate_f32(WidgetId::from_pair("fs_lyr_op", i), target_op, 0.45); let act_t = ctx.animate_bool(WidgetId::from_pair("fs_lyr_act", i), is_active, 0.45); if y_screen + h * 0.65 < lyr_rect.top() - 48.0 || y_screen - h * 0.65 > lyr_rect.bottom() + 48.0 { continue; } let line_visible = op_t > 0.02 || manual_scrolled || upper_visible || !lyr.is_synced; let hit_r = Rect::from_center_size(Pos2::new(lyr_cx, y_screen), Vec2::new(max_line_w, h + 14.0)); let resp = ctx.interact(WidgetId::from_pair("fs_lyr_ln", i), hit_r); let hov_t = ctx.animate_bool( WidgetId::from_pair("fs_lyr_hov", i), resp.hovered && lyr.is_synced && line_visible, 0.18, ); let alpha = op_t.max(0.85 * hov_t) * split_t; if alpha > 0.005 { let col = Color::WHITE.with_alpha_f32(alpha); let txt = if line.text.trim().is_empty() { "• • •" } else { line.text.as_str() }; if act_t < 0.01 { ctx.draw_text_wrapped_scaled( txt, TextStyle::headline(base_sz, col).with_line_height(base_lh), Rect::from_center_size(Pos2::new(lyr_cx, y_screen), Vec2::new(max_line_w, h)), 1.0, TextAlign::Center, ); } else { let sc = (1.0 + 0.2 * act_t) / 1.2; ctx.draw_text_wrapped_scaled( txt, TextStyle::headline(active_sz, col).with_line_height(active_lh), Rect::from_center_size( Pos2::new(lyr_cx, y_screen), Vec2::new(max_line_w * 1.2, h * 1.2), ), sc, TextAlign::Center, ); } } if lyr.is_synced && line_visible { if resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if resp.clicked { actions.push(AppAction::SeekMs(line.time_ms.saturating_add(10))); shell.fs_lyrics_manual_until = 0.0; } } } // Official `SyncLyricsFooter`: Writers + Source (`major`) attribution at `0.50` alpha let has_writers = lyr.writers.as_deref().map_or(false, |s| !s.trim().is_empty()); let has_major = lyr.major.as_deref().map_or(false, |s| !s.trim().is_empty()); if has_writers || has_major { let footer_pad_top = (screen_w * 0.0625).clamp(48.0, 96.0); let footer_sz = (screen_w * 0.0125).clamp(15.0, 20.0); let footer_col = Color::WHITE.with_alpha_f32(0.50 * split_t); let footer_style = TextStyle::medium(footer_sz, footer_col); let mut fy = anchor_y + (total_h + footer_pad_top - shell.fs_lyrics_scroll_y); if let Some(ref writers) = lyr.writers.as_deref().filter(|s| !s.trim().is_empty()) { let txt = if ru { format!("Авторы: {}", writers) } else { format!("Writers: {}", writers) }; let mh = ctx .measure_text(&txt, footer_style, Some(max_line_w)) .y .max(footer_sz * 1.35); if fy + mh >= lyr_rect.top() - 40.0 && fy <= lyr_rect.bottom() + 40.0 { ctx.draw_text_wrapped( &txt, footer_style, Rect::from_xywh(lyr_cx - max_line_w * 0.5, fy, max_line_w, mh + 4.0), Some(3), TextAlign::Center, ); } fy += mh + 8.0; } if let Some(ref major) = lyr.major.as_deref().filter(|s| !s.trim().is_empty()) { let txt = if ru { format!("Источник: {}", major) } else { format!("Source: {}", major) }; let mh = ctx .measure_text(&txt, footer_style, Some(max_line_w)) .y .max(footer_sz * 1.35); if fy + mh >= lyr_rect.top() - 40.0 && fy <= lyr_rect.bottom() + 40.0 { ctx.draw_text_wrapped( &txt, footer_style, Rect::from_xywh(lyr_cx - max_line_w * 0.5, fy, max_line_w, mh + 4.0), Some(2), TextAlign::Center, ); } } } // Official `80px` (`5rem`) top & bottom gradient fade masks into `bg_color` let fade_h = 80.0f32.min(lyr_rect.height() * 0.25); let bg_clear = bg_color.with_alpha(0); ctx.dl().push_gradient_rect( Rect::from_xywh(lyr_rect.left(), lyr_rect.top(), lyr_rect.width(), fade_h), 0.0, bg_color, bg_clear, Vec2::new(0.0, 1.0), ); ctx.dl().push_gradient_rect( Rect::from_xywh( lyr_rect.left(), lyr_rect.bottom() - fade_h, lyr_rect.width(), fade_h, ), 0.0, bg_clear, bg_color, Vec2::new(0.0, 1.0), ); ctx.pop_clip(); } // ============================================================================= // 3. Reusable TrackContextMenu (with Working "Add to playlist >" & "Share >" Submenus) // ============================================================================= pub fn render_track_context_menu( ctx: &mut UiContext, pal: &YmPalette, app: &AppState, shell: &mut ShellUiState, actions: &mut Vec, ) { let Some(menu_state) = shell.track_menu.clone() else { return; }; let i18n = app.i18n(); let tr = &menu_state.track; let is_liked = app.liked_ids.contains(&tr.id); let is_disliked = app.disliked_ids.contains(&tr.id); let is_downloaded = app.is_track_downloaded(&tr.id); let has_album = tr.album_id.is_some(); let multi_artists = tr.artists.len() > 1; let has_artists = !tr.artists.is_empty(); let show_remove_queue = menu_state.from_queue_index.is_some() && !app.is_vibe_active; let show_remove_playlist = menu_state.from_playlist.is_some(); // Count visible items so menu fits tightly on screen let mut item_count = 9usize; // Like, Vibe, Download, PlayNext, PlayLast, Dislike, AddToPlaylist>, Share>, TrackDetails if show_remove_queue { item_count += 1; } if has_album { item_count += 1; } if has_artists { item_count += 1; } if show_remove_playlist { item_count += 1; } if menu_state.from_player_bar { item_count += 3; // Open queue, Sound settings, Fullscreen player } let screen = ctx.screen_rect(); let menu_w = 276.0; let row_h = 36.0; let menu_h = item_count as f32 * row_h + 16.0; let mut mx = menu_state.anchor.x; if mx + menu_w > screen.right() - 8.0 { mx = (menu_state.anchor.x - menu_w).max(8.0); } mx = mx.clamp(8.0, (screen.right() - menu_w - 8.0).max(8.0)); let mut my = menu_state.anchor.y; if menu_state.from_player_bar || menu_state.is_fullscreen || my + menu_h > screen.bottom() - 8.0 { my = (menu_state.anchor.y - menu_h).max(36.0); } my = my.clamp(36.0, (screen.bottom() - menu_h - 8.0).max(36.0)); let menu_rect = Rect::from_xywh(mx, my, menu_w, menu_h); let mut close_menu = false; let mut next_submenu = menu_state.open_submenu; let mut add_pl_row_rect = Rect::ZERO; let mut share_row_rect = Rect::ZERO; let mut artists_row_rect = Rect::ZERO; ctx.with_layer(ZLayer::Popover, |ctx| { let inner = ym_menu_frame(ctx, pal, menu_rect); let mut y = inner.top(); // 1. Like let r = Rect::from_xywh(inner.x, y, inner.w, row_h); if ym_menu_item_ex( ctx, pal, WidgetId::new("tcm_like"), r, if is_liked { Icon::LikedXxs } else { Icon::LikeXxs }, i18n.like(), is_liked, is_liked, false, false, ) .clicked { actions.push(AppAction::ToggleLike(tr.clone())); close_menu = true; } y += row_h; // 2. My Vibe by track let r = Rect::from_xywh(inner.x, y, inner.w, row_h); if ym_menu_item(ctx, pal, WidgetId::new("tcm_vibe"), r, Icon::VibeXxs, i18n.vibe_by_track(), false, false) .clicked { if menu_state.is_fullscreen { actions.push(AppAction::SetFullscreen(false)); } actions.push(AppAction::StartVibeBySeeds { title: tr.title.clone(), seeds: vec![format!("track:{}", tr.id)], }); close_menu = true; } y += row_h; // 3. Download / Delete from device let r = Rect::from_xywh(inner.x, y, inner.w, row_h); if ym_menu_item( ctx, pal, WidgetId::new("tcm_dl"), r, if is_downloaded { Icon::UploadXxs } else { Icon::Download }, if is_downloaded { i18n.delete_from_device() } else { i18n.download() }, is_downloaded, false, ) .clicked { if is_downloaded { actions.push(AppAction::RemoveDownloadedTrack(tr.id.clone())); } else { actions.push(AppAction::DownloadTrack(tr.clone())); } close_menu = true; } y += row_h; // 4. Play next let r = Rect::from_xywh(inner.x, y, inner.w, row_h); if ym_menu_item(ctx, pal, WidgetId::new("tcm_next"), r, Icon::PlayNextXxs, i18n.play_next(), false, false) .clicked { actions.push(AppAction::PlayNext(tr.clone())); close_menu = true; } y += row_h; // 5. Add to end of queue let r = Rect::from_xywh(inner.x, y, inner.w, row_h); if ym_menu_item(ctx, pal, WidgetId::new("tcm_last"), r, Icon::PlayLastXxs, i18n.play_last(), false, false) .clicked { actions.push(AppAction::AddToQueue(tr.clone())); close_menu = true; } y += row_h; // 6. Optional Remove from queue if let Some(qidx) = menu_state.from_queue_index.filter(|_| show_remove_queue) { let r = Rect::from_xywh(inner.x, y, inner.w, row_h); if ym_menu_item( ctx, pal, WidgetId::new("tcm_rm_q"), r, Icon::BucketXxs, i18n.remove_from_queue(), false, false, ) .clicked { actions.push(AppAction::RemoveQueueAt(qidx)); close_menu = true; } y += row_h; } // 7. Dislike let r = Rect::from_xywh(inner.x, y, inner.w, row_h); if ym_menu_item_ex( ctx, pal, WidgetId::new("tcm_dislike"), r, if is_disliked { Icon::DislikedXxs } else { Icon::DislikeXxs }, i18n.dislike(), is_disliked, is_disliked, false, false, ) .clicked { actions.push(AppAction::ToggleDislike(tr.clone())); close_menu = true; } y += row_h; // 8. Add to playlist > (Submenu) let r = Rect::from_xywh(inner.x, y, inner.w, row_h); add_pl_row_rect = r; let pl_resp = ym_menu_item( ctx, pal, WidgetId::new("tcm_add_pl"), r, Icon::AddToPlaylistXxs, i18n.add_to_playlist(), next_submenu == Some(TrackSubmenu::AddToPlaylist), true, ); if pl_resp.hovered || pl_resp.clicked { next_submenu = Some(TrackSubmenu::AddToPlaylist); } y += row_h; // 9. Share > (Submenu) let r = Rect::from_xywh(inner.x, y, inner.w, row_h); share_row_rect = r; let sh_resp = ym_menu_item( ctx, pal, WidgetId::new("tcm_share"), r, Icon::Share, i18n.share(), next_submenu == Some(TrackSubmenu::Share), true, ); if sh_resp.hovered || sh_resp.clicked { next_submenu = Some(TrackSubmenu::Share); } y += row_h; // 10. View album if let Some(ref aid) = tr.album_id { let r = Rect::from_xywh(inner.x, y, inner.w, row_h); if ym_menu_item(ctx, pal, WidgetId::new("tcm_album"), r, Icon::AlbumXxs, i18n.view_album(), false, false) .clicked { if menu_state.is_fullscreen { actions.push(AppAction::SetFullscreen(false)); } actions.push(AppAction::Navigate(Route::Album { id: aid.clone(), title: tr .album_title .clone() .unwrap_or_else(|| i18n.album().to_string()), })); close_menu = true; } y += row_h; } // 11. Go to artist / artists > if has_artists { let r = Rect::from_xywh(inner.x, y, inner.w, row_h); artists_row_rect = r; let lbl = if multi_artists { i18n.go_to_artists() } else { i18n.go_to_artist() }; let art_resp = ym_menu_item( ctx, pal, WidgetId::new("tcm_artist"), r, Icon::ArtistXxs, lbl, next_submenu == Some(TrackSubmenu::Artists), multi_artists, ); if multi_artists { if art_resp.hovered || art_resp.clicked { next_submenu = Some(TrackSubmenu::Artists); } } else if art_resp.clicked { if let Some(first) = tr.artists.first() { if menu_state.is_fullscreen { actions.push(AppAction::SetFullscreen(false)); } actions.push(AppAction::Navigate(Route::Artist { id: first.id.clone(), name: first.name.clone(), })); } close_menu = true; } y += row_h; } // 12. Optional Remove from playlist if let Some((ref ouid, ref pkind, pidx)) = menu_state.from_playlist { let r = Rect::from_xywh(inner.x, y, inner.w, row_h); if ym_menu_item( ctx, pal, WidgetId::new("tcm_rm_pl"), r, Icon::BucketXxs, i18n.remove_from_playlist(), false, false, ) .clicked { actions.push(AppAction::RemoveTrackFromPlaylist { owner_uid: ouid.clone(), kind: pkind.clone(), index: pidx, }); close_menu = true; } y += row_h; } // 13. PlayerBar quick extras: Open queue, Sound settings, Fullscreen player if menu_state.from_player_bar { let r = Rect::from_xywh(inner.x, y, inner.w, row_h); if ym_menu_item(ctx, pal, WidgetId::new("tcm_pb_q"), r, Icon::PlayQueueXxs, i18n.open_queue(), false, false) .clicked { actions.push(AppAction::OpenFullscreenQueue); close_menu = true; } y += row_h; let r = Rect::from_xywh(inner.x, y, inner.w, row_h); if ym_menu_item(ctx, pal, WidgetId::new("tcm_pb_eq"), r, Icon::SettingsXxs, i18n.sound_settings(), false, false) .clicked { actions.push(AppAction::SetEqPopoverOpen(!app.eq_popover_open)); close_menu = true; } y += row_h; let r = Rect::from_xywh(inner.x, y, inner.w, row_h); if ym_menu_item(ctx, pal, WidgetId::new("tcm_pb_fs"), r, Icon::Fullscreen, i18n.fullscreen_player(), false, false) .clicked { actions.push(AppAction::SetFullscreen(true)); close_menu = true; } y += row_h; } // 14. Go to track (opens TrackDetailModal 430px sheet without duplicating "Go to album") let r = Rect::from_xywh(inner.x, y, inner.w, row_h); if ym_menu_item( ctx, pal, WidgetId::new("tcm_info"), r, Icon::NoteXxs, i18n.go_to_track(), false, false, ) .clicked { actions.push(AppAction::OpenTrackDetailModal(tr.clone())); close_menu = true; } // Submenus: Add to playlist >, Share >, Artists > let mut sub_rect = Rect::ZERO; if let Some(sub) = next_submenu { let (anchor_row, sub_w, sub_h) = match sub { TrackSubmenu::AddToPlaylist => ( add_pl_row_rect, 244.0, ((2 + app.user_playlists.len()) as f32 * row_h + 16.0).min(280.0), ), TrackSubmenu::Share => (share_row_rect, 224.0, 2.0 * row_h + 16.0), TrackSubmenu::Artists => ( artists_row_rect, 224.0, tr.artists.len().min(8) as f32 * row_h + 16.0, ), }; let mut sx = menu_rect.right() + 6.0; if sx + sub_w > screen.right() - 8.0 { sx = (menu_rect.left() - sub_w - 6.0).max(8.0); } let sy = (anchor_row.top() - 8.0).clamp(36.0, (screen.bottom() - sub_h - 8.0).max(36.0)); sub_rect = Rect::from_xywh(sx, sy, sub_w, sub_h); let sub_inner = ym_menu_frame(ctx, pal, sub_rect); let mut sy_cur = sub_inner.top(); match sub { TrackSubmenu::AddToPlaylist => { // Create playlist let r = Rect::from_xywh(sub_inner.x, sy_cur, sub_inner.w, row_h); if ym_menu_item( ctx, pal, WidgetId::new("tcm_sub_create_pl"), r, Icon::AddXxs, i18n.create_playlist(), false, false, ) .clicked { actions.push(AppAction::OpenCreatePlaylistModal { initial_track: Some(tr.clone()), }); close_menu = true; } sy_cur += row_h; // My Favorites let r = Rect::from_xywh(sub_inner.x, sy_cur, sub_inner.w, row_h); if ym_menu_item_ex( ctx, pal, WidgetId::new("tcm_sub_likes"), r, if is_liked { Icon::LikedXxs } else { Icon::LikeXxs }, i18n.liked_playlist(), is_liked, is_liked, false, false, ) .clicked { actions.push(AppAction::ToggleLike(tr.clone())); close_menu = true; } sy_cur += row_h; // All user playlists inside a scrollable container (no .take(7) cap!) if !app.user_playlists.is_empty() { let list_h = (sub_inner.bottom() - sy_cur).max(row_h); let list_rect = Rect::from_xywh(sub_inner.x, sy_cur, sub_inner.w, list_h); let scroll_id = WidgetId::new("tcm_sub_pl_scroll"); let scroll_y = ctx.begin_scroll_v(scroll_id, list_rect, 0.0); let total_pl_h = app.user_playlists.len() as f32 * row_h; for (pi, pl) in app.user_playlists.iter().enumerate() { let py = list_rect.top() + pi as f32 * row_h - scroll_y; let r = Rect::from_xywh(list_rect.x, py, list_rect.w, row_h); if r.bottom() < list_rect.top() - 4.0 || r.top() > list_rect.bottom() + 4.0 { continue; } if ym_menu_item( ctx, pal, WidgetId::from_pair("tcm_sub_pl", pi), r, Icon::Playlist, &pl.title, false, false, ) .clicked { actions.push(AppAction::AddTrackToPlaylist { owner_uid: pl.owner_uid.clone(), kind: pl.kind.clone(), track: tr.clone(), }); close_menu = true; } } ctx.end_scroll_v(scroll_id, pal, total_pl_h, true); } } TrackSubmenu::Share => { // 1. Copy link -> arboard clipboard let r = Rect::from_xywh(sub_inner.x, sy_cur, sub_inner.w, row_h); if ym_menu_item( ctx, pal, WidgetId::new("tcm_sub_copy_link"), r, Icon::ChainXxs, i18n.copy_link(), false, false, ) .clicked { actions.push(AppAction::CopyTrackLink(tr.clone())); close_menu = true; } sy_cur += row_h; // 2. HTML embed code -> arboard clipboard let r = Rect::from_xywh(sub_inner.x, sy_cur, sub_inner.w, row_h); if ym_menu_item( ctx, pal, WidgetId::new("tcm_sub_copy_embed"), r, Icon::CodeXxs, i18n.html_code(), false, false, ) .clicked { actions.push(AppAction::CopyTrackEmbed(tr.clone())); close_menu = true; } } TrackSubmenu::Artists => { for (ai, art) in tr.artists.iter().take(8).enumerate() { let r = Rect::from_xywh(sub_inner.x, sy_cur, sub_inner.w, row_h); if ym_menu_item( ctx, pal, WidgetId::from_pair("tcm_sub_art", ai), r, Icon::ArtistXxs, &art.name, false, false, ) .clicked { if menu_state.is_fullscreen { actions.push(AppAction::SetFullscreen(false)); } actions.push(AppAction::Navigate(Route::Artist { id: art.id.clone(), name: art.name.clone(), })); close_menu = true; } sy_cur += row_h; } } } } let mut keep = vec![menu_rect]; if !sub_rect.is_empty() { keep.push(sub_rect); } if ctx.input.clicked_outside_any(&keep) { close_menu = true; } }); if close_menu { shell.track_menu = None; } else if let Some(ref mut tm) = shell.track_menu { tm.open_submenu = next_submenu; } } // ============================================================================= // 4. Reusable EntityContextMenu (Playlist / Album / Artist / Liked) // ============================================================================= pub fn render_entity_context_menu( ctx: &mut UiContext, pal: &YmPalette, app: &AppState, shell: &mut ShellUiState, actions: &mut Vec, ) { let Some(em) = shell.entity_menu.clone() else { return; }; let i18n = app.i18n(); let ru = i18n.is_ru(); let pinned = app.is_pinned(&em.kind, &em.id); let has_tracks = !em.tracks.is_empty(); let can_download = has_tracks && (em.kind == "album" || em.kind == "playlist"); let all_downloaded = can_download && em.tracks.iter().all(|t| app.is_track_downloaded(&t.id)); let mut item_count = 3usize; // Vibe, Pin/Unpin, Share > if has_tracks { item_count += 2; // Play next, Add to queue } if can_download { item_count += 1; // Download / Remove downloaded } if em.is_own_playlist { item_count += 2; // Rename, Delete } let screen = ctx.screen_rect(); let menu_w = 256.0; let row_h = 36.0; let menu_h = item_count as f32 * row_h + 16.0; let mx = em.anchor.x.clamp(8.0, (screen.right() - menu_w - 8.0).max(8.0)); let my = em.anchor.y.clamp(36.0, (screen.bottom() - menu_h - 8.0).max(36.0)); let menu_rect = Rect::from_xywh(mx, my, menu_w, menu_h); let mut close_menu = false; let mut share_sub_open = shell.entity_share_submenu_open; let mut share_row_rect = Rect::ZERO; let mut sub_rect = Rect::ZERO; let mut pending_delete: Option<(u64, String, String)> = None; ctx.with_layer(ZLayer::Popover, |ctx| { let inner = ym_menu_frame(ctx, pal, menu_rect); let mut y = inner.top(); if has_tracks { let r = Rect::from_xywh(inner.x, y, inner.w, row_h); let m = ym_menu_item(ctx, pal, WidgetId::new("ecm_next"), r, Icon::PlayNextXxs, i18n.play_next(), false, false); if m.hovered { share_sub_open = false; } if m.clicked { actions.push(AppAction::PlayTracksNext(em.tracks.clone())); close_menu = true; } y += row_h; let r = Rect::from_xywh(inner.x, y, inner.w, row_h); let m = ym_menu_item(ctx, pal, WidgetId::new("ecm_last"), r, Icon::PlayLastXxs, i18n.play_last(), false, false); if m.hovered { share_sub_open = false; } if m.clicked { actions.push(AppAction::AddTracksToQueue(em.tracks.clone())); close_menu = true; } y += row_h; } // Download / Remove from device (albums & playlists) if can_download { let r = Rect::from_xywh(inner.x, y, inner.w, row_h); let dl_lbl = if all_downloaded { if ru { "Удалить с устройства" } else { "Remove from device" } } else { i18n.download() }; let m = ym_menu_item( ctx, pal, WidgetId::new("ecm_download"), r, if all_downloaded { Icon::UploadXxs } else { Icon::Download }, dl_lbl, all_downloaded, false, ); if m.hovered { share_sub_open = false; } if m.clicked { if all_downloaded { actions.push(AppAction::RemoveDownloadedTracks( em.tracks.iter().map(|t| t.id.clone()).collect(), )); } else { actions.push(AppAction::DownloadTracks(em.tracks.clone())); } close_menu = true; } y += row_h; } // My Vibe by entity let (vibe_lbl, seed) = match em.kind.as_str() { "album" => (i18n.vibe_by_album(), format!("album:{}", em.id)), "artist" => (i18n.vibe_by_artist(), format!("artist:{}", em.id)), "playlist" => ( i18n.vibe_by_playlist(), if let Some(ref ouid) = em.owner_uid { format!("playlist:{}_{}", ouid, em.id) } else { format!("playlist:{}", em.id) }, ), _ => (i18n.my_vibe(), "user:onyourwave".to_string()), }; let r = Rect::from_xywh(inner.x, y, inner.w, row_h); let m = ym_menu_item(ctx, pal, WidgetId::new("ecm_vibe"), r, Icon::VibeXxs, vibe_lbl, false, false); if m.hovered { share_sub_open = false; } if m.clicked { actions.push(AppAction::StartVibeBySeeds { title: em.title.clone(), seeds: vec![seed], }); close_menu = true; } y += row_h; // Pin / Unpin let r = Rect::from_xywh(inner.x, y, inner.w, row_h); let m = ym_menu_item( ctx, pal, WidgetId::new("ecm_pin"), r, if pinned { Icon::UnpinXxs } else { Icon::PinXxs }, if pinned { i18n.unpin() } else { i18n.pin() }, pinned, false, ); if m.hovered { share_sub_open = false; } if m.clicked { actions.push(AppAction::TogglePin { kind: em.kind.clone(), id: em.id.clone(), title: em.title.clone(), subtitle: em.subtitle.clone(), cover_uri: em.cover_uri.clone(), owner_uid: em.owner_uid.clone(), }); close_menu = true; } y += row_h; // Share > (hover submenu with Copy link & HTML embed code matching TrackContextMenu) let r = Rect::from_xywh(inner.x, y, inner.w, row_h); share_row_rect = r; let m = ym_menu_item( ctx, pal, WidgetId::new("ecm_share"), r, Icon::Share, i18n.share(), share_sub_open, true, ); if m.hovered || m.clicked { share_sub_open = true; } y += row_h; // Own playlist CRUD: Rename & Delete (with confirmation modal!) if em.is_own_playlist { let owner = em .owner_uid .clone() .or_else(|| app.account.as_ref().map(|a| a.uid.to_string())) .unwrap_or_default(); let kind = em .id .split_once(':') .map(|(_, k)| k.to_string()) .unwrap_or_else(|| em.id.clone()); let r = Rect::from_xywh(inner.x, y, inner.w, row_h); let m = ym_menu_item(ctx, pal, WidgetId::new("ecm_rename"), r, Icon::PencilXxs, i18n.rename(), false, false); if m.hovered { share_sub_open = false; } if m.clicked { actions.push(AppAction::OpenRenamePlaylistModal { owner_uid: owner.clone(), kind: kind.clone(), current_title: em.title.clone(), }); close_menu = true; } y += row_h; let r = Rect::from_xywh(inner.x, y, inner.w, row_h); let m = ym_menu_item( ctx, pal, WidgetId::new("ecm_delete"), r, Icon::BucketXxs, i18n.delete_playlist(), false, false, ); if m.hovered { share_sub_open = false; } if m.clicked { let uid_num = owner .parse::() .unwrap_or_else(|_| app.account.as_ref().map_or(0, |a| a.uid)); pending_delete = Some((uid_num, kind, em.title.clone())); close_menu = true; } } // Share Submenu: Copy link + Copy HTML embed code if share_sub_open { let sub_w = 224.0; let sub_h = 2.0 * row_h + 16.0; let mut sx = menu_rect.right() + 6.0; if sx + sub_w > screen.right() - 8.0 { sx = (menu_rect.left() - sub_w - 6.0).max(8.0); } let sy = (share_row_rect.top() - 8.0).clamp(36.0, (screen.bottom() - sub_h - 8.0).max(36.0)); sub_rect = Rect::from_xywh(sx, sy, sub_w, sub_h); let sub_inner = ym_menu_frame(ctx, pal, sub_rect); let r1 = Rect::from_xywh(sub_inner.x, sub_inner.top(), sub_inner.w, row_h); if ym_menu_item( ctx, pal, WidgetId::new("ecm_sub_copy_link"), r1, Icon::ChainXxs, i18n.copy_link(), false, false, ) .clicked { actions.push(AppAction::CopyEntityLink { kind: em.kind.clone(), url: em.share_url.clone(), }); close_menu = true; } let r2 = Rect::from_xywh(sub_inner.x, sub_inner.top() + row_h, sub_inner.w, row_h); if ym_menu_item( ctx, pal, WidgetId::new("ecm_sub_copy_embed"), r2, Icon::CodeXxs, i18n.html_code(), false, false, ) .clicked { let embed_src = match em.kind.as_str() { "album" => format!("https://music.yandex.ru/iframe/album/{}", em.id), "artist" => format!("https://music.yandex.ru/iframe/artist/{}", em.id), "playlist" => { let (ouid, pkind) = if let Some((o, k)) = em.id.split_once(':') { (o.to_string(), k.to_string()) } else { ( em.owner_uid .clone() .or_else(|| app.account.as_ref().map(|a| a.uid.to_string())) .unwrap_or_else(|| "yamusic-daily".into()), em.id.clone(), ) }; format!("https://music.yandex.ru/iframe/playlist/{}/{}", ouid, pkind) } _ => em.share_url.clone(), }; let iframe = format!( "", embed_src ); actions.push(AppAction::CopyToClipboard { text: iframe, toast_msg: if ru { "HTML-код скопирован".into() } else { "HTML embed code copied".into() }, }); close_menu = true; } } let mut keep = vec![menu_rect]; if !sub_rect.is_empty() { keep.push(sub_rect); } if ctx.input.clicked_outside_any(&keep) { close_menu = true; } }); if let Some(confirm) = pending_delete { shell.confirm_delete_playlist = Some(confirm); } if close_menu { shell.entity_menu = None; shell.entity_share_submenu_open = false; } else { shell.entity_share_submenu_open = share_sub_open; } } // ============================================================================= // 5. Modals: Vibe Settings, Create/Rename Playlist, Login OAuth, Track Detail // ============================================================================= pub fn render_vibe_settings_modal( ctx: &mut UiContext, pal: &YmPalette, app: &AppState, actions: &mut Vec, ) { let ru = app.i18n().is_ru(); let screen = ctx.screen_rect(); let modal_r = Rect::from_center_size(screen.center(), Vec2::new(520.0, 456.0)); let mut mood = app.config.vibe_mood.clone(); let mut activity = app.config.vibe_activity.clone(); let mut character = app.config.vibe_character.clone(); let mut language = app.config.vibe_language.clone(); let mut changed = false; ctx.with_layer(ZLayer::Modal, |ctx| { ctx.register_blocker(screen); ctx.dl().push_rect(screen, 0.0, pal.bg_overlay); ctx.dl() .push_shadow(modal_r, 20.0, 28.0, 0.0, Vec2::new(0.0, 8.0), pal.shadow_modal); ctx.dl() .push_rect_bordered(modal_r, 20.0, pal.bg_popover, 1.0, pal.border_control); let inner = modal_r.shrink(22.0); let mut y = inner.top(); ctx.draw_text_ellipsis( if ru { "Настроить Мою волну" } else { "My Vibe settings" }, TextStyle::headline(20.0, pal.text_bright), Rect::from_xywh(inner.x, y, inner.w - 32.0, 28.0), TextAlign::Left, ); if icon_button( ctx, WidgetId::new("vibe_modal_close"), Rect::from_xywh(inner.right() - 28.0, y, 28.0, 28.0), Icon::Close, 14.0, pal.text_secondary, pal.text_bright, pal.surface_hover, false, app.i18n().close(), ) .clicked { actions.push(AppAction::SetVibeModalOpen(false)); } y += 40.0; y = draw_vibe_group( ctx, pal, inner.x, y, inner.w, if ru { "По занятию" } else { "Activity" }, if ru { &[ ("wake-up", "Проснуться"), ("work", "Работа"), ("workout", "Тренировка"), ("road", "В дороге"), ("sleep", "Уснуть"), ] } else { &[ ("wake-up", "Wake up"), ("work", "Work"), ("workout", "Workout"), ("road", "On the road"), ("sleep", "Sleep"), ] }, &mut activity, &mut changed, "vg_act", ); y = draw_vibe_group( ctx, pal, inner.x, y, inner.w, if ru { "Под настроение" } else { "Mood" }, if ru { &[ ("active", "Бодрое"), ("fun", "Весёлое"), ("calm", "Спокойное"), ("sad", "Грустное"), ] } else { &[ ("active", "Energetic"), ("fun", "Upbeat"), ("calm", "Calm"), ("sad", "Sad"), ] }, &mut mood, &mut changed, "vg_mood", ); y = draw_vibe_group( ctx, pal, inner.x, y, inner.w, if ru { "Под характер" } else { "Character" }, if ru { &[ ("favorite", "Любимое"), ("discover", "Незнакомое"), ("popular", "Популярное"), ] } else { &[ ("favorite", "Favorites"), ("discover", "Discover"), ("popular", "Popular"), ] }, &mut character, &mut changed, "vg_char", ); let _ = draw_vibe_group( ctx, pal, inner.x, y, inner.w, if ru { "По языку" } else { "Language" }, if ru { &[ ("russian", "Русский"), ("not-russian", "Иностранный"), ("without-words", "Без слов"), ] } else { &[ ("russian", "Russian"), ("not-russian", "Foreign"), ("without-words", "Instrumental"), ] }, &mut language, &mut changed, "vg_lang", ); // Footer buttons let foot_y = inner.bottom() - 38.0; let (reset_resp, _) = secondary_pill_button( ctx, pal, WidgetId::new("vibe_reset_btn"), Pos2::new(inner.x, foot_y), None, if ru { "Сбросить" } else { "Reset" }, 36.0, false, ); if reset_resp.clicked { mood = None; activity = None; character = None; language = None; changed = true; } let done_lbl = if ru { "Готово" } else { "Done" }; let done_w = (ctx.measure_text(done_lbl, TextStyle::medium(14.0, pal.on_yellow), None).x + 36.0).max(100.0); let (done_resp, _) = yellow_pill_button( ctx, pal, WidgetId::new("vibe_done_btn"), Pos2::new(inner.right() - done_w, foot_y), None, done_lbl, 36.0, false, ); if done_resp.clicked || ctx.input.clicked_outside(modal_r) { actions.push(AppAction::SetVibeModalOpen(false)); } }); if changed { actions.push(AppAction::ApplyVibeSettings { mood, activity, character, language, }); } } #[allow(clippy::too_many_arguments)] fn draw_vibe_group( ctx: &mut UiContext, pal: &YmPalette, x: f32, y: f32, max_w: f32, title: &str, options: &[(&str, &str)], selected: &mut Option, changed: &mut bool, id_prefix: &str, ) -> f32 { ctx.draw_text_ellipsis( title, TextStyle::bold(13.5, pal.text_secondary), Rect::from_xywh(x, y, max_w, 20.0), TextAlign::Left, ); let mut cx = x; let mut cy = y + 24.0; let chip_h = 34.0; for &(code, label) in options { let est_w = (ctx.measure_text(label, TextStyle::bold(14.0, pal.text_primary), None).x + 36.0).clamp(56.0, 200.0); if cx + est_w > x + max_w && cx > x { cx = x; cy += chip_h + 8.0; } let is_sel = selected.as_deref() == Some(code); let (resp, r) = secondary_pill_button( ctx, pal, WidgetId::from_pair(id_prefix, code), Pos2::new(cx, cy), None, label, chip_h, is_sel, ); if resp.clicked { if is_sel { *selected = None; } else { *selected = Some(code.to_string()); } *changed = true; } cx += r.width() + 8.0; } cy + chip_h + 14.0 } /// Create / Rename Playlist Modal (`app.playlist_modal`) pub fn render_playlist_modal( ctx: &mut UiContext, pal: &YmPalette, app: &mut AppState, actions: &mut Vec, ) { if matches!(app.playlist_modal, PlaylistModalState::None) { return; } let i18n = app.i18n(); let ru = i18n.is_ru(); let screen = ctx.screen_rect(); let is_create = matches!(app.playlist_modal, PlaylistModalState::Create { .. }); let modal_h = if is_create { 236.0 } else { 196.0 }; let modal_r = Rect::from_center_size(screen.center(), Vec2::new(430.0, modal_h)); let mut close_modal = false; let mut submit = false; ctx.with_layer(ZLayer::Modal, |ctx| { ctx.register_blocker(screen); ctx.dl().push_rect(screen, 0.0, pal.bg_overlay); ctx.dl() .push_shadow(modal_r, 20.0, 28.0, 0.0, Vec2::new(0.0, 8.0), pal.shadow_modal); ctx.dl() .push_rect_bordered(modal_r, 20.0, pal.bg_popover, 1.0, pal.border_control); let inner = modal_r.shrink(22.0); let heading = if is_create { i18n.create_playlist() } else { i18n.rename() }; ctx.draw_text_ellipsis( heading, TextStyle::headline(20.0, pal.text_bright), Rect::from_xywh(inner.x, inner.y, inner.w - 32.0, 28.0), TextAlign::Left, ); if icon_button( ctx, WidgetId::new("pl_modal_close"), Rect::from_xywh(inner.right() - 28.0, inner.y, 28.0, 28.0), Icon::Close, 14.0, pal.text_secondary, pal.text_bright, pal.surface_hover, false, i18n.close(), ) .clicked { close_modal = true; } // Editable title field let input_r = Rect::from_xywh(inner.x, inner.y + 44.0, inner.w, 42.0); let title_ref = match &mut app.playlist_modal { PlaylistModalState::Create { title_draft, .. } => title_draft, PlaylistModalState::Rename { title_draft, .. } => title_draft, PlaylistModalState::None => unreachable!(), }; let ir = text_input_widget( ctx, pal, WidgetId::new("pl_modal_title_input"), input_r, title_ref, TextInputOptions { placeholder: i18n.new_playlist_default(), leading_icon: None, show_clear_button: true, hide_placeholder_when_unfocused: false, font_size: 14.0, pill: false, transparent_bg: false, }, ); if ir.submitted { submit = true; } // Private checkbox toggle for Create mode if let PlaylistModalState::Create { is_private, .. } = &mut app.playlist_modal { let chk_row = Rect::from_xywh(inner.x, input_r.bottom() + 14.0, inner.w, 28.0); let chk_resp = ctx.interact(WidgetId::new("pl_modal_priv"), chk_row); let box_r = Rect::from_xywh(chk_row.x, chk_row.center_y() - 9.0, 18.0, 18.0); ctx.dl().push_rect_bordered( box_r, 5.0, if *is_private { pal.yellow } else { Color::TRANSPARENT }, 1.5, if *is_private { pal.yellow } else { pal.input_border }, ); if *is_private { ctx.draw_icon( Icon::CheckXxs, Rect::from_center_size(box_r.center(), Vec2::splat(14.0)), pal.on_yellow, ); } ctx.draw_text_ellipsis( i18n.private_playlist(), TextStyle::medium(13.5, pal.text_primary), Rect::from_xywh(box_r.right() + 10.0, chk_row.y, inner.w - 30.0, chk_row.h), TextAlign::Left, ); if chk_resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if chk_resp.clicked { *is_private = !*is_private; } } // Footer: Cancel + Save/Create let foot_y = inner.bottom() - 38.0; let (cancel_resp, _) = secondary_pill_button( ctx, pal, WidgetId::new("pl_modal_cancel"), Pos2::new(inner.x, foot_y), None, i18n.cancel(), 36.0, false, ); if cancel_resp.clicked { close_modal = true; } let confirm_lbl = if is_create { if ru { "Создать" } else { "Create" } } else { i18n.save() }; let cw = (ctx.measure_text(confirm_lbl, TextStyle::medium(14.0, pal.on_yellow), None).x + 36.0).max(108.0); let can_submit = match &app.playlist_modal { PlaylistModalState::Create { title_draft, .. } | PlaylistModalState::Rename { title_draft, .. } => !title_draft.trim().is_empty(), PlaylistModalState::None => false, }; let (ok_resp, _) = yellow_pill_button( ctx, pal, WidgetId::new("pl_modal_ok"), Pos2::new(inner.right() - cw, foot_y), None, confirm_lbl, 36.0, !can_submit, ); if ok_resp.clicked && can_submit { submit = true; } if ctx.input.clicked_outside(modal_r) { close_modal = true; } }); if submit { match app.playlist_modal.clone() { PlaylistModalState::Create { title_draft, is_private, initial_track, } => { if !title_draft.trim().is_empty() { actions.push(AppAction::CreatePlaylist { title: title_draft.trim().to_string(), is_private, initial_track, }); } } PlaylistModalState::Rename { owner_uid, kind, title_draft, } => { if !title_draft.trim().is_empty() { actions.push(AppAction::RenamePlaylist { owner_uid, kind, new_title: title_draft.trim().to_string(), }); } } PlaylistModalState::None => {} } } else if close_modal { actions.push(AppAction::ClosePlaylistModal); } } /// Delete Playlist Confirmation Dialog (`Отмена` / `Удалить`) pub fn render_delete_playlist_confirm_modal( ctx: &mut UiContext, pal: &YmPalette, app: &AppState, shell: &mut ShellUiState, actions: &mut Vec, ) { let Some((owner_uid, kind, title)) = shell.confirm_delete_playlist.clone() else { return; }; let i18n = app.i18n(); let ru = i18n.is_ru(); let screen = ctx.screen_rect(); let modal_w = 420.0f32.min(screen.width() - 48.0); let modal_h = 188.0; let modal_r = Rect::from_center_size(screen.center(), Vec2::new(modal_w, modal_h)); let mut close_modal = false; let mut confirm = false; ctx.with_layer(ZLayer::Modal, |ctx| { ctx.register_blocker(screen); ctx.dl().push_rect(screen, 0.0, css_rgba(0, 0, 0, 150)); ctx.dl() .push_shadow(modal_r, 20.0, 32.0, 0.0, Vec2::new(0.0, 8.0), pal.shadow_modal); ctx.dl() .push_rect_bordered(modal_r, 20.0, pal.bg_popover, 1.0, pal.border_control); let inner = modal_r.shrink(24.0); let heading = if ru { "Удалить плейлист?" } else { "Delete playlist?" }; ctx.draw_text_ellipsis( heading, TextStyle::headline(19.0, pal.text_primary), Rect::from_xywh(inner.x, inner.y, inner.w - 36.0, 28.0), TextAlign::Left, ); let close_r = Rect::from_xywh(inner.right() - 28.0, inner.y, 28.0, 28.0); if icon_button( ctx, WidgetId::new("del_pl_close"), close_r, Icon::CloseXxs, 18.0, pal.surface_hover, pal.text_secondary, pal.text_primary, false, i18n.close(), ) .clicked { close_modal = true; } let body = if ru { format!("Плейлист «{}» будет удалён без возможности восстановления.", title) } else { format!("Playlist \"{}\" will be permanently deleted.", title) }; ctx.draw_text_wrapped( &body, TextStyle::medium(13.5, pal.text_secondary), Rect::from_xywh(inner.x, inner.y + 42.0, inner.w, 48.0), Some(2), TextAlign::Left, ); let foot_y = inner.bottom() - 36.0; let (cancel_resp, _) = secondary_pill_button( ctx, pal, WidgetId::new("del_pl_cancel"), Pos2::new(inner.x, foot_y), None, i18n.cancel(), 36.0, false, ); if cancel_resp.clicked { close_modal = true; } let del_lbl = if ru { "Удалить" } else { "Delete" }; let dw = (ctx.measure_text(del_lbl, TextStyle::medium(14.0, Color::WHITE), None).x + 36.0) .max(108.0); let del_r = Rect::from_xywh(inner.right() - dw, foot_y, dw, 36.0); let del_resp = ctx.interact(WidgetId::new("del_pl_confirm"), del_r); let del_bg = if del_resp.hovered { Color::rgb(0xFF, 0x4A, 0x4D) } else { pal.accent_coral }; ctx.dl().push_rect(del_r, 18.0, del_bg); ctx.draw_text_ellipsis( del_lbl, TextStyle::medium(14.0, Color::WHITE), del_r, TextAlign::Center, ); if del_resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if del_resp.clicked { confirm = true; } if ctx.input.clicked_outside(modal_r) { close_modal = true; } }); if confirm { actions.push(AppAction::DeletePlaylist { owner_uid: owner_uid.to_string(), kind, }); shell.confirm_delete_playlist = None; } else if close_modal { shell.confirm_delete_playlist = None; } } /// OAuth Login Modal pub fn render_login_modal( ctx: &mut UiContext, pal: &YmPalette, app: &mut AppState, actions: &mut Vec, ) { let i18n = app.i18n(); let ru = i18n.is_ru(); let screen = ctx.screen_rect(); let modal_r = Rect::from_center_size(screen.center(), Vec2::new(460.0, 286.0)); ctx.with_layer(ZLayer::Modal, |ctx| { ctx.register_blocker(screen); ctx.dl().push_rect(screen, 0.0, pal.bg_overlay); ctx.dl() .push_shadow(modal_r, 20.0, 28.0, 0.0, Vec2::new(0.0, 8.0), pal.shadow_modal); ctx.dl() .push_rect_bordered(modal_r, 20.0, pal.bg_popover, 1.0, pal.border_control); let inner = modal_r.shrink(22.0); ctx.draw_text_ellipsis( if ru { "Вход в Яндекс Музыку" } else { "Sign in to Yandex Music" }, TextStyle::headline(20.0, pal.text_bright), Rect::from_xywh(inner.x, inner.y, inner.w - 32.0, 28.0), TextAlign::Left, ); if icon_button( ctx, WidgetId::new("login_close_btn"), Rect::from_xywh(inner.right() - 28.0, inner.y, 28.0, 28.0), Icon::Close, 14.0, pal.text_secondary, pal.text_bright, pal.surface_hover, false, i18n.close(), ) .clicked { actions.push(AppAction::SetLoginModalOpen(false)); } let desc = if ru { "Нажмите «Войти через Яндекс ID» — откроется окно входа и авторизация завершится автоматически. Либо вставьте OAuth-токен ниже." } else { "Click \"Sign in with Yandex ID\" to open the sign-in window, or paste an OAuth token manually below." }; ctx.draw_text_wrapped( desc, TextStyle::regular(13.0, pal.text_secondary), Rect::from_xywh(inner.x, inner.y + 36.0, inner.w, 46.0), Some(3), TextAlign::Left, ); let (oauth_resp, _) = yellow_pill_button( ctx, pal, WidgetId::new("login_oauth_btn"), Pos2::new(inner.x, inner.y + 92.0), Some(Icon::Plus), if ru { "Войти через Яндекс ID" } else { "Sign in with Yandex ID" }, 40.0, false, ); if oauth_resp.clicked { actions.push(AppAction::OpenOAuthBrowser); } let inp_r = Rect::from_xywh(inner.x, inner.y + 148.0, inner.w, 40.0); let ir = text_input_widget( ctx, pal, WidgetId::new("login_token_input"), inp_r, &mut app.token_input, TextInputOptions { placeholder: if ru { "Вставьте OAuth-токен (y0_...) или полный URL" } else { "Paste OAuth token (y0_...) or full URL" }, leading_icon: None, show_clear_button: true, hide_placeholder_when_unfocused: false, font_size: 13.5, pill: false, transparent_bg: false, }, ); if ir.submitted && !app.token_input.trim().is_empty() { actions.push(AppAction::SubmitOAuthToken(app.token_input.clone())); } let foot_y = inner.bottom() - 36.0; let (cancel_resp, _) = secondary_pill_button( ctx, pal, WidgetId::new("login_cancel_btn"), Pos2::new(inner.x, foot_y), None, i18n.cancel(), 36.0, false, ); if cancel_resp.clicked { actions.push(AppAction::SetLoginModalOpen(false)); } let ok_lbl = i18n.log_in(); let ok_w = (ctx.measure_text(ok_lbl, TextStyle::medium(14.0, pal.on_yellow), None).x + 62.0).max(110.0); let can_submit = !app.token_input.trim().is_empty(); let (ok_resp, _) = yellow_pill_button( ctx, pal, WidgetId::new("login_submit_btn"), Pos2::new(inner.right() - ok_w, foot_y), Some(Icon::Check), ok_lbl, 36.0, !can_submit, ); if ok_resp.clicked && can_submit { actions.push(AppAction::SubmitOAuthToken(app.token_input.clone())); } if ctx.input.clicked_outside(modal_r) { actions.push(AppAction::SetLoginModalOpen(false)); } }); } /// Official Yandex Music 5.129.0 430px Right-Side Slide-Over `TrackModal` (`.TrackModal_root__QrFg6`): /// - Full-height right sheet (`top: 12px`, `right: 12px`, `bottom: 12px`, `width: 430px`, `radius: 20px`) /// - Header: 88×88 cover, Track Title + Explicit, clickable `SeparatedArtists`, action row /// (`▶ Слушать`/`⏸ Пауза` yellow pill + Like + Dislike + Share/Copy link) /// - Album card section (`Из альбома` / `From album`) navigating to `Route::Album` /// - Lyrics preview section (`Текст песни` / `Lyrics`) with button to open Fullscreen SyncLyrics pub fn render_track_detail_modal( ctx: &mut UiContext, pal: &YmPalette, covers: &mut CoverCache, app: &AppState, actions: &mut Vec, ) { let Some(ref tr) = app.track_detail_modal else { return; }; let i18n = app.i18n(); let ru = i18n.is_ru(); let screen = ctx.screen_rect(); let panel_w = 430.0f32.min((screen.width() - 24.0).max(280.0)); let panel_r = Rect::from_xywh( screen.right() - panel_w - 12.0, 12.0, panel_w, (screen.height() - 24.0).max(260.0), ); let is_curr = app.current_track().map_or(false, |c| c.id == tr.id); let is_playing = is_curr && app.is_audio_playing(); let is_liked = app.liked_ids.contains(&tr.id); let is_disliked = app.disliked_ids.contains(&tr.id); let matching_lyrics = app .modal_lyrics .as_ref() .filter(|l| l.track_id == tr.id && !l.lines.is_empty()) .or_else(|| { app.current_lyrics .as_ref() .filter(|l| l.track_id == tr.id && !l.lines.is_empty()) }); ctx.with_layer(ZLayer::Modal, |ctx| { ctx.register_blocker(screen); // Subtle scrim behind slide-over panel ctx.dl().push_rect(screen, 0.0, css_rgba(0, 0, 0, 100)); ctx.dl().push_shadow( panel_r, 20.0, 28.0, 0.0, Vec2::new(-4.0, 6.0), pal.shadow_modal, ); ctx.dl().push_backdrop_blur( panel_r, 20.0, 2.0, pal.bg_popover.with_alpha(238), 1.0, pal.border_subtle, ); // Top-right Close `×` button (placed below the 32px TitleBar) let close_r = Rect::from_xywh(panel_r.right() - 48.0, panel_r.top() + 28.0, 32.0, 32.0); if icon_button( ctx, WidgetId::new("tdm_close"), close_r, Icon::Close, 16.0, pal.text_secondary, pal.text_bright, pal.surface_hover, false, i18n.close(), ) .clicked { actions.push(AppAction::CloseTrackDetailModal); } let body_viewport = Rect::from_min_max( Pos2::new(panel_r.left() + 24.0, panel_r.top() + 44.0), Pos2::new(panel_r.right() - 24.0, panel_r.bottom() - 20.0), ); let scroll_id = WidgetId::new("track_modal_scroll"); let scroll_y = ctx.begin_scroll_v(scroll_id, body_viewport, 0.0); let x = body_viewport.left(); let w = body_viewport.width(); let mut y = body_viewport.top() - scroll_y; // 1. Header: 88×88 cover + Track Title + Explicit + clickable SeparatedArtists let cov_r = Rect::from_xywh(x, y, 88.0, 88.0); draw_cover_art( ctx, pal, covers, cov_r, tr.cover_uri.as_deref(), &tr.id, 8.0, false, false, ); let tx = cov_r.right() + 16.0; let tw = (body_viewport.right() - tx - 32.0).max(80.0); let full_title = tr.full_title(); let title_w_avail = tw - if tr.is_explicit { 22.0 } else { 0.0 }; let measured_tw = ctx .measure_text(&full_title, TextStyle::bold(18.0, pal.text_bright), None) .x .min(title_w_avail); ctx.draw_text_ellipsis( &full_title, TextStyle::bold(18.0, pal.text_bright), Rect::from_xywh(tx, cov_r.top() + 12.0, title_w_avail, 26.0), TextAlign::Left, ); if tr.is_explicit { ctx.draw_icon( Icon::Explicit, Rect::from_center_size( Pos2::new(tx + measured_tw + 11.0, cov_r.top() + 25.0), Vec2::splat(18.0), ), pal.text_secondary, ); } let art_r = Rect::from_xywh(tx, cov_r.top() + 44.0, tw + 24.0, 22.0); if let Some((aid, aname)) = separated_artists( ctx, pal, WidgetId::new("tdm_artists"), art_r, &tr.artists, 14.0, pal.text_secondary, pal.text_primary, TextAlign::Left, ) { actions.push(AppAction::CloseTrackDetailModal); actions.push(AppAction::Navigate(Route::Artist { id: aid, name: aname })); } y = cov_r.bottom() + 20.0; // Action row: ▶ Слушать / ⏸ Пауза yellow pill + Like + Dislike + Share/Copy link let play_lbl = if is_playing { i18n.pause() } else { i18n.listen() }; let play_ic = if is_playing { Icon::PauseXxs } else { Icon::PlayXxs }; let (play_resp, play_rect) = yellow_pill_button( ctx, pal, WidgetId::new("tdm_play"), Pos2::new(x, y), Some(play_ic), play_lbl, 40.0, false, ); if play_resp.clicked { if is_curr { actions.push(AppAction::TogglePlay); } else { actions.push(AppAction::PlayTracks { tracks: vec![tr.clone()], start_index: 0, context_name: tr.title.clone(), context_key: format!("track:{}", tr.id), is_vibe: false, }); } } let mut bx = play_rect.right() + 10.0; let like_r = Rect::from_xywh(bx, y, 40.0, 40.0); ctx.dl().push_circle(like_r.center(), 20.0, pal.surface_secondary); if icon_button( ctx, WidgetId::new("tdm_like"), like_r, if is_liked { Icon::Liked } else { Icon::Like }, 22.0, if is_liked { pal.accent_coral } else { pal.text_primary }, if is_liked { pal.accent_coral_hover } else { pal.text_bright }, pal.surface_hover, false, i18n.like(), ) .clicked { actions.push(AppAction::ToggleLike(tr.clone())); } bx += 48.0; let dis_r = Rect::from_xywh(bx, y, 40.0, 40.0); ctx.dl().push_circle(dis_r.center(), 20.0, pal.surface_secondary); if icon_button( ctx, WidgetId::new("tdm_dislike"), dis_r, if is_disliked { Icon::Disliked } else { Icon::Dislike }, 22.0, if is_disliked { pal.text_bright } else { pal.text_primary }, pal.text_bright, pal.surface_hover, false, i18n.dislike(), ) .clicked { actions.push(AppAction::ToggleDislike(tr.clone())); } bx += 48.0; let share_r = Rect::from_xywh(bx, y, 40.0, 40.0); ctx.dl().push_circle(share_r.center(), 20.0, pal.surface_secondary); if icon_button( ctx, WidgetId::new("tdm_share"), share_r, Icon::Share, 20.0, pal.text_primary, pal.text_bright, pal.surface_hover, false, i18n.copy_link(), ) .clicked { actions.push(AppAction::CopyTrackLink(tr.clone())); } y += 60.0; // 2. Album card section (`Из альбома` / `From album`) if let Some(ref aid) = tr.album_id { ctx.draw_text_ellipsis( if ru { "Из альбома" } else { "From album" }, TextStyle::bold(13.5, pal.text_secondary), Rect::from_xywh(x, y, w, 20.0), TextAlign::Left, ); y += 26.0; let album_card_r = Rect::from_xywh(x, y, w, 72.0); let album_resp = ctx.interact(WidgetId::new("tdm_album_card"), album_card_r); ctx.dl().push_rect( album_card_r, 12.0, if album_resp.hovered { pal.surface_hover } else { pal.surface_secondary }, ); let acov = Rect::from_xywh(album_card_r.left() + 10.0, album_card_r.top() + 10.0, 52.0, 52.0); draw_cover_art( ctx, pal, covers, acov, tr.cover_uri.as_deref(), aid, 6.0, false, false, ); let atx = acov.right() + 12.0; let atw = (album_card_r.right() - atx - 30.0).max(60.0); let album_name = tr .album_title .clone() .unwrap_or_else(|| i18n.album().to_string()); ctx.draw_text_ellipsis( &album_name, TextStyle::medium(14.0, pal.text_primary), Rect::from_xywh(atx, album_card_r.top() + 14.0, atw, 20.0), TextAlign::Left, ); ctx.draw_text_ellipsis( &tr.artists_string(), TextStyle::regular(12.5, pal.text_secondary), Rect::from_xywh(atx, album_card_r.top() + 36.0, atw, 18.0), TextAlign::Left, ); ctx.draw_icon( Icon::ArrowRightXxs, Rect::from_center_size( Pos2::new(album_card_r.right() - 18.0, album_card_r.center_y()), Vec2::splat(18.0), ), pal.text_secondary, ); if album_resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if album_resp.clicked { actions.push(AppAction::CloseTrackDetailModal); actions.push(AppAction::Navigate(Route::Album { id: aid.clone(), title: album_name, })); } y += 92.0; } // 3. Lyrics preview section (`Текст песни` / `Lyrics`) if matching_lyrics.is_some() || tr.has_lyrics { ctx.draw_text_ellipsis( i18n.lyrics(), TextStyle::bold(13.5, pal.text_secondary), Rect::from_xywh(x, y, w, 20.0), TextAlign::Left, ); y += 26.0; let preview_text = if let Some(lyr) = matching_lyrics { let mut lines: Vec<&str> = lyr .lines .iter() .map(|l| l.text.trim()) .filter(|s| !s.is_empty()) .take(14) .collect(); if lyr.lines.len() > 14 { lines.push("…"); } lines.join("\n") } else if ru { "Синхронизированный текст доступен в полноэкранном плеере".to_string() } else { "Synced lyrics are available in the fullscreen player".to_string() }; let text_w = (w - 32.0).max(120.0); let measured_lyr = ctx.measure_text( &preview_text, TextStyle::medium(14.0, pal.text_primary), Some(text_w), ); let writers_h = matching_lyrics .and_then(|l| l.writers.as_ref()) .map_or(0.0, |_| 28.0); let card_h = 16.0 + measured_lyr.y.max(44.0) + writers_h + 56.0; let lyr_card_r = Rect::from_xywh(x, y, w, card_h); ctx.dl().push_rect(lyr_card_r, 14.0, pal.surface_secondary); ctx.draw_text_wrapped( &preview_text, TextStyle::medium(14.0, pal.text_primary), Rect::from_xywh(x + 16.0, y + 16.0, text_w, measured_lyr.y + 8.0), None, TextAlign::Left, ); if let Some(writers) = matching_lyrics.and_then(|l| l.writers.as_ref()) { let w_str = if ru { format!("Авторы: {}", writers) } else { format!("Writers: {}", writers) }; ctx.draw_text_ellipsis( &w_str, TextStyle::regular(12.0, pal.text_secondary), Rect::from_xywh( x + 16.0, y + 22.0 + measured_lyr.y.max(44.0), text_w, 18.0, ), TextAlign::Left, ); } let btn_y = lyr_card_r.bottom() - 48.0; let (sync_resp, _) = secondary_pill_button( ctx, pal, WidgetId::new("tdm_open_sync_lyrics"), Pos2::new(x + 16.0, btn_y), Some(Icon::SyncLyricsXxs), i18n.open_sync_lyrics(), 36.0, false, ); if sync_resp.clicked { actions.push(AppAction::CloseTrackDetailModal); if !is_curr { actions.push(AppAction::PlayTracks { tracks: vec![tr.clone()], start_index: 0, context_name: tr.title.clone(), context_key: format!("track:{}", tr.id), is_vibe: false, }); } actions.push(AppAction::SetFullscreen(true)); if !app.fullscreen_lyrics_open { actions.push(AppAction::ToggleFullscreenLyrics); } } y = lyr_card_r.bottom() + 16.0; } let total_h = (y - (body_viewport.top() - scroll_y)).max(0.0); ctx.end_scroll_v(scroll_id, pal, total_h, true); if ctx.input.clicked_outside(panel_r) { actions.push(AppAction::CloseTrackDetailModal); } }); } // ============================================================================= // 6. Floating 10-Band EQ Popover (above Player Bar) // ============================================================================= pub fn render_eq_popover( ctx: &mut UiContext, pal: &YmPalette, app: &AppState, actions: &mut Vec, ) { let ru = app.i18n().is_ru(); let screen = ctx.screen_rect(); let pop_w = 436.0; let pop_h = 248.0; let pop_r = Rect::from_xywh( (screen.right() - pop_w - 20.0).max(8.0), (screen.bottom() - PLAYER_BAR_HEIGHT - pop_h - 26.0).max(36.0), pop_w, pop_h, ); let mut enabled = app.config.eq_enabled; let mut bands = app.config.eq_bands_db; let mut changed = false; ctx.with_layer(ZLayer::Popover, |ctx| { ctx.register_blocker(pop_r); ctx.dl() .push_shadow(pop_r, 16.0, 22.0, 0.0, Vec2::new(0.0, 6.0), pal.shadow_menu); ctx.dl() .push_backdrop_blur(pop_r, 16.0, 2.0, pal.bg_menu, 1.0, pal.border_control); let inner = pop_r.shrink(14.0); // Header: Title + Enabled toggle + Close `×` ctx.draw_text_ellipsis( if ru { "Эквалайзер" } else { "Equalizer" }, TextStyle::bold(15.0, pal.text_bright), Rect::from_xywh(inner.x, inner.y, 120.0, 24.0), TextAlign::Left, ); let tog_r = Rect::from_xywh(inner.x + 126.0, inner.y, 110.0, 24.0); let tog_resp = ctx.interact(WidgetId::new("eq_enable_tog"), tog_r); let box_r = Rect::from_xywh(tog_r.x, tog_r.center_y() - 8.0, 16.0, 16.0); ctx.dl().push_rect_bordered( box_r, 4.0, if enabled { pal.yellow } else { Color::TRANSPARENT }, 1.5, if enabled { pal.yellow } else { pal.input_border }, ); if enabled { ctx.draw_icon( Icon::CheckXxs, Rect::from_center_size(box_r.center(), Vec2::splat(13.0)), pal.on_yellow, ); } ctx.draw_text_ellipsis( if ru { "Включён" } else { "Enabled" }, TextStyle::medium(12.5, pal.text_primary), Rect::from_xywh(box_r.right() + 6.0, tog_r.y, 84.0, 24.0), TextAlign::Left, ); if tog_resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if tog_resp.clicked { enabled = !enabled; changed = true; } if icon_button( ctx, WidgetId::new("eq_close_btn"), Rect::from_xywh(inner.right() - 24.0, inner.y, 24.0, 24.0), Icon::Close, 12.0, pal.text_secondary, pal.text_bright, pal.surface_hover, false, app.i18n().close(), ) .clicked { actions.push(AppAction::SetEqPopoverOpen(false)); } // Preset chips row let mut px = inner.x; let py = inner.y + 32.0; for (pi, preset) in EQ_PRESETS.iter().take(5).enumerate() { let lbl_w = ctx .measure_text(preset.name, TextStyle::medium(11.5, pal.text_primary), None) .x + 16.0; let pr = Rect::from_xywh(px, py, lbl_w, 24.0); let presp = ctx.interact(WidgetId::from_pair("eq_preset", pi), pr); ctx.dl().push_rect( pr, 12.0, if presp.hovered { pal.chip_hover } else { pal.chip_bg }, ); ctx.draw_text_ellipsis( preset.name, TextStyle::medium(11.5, pal.text_primary), pr, TextAlign::Center, ); if presp.hovered { ctx.set_cursor(CursorKind::Pointer); } if presp.clicked { enabled = true; bands = preset.gains; changed = true; } px += lbl_w + 6.0; } // 10 vertical band sliders let band_top = py + 34.0; let band_h = (inner.bottom() - band_top - 22.0).max(80.0); let col_w = inner.w / 10.0; for i in 0..10 { let bx = inner.x + i as f32 * col_w; let sr = Rect::from_xywh(bx + 4.0, band_top, col_w - 8.0, band_h); let norm = ((bands[i] + 12.0) / 24.0).clamp(0.0, 1.0); let sresp = ym_vertical_slider( ctx, pal, WidgetId::from_pair("eq_band", i), sr, norm, false, if enabled { pal.yellow } else { pal.text_primary }, ); if let Some(v) = sresp.value { bands[i] = (v * 24.0 - 12.0).clamp(-12.0, 12.0); enabled = true; changed = true; } ctx.draw_text_ellipsis( EQ_LABELS[i], TextStyle::bold(10.0, pal.text_secondary), Rect::from_xywh(bx, band_top + band_h + 4.0, col_w, 16.0), TextAlign::Center, ); } if ctx.input.clicked_outside(pop_r) { actions.push(AppAction::SetEqPopoverOpen(false)); } }); if changed { actions.push(AppAction::UpdateEq { enabled, bands }); } } // ============================================================================= // 7. Floating Toast Notification // ============================================================================= pub fn render_toast(ctx: &mut UiContext, pal: &YmPalette, msg: &str) { let screen = ctx.screen_rect(); let max_w = (screen.width() - 64.0).min(520.0); let text_sz = ctx.measure_text(msg, TextStyle::medium(13.5, pal.text_bright), Some(max_w - 32.0)); let w = (text_sz.x + 36.0).clamp(160.0, max_w); let h = (text_sz.y + 20.0).max(40.0); let rect = Rect::from_center_size( Pos2::new(screen.center_x(), screen.bottom() - PLAYER_BAR_HEIGHT - 44.0), Vec2::new(w, h), ); ctx.with_layer(ZLayer::Titlebar, |ctx| { ctx.dl() .push_shadow(rect, 12.0, 18.0, 0.0, Vec2::new(0.0, 4.0), pal.shadow_menu); ctx.dl() .push_rect_bordered(rect, 12.0, pal.bg_popover, 1.0, pal.border_control); ctx.draw_text_ellipsis( msg, TextStyle::medium(13.5, pal.text_bright), rect.shrink2(Vec2::new(14.0, 4.0)), TextAlign::Center, ); }); } // ============================================================================= // 8. Theme-Aware Streaming Animated Splash Screen (`splash_dark.webp` / `splash_light.webp`) // ============================================================================= struct SplashFrame { index: usize, width: u32, height: u32, premul_rgba: Vec, } pub struct SplashPlayer { started_at: Instant, is_dark: bool, rx: Receiver, tex_id: Option, pending: Option, } impl SplashPlayer { /// Spawns a bounded 4-frame background WebP decoder selecting `splash_dark.webp` on `#000` /// or `splash_light.webp` on `#FFF` to match official Yandex Music 5.129.0 SplashScreen 1-to-1! pub fn spawn(is_dark: bool) -> Self { let (tx, rx) = crossbeam_channel::bounded::(4); std::thread::Builder::new() .name("ym-splash-decode".into()) .spawn(move || { use image::AnimationDecoder; static SPLASH_DARK_WEBP: &[u8] = include_bytes!("../../assets/icons/splash_dark.webp"); static SPLASH_LIGHT_WEBP: &[u8] = include_bytes!("../../assets/icons/splash_light.webp"); let bytes = if is_dark { SPLASH_DARK_WEBP } else { SPLASH_LIGHT_WEBP }; let Ok(dec) = image::codecs::webp::WebPDecoder::new(std::io::Cursor::new(bytes)) else { return; }; for (index, frame_res) in dec.into_frames().enumerate() { let Ok(frame) = frame_res else { break }; let buf = frame.into_buffer(); let (width, height) = (buf.width(), buf.height()); let premul_rgba = premultiply_rgba_srgb(buf.as_raw()); if tx .send(SplashFrame { index, width, height, premul_rgba, }) .is_err() { break; } } }) .ok(); Self { started_at: Instant::now(), is_dark, rx, tex_id: None, pending: None, } } fn advance(&mut self, textures: &mut TextureRegistry, target_frame: usize) { let mut latest: Option = None; if let Some(ref p) = self.pending { if p.index <= target_frame { latest = self.pending.take(); } } if self.pending.is_none() { while let Ok(f) = self.rx.try_recv() { if f.index <= target_frame { latest = Some(f); } else { self.pending = Some(f); break; } } } if let Some(f) = latest { let id = match self.tex_id { Some(id) => id, None => { let id = textures.allocate_id(); self.tex_id = Some(id); id } }; textures.upload_rgba_premul_with_id(id, f.width, f.height, f.premul_rgba); } } /// Renders splash frame; returns `true` when finished/skipped (and frees its GPU texture!). pub fn render(&mut self, ctx: &mut UiContext) -> bool { let elapsed = self.started_at.elapsed().as_secs_f32(); if elapsed >= 3.20 { self.release_texture(&mut ctx.textures); return true; } let target_frame = ((elapsed * 30.0).floor() as usize).min(89); self.advance(&mut ctx.textures, target_frame); let fade = if elapsed <= 3.00 { 1.0f32 } else { let u = ((elapsed - 3.00) / 0.20).clamp(0.0, 1.0); 1.0 - (u * u * (3.0 - 2.0 * u)) }; let screen = ctx.screen_rect(); let mut skipped = false; ctx.with_layer(ZLayer::Titlebar, |ctx| { ctx.register_blocker(screen); let resp = ctx.interact(WidgetId::new("ym_splash_click"), screen); if resp.clicked { skipped = true; } let bg = if self.is_dark { Color::BLACK } else { Color::WHITE }.with_alpha_f32(fade); ctx.dl().push_rect(screen, 0.0, bg); // Exact `.SplashScreen_video { width: 65%; aspect-ratio: 1 }` let stage_sz = (screen.width() * 0.65).min(screen.height() * 0.95); let video_r = Rect::from_center_size(screen.center(), Vec2::splat(stage_sz)); if let Some(tex_id) = self.tex_id { ctx.dl() .push_image(video_r, tex_id, CornerRadii::ZERO, Color::WHITE.with_alpha_f32(fade)); } }); if skipped { self.release_texture(&mut ctx.textures); true } else { ctx.request_repaint(); false } } pub fn release_texture(&mut self, textures: &mut TextureRegistry) { if let Some(id) = self.tex_id.take() { textures.free(id); } } }