use crate::app::state::{ AppAction, AppState, ForYouTab, Route, SearchBrowseTab, SearchFilter, }; use crate::covers::CoverCache; use crate::engine::input::WidgetId; use crate::engine::text::{RichSpan, TextAlign, TextStyle}; use crate::engine::theme::{YmPalette, TRACK_ROW_HEIGHT}; use crate::engine::types::{Color, CursorKind, Pos2, Rect, Vec2}; use crate::engine::widgets::{ draw_cover_art, media_card, secondary_pill_button, stacked_mix_card, text_input_widget, track_row, TextInputOptions, TrackRowAction, TrackRowOptions, }; use crate::engine::UiContext; use crate::icons::Icon; use crate::views::overlays::{EntityContextMenuState, ShellUiState}; const AI_PROMPTS_RU: &[(&str, &str)] = &[ ("Хочу музыку, от которой", "мурашки по коже"), ("Музыка, под которую хочется", "танцевать одному"), ("Очень хочу удивиться.", "Что послушать?"), ("Собираюсь на вечеринку,", "нужен заряд"), ("Спокойная электроника", "для фокуса и работы"), ("Тёплый вечерний джаз", "и акустика"), ]; const AI_PROMPTS_EN: &[(&str, &str)] = &[ ("I want music that will give me", "goosebumps"), ("Music to dance to when I'm", "alone"), ("I really want to be surprised.", "What should I listen to?"), ("Picking the perfect outfit for", "party"), ("Calm ambient electronics", "for deep focus"), ("Warm late-night jazz", "and acoustic vibes"), ]; const FALLBACK_MIX_CARDS: &[(&str, &str, &str, Color, Color, Color)] = &[ ( "autumn", "Осень", "Autumn", Color::rgb(0x6E, 0x52, 0x3C), Color::rgb(0xC8, 0x8A, 0x5A), Color::rgb(0x78, 0x42, 0x22), ), ( "mood", "Настроение", "Mood", Color::rgb(0xA3, 0x90, 0x28), Color::rgb(0xFF, 0xE2, 0x58), Color::rgb(0xF5, 0x9F, 0x2A), ), ( "activity", "Занятия", "Activity", Color::rgb(0x5B, 0xAD, 0xD6), Color::rgb(0xE0, 0x78, 0x52), Color::rgb(0xC8, 0x3A, 0x20), ), ( "genres", "Жанры", "Genres", Color::rgb(0xA3, 0x75, 0x28), Color::rgb(0xFF, 0xE8, 0x52), Color::rgb(0xFF, 0x8A, 0xC8), ), ( "era", "Эпоха", "Era", Color::rgb(0x93, 0x70, 0x38), Color::rgb(0xB8, 0x9A, 0x58), Color::rgb(0x8E, 0x6E, 0x36), ), ]; /// Exact Yandex Music Desktop 5.129.0 Search Page (`pages_api_spec.md` §4 & `themes_i18n_icons_spec.md` §4.3-4.4): /// - Theme-aware Search pill (`pal.input_bg`, `pal.input_border`); empty & unfocused shows NO placeholder text (matches `search.jpg`!) /// - 500ms debounced live search as user types + instant on Enter /// - All 5 localized results tabs (`Все`/`Треки`/`Исполнители`/`Альбомы`/`Плейлисты`) with FULL Albums & Playlists media grids /// - Working `<` and `>` circular buttons scrolling the horizontal AI prompts carousel (`ScrollState::scroll_by_x`) /// - Clickable "Миксы >" heading (-> `Route::Metatags`), Mix cards with exact 8px 50%-opacity folder tab (-> `Route::Metatag`), /// and clickable "Откройте для себя плейлисты >" heading! pub fn render_search( ctx: &mut UiContext, pal: &YmPalette, covers: &mut CoverCache, app: &mut AppState, shell: &mut ShellUiState, rect: Rect, actions: &mut Vec, ) { let t = app.i18n(); let ru = t.is_ru(); let ai_prompts = if ru { AI_PROMPTS_RU } else { AI_PROMPTS_EN }; let is_playing = app.is_audio_playing(); let current_track_id = app.current_track().map(|tr| tr.id.clone()); // `views/mod.rs` already insets `inner_r` by (25, 13, 25, 0) -> rect starts at exact CDP (249, 45)! let x = rect.left(); let avail_w = rect.width().max(300.0); // 1. Exact CDP Search Pill: y = rect.top + 12 (lands at exact y=57.0!), height = 40.0, radius = 20.0 let bar_rect = Rect::from_xywh(x, rect.top() + 12.0, avail_w, 40.0); let mut query_buf = app.search_query.clone(); let ti = text_input_widget( ctx, pal, WidgetId::new("search_main_input"), bar_rect, &mut query_buf, TextInputOptions { placeholder: t.search_placeholder(), leading_icon: Some(Icon::Search), show_clear_button: true, // Exact 5.129.0 `search.jpg` parity: NO placeholder text when empty & unfocused! hide_placeholder_when_unfocused: true, transparent_bg: false, font_size: 14.0, pill: true, }, ); if ti.cleared { actions.push(AppAction::SetSearchQuery(String::new())); } else if ti.changed { // Live 500ms debounced search! actions.push(AppAction::SetSearchQuery(query_buf.clone())); } if ti.submitted && !query_buf.trim().is_empty() { actions.push(AppAction::RunSearchNow(query_buf.trim().to_string())); } // 2. Scrollable Body below Search Pill (57 + 40 + 20 = 117 exact!) let body_top = bar_rect.bottom() + 20.0; let body_vp = Rect::from_min_max(Pos2::new(rect.left(), body_top), rect.max()); let scroll_id = WidgetId::new("search_page_scroll"); let scroll_y = ctx.begin_scroll_v(scroll_id, body_vp, 0.0); let mut y = body_top - scroll_y; let content_w = (avail_w - 6.0).max(280.0); if app.search_loading { ctx.draw_text_ellipsis( t.loading(), TextStyle::medium(15.0, pal.text_secondary), Rect::from_xywh(x, y, content_w, 24.0), TextAlign::Left, ); y += 32.0; } else if let Some(res) = app .search_results .clone() .filter(|_| !app.search_query.trim().is_empty()) { // --------------------------------------------------------------------- // SEARCH RESULTS VIEW (All 5 localized tabs + Full Albums & Playlists grids!) // --------------------------------------------------------------------- let mut tx = x; for (f, label) in [ (SearchFilter::All, t.search_all()), (SearchFilter::Tracks, t.tracks()), (SearchFilter::Artists, t.artists()), (SearchFilter::Albums, t.albums()), (SearchFilter::Playlists, t.playlists()), ] { let (resp, r) = secondary_pill_button( ctx, pal, WidgetId::from_pair("search_tab", f as u8), Pos2::new(tx, y), None, label, 36.0, app.search_filter == f, ); if resp.clicked { actions.push(AppAction::SetSearchFilter(f)); } tx = r.right() + 8.0; } y += 56.0; let empty_for_filter = match app.search_filter { SearchFilter::All => { res.best_track.is_none() && res.best_artist.is_none() && res.best_album.is_none() && res.best_playlist.is_none() && res.tracks.is_empty() && res.artists.is_empty() && res.albums.is_empty() && res.playlists.is_empty() } SearchFilter::Tracks => res.tracks.is_empty(), SearchFilter::Artists => res.artists.is_empty(), SearchFilter::Albums => res.albums.is_empty(), SearchFilter::Playlists => res.playlists.is_empty(), }; if empty_for_filter { ctx.draw_text_ellipsis( t.search_not_found_title(), TextStyle::headline(22.0, pal.text_bright), Rect::from_xywh(x, y, content_w, 28.0), TextAlign::Left, ); y += 34.0; ctx.draw_text_ellipsis( t.search_not_found_desc(), TextStyle::regular(14.0, pal.text_secondary), Rect::from_xywh(x, y, content_w, 22.0), TextAlign::Left, ); y += 32.0; } else { // Best match hero card on All tab (Track, Artist, Album, OR Playlist + right-click context menu!) if app.search_filter == SearchFilter::All { let kind_hint = res.best_kind.as_deref(); let show_artist = (kind_hint == Some("artist") || res.best_track.is_none()) && res.best_artist.is_some(); let show_album = !show_artist && (kind_hint == Some("album") || res.best_track.is_none()) && res.best_album.is_some(); let show_playlist = !show_artist && !show_album && (kind_hint == Some("playlist") || res.best_track.is_none()) && res.best_playlist.is_some(); if res.best_track.is_some() || show_artist || show_album || show_playlist { ctx.draw_text_ellipsis( t.search_best_results(), TextStyle::headline(20.0, pal.text_bright), Rect::from_xywh(x, y, content_w, 26.0), TextAlign::Left, ); y += 34.0; let card_r = Rect::from_xywh(x, y, content_w.min(460.0), 92.0); let resp = ctx.interact(WidgetId::new("search_best_match"), card_r); ctx.dl().push_rect( card_r, 14.0, if resp.hovered { pal.surface_hover } else { pal.surface_secondary }, ); let cov_r = Rect::from_xywh(card_r.left() + 14.0, card_r.top() + 14.0, 64.0, 64.0); let play_r = Rect::from_center_size( Pos2::new(card_r.right() - 36.0, card_r.center_y()), Vec2::splat(40.0), ); let play_resp = ctx.interact(WidgetId::new("search_best_play"), play_r); let text_x = cov_r.right() + 14.0; let text_w = (play_r.left() - text_x - 12.0).max(80.0); let rclick_pos = ctx .input .pointer_pos .unwrap_or(Pos2::new(card_r.center_x(), card_r.bottom())); if show_artist { if let Some(ref ba) = res.best_artist { draw_cover_art( ctx, pal, covers, cov_r, ba.cover_uri.as_deref(), &format!("art_{}", ba.id), 32.0, true, false, ); ctx.draw_text_ellipsis( &ba.name, TextStyle::bold(16.5, pal.text_bright), Rect::from_xywh(text_x, card_r.top() + 22.0, text_w, 24.0), TextAlign::Left, ); ctx.draw_text_ellipsis( t.artist(), TextStyle::regular(13.0, pal.text_secondary), Rect::from_xywh(text_x, card_r.top() + 48.0, text_w, 20.0), TextAlign::Left, ); ctx.dl().push_circle( play_r.center(), 20.0, if play_resp.hovered { pal.yellow_hover } else { pal.yellow }, ); ctx.draw_icon( Icon::PlayXxs, Rect::from_center_size(play_r.center(), Vec2::splat(20.0)), pal.on_yellow, ); if play_resp.hovered || resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if resp.right_clicked { shell.open_entity_menu(EntityContextMenuState { kind: "artist".into(), id: ba.id.clone(), title: ba.name.clone(), subtitle: t.artist().into(), cover_uri: ba.cover_uri.clone(), owner_uid: None, is_own_playlist: false, tracks: Vec::new(), anchor: rclick_pos, share_url: format!("https://music.yandex.ru/artist/{}", ba.id), }); } else if play_resp.clicked { actions.push(AppAction::PlayArtist { id: ba.id.clone(), name: ba.name.clone(), }); } else if resp.clicked { actions.push(AppAction::Navigate(Route::Artist { id: ba.id.clone(), name: ba.name.clone(), })); } } } else if show_album { if let Some(ref balb) = res.best_album { draw_cover_art( ctx, pal, covers, cov_r, balb.cover_uri.as_deref(), &format!("alb_{}", balb.id), 10.0, false, false, ); ctx.draw_text_ellipsis( &balb.title, TextStyle::bold(16.5, pal.text_bright), Rect::from_xywh(text_x, card_r.top() + 22.0, text_w, 24.0), TextAlign::Left, ); let sub = balb .artists .first() .map(|a| format!("{} · {}", t.album(), a.name)) .unwrap_or_else(|| t.album().into()); ctx.draw_text_ellipsis( &sub, TextStyle::regular(13.0, pal.text_secondary), Rect::from_xywh(text_x, card_r.top() + 48.0, text_w, 20.0), TextAlign::Left, ); ctx.dl().push_circle( play_r.center(), 20.0, if play_resp.hovered { pal.yellow_hover } else { pal.yellow }, ); ctx.draw_icon( Icon::PlayXxs, Rect::from_center_size(play_r.center(), Vec2::splat(20.0)), pal.on_yellow, ); if play_resp.hovered || resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if resp.right_clicked { shell.open_entity_menu(EntityContextMenuState { kind: "album".into(), id: balb.id.clone(), title: balb.title.clone(), subtitle: sub, cover_uri: balb.cover_uri.clone(), owner_uid: None, is_own_playlist: false, tracks: Vec::new(), anchor: rclick_pos, share_url: format!("https://music.yandex.ru/album/{}", balb.id), }); } else if play_resp.clicked { actions.push(AppAction::PlayAlbum { id: balb.id.clone(), title: balb.title.clone(), }); } else if resp.clicked { actions.push(AppAction::Navigate(Route::Album { id: balb.id.clone(), title: balb.title.clone(), })); } } } else if show_playlist { if let Some(ref bpl) = res.best_playlist { draw_cover_art( ctx, pal, covers, cov_r, bpl.cover_uri.as_deref(), &format!("pl_{}_{}", bpl.owner_uid, bpl.kind), 10.0, false, false, ); ctx.draw_text_ellipsis( &bpl.title, TextStyle::bold(16.5, pal.text_bright), Rect::from_xywh(text_x, card_r.top() + 22.0, text_w, 24.0), TextAlign::Left, ); let sub = if bpl.owner_name.is_empty() { t.playlist().to_string() } else { format!("{} · {}", t.playlist(), bpl.owner_name) }; ctx.draw_text_ellipsis( &sub, TextStyle::regular(13.0, pal.text_secondary), Rect::from_xywh(text_x, card_r.top() + 48.0, text_w, 20.0), TextAlign::Left, ); ctx.dl().push_circle( play_r.center(), 20.0, if play_resp.hovered { pal.yellow_hover } else { pal.yellow }, ); ctx.draw_icon( Icon::PlayXxs, Rect::from_center_size(play_r.center(), Vec2::splat(20.0)), pal.on_yellow, ); if play_resp.hovered || resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if resp.right_clicked { shell.open_entity_menu(EntityContextMenuState { kind: "playlist".into(), id: format!("{}:{}", bpl.owner_uid, bpl.kind), title: bpl.title.clone(), subtitle: sub, cover_uri: bpl.cover_uri.clone(), owner_uid: Some(bpl.owner_uid.clone()), is_own_playlist: false, tracks: Vec::new(), anchor: rclick_pos, share_url: format!( "https://music.yandex.ru/users/{}/playlists/{}", bpl.owner_uid, bpl.kind ), }); } else if play_resp.clicked { actions.push(AppAction::PlayPlaylist { owner_uid: bpl.owner_uid.clone(), kind: bpl.kind.clone(), title: bpl.title.clone(), }); } else if resp.clicked { actions.push(AppAction::Navigate(Route::Playlist { owner_uid: bpl.owner_uid.clone(), kind: bpl.kind.clone(), title: bpl.title.clone(), })); } } } else if let Some(ref bt) = res.best_track { draw_cover_art( ctx, pal, covers, cov_r, bt.cover_uri.as_deref(), &bt.id, 10.0, false, false, ); ctx.draw_text_ellipsis( &bt.full_title(), TextStyle::bold(16.5, pal.text_bright), Rect::from_xywh(text_x, card_r.top() + 22.0, text_w, 24.0), TextAlign::Left, ); ctx.draw_text_ellipsis( &format!("{} · {}", t.track(), bt.artists_string()), TextStyle::regular(13.0, pal.text_secondary), Rect::from_xywh(text_x, card_r.top() + 48.0, text_w, 20.0), TextAlign::Left, ); ctx.dl().push_circle( play_r.center(), 20.0, if play_resp.hovered { pal.yellow_hover } else { pal.yellow }, ); ctx.draw_icon( Icon::PlayXxs, Rect::from_center_size(play_r.center(), Vec2::splat(20.0)), pal.on_yellow, ); if play_resp.hovered || resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if resp.right_clicked { shell.open_track_menu(bt.clone(), rclick_pos); } else if play_resp.clicked || resp.clicked { actions.push(AppAction::PlayTracks { tracks: vec![bt.clone()], start_index: 0, context_name: format!("{}: {}", t.search(), res.query), context_key: format!("search:{}", res.query), is_vibe: false, }); } } y += 112.0; } } // Tracks section (All or Tracks tab) if matches!(app.search_filter, SearchFilter::All | SearchFilter::Tracks) && !res.tracks.is_empty() { ctx.draw_text_ellipsis( t.tracks(), TextStyle::headline(20.0, pal.text_bright), Rect::from_xywh(x, y, content_w, 26.0), TextAlign::Left, ); y += 34.0; let limit = if app.search_filter == SearchFilter::All { 6 } else { res.tracks.len() }; for (idx, tr) in res.tracks.iter().take(limit).enumerate() { let row_r = Rect::from_xywh(x, y, content_w, TRACK_ROW_HEIGHT); if row_r.bottom() >= body_vp.top() - 60.0 && row_r.top() <= body_vp.bottom() + 60.0 { let is_curr = current_track_id.as_deref() == Some(tr.id.as_str()); match track_row( ctx, pal, covers, WidgetId::from_pair("search_tr", &tr.id), row_r, tr, TrackRowOptions { index: None, show_chart_rank: false, show_cover: true, is_current: is_curr, is_playing: is_curr && is_playing, is_liked: app.liked_ids.contains(&tr.id), is_disliked: app.disliked_ids.contains(&tr.id), is_downloaded: app.is_track_downloaded(&tr.id), menu_open: shell.is_track_menu_open(&tr.id), }, ) { TrackRowAction::Play => { actions.push(AppAction::PlayTracks { tracks: res.tracks.clone(), start_index: idx, context_name: format!("{}: {}", t.search(), res.query), context_key: format!("search:{}", res.query), is_vibe: false, }); } TrackRowAction::ToggleLike => { actions.push(AppAction::ToggleLike(tr.clone())); } TrackRowAction::ToggleDislike => { actions.push(AppAction::ToggleDislike(tr.clone())); } TrackRowAction::OpenArtist(id, name) => { actions.push(AppAction::Navigate(Route::Artist { id, name })); } TrackRowAction::OpenAlbum(id) => { actions.push(AppAction::Navigate(Route::Album { id, title: tr .album_title .clone() .unwrap_or_else(|| t.album().into()), })); } TrackRowAction::OpenContextMenu(pos) => { shell.open_track_menu(tr.clone(), pos); } TrackRowAction::None => {} } } y += TRACK_ROW_HEIGHT; } y += 22.0; } // Artists section (horizontal carousel on All, multi-column grid on Artists tab) if matches!(app.search_filter, SearchFilter::All | SearchFilter::Artists) && !res.artists.is_empty() { ctx.draw_text_ellipsis( t.artists(), TextStyle::headline(20.0, pal.text_bright), Rect::from_xywh(x, y, content_w, 26.0), TextAlign::Left, ); y += 36.0; if app.search_filter == SearchFilter::All { let card_w = 152.0; let card_h = card_w + 50.0; let row_vp = Rect::from_xywh(x, y, content_w, card_h); let h_id = WidgetId::new("search_artists_hscroll"); let sx = ctx.begin_scroll_h(h_id, row_vp, 0.0); let mut cx = x - sx; for art in res.artists.iter().take(12) { let cr = Rect::from_xywh(cx, y, card_w, card_h); let m = media_card( ctx, pal, covers, WidgetId::from_pair("s_art", &art.id), cr, &art.name, t.artist(), art.cover_uri.as_deref(), &format!("art_{}", art.id), true, false, ); if m.play_clicked { actions.push(AppAction::PlayArtist { id: art.id.clone(), name: art.name.clone(), }); } else if m.clicked { actions.push(AppAction::Navigate(Route::Artist { id: art.id.clone(), name: art.name.clone(), })); } cx += card_w + 16.0; } ctx.end_scroll_h(h_id, pal, res.artists.len().min(12) as f32 * (card_w + 16.0), false); y += card_h + 24.0; } else { let gap = 16.0; let cols = ((content_w + gap) / 176.0).floor().clamp(2.0, 6.0) as usize; let card_w = ((content_w - gap * (cols as f32 - 1.0)) / cols as f32).max(120.0); let card_h = card_w + 52.0; for (idx, art) in res.artists.iter().enumerate() { let col = idx % cols; let row = idx / cols; let cr = Rect::from_xywh( x + col as f32 * (card_w + gap), y + row as f32 * (card_h + 16.0), card_w, card_h, ); if cr.bottom() >= body_vp.top() - 40.0 && cr.top() <= body_vp.bottom() + 40.0 { let m = media_card( ctx, pal, covers, WidgetId::from_pair("s_art_grid", &art.id), cr, &art.name, t.artist(), art.cover_uri.as_deref(), &format!("art_{}", art.id), true, false, ); if m.play_clicked { actions.push(AppAction::PlayArtist { id: art.id.clone(), name: art.name.clone(), }); } else if m.clicked { actions.push(AppAction::Navigate(Route::Artist { id: art.id.clone(), name: art.name.clone(), })); } } } let rows = res.artists.len().div_ceil(cols); y += rows as f32 * (card_h + 16.0) + 12.0; } } // Albums section (horizontal carousel on All, FULL multi-column grid on Albums tab!) if matches!(app.search_filter, SearchFilter::All | SearchFilter::Albums) && !res.albums.is_empty() { ctx.draw_text_ellipsis( t.albums(), TextStyle::headline(20.0, pal.text_bright), Rect::from_xywh(x, y, content_w, 26.0), TextAlign::Left, ); y += 36.0; if app.search_filter == SearchFilter::All { let card_w = 160.0; let card_h = card_w + 52.0; let row_vp = Rect::from_xywh(x, y, content_w, card_h); let h_id = WidgetId::new("search_albums_hscroll"); let sx = ctx.begin_scroll_h(h_id, row_vp, 0.0); let mut cx = x - sx; for alb in res.albums.iter().take(12) { let cr = Rect::from_xywh(cx, y, card_w, card_h); let sub = alb .artists .first() .map(|a| a.name.as_str()) .unwrap_or(t.album()); let m = media_card( ctx, pal, covers, WidgetId::from_pair("s_alb", &alb.id), cr, &alb.title, sub, alb.cover_uri.as_deref(), &format!("alb_{}", alb.id), false, false, ); if m.play_clicked { actions.push(AppAction::PlayAlbum { id: alb.id.clone(), title: alb.title.clone(), }); } else if m.clicked { actions.push(AppAction::Navigate(Route::Album { id: alb.id.clone(), title: alb.title.clone(), })); } cx += card_w + 16.0; } ctx.end_scroll_h(h_id, pal, res.albums.len().min(12) as f32 * (card_w + 16.0), false); y += card_h + 24.0; } else { let gap = 16.0; let cols = ((content_w + gap) / 184.0).floor().clamp(2.0, 6.0) as usize; let card_w = ((content_w - gap * (cols as f32 - 1.0)) / cols as f32).max(120.0); let card_h = card_w + 54.0; for (idx, alb) in res.albums.iter().enumerate() { let col = idx % cols; let row = idx / cols; let cr = Rect::from_xywh( x + col as f32 * (card_w + gap), y + row as f32 * (card_h + 16.0), card_w, card_h, ); if cr.bottom() >= body_vp.top() - 40.0 && cr.top() <= body_vp.bottom() + 40.0 { let sub = alb .artists .first() .map(|a| a.name.as_str()) .unwrap_or(t.album()); let m = media_card( ctx, pal, covers, WidgetId::from_pair("s_alb_grid", &alb.id), cr, &alb.title, sub, alb.cover_uri.as_deref(), &format!("alb_{}", alb.id), false, false, ); if m.play_clicked { actions.push(AppAction::PlayAlbum { id: alb.id.clone(), title: alb.title.clone(), }); } else if m.clicked { actions.push(AppAction::Navigate(Route::Album { id: alb.id.clone(), title: alb.title.clone(), })); } } } let rows = res.albums.len().div_ceil(cols); y += rows as f32 * (card_h + 16.0) + 12.0; } } // Playlists section (horizontal carousel on All, FULL multi-column grid on Playlists tab!) if matches!(app.search_filter, SearchFilter::All | SearchFilter::Playlists) && !res.playlists.is_empty() { ctx.draw_text_ellipsis( t.playlists(), TextStyle::headline(20.0, pal.text_bright), Rect::from_xywh(x, y, content_w, 26.0), TextAlign::Left, ); y += 36.0; if app.search_filter == SearchFilter::All { let card_w = 160.0; let card_h = card_w + 52.0; let row_vp = Rect::from_xywh(x, y, content_w, card_h); let h_id = WidgetId::new("search_playlists_hscroll"); let sx = ctx.begin_scroll_h(h_id, row_vp, 0.0); let mut cx = x - sx; for pl in res.playlists.iter().take(12) { let cr = Rect::from_xywh(cx, y, card_w, card_h); let m = media_card( ctx, pal, covers, WidgetId::from_pair("s_pl", format!("{}_{}", pl.owner_uid, pl.kind)), cr, &pl.title, &pl.owner_name, pl.cover_uri.as_deref(), &format!("pl_{}_{}", pl.owner_uid, pl.kind), false, false, ); if m.play_clicked { actions.push(AppAction::PlayPlaylist { owner_uid: pl.owner_uid.clone(), kind: pl.kind.clone(), title: pl.title.clone(), }); } else if m.clicked { actions.push(AppAction::Navigate(Route::Playlist { owner_uid: pl.owner_uid.clone(), kind: pl.kind.clone(), title: pl.title.clone(), })); } cx += card_w + 16.0; } ctx.end_scroll_h( h_id, pal, res.playlists.len().min(12) as f32 * (card_w + 16.0), false, ); y += card_h + 24.0; } else { let gap = 16.0; let cols = ((content_w + gap) / 184.0).floor().clamp(2.0, 6.0) as usize; let card_w = ((content_w - gap * (cols as f32 - 1.0)) / cols as f32).max(120.0); let card_h = card_w + 54.0; for (idx, pl) in res.playlists.iter().enumerate() { let col = idx % cols; let row = idx / cols; let cr = Rect::from_xywh( x + col as f32 * (card_w + gap), y + row as f32 * (card_h + 16.0), card_w, card_h, ); if cr.bottom() >= body_vp.top() - 40.0 && cr.top() <= body_vp.bottom() + 40.0 { let m = media_card( ctx, pal, covers, WidgetId::from_pair( "s_pl_grid", format!("{}_{}", pl.owner_uid, pl.kind), ), cr, &pl.title, &pl.owner_name, pl.cover_uri.as_deref(), &format!("pl_{}_{}", pl.owner_uid, pl.kind), false, false, ); if m.play_clicked { actions.push(AppAction::PlayPlaylist { owner_uid: pl.owner_uid.clone(), kind: pl.kind.clone(), title: pl.title.clone(), }); } else if m.clicked { actions.push(AppAction::Navigate(Route::Playlist { owner_uid: pl.owner_uid.clone(), kind: pl.kind.clone(), title: pl.title.clone(), })); } } } let rows = res.playlists.len().div_ceil(cols); y += rows as f32 * (card_h + 16.0) + 12.0; } } } } else { // --------------------------------------------------------------------- // EMPTY SEARCH LANDING VIEW (AI Prompts + Popular/History + Mixes + Discover Playlists) // --------------------------------------------------------------------- // 2a. AI Prompt Suggestions Strip (h=48, orb + horizontally scrollable prompts + working `<` `>` arrows!) let ai_row = Rect::from_xywh(x, y, content_w, 48.0); let orb_c = Pos2::new(ai_row.left() + 24.0, ai_row.center_y()); let glow_tex = ctx.icons.get_official_search_orb(&mut ctx.textures); let glow_r = Rect::from_center_size(orb_c, Vec2::new(62.0, 54.0)); ctx.dl().push_image(glow_r, glow_tex, 0.0, Color::WHITE); let ai_scroll_id = WidgetId::new("search_ai_prompts_hscroll"); let prompts_left = ai_row.left() + 72.0; let prompts_right = (ai_row.right() - 86.0).max(prompts_left + 120.0); let prompts_vp = Rect::from_min_max( Pos2::new(prompts_left, ai_row.top()), Pos2::new(prompts_right, ai_row.bottom()), ); let prompt_scroll_x = ctx.begin_scroll_h(ai_scroll_id, prompts_vp, 0.0); let step_x = 224.0_f32; let lead_col = if pal.is_dark { Color::rgb(0xB2, 0x6E, 0xF3) } else { Color::rgb(0x7B, 0x3A, 0xD4) }; for (i, &(lead, rest)) in ai_prompts.iter().enumerate() { let pr = Rect::from_xywh( prompts_left + i as f32 * step_x - prompt_scroll_x, ai_row.top() + 5.0, 200.0, 38.0, ); if pr.right() < prompts_vp.left() - 10.0 || pr.left() > prompts_vp.right() + 10.0 { continue; } let resp = ctx.interact(WidgetId::from_pair("ai_prompt", i), pr); let rest_col = if resp.hovered { pal.text_bright } else { pal.text_primary }; let lead_line = format!("{}\n", lead); let spans = [ RichSpan::new(&lead_line, TextStyle::medium(13.5, lead_col)), RichSpan::new(rest, TextStyle::medium(13.5, rest_col)), ]; ctx.draw_rich_text(&spans, pr, Some(2), TextAlign::Left); if resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if resp.clicked { let q = format!("{} {}", lead, rest); actions.push(AppAction::RunSearchNow(q)); } } let prompts_total_w = ai_prompts.len() as f32 * step_x; ctx.end_scroll_h(ai_scroll_id, pal, prompts_total_w, false); // Smooth 36px right-edge horizontal gradient fade so trailing prompt text fades cleanly! let fade_r = Rect::from_xywh( (prompts_right - 36.0).max(prompts_left), ai_row.top(), 36.0_f32.min(prompts_vp.width()), ai_row.height(), ); ctx.dl().push_gradient_rect( fade_r, 0.0, pal.bg_content.with_alpha(0), pal.bg_content, Vec2::new(1.0, 0.0), ); if prompt_scroll_x > 2.0 { let fade_l = Rect::from_xywh( prompts_left, ai_row.top(), 24.0_f32.min(prompts_vp.width()), ai_row.height(), ); ctx.dl().push_gradient_rect( fade_l, 0.0, pal.bg_content, pal.bg_content.with_alpha(0), Vec2::new(1.0, 0.0), ); } // Working `<` and `>` circular buttons scrolling the AI prompt carousel! let (can_left, can_right) = ctx .scrolls .get(ai_scroll_id) .map(|s| (s.can_scroll_left(), s.can_scroll_right())) .unwrap_or((false, prompts_total_w > prompts_vp.width() + 10.0)); let l_btn_c = Pos2::new(ai_row.right() - 58.0, ai_row.center_y()); let r_btn_c = Pos2::new(ai_row.right() - 16.0, ai_row.center_y()); for (c, ic, enabled, is_right) in [ (l_btn_c, Icon::ArrowLeftXxs, can_left, false), (r_btn_c, Icon::ArrowRightXxs, can_right, true), ] { let br = Rect::from_center_size(c, Vec2::splat(32.0)); let resp = ctx.interact(WidgetId::from_pair("ai_arrow", is_right), br); let stroke_col = if enabled { if resp.hovered { pal.text_primary } else { pal.input_border } } else { pal.border_control }; let ic_col = if enabled { if resp.hovered { pal.text_bright } else { pal.text_primary } } else { pal.text_disabled }; if enabled && resp.hovered { ctx.dl().push_circle(c, 15.0, pal.surface_hover); ctx.set_cursor(CursorKind::Pointer); } ctx.dl().push_circle_stroke(c, 15.0, 2.0, stroke_col); ctx.draw_icon(ic, Rect::from_center_size(c, Vec2::splat(20.0)), ic_col); if enabled && resp.clicked { let step = (prompts_vp.width() * 0.5).max(160.0); let delta = if is_right { step } else { -step }; ctx.scrolls.scroll_by_x(ai_scroll_id, delta); ctx.request_repaint(); } } y += 48.0 + 36.0; // exact CDP y = 201! // 2b. [Popular] History browse tabs (100% theme-aware!) let mut bx = x; for (tab, label) in [ ( SearchBrowseTab::Popular, if ru { "Популярное" } else { "Popular" }, ), (SearchBrowseTab::History, t.history()), ] { let active = app.search_browse_tab == tab; let tw = ctx .measure_text(label, TextStyle::bold(14.0, pal.text_primary), None) .x + 32.0; let tr = Rect::from_xywh(bx, y, tw.max(80.0), 36.0); let resp = ctx.interact(WidgetId::from_pair("search_browse_tab", tab as u8), tr); if active { ctx.dl().push_rect(tr, 18.0, pal.input_bg); } else if resp.hovered { ctx.dl().push_rect(tr, 18.0, pal.surface_secondary); } ctx.draw_text_ellipsis( label, TextStyle::bold(14.0, pal.text_primary), tr, TextAlign::Center, ); if resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if resp.clicked { actions.push(AppAction::SetSearchBrowseTab(tab)); } bx = tr.right() + 8.0; } y += 36.0 + 43.0; // exact CDP y = 280! if app.search_browse_tab == SearchBrowseTab::History { if app.config.search_history.is_empty() { ctx.draw_text_ellipsis( t.search_history_empty(), TextStyle::regular(14.0, pal.text_secondary), Rect::from_xywh(x, y, content_w, 22.0), TextAlign::Left, ); y += 32.0; } else { let mut hx = x; let history_terms = app.config.search_history.clone(); for (idx, term) in history_terms.iter().enumerate() { let est_w = (ctx .measure_text(term, TextStyle::bold(14.0, pal.text_primary), None) .x + 60.0) .clamp(60.0, 200.0); if hx + est_w > x + content_w && hx > x { hx = x; y += 44.0; } let (resp, r) = secondary_pill_button( ctx, pal, WidgetId::from_pair("search_hist_term", idx), Pos2::new(hx, y), Some(Icon::History), term, 36.0, false, ); if resp.clicked { actions.push(AppAction::RunSearchNow(term.clone())); } hx = r.right() + 8.0; } let (clr_resp, _) = secondary_pill_button( ctx, pal, WidgetId::new("search_hist_clear"), Pos2::new(hx, y), None, t.clear(), 36.0, false, ); if clr_resp.clicked { actions.push(AppAction::ClearSearchHistory); } y += 56.0; } } else { // 2c. Clickable "Миксы >" / "Mixes >" Heading -> navigates to `Route::Metatags`! let mixes_title = t.mixes(); let mixes_w = ctx .measure_text(mixes_title, TextStyle::headline(24.0, pal.text_primary), None) .x + 30.0; let mixes_head_r = Rect::from_xywh(x, y, mixes_w, 28.0); let mixes_head_resp = ctx.interact(WidgetId::new("search_mixes_heading"), mixes_head_r); ctx.draw_text_ellipsis( mixes_title, TextStyle::headline( 24.0, if mixes_head_resp.hovered { pal.text_bright } else { pal.text_primary }, ), mixes_head_r, TextAlign::Left, ); ctx.draw_icon( Icon::ArrowRight, Rect::from_center_size( Pos2::new(mixes_head_r.right() - 12.0, mixes_head_r.center_y()), Vec2::splat(22.0), ), if mixes_head_resp.hovered { pal.text_primary } else { pal.text_secondary }, ); if mixes_head_resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if mixes_head_resp.clicked { actions.push(AppAction::Navigate(Route::Metatags)); } y += 28.0 + 27.0; // exact CDP y = 335 (tab y=335, cover y=343)! // 5 Mix Cards with exact 8px 50%-opacity folder tab (`stacked_mix_card`) -> opens `Route::Metatag`! let card_sz = 114.5_f32; let side_pad = 38.2_f32; let gap = if content_w >= 960.0 { 92.3 } else { ((content_w - side_pad - 16.0 - card_sz * 5.0) / 4.0).clamp(16.0, 92.3) }; let server_leaves: Vec<(String, String, Option, Option)> = app .metatags .iter() .flat_map(|tree| tree.leaves.iter()) .take(5) .map(|leaf| { ( leaf.id.clone(), leaf.title.clone(), leaf.cover_uri.clone(), leaf.color_hex.as_deref().and_then(Color::from_hex_str), ) }) .collect(); for i in 0..5 { let (meta_id, lbl, cov_uri, tab_c, c1, c2) = if let Some((id, title, uri, col)) = server_leaves.get(i) { let (_, _, _, fb_tab, fb_c1, fb_c2) = FALLBACK_MIX_CARDS[i]; ( id.clone(), title.clone(), uri.as_deref(), col.unwrap_or(fb_tab), fb_c1, fb_c2, ) } else { let (id, tru, ten, fb_tab, fb_c1, fb_c2) = FALLBACK_MIX_CARDS[i]; ( id.to_string(), if ru { tru.to_string() } else { ten.to_string() }, None, fb_tab, fb_c1, fb_c2, ) }; let cx = x + side_pad + i as f32 * (card_sz + gap); let cr = Rect::from_xywh(cx, y, card_sz, card_sz + 46.0); let resp = stacked_mix_card( ctx, pal, covers, WidgetId::from_pair("search_mix_card", i), cr, &lbl, tab_c, c1, c2, cov_uri, &meta_id, ); if resp.clicked { actions.push(AppAction::Navigate(Route::Metatag { id: meta_id, title: lbl, })); } } y += card_sz + 46.0 + 67.5; // 2d. Clickable "Откройте для себя плейлисты >" / "Discover these playlists >" Heading! let disc_title = t.discover_playlists(); let disc_w = ctx .measure_text(disc_title, TextStyle::headline(24.0, pal.text_primary), None) .x + 30.0; let disc_head_r = Rect::from_xywh(x, y, disc_w, 28.0); let disc_head_resp = ctx.interact(WidgetId::new("search_discover_heading"), disc_head_r); ctx.draw_text_ellipsis( disc_title, TextStyle::headline( 24.0, if disc_head_resp.hovered { pal.text_bright } else { pal.text_primary }, ), disc_head_r, TextAlign::Left, ); ctx.draw_icon( Icon::ArrowRight, Rect::from_center_size( Pos2::new(disc_head_r.right() - 12.0, disc_head_r.center_y()), Vec2::splat(22.0), ), if disc_head_resp.hovered { pal.text_primary } else { pal.text_secondary }, ); if disc_head_resp.hovered { ctx.set_cursor(CursorKind::Pointer); } if disc_head_resp.clicked { actions.push(AppAction::SetForYouTab(ForYouTab::Trends)); actions.push(AppAction::Navigate(Route::ForYou)); } y += 28.0 + 16.0; // Discover Playlists horizontal carousel (`190.8px` cards, `16px` gap) let pl_w = 190.8_f32; let pl_h = pl_w + 54.0; let disc_vp = Rect::from_xywh(x, y, content_w, pl_h); let disc_scroll_id = WidgetId::new("search_discover_scroll"); let disc_sx = ctx.begin_scroll_h(disc_scroll_id, disc_vp, 0.0); let playlists = app.landing.popular_playlists.clone(); let mut px = x - disc_sx; for pl in &playlists { let cr = Rect::from_xywh(px, y, pl_w, pl_h); if cr.right() >= disc_vp.left() - 20.0 && cr.left() <= disc_vp.right() + 20.0 { let m = media_card( ctx, pal, covers, WidgetId::from_pair("disc_pl", format!("{}_{}", pl.owner_uid, pl.kind)), cr, &pl.title, &pl.owner_name, pl.cover_uri.as_deref(), &format!("disc_{}_{}", pl.owner_uid, pl.kind), false, false, ); if m.play_clicked { actions.push(AppAction::PlayPlaylist { owner_uid: pl.owner_uid.clone(), kind: pl.kind.clone(), title: pl.title.clone(), }); } else if m.clicked { actions.push(AppAction::Navigate(Route::Playlist { owner_uid: pl.owner_uid.clone(), kind: pl.kind.clone(), title: pl.title.clone(), })); } } px += pl_w + 16.0; } ctx.end_scroll_h( disc_scroll_id, pal, playlists.len() as f32 * (pl_w + 16.0), false, ); y += pl_h + 24.0; } } let total_h = y - (body_top - scroll_y); ctx.end_scroll_v(scroll_id, pal, total_h, true); }