use std::time::Instant; use crossbeam_channel::Receiver; use crate::api::models::{format_ms, Track, TrackLyrics, UpdateInfo}; use crate::app::i18n::APP_VERSION; use crate::app::state::is_newer_version; use crate::app::{AppAction, AppState, PlaylistModalState, RepeatMode, RightDrawerTab, Route}; use crate::audio::dsp::{active_eq_preset_name, EQ_LABELS, EQ_PRESETS}; use crate::config::AudioQuality; use crate::covers::CoverCache; use crate::engine::text::RichSpan; use crate::engine::textures::{premultiply_rgba_srgb, TextureRegistry}; use crate::engine::widgets::{ draw_cover_art, draw_downloading_progress, icon_button, secondary_pill_button, separated_artists, text_input_widget, yellow_pill_button, ym_menu_frame, ym_menu_item, ym_menu_item_ex, ym_volume_capsule, SliderResponse, 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, pub last_route: Option, pub route_transition_start: f64, pub last_drawer_tab: Option, pub fs_slide_dy: f32, pub eq_presets_dropdown_open: bool, } 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 = if app.right_drawer != RightDrawerTab::None { shell.last_drawer_tab = Some(app.right_drawer); app.right_drawer } else { shell.last_drawer_tab.unwrap_or(RightDrawerTab::Queue) }; 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 mut screen = ctx.screen_rect(); if shell.fs_slide_dy.abs() > 0.5 { screen = Rect::from_xywh( screen.left(), screen.top() + shell.fs_slide_dy, screen.width(), screen.height(), ); } 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, 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 / Downloading / Delete from device (`TrackContextMenuDownloadItem`) let is_downloading = app.is_track_downloading(&tr.id); let r = Rect::from_xywh(inner.x, y, inner.w, row_h); if is_downloading { let dl_resp = ctx.interact(WidgetId::new("tcm_dl"), r); if dl_resp.hovered { ctx.dl().push_rect(r, 8.0, pal.surface_hover); ctx.set_cursor(CursorKind::Pointer); } draw_downloading_progress( ctx, pal, Pos2::new(r.left() + 18.0, r.center_y()), 20.0, app.track_download_progress(&tr.id), true, dl_resp.hovered, ); ctx.draw_text_ellipsis( i18n.stop_download(), TextStyle::medium(13.5, pal.text_primary), Rect::from_xywh(r.left() + 38.0, r.top(), (r.width() - 46.0).max(40.0), r.height()), TextAlign::Left, ); if dl_resp.clicked { actions.push(AppAction::CancelDownload); close_menu = true; } } else 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.consume_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.consume_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.consume_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.consume_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.consume_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.consume_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.text_bright } else { pal.text_primary }, 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.consume_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, shell: &mut ShellUiState, anim_t: f32, eq_expand_t: f32, actions: &mut Vec, ) { let i18n = app.i18n(); let ru = i18n.is_ru(); let screen = ctx.screen_rect(); let open = app.eq_popover_open; let alpha = anim_t.clamp(0.0, 1.0); let expand_t = eq_expand_t.clamp(0.0, 1.0); let pop_w = (screen.width() - 32.0).clamp(320.0, 430.0); let qualities = [ ( AudioQuality::Lossless, if ru { "Превосходное" } else { "Superb" }, if ru { "Музыка в lossless и других высококачественных форматах для быстрого интернета и хорошей акустики" } else { "Music in lossless and other high-quality formats for fast internet connections and superior acoustic systems" }, ), ( AudioQuality::High, if ru { "Оптимальное" } else { "Balanced" }, if ru { "Сбалансированный звук для большинства устройств" } else { "Balanced sound for most devices" }, ), ( AudioQuality::Standard, if ru { "Экономичное" } else { "Efficient" }, if ru { "Стабильное звучание при медленном интернете" } else { "Stable sound with a slow internet connection" }, ), ]; let txt_w = (pop_w - 72.0).max(120.0); let mut row_heights = [0.0f32; 3]; let mut total_rows_h = 0.0f32; for (idx, (_, _, sub)) in qualities.iter().enumerate() { let sub_h = ctx .measure_text(sub, TextStyle::regular(12.0, pal.text_secondary), Some(txt_w)) .y .max(16.0); let rh = 10.0 + 19.0 + 3.0 + sub_h + 10.0; row_heights[idx] = rh; total_rows_h += rh + 4.0; } // Header (20+32+18) + Quality rows + Gap (20) + EQ header (28) + Bottom pad (22) let base_h = 70.0 + total_rows_h + 20.0 + 28.0 + 22.0; let eq_extra_h = 246.0 * expand_t; let pop_h = (base_h + eq_extra_h).min((screen.height() - PLAYER_BAR_HEIGHT - 56.0).max(280.0)); // Official `Modal` (`placement="right"`, `1372-8bc732062b5d53ca.js`): glides smoothly in from right edge! let slide_dx = (1.0 - alpha) * 32.0; let pop_r = Rect::from_xywh( (screen.right() - pop_w - 16.0).max(16.0) + slide_dx, (screen.bottom() - PLAYER_BAR_HEIGHT - pop_h - 18.0).max(40.0), pop_w, pop_h, ); let mut enabled = app.config.eq_enabled; let mut preamp = app.config.eq_preamp; let mut bands = app.config.eq_bands_db; let mut changed = false; ctx.with_layer(ZLayer::Popover, |ctx| { if open { ctx.register_blocker(pop_r); } ctx.dl().push_shadow( pop_r, 16.0, 24.0, 0.0, Vec2::new(0.0, 6.0), pal.shadow_menu.scale_alpha(alpha), ); ctx.dl().push_rect_bordered( pop_r, 16.0, pal.bg_popover.scale_alpha(alpha), 1.0, pal.border_subtle.scale_alpha(alpha), ); ctx.push_clip(pop_r, 16.0); // Header: `"Настройки звука"` + filled circular Close `×` (`radius="round" color="secondary"`) let hdr_r = Rect::from_xywh(pop_r.left() + 24.0, pop_r.top() + 20.0, pop_w - 48.0, 32.0); ctx.draw_text_ellipsis( i18n.sound_settings(), TextStyle::headline(20.0, pal.text_bright.scale_alpha(alpha)), Rect::from_xywh(hdr_r.left(), hdr_r.top(), hdr_r.width() - 40.0, hdr_r.height()), TextAlign::Left, ); let close_r = Rect::from_xywh(hdr_r.right() - 32.0, hdr_r.top(), 32.0, 32.0); ctx.dl() .push_circle(close_r.center(), 16.0, pal.surface_hover.scale_alpha(alpha)); if open && icon_button( ctx, WidgetId::new("qs_close_btn"), close_r, Icon::Close, 14.0, pal.text_bright.scale_alpha(alpha), pal.text_bright.scale_alpha(alpha), pal.surface_hover.scale_alpha(alpha), false, i18n.close(), ) .clicked { shell.eq_presets_dropdown_open = false; actions.push(AppAction::SetEqPopoverOpen(false)); } // 3 Official Quality Options (`QualitySettings_item`) let mut y = hdr_r.bottom() + 18.0; for (idx, (q, title, sub)) in qualities.iter().enumerate() { let rh = row_heights[idx]; let row_r = Rect::from_xywh(pop_r.left() + 10.0, y, pop_w - 20.0, rh); let resp = if open { ctx.interact(WidgetId::from_pair("qs_qual", *q as u8), row_r) } else { Default::default() }; let active = app.config.audio_quality == *q; if resp.hovered { ctx.dl() .push_rect(row_r, 10.0, pal.surface_hover.scale_alpha(alpha)); ctx.set_cursor(CursorKind::Pointer); } let row_txt_x = row_r.left() + 14.0; let row_txt_w = (row_r.width() - 48.0).max(80.0); ctx.draw_text_ellipsis( title, TextStyle::bold(14.5, pal.text_bright.scale_alpha(alpha)), Rect::from_xywh(row_txt_x, row_r.top() + 9.0, row_txt_w, 19.0), TextAlign::Left, ); ctx.draw_text_wrapped( sub, TextStyle::regular(12.0, pal.text_secondary.scale_alpha(alpha)), Rect::from_xywh(row_txt_x, row_r.top() + 31.0, row_txt_w, rh - 36.0), None, TextAlign::Left, ); if active { ctx.draw_icon( Icon::CheckXxs, Rect::from_center_size( Pos2::new(row_r.right() - 18.0, row_r.center_y()), Vec2::splat(16.0), ), pal.text_bright.scale_alpha(alpha), ); } if resp.clicked && !active { actions.push(AppAction::SetAudioQuality(*q)); } y += rh + 4.0; } // Clean official vertical spacing before Equalizer section (no extra divider line) y += 20.0; // Inline Official Equalizer (`Equalizer_header` + animated expandable Preamp + 10 bands + Presets) let eq_area = Rect::from_min_max( Pos2::new(pop_r.left() + 24.0, y), Pos2::new(pop_r.right() - 24.0, pop_r.bottom() - 20.0), ); let dd_anchor = render_equalizer_body( ctx, pal, eq_area, if ru { "Эквалайзер" } else { "Equalizer" }, ru, &mut enabled, &mut preamp, &mut bands, &mut changed, &mut shell.eq_presets_dropdown_open, alpha, expand_t, false, open, "qs_eq", ); ctx.pop_clip(); // Render floating presets dropdown OUTSIDE popover clip so `placement: "top"` is never cut off! let mut dd_rect: Option = None; if open && shell.eq_presets_dropdown_open { if let Some((sel_r, sel_clicked)) = dd_anchor { dd_rect = render_eq_presets_dropdown( ctx, pal, sel_r, pop_r, ru, &mut enabled, &mut preamp, &mut bands, &mut changed, &mut shell.eq_presets_dropdown_open, sel_clicked, "qs_eq", ); } } if open { let mut keep = vec![pop_r]; if let Some(dr) = dd_rect { keep.push(dr); } if ctx.input.consume_clicked_outside_any(&keep) { shell.eq_presets_dropdown_open = false; actions.push(AppAction::SetEqPopoverOpen(false)); } } }); if changed { actions.push(AppAction::UpdateEq { enabled, preamp, bands, }); } } /// 1-to-1 Official `EqualizerModal` (`Equalizer_modal__yW0lz`, `430px` centered modal). pub fn render_equalizer_modal( ctx: &mut UiContext, pal: &YmPalette, app: &AppState, shell: &mut ShellUiState, anim_t: f32, actions: &mut Vec, ) { let i18n = app.i18n(); let ru = i18n.is_ru(); let open = app.equalizer_modal_open; let alpha = anim_t.clamp(0.0, 1.0); let screen = ctx.screen_rect(); let modal_w = (screen.width() - 48.0).clamp(320.0, 430.0); let modal_h = 370.0; let modal_r = Rect::from_center_size( Pos2::new(screen.center_x(), screen.center_y()), Vec2::new(modal_w, modal_h), ); let mut enabled = app.config.eq_enabled; let mut preamp = app.config.eq_preamp; let mut bands = app.config.eq_bands_db; let mut changed = false; ctx.with_layer(ZLayer::Modal, |ctx| { if open { ctx.register_blocker(screen); } ctx.dl().push_rect( screen, 0.0, Color::rgba(0, 0, 0, (150.0 * alpha).round() as u8), ); ctx.dl().push_shadow( modal_r, 16.0, 32.0, 0.0, Vec2::new(0.0, 8.0), pal.shadow_modal.scale_alpha(alpha), ); ctx.dl().push_rect_bordered( modal_r, 16.0, pal.bg_popover.scale_alpha(alpha), 1.0, pal.border_subtle.scale_alpha(alpha), ); let hdr_r = Rect::from_xywh(modal_r.left() + 24.0, modal_r.top() + 20.0, modal_w - 48.0, 32.0); ctx.draw_text_ellipsis( if ru { "Эквалайзер" } else { "Equalizer" }, TextStyle::headline(20.0, pal.text_bright.scale_alpha(alpha)), Rect::from_xywh(hdr_r.left(), hdr_r.top(), hdr_r.width() - 40.0, hdr_r.height()), TextAlign::Left, ); let eq_close_r = Rect::from_xywh(hdr_r.right() - 32.0, hdr_r.top(), 32.0, 32.0); ctx.dl() .push_circle(eq_close_r.center(), 16.0, pal.surface_hover.scale_alpha(alpha)); if open && icon_button( ctx, WidgetId::new("eq_modal_close"), eq_close_r, Icon::Close, 14.0, pal.text_bright.scale_alpha(alpha), pal.text_bright.scale_alpha(alpha), pal.surface_hover.scale_alpha(alpha), false, i18n.close(), ) .clicked { shell.eq_presets_dropdown_open = false; actions.push(AppAction::SetEqualizerModalOpen(false)); } let eq_area = Rect::from_min_max( Pos2::new(modal_r.left() + 20.0, hdr_r.bottom() + 24.0), Pos2::new(modal_r.right() - 20.0, modal_r.bottom() - 20.0), ); let is_disabled = !enabled; let dd_anchor = render_equalizer_body( ctx, pal, eq_area, if ru { "Включить" } else { "Turn on" }, ru, &mut enabled, &mut preamp, &mut bands, &mut changed, &mut shell.eq_presets_dropdown_open, alpha, 1.0, is_disabled, open, "em_eq", ); let mut dd_rect: Option = None; if open && shell.eq_presets_dropdown_open { if let Some((sel_r, sel_clicked)) = dd_anchor { dd_rect = render_eq_presets_dropdown( ctx, pal, sel_r, modal_r, ru, &mut enabled, &mut preamp, &mut bands, &mut changed, &mut shell.eq_presets_dropdown_open, sel_clicked, "em_eq", ); } } if open { let mut keep = vec![modal_r]; if let Some(dr) = dd_rect { keep.push(dr); } if ctx.input.consume_clicked_outside_any(&keep) { shell.eq_presets_dropdown_open = false; actions.push(AppAction::SetEqualizerModalOpen(false)); } } }); if changed { actions.push(AppAction::UpdateEq { enabled, preamp, bands, }); } } /// Official `EqualizerSlider` (`8711fa44496b8e09.css:340-416` + `.d6VuG0HnwpGO47uPjPeb` + `.P8_ABi1YnAOS8p8EY87f`): /// - Thin `1px` (`0.0625rem`) muted vertical track (NO yellow fill from bottom) /// - Centered `8×1px` `0 dB` serif tick /// - Always-visible `13px` (`0.8125rem`) hollow dark-filled circular thumb with `1.5px` yellow border (`border_control` when disabled) fn eq_vertical_slider( ctx: &mut UiContext, pal: &YmPalette, id: WidgetId, rect: Rect, norm_val: f32, disabled: bool, interactive: bool, alpha: f32, ) -> SliderResponse { let resp = if !disabled && interactive { ctx.interact(id, rect) } else { Default::default() }; let active = !disabled && (resp.hovered || resp.pressed || resp.dragged); let cx = rect.center_x(); let top = rect.top() + 7.0; let bot = rect.bottom() - 7.0; let track_h = (bot - top).max(20.0); // Thin 1.5px muted vertical track (`trackSize_xxs`) let track_col = pal.border_control.scale_alpha(alpha); ctx.dl() .push_rect(Rect::from_xywh(cx - 0.75, top, 1.5, track_h), 0.75, track_col); // Centered 8×1px horizontal serif tick at midpoint (`EqualizerSlider_serif`) ctx.dl().push_rect( Rect::from_xywh((cx - 4.0).round(), (top + track_h * 0.5).round(), 8.0, 1.0), 0.0, track_col, ); // Official circular thumb (`14px` diameter, medium-gray interior + crisp `1.5px` yellow ring) let frac = norm_val.clamp(0.0, 1.0); let thumb_y = bot - frac * track_h; let thumb_r = if active { 7.5 } else { 7.0 }; let thumb_fill = if pal.is_dark { Color::rgb(0x42, 0x42, 0x42) } else { Color::rgb(0xE0, 0xE0, 0xE0) } .scale_alpha(alpha); let border_col = if disabled { pal.border_control.scale_alpha(alpha) } else { pal.yellow.scale_alpha(alpha) }; ctx.dl().push_rect_bordered( Rect::from_center_size(Pos2::new(cx, thumb_y), Vec2::splat(thumb_r * 2.0)), thumb_r, thumb_fill, 1.5, border_col, ); if active { ctx.set_cursor(CursorKind::Pointer); } let mut new_val = None; if !disabled && interactive && (resp.pressed || resp.dragged || resp.clicked) { if let Some(p) = ctx.input.pointer_pos { new_val = Some((1.0 - (p.y - top) / track_h).clamp(0.0, 1.0)); } } SliderResponse { value: new_val, hovered: resp.hovered, dragging: resp.pressed || resp.dragged, } } /// Shared official Yandex Music 5.129.0 Equalizer UI (module `31051`, `8711fa44496b8e09.css:136-422`): /// Header + Toggle -> Expandable (Preamp + `12dB/0dB/-12dB` labels + 10 frequency bands) -> Full-width Pill Preset Selector. #[allow(clippy::too_many_arguments)] fn render_equalizer_body( ctx: &mut UiContext, pal: &YmPalette, area: Rect, toggle_title: &str, ru: bool, enabled: &mut bool, preamp: &mut f32, bands: &mut [f32; 10], changed: &mut bool, dropdown_open: &mut bool, anim_alpha: f32, expand_t: f32, is_disabled: bool, interactive: bool, salt: &str, ) -> Option<(Rect, bool)> { // 1. Header row: Title + official Toggle (`32×20px`, `16px` knob, `rqUESGQ8jp3tbDawOzuG`) let hdr_r = Rect::from_xywh(area.left(), area.top(), area.width(), 24.0); ctx.draw_text_ellipsis( toggle_title, TextStyle::medium(16.0, pal.text_bright.scale_alpha(anim_alpha)), Rect::from_xywh(hdr_r.left(), hdr_r.top(), hdr_r.width() - 44.0, hdr_r.height()), TextAlign::Left, ); let sw_w = 32.0; let sw_h = 20.0; let sw_r = Rect::from_xywh(hdr_r.right() - sw_w, hdr_r.center_y() - sw_h * 0.5, sw_w, sw_h); let sw_id = WidgetId::new(salt).with("toggle"); let sw_resp = if interactive { ctx.interact(sw_id, sw_r) } else { Default::default() }; let tog_t = ctx.animate_bool(sw_id.with("anim"), *enabled, 0.16); let track_col = pal.surface_hover.lerp(pal.yellow, tog_t).scale_alpha(anim_alpha); ctx.dl().push_rect(sw_r, sw_h * 0.5, track_col); let knob_x = sw_r.left() + 10.0 + tog_t * 12.0; let knob_col = if tog_t > 0.5 { pal.on_yellow } else if sw_resp.hovered { pal.text_bright } else { pal.text_secondary }; ctx.dl() .push_circle(Pos2::new(knob_x, sw_r.center_y()), 8.0, knob_col.scale_alpha(anim_alpha)); if sw_resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if sw_resp.clicked { *enabled = !*enabled; *changed = true; if !*enabled { *dropdown_open = false; } } if expand_t <= 0.01 { return None; } let content_alpha = (anim_alpha * expand_t).clamp(0.0, 1.0); let clip_h = (246.0 * expand_t).max(0.0); ctx.push_clip( Rect::from_xywh(area.left() - 4.0, hdr_r.bottom(), area.width() + 8.0, clip_h), 0.0, ); let y = hdr_r.bottom() + 16.0; let sliders_h = 144.0; // `9rem` let lbl_col = if is_disabled { pal.text_disabled } else { pal.text_secondary } .scale_alpha(content_alpha); // 2. Left Preamp column (`Equalizer_preamp`) + amp labels (`12dB / 0dB / -12dB`) let preamp_w = 42.0; let preamp_r = Rect::from_xywh(area.left(), y, preamp_w, sliders_h); let preamp_norm = ((*preamp - 0.5) / 1.0).clamp(0.0, 1.0); let presp = eq_vertical_slider( ctx, pal, WidgetId::new(salt).with("preamp"), preamp_r, preamp_norm, is_disabled, interactive && expand_t > 0.85, content_alpha, ); if presp.hovered || presp.dragging { ctx.show_tooltip(preamp_r, format!("{:.2}×", *preamp)); } if let Some(v) = presp.value { let next = ((0.5 + v * 1.0) * 20.0).round() / 20.0; let clamped = next.clamp(0.5, 1.5); if (clamped - *preamp).abs() >= 0.025 { *preamp = clamped; *changed = true; } } ctx.draw_text_ellipsis( if ru { "уровень" } else { "level" }, TextStyle::regular(11.5, lbl_col), Rect::from_xywh(area.left() - 4.0, y + sliders_h + 8.0, preamp_w + 8.0, 16.0), TextAlign::Center, ); let scale_x = area.left() + preamp_w + 2.0; let scale_w = 34.0; ctx.draw_text_ellipsis( "12dB", TextStyle::regular(11.0, lbl_col), Rect::from_xywh(scale_x, y, scale_w, 16.0), TextAlign::Left, ); ctx.draw_text_ellipsis( "0dB", TextStyle::regular(11.0, lbl_col), Rect::from_xywh(scale_x, y + sliders_h * 0.5 - 8.0, scale_w, 16.0), TextAlign::Left, ); ctx.draw_text_ellipsis( "-12dB", TextStyle::regular(11.0, lbl_col), Rect::from_xywh(scale_x, y + sliders_h - 16.0, scale_w, 16.0), TextAlign::Left, ); // 3. 10 Frequency Sliders (`60`..`16k`) let grid_x = scale_x + scale_w + 4.0; let grid_w = (area.right() - grid_x).max(160.0); let col_w = grid_w / 10.0; for i in 0..10 { let bx = grid_x + i as f32 * col_w; let sr = Rect::from_xywh(bx + 1.0, y, (col_w - 2.0).max(18.0), sliders_h); let norm = ((bands[i] + 12.0) / 24.0).clamp(0.0, 1.0); let sresp = eq_vertical_slider( ctx, pal, WidgetId::new(salt).with("band").with(i), sr, norm, is_disabled, interactive && expand_t > 0.85, content_alpha, ); if sresp.hovered || sresp.dragging { ctx.show_tooltip(sr, format!("{:+.1} dB", bands[i])); } if let Some(v) = sresp.value { let db = ((v * 24.0 - 12.0) * 2.0).round() * 0.5; let clamped = db.clamp(-12.0, 12.0); if (clamped - bands[i]).abs() >= 0.25 { bands[i] = clamped; *changed = true; } } ctx.draw_text_ellipsis( EQ_LABELS[i], TextStyle::regular(11.5, lbl_col), Rect::from_xywh(bx, y + sliders_h + 8.0, col_w, 16.0), TextAlign::Center, ); } // 4. Full-width Outlined Pill Preset Selector BELOW sliders (`EqualizerPresets_button`, `radius = h/2`) let sel_y = y + sliders_h + 8.0 + 16.0 + 18.0; let sel_h = 44.0; let sel_r = Rect::from_xywh(area.left(), sel_y, area.width(), sel_h); let sel_resp = if !is_disabled && interactive && expand_t > 0.85 { ctx.interact(WidgetId::new(salt).with("preset_sel"), sel_r) } else { Default::default() }; let sel_bg = if sel_resp.hovered { pal.surface_hover.scale_alpha(content_alpha) } else { Color::TRANSPARENT }; let sel_border = if is_disabled { pal.border_subtle.scale_alpha(content_alpha) } else { pal.border_control.scale_alpha(content_alpha) }; ctx.dl() .push_rect_bordered(sel_r, sel_h * 0.5, sel_bg, 1.0, sel_border); let preset_lbl = active_eq_preset_name(bands, ru); let label_col = if is_disabled { pal.text_disabled } else { pal.text_bright } .scale_alpha(content_alpha); ctx.draw_text_ellipsis( preset_lbl, TextStyle::bold(13.5, label_col), Rect::from_xywh(sel_r.left() + 18.0, sel_r.top(), sel_r.width() - 46.0, sel_r.height()), TextAlign::Left, ); ctx.draw_icon( Icon::ArrowDown, Rect::from_center_size(Pos2::new(sel_r.right() - 20.0, sel_r.center_y()), Vec2::splat(16.0)), if is_disabled { pal.text_disabled } else { pal.text_bright } .scale_alpha(content_alpha), ); if sel_resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if sel_resp.clicked { *dropdown_open = !*dropdown_open; } ctx.pop_clip(); if *dropdown_open { Some((sel_r, sel_resp.clicked)) } else { None } } /// Floating upward Equalizer Presets dropdown (`EqualizerPresets_container`, `placement: "top"`). #[allow(clippy::too_many_arguments)] fn render_eq_presets_dropdown( ctx: &mut UiContext, pal: &YmPalette, sel_r: Rect, parent_r: Rect, ru: bool, enabled: &mut bool, preamp: &mut f32, bands: &mut [f32; 10], changed: &mut bool, dropdown_open: &mut bool, sel_clicked: bool, salt: &str, ) -> Option { let screen = ctx.screen_rect(); let max_above = (sel_r.top() - screen.top() - 24.0).max(140.0); let dd_h = 260.0f32.min(max_above); let dd_r = Rect::from_xywh(sel_r.left(), (sel_r.top() - dd_h - 6.0).max(screen.top() + 12.0), sel_r.width(), dd_h); ctx.register_blocker(dd_r); ctx.dl() .push_shadow(dd_r, 14.0, 20.0, 0.0, Vec2::new(0.0, 6.0), pal.shadow_menu); ctx.dl() .push_rect_bordered(dd_r, 14.0, pal.bg_popover, 1.0, pal.border_control); let dd_scroll_id = WidgetId::new(salt).with("dd_scroll"); let dd_inner = dd_r.shrink2(Vec2::new(6.0, 6.0)); let scroll_y = ctx.begin_scroll_v(dd_scroll_id, dd_inner, 0.0); let mut dy = dd_inner.top() - scroll_y; let row_h = 36.0; let cur_name = active_eq_preset_name(bands, ru); for (pi, preset) in EQ_PRESETS.iter().enumerate() { let pname = preset.name(ru); let rr = Rect::from_xywh(dd_inner.left(), dy, dd_inner.width() - 8.0, row_h); let rresp = ctx.interact(WidgetId::new(salt).with("dd_item").with(pi), rr); let is_cur = pname == cur_name; if rresp.hovered { ctx.dl().push_rect(rr, 8.0, pal.surface_hover); ctx.set_cursor(CursorKind::Pointer); } ctx.draw_text_ellipsis( pname, TextStyle::medium(13.5, if is_cur { pal.text_bright } else { pal.text_primary }), Rect::from_xywh(rr.left() + 12.0, rr.top(), rr.width() - 36.0, rr.height()), TextAlign::Left, ); if is_cur { ctx.draw_icon( Icon::CheckXxs, Rect::from_center_size(Pos2::new(rr.right() - 14.0, rr.center_y()), Vec2::splat(15.0)), pal.yellow, ); } if rresp.clicked { *bands = preset.gains; if pi == 0 { *preamp = 1.0; } *enabled = true; *changed = true; *dropdown_open = false; } dy += row_h; } let total_dd_h = dy - (dd_inner.top() - scroll_y); ctx.end_scroll_v(dd_scroll_id, pal, total_dd_h, true); if ctx.input.clicked_outside(dd_r) && !sel_clicked { *dropdown_open = false; if ctx.input.pointer_pos.map_or(false, |p| parent_r.contains(p)) { ctx.input.consume_pointer_press(); } } Some(dd_r) } /// 1-to-1 Official `ShortcutsModal` (`29c95960ed6ac633.css:137-238`, `settings/page.js:1076-1175`). pub fn render_shortcuts_modal( ctx: &mut UiContext, pal: &YmPalette, app: &AppState, anim_t: f32, actions: &mut Vec, ) { let i18n = app.i18n(); let ru = i18n.is_ru(); let open = app.shortcuts_modal_open; let alpha = anim_t.clamp(0.0, 1.0); let screen = ctx.screen_rect(); let modal_w = (screen.width() - 48.0).clamp(320.0, 430.0); let modal_h = (screen.height() - 84.0).clamp(320.0, 560.0); let slide_dy = (1.0 - alpha) * 14.0; let modal_r = Rect::from_center_size( Pos2::new(screen.center_x(), screen.center_y() + slide_dy), Vec2::new(modal_w, modal_h), ); ctx.with_layer(ZLayer::Modal, |ctx| { if open { ctx.register_blocker(screen); } ctx.dl().push_rect( screen, 0.0, Color::rgba(0, 0, 0, (150.0 * alpha).round() as u8), ); ctx.dl().push_shadow( modal_r, 16.0, 32.0, 0.0, Vec2::new(0.0, 8.0), pal.shadow_modal.scale_alpha(alpha), ); ctx.dl().push_rect_bordered( modal_r, 16.0, pal.bg_popover.scale_alpha(alpha), 1.0, pal.border_subtle.scale_alpha(alpha), ); let hdr_r = Rect::from_xywh(modal_r.left() + 20.0, modal_r.top() + 18.0, modal_w - 40.0, 32.0); ctx.draw_text_ellipsis( if ru { "Горячие клавиши" } else { "Hot keys" }, TextStyle::headline(20.0, pal.text_bright.scale_alpha(alpha)), Rect::from_xywh(hdr_r.left(), hdr_r.top(), hdr_r.width() - 36.0, hdr_r.height()), TextAlign::Left, ); if icon_button( ctx, WidgetId::new("sc_modal_close"), Rect::from_xywh(hdr_r.right() - 30.0, hdr_r.top() + 1.0, 30.0, 30.0), Icon::Close, 15.0, pal.text_secondary, pal.text_bright, pal.surface_hover, false, i18n.close(), ) .clicked { actions.push(AppAction::SetShortcutsModalOpen(false)); } let shortcuts: &[(&str, &str, &[&str])] = &[ ("Пауза / Воспроизведение", "Play / Pause", &["K"]), ("Включить или выключить звук", "Mute / Unmute", &["M"]), ("Прибавить громкость", "Increase volume", &["↑"]), ("Уменьшить громкость", "Decrease volume", &["↓"]), ("Нравится", "Like", &["F"]), ("Не нравится", "Dislike", &["D"]), ("Следующий трек", "Next track", &["N"]), ("Предыдущий трек", "Previous track", &["P"]), ("Перемотка вперёд", "Seek forward", &["→", "L"]), ("Перемотка назад", "Seek backward", &["←", "J"]), ("Повтор трека или очереди", "Repeat", &["R"]), ("Перемешать", "Shuffle", &["S"]), ("Полноэкранный плеер", "Fullscreen player", &["W"]), ("Закрыть", "Close", &["Esc"]), ]; let scroll_r = Rect::from_min_max( Pos2::new(modal_r.left() + 20.0, hdr_r.bottom() + 18.0), Pos2::new(modal_r.right() - 16.0, modal_r.bottom() - 20.0), ); let scroll_id = WidgetId::new("shortcuts_modal_scroll"); let scroll_y = ctx.begin_scroll_v(scroll_id, scroll_r, 0.0); let mut y = scroll_r.top() - scroll_y; let or_word = if ru { "или" } else { "or" }; let or_w = ctx .measure_text(or_word, TextStyle::regular(12.5, pal.text_secondary), None) .x + 12.0; for (label_ru, label_en, keys) in shortcuts { let row_h = 34.0; let mut right_x = scroll_r.right() - 6.0; for (ki, key) in keys.iter().rev().enumerate() { let kw = (ctx .measure_text(key, TextStyle::medium(12.5, pal.text_bright), None) .x + 16.0) .max(32.0); let kr = Rect::from_xywh(right_x - kw, y + 4.0, kw, 26.0); ctx.dl().push_rect_bordered( kr, 6.0, pal.surface_hover, 1.0, pal.border_control, ); ctx.draw_text_ellipsis( key, TextStyle::medium(12.5, pal.text_bright), kr, TextAlign::Center, ); right_x = kr.left() - 6.0; if ki + 1 < keys.len() { let or_r = Rect::from_xywh(right_x - or_w, y, or_w, row_h); ctx.draw_text_ellipsis( or_word, TextStyle::regular(12.5, pal.text_secondary), or_r, TextAlign::Center, ); right_x = or_r.left() - 6.0; } } let text_w = (right_x - scroll_r.left() - 10.0).max(100.0); ctx.draw_text_ellipsis( if ru { label_ru } else { label_en }, TextStyle::regular(14.0, pal.text_bright), Rect::from_xywh(scroll_r.left(), y, text_w, row_h), TextAlign::Left, ); y += row_h + 4.0; } let total_h = y - (scroll_r.top() - scroll_y); ctx.end_scroll_v(scroll_id, pal, total_h, true); if open && ctx.input.consume_clicked_outside(modal_r) { actions.push(AppAction::SetShortcutsModalOpen(false)); } }); } // ============================================================================= // 7. Floating Toast Notification // ============================================================================= pub fn render_toast(ctx: &mut UiContext, pal: &YmPalette, msg: &str) { render_toast_with_offset(ctx, pal, msg, 0.0); } pub fn render_toast_with_offset(ctx: &mut UiContext, pal: &YmPalette, msg: &str, extra_bottom_offset: f32) { 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 - extra_bottom_offset, ), 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, ); }); } /// 1-to-1 Official `NotificationUpdate` (`28bcd8bd8493d95a.css:1-15` + `5eace9426adf24a8.css:12-23`): /// Frosted floating bottom bar with available version text, `"Что нового?"` button, /// yellow `"Обновить"` CTA button (`min-width: 112px`), and dismiss `×`. pub fn render_update_notification( ctx: &mut UiContext, pal: &YmPalette, app: &AppState, upd: &UpdateInfo, actions: &mut Vec, ) { let i18n = app.i18n(); let anim_t = if app.fixed_vibe_time.is_some() { 1.0 } else { let raw = ctx.animate_bool(WidgetId::new("ym_update_notif_anim"), true, 0.24); let u = 1.0 - raw; 1.0 - u * u * u }; let screen = ctx.screen_rect(); let bottom_margin = if matches!(app.route, Route::MyVibe) { 26.0 } else { PLAYER_BAR_HEIGHT + 22.0 }; let bar_w = (screen.width() - 64.0).clamp(430.0, 560.0); let bar_h = 54.0; let slide_dy = (1.0 - anim_t) * 26.0; let rect = Rect::from_xywh( (screen.center_x() - bar_w * 0.5).round(), (screen.bottom() - bottom_margin - bar_h + slide_dy).round(), bar_w, bar_h, ); ctx.with_layer(ZLayer::Titlebar, |ctx| { ctx.register_blocker(rect); ctx.dl() .push_shadow(rect, 16.0, 22.0, 0.0, Vec2::new(0.0, 4.0), pal.shadow_menu); ctx.dl().push_backdrop_blur( rect, 16.0, 2.5, pal.bg_popover.with_alpha(235), 1.0, pal.border_control, ); // Left: Yellow status dot + `"Доступна версия vX.Y.Z"` let dot_pos = Pos2::new(rect.left() + 20.0, rect.center_y()); ctx.dl().push_circle(dot_pos, 4.0, pal.yellow); let close_sz = 28.0; let close_r = Rect::from_xywh( rect.right() - close_sz - 10.0, rect.center_y() - close_sz * 0.5, close_sz, close_sz, ); let upd_lbl = i18n.update_btn(); let on_yellow = Color::rgb(0x19, 0x19, 0x19); let upd_txt_w = ctx .measure_text(upd_lbl, TextStyle::bold(13.5, on_yellow), None) .x; let upd_w = (upd_txt_w + 32.0).max(114.0).ceil(); let upd_r = Rect::from_xywh( close_r.left() - upd_w - 8.0, rect.center_y() - 18.0, upd_w, 36.0, ); let wn_lbl = i18n.whats_new(); let wn_txt_w = ctx .measure_text(wn_lbl, TextStyle::medium(12.5, pal.text_primary), None) .x; let wn_w = (wn_txt_w + 22.0).max(88.0).ceil(); let wn_r = Rect::from_xywh( upd_r.left() - wn_w - 8.0, rect.center_y() - 16.0, wn_w, 32.0, ); let text_x = rect.left() + 34.0; let text_w = (wn_r.left() - text_x - 10.0).max(80.0); let msg = i18n.update_available_banner(&upd.version); ctx.draw_text_ellipsis( &msg, TextStyle::medium(14.0, pal.text_bright), Rect::from_xywh(text_x, rect.top(), text_w, rect.height()), TextAlign::Left, ); // Secondary "Что нового?" pill let wn_resp = ctx.interact(WidgetId::new("upd_notif_changelog"), wn_r); if wn_resp.hovered { ctx.dl().push_rect(wn_r, 16.0, pal.surface_hover); ctx.set_cursor(CursorKind::Pointer); } else { ctx.dl().push_rect(wn_r, 16.0, pal.surface_secondary); } ctx.draw_text_ellipsis( wn_lbl, TextStyle::medium(12.5, pal.text_primary), wn_r, TextAlign::Center, ); if wn_resp.clicked { actions.push(AppAction::OpenReleaseNotesModal); } // Primary yellow "Обновить" button (`min-width: 7.875rem`) let upd_resp = ctx.interact(WidgetId::new("upd_notif_install"), upd_r); ctx.dl().push_rect( upd_r, 18.0, if upd_resp.hovered { pal.yellow_hover } else { pal.yellow }, ); ctx.draw_text_ellipsis( upd_lbl, TextStyle::bold(13.5, on_yellow), upd_r, TextAlign::Center, ); if upd_resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if upd_resp.clicked { actions.push(AppAction::InstallUpdate); } // Dismiss × button if icon_button( ctx, WidgetId::new("upd_notif_close"), close_r, Icon::Close, 14.0, pal.text_secondary, pal.text_bright, pal.surface_hover, false, "", ) .clicked { actions.push(AppAction::DismissUpdateNotification); } }); } /// 1-to-1 Official `ReleaseNotesModal` (`28bcd8bd8493d95a.css:16-100`, `7956-fd3a458349d8bd97.js:490-525`). pub fn render_release_notes_modal( ctx: &mut UiContext, pal: &YmPalette, app: &AppState, anim_t: f32, actions: &mut Vec, ) { let i18n = app.i18n(); let ru = i18n.is_ru(); let open = app.release_notes_modal_open; let alpha = anim_t.clamp(0.0, 1.0); let screen = ctx.screen_rect(); let modal_w = (screen.width() - 48.0).clamp(320.0, 460.0); let modal_h = (screen.height() - 84.0).clamp(320.0, 500.0); let slide_dy = (1.0 - alpha) * 14.0; let modal_r = Rect::from_center_size( Pos2::new(screen.center_x(), screen.center_y() + slide_dy), Vec2::new(modal_w, modal_h), ); ctx.with_layer(ZLayer::Modal, |ctx| { if open { ctx.register_blocker(screen); } ctx.dl().push_rect( screen, 0.0, Color::rgba(0, 0, 0, (150.0 * alpha).round() as u8), ); ctx.dl().push_shadow( modal_r, 16.0, 32.0, 0.0, Vec2::new(0.0, 8.0), pal.shadow_modal.scale_alpha(alpha), ); ctx.dl().push_rect_bordered( modal_r, 16.0, pal.bg_popover.scale_alpha(alpha), 1.0, pal.border_subtle.scale_alpha(alpha), ); // Header (`padding: 16px`, title + circular close ×) let hdr_r = Rect::from_xywh(modal_r.left() + 20.0, modal_r.top() + 14.0, modal_w - 40.0, 34.0); ctx.draw_text_ellipsis( i18n.whats_new(), TextStyle::headline(20.0, pal.text_bright.scale_alpha(alpha)), Rect::from_xywh(hdr_r.left(), hdr_r.top(), hdr_r.width() - 36.0, hdr_r.height()), TextAlign::Left, ); let close_r = Rect::from_xywh(hdr_r.right() - 32.0, hdr_r.top() + 1.0, 32.0, 32.0); if open && icon_button( ctx, WidgetId::new("rn_modal_close"), close_r, Icon::Close, 16.0, pal.text_secondary, pal.text_bright, pal.surface_hover, false, "", ) .clicked { actions.push(AppAction::CloseReleaseNotesModal); } let mut content_top = hdr_r.bottom() + 10.0; // Optional update banner inside modal if newer version is available if let Some(ref upd) = app.available_update { let banner_r = Rect::from_xywh(modal_r.left() + 20.0, content_top, modal_w - 40.0, 48.0); ctx.dl().push_rect_bordered( banner_r, 12.0, pal.surface_secondary, 1.0, pal.yellow.with_alpha(120), ); let on_yellow = Color::rgb(0x19, 0x19, 0x19); let btn_lbl = i18n.update_btn(); let btn_w = (ctx .measure_text(btn_lbl, TextStyle::bold(13.0, on_yellow), None) .x + 24.0) .max(94.0) .ceil(); let btn_r = Rect::from_xywh( banner_r.right() - btn_w - 8.0, banner_r.center_y() - 16.0, btn_w, 32.0, ); let upd_resp = ctx.interact(WidgetId::new("rn_modal_upd_btn"), btn_r); ctx.dl().push_rect( btn_r, 16.0, if upd_resp.hovered { pal.yellow_hover } else { pal.yellow }, ); ctx.draw_text_ellipsis( btn_lbl, TextStyle::bold(13.0, on_yellow), btn_r, TextAlign::Center, ); if upd_resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if upd_resp.clicked { actions.push(AppAction::InstallUpdate); } ctx.draw_text_ellipsis( &i18n.update_available_banner(&upd.version), TextStyle::bold(13.5, pal.text_bright), Rect::from_xywh( banner_r.left() + 14.0, banner_r.top(), (btn_r.left() - banner_r.left() - 22.0).max(60.0), banner_r.height(), ), TextAlign::Left, ); content_top = banner_r.bottom() + 12.0; } // Scrollable list of release notes let scroll_r = Rect::from_min_max( Pos2::new(modal_r.left() + 20.0, content_top), Pos2::new(modal_r.right() - 12.0, modal_r.bottom() - 16.0), ); let scroll_id = WidgetId::new("release_notes_scroll"); let scroll_y = ctx.begin_scroll_v(scroll_id, scroll_r, 0.0); let body_w = (scroll_r.width() - 16.0).max(160.0); let mut y = scroll_r.top() - scroll_y; if app.releases.is_empty() { let empty_msg = if ru { "Список изменений пуст" } else { "No release notes available" }; ctx.draw_text_ellipsis( empty_msg, TextStyle::regular(13.5, pal.text_secondary), Rect::from_xywh(scroll_r.left(), y + 12.0, body_w, 22.0), TextAlign::Left, ); y += 40.0; } else { for (idx, entry) in app.releases.iter().enumerate() { // Version heading + badge + date let ver_text = if entry.name.is_empty() { format!("v{}", entry.version) } else { entry.name.clone() }; let ver_style = TextStyle::bold(15.5, pal.text_bright); let ver_w = ctx.measure_text(&ver_text, ver_style, None).x.min(body_w * 0.65); ctx.draw_text_ellipsis( &ver_text, ver_style, Rect::from_xywh(scroll_r.left(), y, ver_w + 4.0, 22.0), TextAlign::Left, ); let is_current = entry.version == APP_VERSION; let is_newer = is_newer_version(&entry.version, APP_VERSION); if is_current || is_newer { let badge_txt = if is_newer { i18n.new_version_badge() } else { i18n.current_version_badge() }; let badge_col = if is_newer { Color::rgb(0x19, 0x19, 0x19) } else { pal.text_primary }; let badge_bg = if is_newer { pal.yellow } else { pal.surface_secondary }; let bw = ctx .measure_text(badge_txt, TextStyle::bold(11.0, badge_col), None) .x + 14.0; let br = Rect::from_xywh(scroll_r.left() + ver_w + 10.0, y + 2.0, bw, 18.0); ctx.dl().push_rect(br, 9.0, badge_bg); ctx.draw_text_ellipsis( badge_txt, TextStyle::bold(11.0, badge_col), br, TextAlign::Center, ); } if !entry.date.is_empty() { ctx.draw_text_ellipsis( &entry.date, TextStyle::regular(12.5, pal.text_secondary), Rect::from_xywh(scroll_r.left(), y + 1.0, body_w, 20.0), TextAlign::Right, ); } y += 28.0; // Markdown release notes lines for raw_line in entry.body.lines() { let line = raw_line.trim(); if line.is_empty() || line == "---" || line == "***" { continue; } if let Some(heading) = line .strip_prefix("### ") .or_else(|| line.strip_prefix("## ")) .or_else(|| line.strip_prefix("# ")) { let clean = heading.trim(); let h_style = TextStyle::bold(13.5, pal.text_bright); let sz = ctx.measure_text(clean, h_style, Some(body_w)); let lh = (sz.y + 4.0).max(20.0); ctx.draw_text_wrapped( clean, h_style, Rect::from_xywh(scroll_r.left(), y, body_w, lh), None, TextAlign::Left, ); y += lh + 4.0; } else if let Some(bullet) = line .strip_prefix("- ") .or_else(|| line.strip_prefix("* ")) { let item_x = scroll_r.left() + 14.0; let item_w = (body_w - 14.0).max(100.0); ctx.dl().push_circle(Pos2::new(scroll_r.left() + 5.0, y + 9.0), 2.0, pal.text_secondary); let spans = parse_release_note_spans(bullet.trim(), pal); let plain: String = spans.iter().map(|s| s.text).collect(); let sz = ctx.measure_text( &plain, TextStyle::regular(13.5, pal.text_primary), Some(item_w), ); let lh = (sz.y + 4.0).max(20.0); ctx.draw_rich_text( &spans, Rect::from_xywh(item_x, y, item_w, lh), None, TextAlign::Left, ); y += lh + 4.0; } else { let spans = parse_release_note_spans(line, pal); let plain: String = spans.iter().map(|s| s.text).collect(); let sz = ctx.measure_text( &plain, TextStyle::regular(13.5, pal.text_primary), Some(body_w), ); let lh = (sz.y + 4.0).max(20.0); ctx.draw_rich_text( &spans, Rect::from_xywh(scroll_r.left(), y, body_w, lh), None, TextAlign::Left, ); y += lh + 4.0; } } if idx + 1 < app.releases.len() { y += 8.0; ctx.dl().push_rect( Rect::from_xywh(scroll_r.left(), y, body_w, 1.0), 0.0, pal.border_subtle, ); y += 14.0; } else { y += 8.0; } } } let total_h = y - (scroll_r.top() - scroll_y); ctx.end_scroll_v(scroll_id, pal, total_h, true); if open && ctx.input.consume_clicked_outside(modal_r) { actions.push(AppAction::CloseReleaseNotesModal); } }); } fn parse_release_note_spans<'a>(line: &'a str, pal: &YmPalette) -> Vec> { let mut spans = Vec::new(); let mut rest = line; let code_col = if pal.is_dark { pal.yellow } else { pal.outline_selected }; while !rest.is_empty() { let next_bold = rest.find("**"); let next_code = rest.find('`'); let next = match (next_bold, next_code) { (Some(b), Some(c)) => Some((b <= c, b.min(c))), (Some(b), None) => Some((true, b)), (None, Some(c)) => Some((false, c)), (None, None) => None, }; match next { None => { spans.push(RichSpan::new(rest, TextStyle::regular(13.5, pal.text_primary))); break; } Some((is_bold, idx)) => { if idx > 0 { spans.push(RichSpan::new( &rest[..idx], TextStyle::regular(13.5, pal.text_primary), )); } let delim = if is_bold { "**" } else { "`" }; let after = &rest[idx + delim.len()..]; if let Some(end) = after.find(delim) { let inner = &after[..end]; let style = if is_bold { TextStyle::bold(13.5, pal.text_bright) } else { TextStyle::medium(13.0, code_col) }; spans.push(RichSpan::new(inner, style)); rest = &after[end + delim.len()..]; } else { spans.push(RichSpan::new( &rest[idx..], TextStyle::regular(13.5, pal.text_primary), )); break; } } } } if spans.is_empty() { spans.push(RichSpan::new(line, TextStyle::regular(13.5, pal.text_primary))); } spans } // ============================================================================= // 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::(1); 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); } } }