2609 lines
98 KiB
Rust
2609 lines
98 KiB
Rust
use std::cell::RefCell;
|
||
|
||
use crate::api::models::{format_ms, Track, VibeStationSummary, WordsCard};
|
||
use crate::api::YandexApiClient;
|
||
use crate::app::i18n::APP_VERSION;
|
||
use crate::app::state::{
|
||
parse_hex_rgb, vibe_bucket_primary_rgb, AppAction, AppState, RepeatMode, Route,
|
||
};
|
||
use crate::covers::CoverCache;
|
||
use crate::engine::input::{Key, WidgetId, ZLayer};
|
||
use crate::engine::text::{RichSpan, TextAlign, TextStyle};
|
||
use crate::engine::theme::YmPalette;
|
||
use crate::engine::types::{
|
||
css_rgba, Color, CornerRadii, CursorKind, Pos2, Rect, Vec2, VIBE_TEXTURE_ID,
|
||
};
|
||
use crate::engine::widgets::{
|
||
draw_cover_art, ym_menu_divider, ym_menu_frame, ym_menu_item, ym_menu_item_ex,
|
||
ym_volume_capsule,
|
||
};
|
||
use crate::engine::UiContext;
|
||
use crate::icons::Icon;
|
||
use crate::views::overlays::ShellUiState;
|
||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||
enum VibeSubmenu {
|
||
None,
|
||
AddToPlaylist,
|
||
Share,
|
||
Artists,
|
||
}
|
||
|
||
struct VibePageLocalState {
|
||
wheel_scroll_pos: Option<f32>,
|
||
wheel_scroll_vel: f32,
|
||
wheel_scroll_target: Option<f32>,
|
||
submenu: VibeSubmenu,
|
||
submenu_anchor_y: f32,
|
||
words_popover_open: bool,
|
||
words_popover_track_id: String,
|
||
}
|
||
|
||
impl Default for VibePageLocalState {
|
||
fn default() -> Self {
|
||
Self {
|
||
wheel_scroll_pos: None,
|
||
wheel_scroll_vel: 0.0,
|
||
wheel_scroll_target: None,
|
||
submenu: VibeSubmenu::None,
|
||
submenu_anchor_y: 0.0,
|
||
words_popover_open: false,
|
||
words_popover_track_id: String::new(),
|
||
}
|
||
}
|
||
}
|
||
|
||
const WORDS_LOADING_PHRASES_RU: &[&str] = &[
|
||
"Собираю интересное силой ИИ",
|
||
"Настраиваюсь",
|
||
"Ловлю ритм",
|
||
"Читаю про артиста",
|
||
"Изучаю звучание",
|
||
];
|
||
|
||
const WORDS_LOADING_PHRASES_EN: &[&str] = &[
|
||
"Using the AI power to collect interesting stuff",
|
||
"Getting ready",
|
||
"Getting in the rhythm",
|
||
"Reading about the artist",
|
||
"Analyzing the sound",
|
||
];
|
||
|
||
thread_local! {
|
||
static VIBE_LOCAL: RefCell<VibePageLocalState> = RefCell::new(VibePageLocalState::default());
|
||
}
|
||
|
||
/// Full-bleed "My Vibe" stage (1-to-1 with Yandex Music Desktop 5.129.0):
|
||
/// - `pal.bg_basic` stage + 16-stop track bucket gradient + `VIBE_TEXTURE_ID` orb at exact 250% meta scale
|
||
/// - Idle "Моя волна"/"My Vibe" vs playing Artist name dynamic headline
|
||
/// - 96x96 floating cover, 64px progress capsule with marquee & hover timecode pill
|
||
/// - 48x48 Volume (with 44x216 vertical hover popover), Dislike, Like, More (`VibeContextMenu`)
|
||
/// - Transport row (Prev / 64px Play-Pause / Next)
|
||
/// - AI meteor glow settings button + bottom-right `5.129.0` version badge
|
||
/// - Left `WheelDesktop` curved arc carousel with exact `120*(1+cos(theta))` arc math & item routing
|
||
pub fn render_my_vibe(
|
||
ctx: &mut UiContext,
|
||
pal: &YmPalette,
|
||
covers: &mut CoverCache,
|
||
app: &mut AppState,
|
||
shell: &mut ShellUiState,
|
||
rect: Rect,
|
||
actions: &mut Vec<AppAction>,
|
||
) {
|
||
let t = app.i18n();
|
||
let ru = t.is_ru();
|
||
let is_playing = app.is_audio_playing();
|
||
let position_ms = app.position_ms();
|
||
let duration_ms = app.duration_ms();
|
||
let volume = app.config.volume;
|
||
let muted = app.config.muted;
|
||
let current_track: Option<Track> = app.current_track().cloned();
|
||
let is_liked = current_track
|
||
.as_ref()
|
||
.map_or(false, |tr| app.liked_ids.contains(&tr.id));
|
||
let is_disliked = current_track
|
||
.as_ref()
|
||
.map_or(false, |tr| app.disliked_ids.contains(&tr.id));
|
||
|
||
// Swapchain is already cleared to `pal.bg_basic` (`#000000` dark / `#F5F5F5` light),
|
||
// so skip drawing a redundant full-stage blended quad over the entire screen!
|
||
ctx.push_clip(rect, 0.0);
|
||
|
||
let left_w = if rect.width() > 780.0 { 380.0 } else { 0.0 };
|
||
let hero_rect = Rect::from_min_max(
|
||
Pos2::new(rect.left() + left_w, rect.top()),
|
||
rect.max(),
|
||
);
|
||
|
||
// 1. RIGHT HERO STAGE — Exact `.DefaultLayout_rootNewVibe__MSDOn` 16-stop exponential-decay 270deg gradient
|
||
// Show white "My Vibe"/"Моя волна" headline when paused; artist name only while actively playing!
|
||
let has_active_track = current_track.is_some() && is_playing;
|
||
let target_fade = if has_active_track { 1.0_f32 } else { 0.0_f32 };
|
||
let play_fade_raw = ctx.animate_bool(
|
||
WidgetId::new("vibe_play_expand_t"),
|
||
has_active_track,
|
||
0.85,
|
||
);
|
||
if (play_fade_raw - target_fade).abs() > 0.001 {
|
||
ctx.request_repaint();
|
||
}
|
||
// Smooth cubic ease-in-out (`3t^2 - 2t^3`) so pause/resume fades feel velvety instead of linear
|
||
let play_fade_t = play_fade_raw * play_fade_raw * (3.0 - 2.0 * play_fade_raw);
|
||
|
||
// Keep track color alive while `current_track.is_some()` (not gated on `is_playing`) so pausing
|
||
// smoothly fades out the 16-stop ambient gradient over ~0.85s instead of snapping off in 1 frame.
|
||
let bucket_primary: Option<Color> = if current_track.is_some() && play_fade_t > 0.003 {
|
||
let raw_rgb = current_track.as_ref().and_then(|tr| {
|
||
tr.derived_average_hex
|
||
.as_deref()
|
||
.and_then(parse_hex_rgb)
|
||
.or_else(|| tr.derived_accent_hex.as_deref().and_then(parse_hex_rgb))
|
||
.or_else(|| {
|
||
tr.cover_uri
|
||
.as_deref()
|
||
.and_then(|u| covers.get_or_fetch(u, 100))
|
||
.map(|(_, dom, _)| [dom.r, dom.g, dom.b])
|
||
})
|
||
});
|
||
let b = vibe_bucket_primary_rgb(raw_rgb);
|
||
Some(Color::rgb(b[0], b[1], b[2]))
|
||
} else {
|
||
None
|
||
};
|
||
|
||
let cx = hero_rect.center_x();
|
||
if let Some(amb) = bucket_primary {
|
||
if play_fade_t > 0.003 {
|
||
const STOPS: [(f32, f32); 16] = [
|
||
(0.00, 1.000),
|
||
(0.10, 0.844),
|
||
(0.19, 0.712),
|
||
(0.25, 0.602),
|
||
(0.30, 0.506),
|
||
(0.34, 0.427),
|
||
(0.37, 0.362),
|
||
(0.40, 0.305),
|
||
(0.42, 0.258),
|
||
(0.44, 0.218),
|
||
(0.47, 0.184),
|
||
(0.50, 0.151),
|
||
(0.54, 0.118),
|
||
(0.60, 0.082),
|
||
(0.67, 0.045),
|
||
(0.75, 0.000),
|
||
];
|
||
let total_w = rect.width();
|
||
// In light theme, blend slightly softer so dark text retains crisp contrast over the wash
|
||
let intensity = if pal.is_dark { 1.0 } else { 0.32 };
|
||
let stop_col = |k: f32| -> Color {
|
||
let f = (k * play_fade_t * intensity).clamp(0.0, 1.0);
|
||
pal.bg_basic.lerp(amb, f)
|
||
};
|
||
let y_top = rect.top().floor();
|
||
let y_bot = rect.bottom().ceil();
|
||
let right_edge = rect.right().ceil();
|
||
for (idx, w) in STOPS.windows(2).enumerate() {
|
||
let (p_right, k_right) = w[0];
|
||
let (p_left, k_left) = w[1];
|
||
let x_left = (rect.right() - total_w * p_left).floor();
|
||
let x_right_base = if idx == 0 {
|
||
right_edge
|
||
} else {
|
||
(rect.right() - total_w * p_right).floor()
|
||
};
|
||
// Snap strip boundaries to integer pixels and overlap adjacent strips by 1px on the
|
||
// shared edge (where `cr` matches the prior strip's `cl`) so HiDPI/fractional scales
|
||
// never leave dark vertical hairlines between stops.
|
||
let x_right = if idx == 0 {
|
||
x_right_base
|
||
} else {
|
||
(x_right_base + 1.0).min(right_edge)
|
||
};
|
||
if x_right <= x_left {
|
||
continue;
|
||
}
|
||
let strip = Rect::from_min_max(
|
||
Pos2::new(x_left, y_top),
|
||
Pos2::new(x_right, y_bot),
|
||
);
|
||
let cl = stop_col(k_left);
|
||
let cr = stop_col(k_right);
|
||
ctx.dl()
|
||
.push_gradient_rect(strip, 0.0, cl, cr, Vec2::new(1.0, 0.0));
|
||
}
|
||
}
|
||
}
|
||
|
||
// 2. VIBE WEBGL-EQUIVALENT VULKAN ORB — Exact `.VibePage_vibeAnimation { width: 250%; inset: 50% }`
|
||
// Decouple orb vertical center (`318.0` at 800px height) from headline vertical center (`247.0` at 800px height)!
|
||
let orb_cy = rect.top() + (rect.height() * 0.3975).clamp(240.0, 318.0);
|
||
let headline_cy = rect.top() + (rect.height() * 0.30875).clamp(175.0, 247.0);
|
||
let entity_meta_w = (rect.width() * 0.60 - 72.0).max(280.0);
|
||
let orb_sz = entity_meta_w * 2.25;
|
||
let orb_rect = Rect::from_center_size(Pos2::new(cx, orb_cy), Vec2::splat(orb_sz));
|
||
ctx.dl().push_image(orb_rect, VIBE_TEXTURE_ID, 0.0, Color::WHITE);
|
||
|
||
// 3. HEADLINE: Idle "Моя волна"/"My Vibe" vs Playing yellow label + dynamic Artist Name
|
||
let default_vibe_title = t.my_vibe();
|
||
let vibe_label = if app.active_vibe_title.is_empty()
|
||
|| app.active_vibe_title == "My Vibe"
|
||
|| app.active_vibe_title == "Моя волна"
|
||
{
|
||
default_vibe_title
|
||
} else {
|
||
app.active_vibe_title.as_str()
|
||
};
|
||
|
||
// Crossfade smoothly between Playing (Artist Name) and Idle ("My Vibe"/"Моя волна")
|
||
let playing_alpha = play_fade_t.clamp(0.0, 1.0);
|
||
let idle_alpha = (1.0 - play_fade_t).clamp(0.0, 1.0);
|
||
|
||
// 3a. Top Source Context Header (`y = rect.top() + 54.0`, official `VIBE_PAGE_CONTEXT_BLOCK`)
|
||
let is_custom_vibe_station = app.is_vibe_active
|
||
&& !app.active_vibe_title.is_empty()
|
||
&& !app.active_vibe_title.eq_ignore_ascii_case("My Vibe")
|
||
&& !app.active_vibe_title.eq_ignore_ascii_case("Моя волна");
|
||
let is_non_vibe_context = !app.is_vibe_active
|
||
&& !app.context_name.is_empty()
|
||
&& !app.context_name.eq_ignore_ascii_case("My Vibe")
|
||
&& !app.context_name.eq_ignore_ascii_case("Моя волна");
|
||
let top_y = rect.top() + 54.0;
|
||
let reset_tooltip = if ru {
|
||
"Сбросить на Мою волну"
|
||
} else {
|
||
"Reset to My Vibe"
|
||
};
|
||
|
||
if is_non_vibe_context || is_custom_vibe_station {
|
||
// Exact official 5.129.0 `.VibeResetButton_button__i8Cvy` + `.VibeResetButton_context__hsTlv`:
|
||
// ONE unified dark translucent 44px pill (radius 22px) with electric yellow 19px Headline text
|
||
// and a filled 22px yellow circle (`×` dark `#141414` inside) on the right of the SAME pill!
|
||
let pill_label = if is_non_vibe_context {
|
||
app.context_name.as_str()
|
||
} else {
|
||
vibe_label
|
||
};
|
||
let yellow = if pal.is_dark {
|
||
Color::rgb(0xFF, 0xFF, 0x00)
|
||
} else {
|
||
Color::rgb(0xFF, 0xEE, 0x00)
|
||
};
|
||
let lbl_style = TextStyle::headline(19.0, yellow);
|
||
let max_pill_w = (hero_rect.width() - 80.0).clamp(160.0, 440.0);
|
||
let max_text_w = (max_pill_w - 64.0).max(40.0);
|
||
let text_w = ctx.measure_text(pill_label, lbl_style, None).x.min(max_text_w);
|
||
let pill_w = (20.0 + text_w + 10.0 + 22.0 + 12.0).clamp(96.0, max_pill_w);
|
||
let pill_r = Rect::from_center_size(Pos2::new(cx, top_y), Vec2::new(pill_w, 44.0));
|
||
|
||
let close_center = Pos2::new(pill_r.right() - 12.0 - 11.0, pill_r.center_y());
|
||
let reset_r = Rect::from_center_size(close_center, Vec2::splat(32.0));
|
||
let reset_resp = ctx.interact(WidgetId::new("vb_ctx_reset_btn"), reset_r);
|
||
let pill_resp = ctx.interact(WidgetId::new("vb_ctx_source_pill"), pill_r);
|
||
|
||
let pill_bg = if pill_resp.pressed || reset_resp.pressed {
|
||
css_rgba(0, 0, 0, 153) // rgba(0,0,0,0.60)
|
||
} else if pill_resp.hovered || reset_resp.hovered {
|
||
css_rgba(0, 0, 0, 102) // rgba(0,0,0,0.40)
|
||
} else {
|
||
css_rgba(0, 0, 0, 77) // rgba(0,0,0,0.30)
|
||
};
|
||
ctx.dl().push_rect(pill_r, 22.0, pill_bg);
|
||
ctx.draw_text_ellipsis(
|
||
pill_label,
|
||
lbl_style,
|
||
Rect::from_xywh(
|
||
pill_r.left() + 20.0,
|
||
pill_r.top(),
|
||
(text_w + 4.0).min(pill_r.width() - 56.0).max(20.0),
|
||
pill_r.height(),
|
||
),
|
||
TextAlign::Left,
|
||
);
|
||
|
||
let close_rad = if reset_resp.hovered { 11.5 } else { 11.0 };
|
||
ctx.dl().push_circle(close_center, close_rad, yellow);
|
||
ctx.draw_icon(
|
||
Icon::Close,
|
||
Rect::from_center_size(close_center, Vec2::splat(12.0)),
|
||
Color::rgb(0x14, 0x14, 0x14),
|
||
);
|
||
|
||
if reset_resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
ctx.show_tooltip(reset_r, reset_tooltip);
|
||
} else if pill_resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if reset_resp.clicked {
|
||
actions.push(AppAction::ResetContextToMyVibe);
|
||
} else if pill_resp.clicked {
|
||
if is_non_vibe_context {
|
||
actions.push(AppAction::NavigateToCurrentContext);
|
||
} else {
|
||
actions.push(AppAction::ResetContextToMyVibe);
|
||
}
|
||
}
|
||
} else if playing_alpha > 0.005 && current_track.is_some() {
|
||
// Default My Vibe playing: top Vibe label (`pal.logo_text`: #FFFF00 dark / #000000 light)
|
||
let top_lbl_r = Rect::from_center_size(
|
||
Pos2::new(cx, top_y),
|
||
Vec2::new((hero_rect.width() - 64.0).max(200.0), 28.0),
|
||
);
|
||
let lbl_col = pal
|
||
.logo_text
|
||
.with_alpha(((pal.logo_text.a as f32) * playing_alpha).round() as u8);
|
||
ctx.draw_text_ellipsis(
|
||
vibe_label,
|
||
TextStyle::headline(18.0, lbl_col),
|
||
top_lbl_r,
|
||
TextAlign::Center,
|
||
);
|
||
}
|
||
|
||
if playing_alpha > 0.005 {
|
||
if let Some(ref tr) = current_track {
|
||
let artist_str = tr.artists_string();
|
||
let char_len = artist_str.chars().count();
|
||
let max_w = (hero_rect.width() - 64.0).max(260.0);
|
||
// Exact `useDynamicText` (`iM`: 44..104px)
|
||
let art_sz = (if char_len <= 8 {
|
||
100.0_f32
|
||
} else if char_len <= 14 {
|
||
80.0_f32
|
||
} else if char_len <= 22 {
|
||
64.0_f32
|
||
} else {
|
||
48.0_f32
|
||
})
|
||
.min(max_w / (char_len.max(4) as f32 * 0.52))
|
||
.clamp(44.0, 104.0);
|
||
|
||
let headline_r = Rect::from_center_size(
|
||
Pos2::new(cx, headline_cy),
|
||
Vec2::new(max_w, 132.0),
|
||
);
|
||
let art_col = pal
|
||
.text_bright
|
||
.with_alpha(((pal.text_bright.a as f32) * playing_alpha).round() as u8);
|
||
ctx.draw_text_wrapped(
|
||
&artist_str,
|
||
TextStyle::headline(art_sz, art_col).with_line_height(art_sz * 0.94),
|
||
headline_r,
|
||
Some(2),
|
||
TextAlign::Center,
|
||
);
|
||
if has_active_track {
|
||
let hl_resp = ctx.interact(WidgetId::new("my_vibe_title_click"), headline_r);
|
||
if hl_resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if hl_resp.clicked {
|
||
if let Some(first) = tr.artists.first() {
|
||
actions.push(AppAction::Navigate(Route::Artist {
|
||
id: first.id.clone(),
|
||
name: first.name.clone(),
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if idle_alpha > 0.005 {
|
||
let headline_r = Rect::from_center_size(
|
||
Pos2::new(cx, headline_cy),
|
||
Vec2::new((hero_rect.width() - 40.0).max(260.0), 124.0),
|
||
);
|
||
let hl_size = if vibe_label.chars().count() > 14 {
|
||
64.0
|
||
} else {
|
||
104.0
|
||
};
|
||
let idle_col = pal
|
||
.text_bright
|
||
.with_alpha(((pal.text_bright.a as f32) * idle_alpha).round() as u8);
|
||
ctx.draw_text_ellipsis(
|
||
vibe_label,
|
||
TextStyle::headline(hl_size, idle_col),
|
||
headline_r,
|
||
TextAlign::Center,
|
||
);
|
||
if !has_active_track {
|
||
let hl_resp = ctx.interact(WidgetId::new("my_vibe_title_click"), headline_r);
|
||
if hl_resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if hl_resp.clicked {
|
||
actions.push(AppAction::ToggleMyVibe);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 4. FLOATING 96x96 TRACK COVER (exact CDP 1280x800 Y=452; click opens Album page or Fullscreen player)
|
||
let cov_center = Pos2::new(cx, rect.top() + (rect.height() * 0.565).clamp(330.0, 452.0));
|
||
let cov_rect = Rect::from_center_size(cov_center, Vec2::splat(96.0));
|
||
if let Some(ref tr) = current_track {
|
||
draw_cover_art(
|
||
ctx,
|
||
pal,
|
||
covers,
|
||
cov_rect,
|
||
tr.cover_uri.as_deref(),
|
||
&tr.id,
|
||
8.0,
|
||
false,
|
||
false,
|
||
);
|
||
let cov_resp = ctx.interact(WidgetId::new("vb_cover_album"), cov_rect);
|
||
if cov_resp.hovered {
|
||
ctx.dl().push_rect(cov_rect, 8.0, css_rgba(255, 255, 255, 22));
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if cov_resp.clicked {
|
||
// Exact official 5.129.0 (`4362 @ 23000`): opens Album page with bottom PlayerBar;
|
||
// falls back to Fullscreen player modal (`SetFullscreen(true)`) if album is missing.
|
||
if let Some(ref aid) = tr.album_id {
|
||
actions.push(AppAction::Navigate(Route::Album {
|
||
id: aid.clone(),
|
||
title: tr
|
||
.album_title
|
||
.clone()
|
||
.unwrap_or_else(|| t.album().to_string()),
|
||
}));
|
||
} else {
|
||
actions.push(AppAction::SetFullscreen(true));
|
||
}
|
||
}
|
||
}
|
||
|
||
// 5. PROGRESS CAPSULE (`VibePlayerbarTimecodeContent`: 64px height, 32px radius, hover timecode pill)
|
||
let pill_y = cov_center.y + 96.0;
|
||
let capsule_w = (hero_rect.width() * 0.52).clamp(260.0, 360.0);
|
||
let capsule_r = Rect::from_center_size(Pos2::new(cx, pill_y), Vec2::new(capsule_w, 64.0));
|
||
let cap_id = WidgetId::new("vibe_capsule_scrub");
|
||
let cap_resp = ctx.interact(cap_id, capsule_r);
|
||
let cap_scrubbing = cap_resp.hovered || cap_resp.pressed || cap_resp.dragged;
|
||
|
||
let cap_base = pal.surface_secondary;
|
||
let cap_fill = pal.surface_hover;
|
||
ctx.dl().push_rect(capsule_r, 32.0, cap_base);
|
||
|
||
let progress = if duration_ms > 0 {
|
||
(position_ms as f32 / duration_ms as f32).clamp(0.0, 1.0)
|
||
} else {
|
||
0.0
|
||
};
|
||
if cap_resp.pressed || cap_resp.dragged {
|
||
if let Some(p) = ctx.input.pointer_pos {
|
||
let frac = ((p.x - capsule_r.left()) / capsule_r.width().max(1.0)).clamp(0.0, 1.0);
|
||
shell.vibe_scrub_frac = Some(frac);
|
||
}
|
||
}
|
||
let display_progress = shell.vibe_scrub_frac.unwrap_or(progress);
|
||
let fill_w = (capsule_r.width() * display_progress).max(0.0);
|
||
if fill_w > 1.0 {
|
||
ctx.push_clip(
|
||
Rect::from_xywh(capsule_r.x, capsule_r.y, fill_w, capsule_r.h),
|
||
0.0,
|
||
);
|
||
ctx.dl().push_rect(capsule_r, 32.0, cap_fill);
|
||
ctx.pop_clip();
|
||
}
|
||
|
||
let cap_text_col = if pal.is_dark {
|
||
css_rgba(255, 255, 255, 210)
|
||
} else {
|
||
pal.text_primary
|
||
};
|
||
let track_label = current_track
|
||
.as_ref()
|
||
.map(|tr| {
|
||
if has_active_track {
|
||
tr.full_title()
|
||
} else {
|
||
format!("{} — {}", tr.artists_string(), tr.full_title())
|
||
}
|
||
})
|
||
.unwrap_or_else(|| {
|
||
if ru {
|
||
"Моя волна — Нажмите, чтобы включить".into()
|
||
} else {
|
||
"My Vibe — Click to play".into()
|
||
}
|
||
});
|
||
let is_explicit = current_track.as_ref().map_or(false, |tr| tr.is_explicit);
|
||
let right_pad = if is_explicit { 44.0 } else { 24.0 };
|
||
let text_pad_l = 24.0;
|
||
let cap_text_r = Rect::from_xywh(
|
||
capsule_r.left() + text_pad_l,
|
||
capsule_r.top() + 4.0,
|
||
(capsule_r.width() - text_pad_l - right_pad).max(60.0),
|
||
capsule_r.height() - 8.0,
|
||
);
|
||
let cap_style = TextStyle::headline(19.0, cap_text_col);
|
||
let label_w = ctx.measure_text(&track_label, cap_style, None).x;
|
||
if label_w > cap_text_r.width() + 2.0 {
|
||
// True transparent per-glyph alpha fade over the glowing orange glass capsule (ZERO opaque fade boxes!)
|
||
let right_fade_px = 22.0_f32;
|
||
if ctx.input.time > 0.001 {
|
||
let gap = 48.0_f32;
|
||
let cycle_dist = label_w + gap;
|
||
let speed = 34.0_f32;
|
||
let pause_s = 1.6_f32;
|
||
let total_cycle = pause_s + cycle_dist / speed;
|
||
let phase = (ctx.input.time as f32).rem_euclid(total_cycle);
|
||
let offset = if phase < pause_s {
|
||
0.0
|
||
} else {
|
||
(phase - pause_s) * speed
|
||
};
|
||
let left_fade_px = offset.min(22.0);
|
||
|
||
let x1 = cap_text_r.left() - offset;
|
||
ctx.draw_text_marquee_fade(
|
||
&track_label,
|
||
cap_style,
|
||
x1,
|
||
cap_text_r.center_y(),
|
||
cap_text_r,
|
||
left_fade_px,
|
||
right_fade_px,
|
||
);
|
||
let x2 = x1 + cycle_dist;
|
||
if x2 < cap_text_r.right() {
|
||
ctx.draw_text_marquee_fade(
|
||
&track_label,
|
||
cap_style,
|
||
x2,
|
||
cap_text_r.center_y(),
|
||
cap_text_r,
|
||
left_fade_px,
|
||
right_fade_px,
|
||
);
|
||
}
|
||
ctx.request_repaint();
|
||
} else {
|
||
ctx.draw_text_marquee_fade(
|
||
&track_label,
|
||
cap_style,
|
||
cap_text_r.left(),
|
||
cap_text_r.center_y(),
|
||
cap_text_r,
|
||
0.0,
|
||
right_fade_px,
|
||
);
|
||
}
|
||
} else {
|
||
ctx.draw_text_ellipsis(&track_label, cap_style, cap_text_r, TextAlign::Center);
|
||
}
|
||
if is_explicit {
|
||
ctx.draw_icon(
|
||
Icon::Explicit,
|
||
Rect::from_center_size(
|
||
Pos2::new(capsule_r.right() - 24.0, capsule_r.center_y()),
|
||
Vec2::splat(18.0),
|
||
),
|
||
cap_text_col,
|
||
);
|
||
}
|
||
|
||
if cap_scrubbing {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
if duration_ms > 0 {
|
||
if let Some(pos) = ctx.input.pointer_pos {
|
||
let hover_frac = ((pos.x - capsule_r.left()) / capsule_r.width().max(1.0)).clamp(0.0, 1.0);
|
||
let hover_ms = (hover_frac * duration_ms as f32) as u64;
|
||
let tip_text = format!("{} / {}", format_ms(hover_ms), format_ms(duration_ms));
|
||
let tip_sz = ctx.measure_text(&tip_text, TextStyle::bold(13.0, pal.text_bright), None);
|
||
let tip_w = tip_sz.x + 22.0;
|
||
let tip_x = pos
|
||
.x
|
||
.clamp(capsule_r.left() + tip_w * 0.5, capsule_r.right() - tip_w * 0.5);
|
||
let tip_r = Rect::from_center_size(
|
||
Pos2::new(tip_x, capsule_r.top() - 18.0),
|
||
Vec2::new(tip_w, 28.0),
|
||
);
|
||
ctx.dl().push_shadow(
|
||
tip_r,
|
||
14.0,
|
||
12.0,
|
||
0.0,
|
||
Vec2::new(0.0, 2.0),
|
||
pal.shadow_menu,
|
||
);
|
||
ctx.dl().push_rect_bordered(
|
||
tip_r,
|
||
14.0,
|
||
pal.bg_popover,
|
||
1.0,
|
||
pal.border_subtle,
|
||
);
|
||
ctx.draw_text_ellipsis(
|
||
&tip_text,
|
||
TextStyle::bold(13.0, pal.text_bright),
|
||
tip_r,
|
||
TextAlign::Center,
|
||
);
|
||
}
|
||
}
|
||
}
|
||
// Commit seek ONCE on pointer release or click (eliminates 60Hz seek command spam during drag!)
|
||
if let Some(f) = shell.vibe_scrub_frac {
|
||
if !ctx.input.left_down {
|
||
actions.push(AppAction::SeekFraction(f));
|
||
shell.vibe_scrub_frac = None;
|
||
}
|
||
} else if cap_resp.clicked {
|
||
if let Some(pos) = ctx.input.pointer_pos {
|
||
let f = ((pos.x - capsule_r.left()) / capsule_r.width().max(1.0)).clamp(0.0, 1.0);
|
||
actions.push(AppAction::SeekFraction(f));
|
||
}
|
||
}
|
||
|
||
// 6. SIDE 48x48 CIRCULAR BUTTONS (Volume, Dislike, Like, More)
|
||
let btn_y = pill_y;
|
||
let col_side_hi = if pal.is_dark {
|
||
css_rgba(255, 255, 255, 196)
|
||
} else {
|
||
pal.text_primary
|
||
};
|
||
let col_side_lo = if pal.is_dark {
|
||
css_rgba(255, 255, 255, 165)
|
||
} else {
|
||
pal.text_secondary
|
||
};
|
||
|
||
// Helper for 48x48 translucent circle buttons
|
||
let draw_vibe_circle_btn = |ctx: &mut UiContext,
|
||
center: Pos2,
|
||
id: &str,
|
||
ic: Icon,
|
||
tint: Color|
|
||
-> bool {
|
||
let r = Rect::from_center_size(center, Vec2::splat(48.0));
|
||
let wid = WidgetId::new(id);
|
||
let resp = ctx.interact(wid, r);
|
||
let hov_t = ctx.animate_bool(wid.with("hov"), resp.hovered, 0.25);
|
||
let bg = pal.surface_secondary.lerp(pal.surface_hover, hov_t);
|
||
ctx.dl().push_circle(center, 24.0 * (1.0 + 0.04 * hov_t), bg);
|
||
ctx.draw_icon(
|
||
ic,
|
||
Rect::from_center_size(center, Vec2::splat(24.0)),
|
||
tint.lerp(pal.text_bright, hov_t),
|
||
);
|
||
if resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
resp.clicked
|
||
};
|
||
|
||
// 6a. Volume Button + Vertical Hover Popover (44x216, Kawase blur, 1% wheel step)
|
||
let vol_btn_center = Pos2::new(capsule_r.left() - 80.0, btn_y);
|
||
let vol_btn_r = Rect::from_center_size(vol_btn_center, Vec2::splat(48.0));
|
||
if draw_vibe_circle_btn(
|
||
ctx,
|
||
vol_btn_center,
|
||
"vb_vol",
|
||
if muted || volume < 0.01 {
|
||
Icon::VolumeOff
|
||
} else {
|
||
Icon::Volume
|
||
},
|
||
col_side_hi,
|
||
) {
|
||
actions.push(AppAction::ToggleMute);
|
||
}
|
||
|
||
let vol_slider_box = Rect::from_xywh(
|
||
vol_btn_center.x - 22.0,
|
||
vol_btn_r.top() - 224.0,
|
||
44.0,
|
||
216.0,
|
||
);
|
||
let vol_bridge = vol_btn_r.union(vol_slider_box);
|
||
let vol_hovered = ctx
|
||
.input
|
||
.pointer_pos
|
||
.map_or(false, |p| vol_bridge.contains(p));
|
||
if vol_hovered {
|
||
shell.vibe_vol_open = true;
|
||
} else if !ctx.input.left_down {
|
||
shell.vibe_vol_open = false;
|
||
}
|
||
if shell.vibe_vol_open {
|
||
if vol_hovered && ctx.input.wheel_delta.y.abs() > 0.1 {
|
||
let delta = if ctx.input.wheel_delta.y > 0.0 {
|
||
0.01
|
||
} else {
|
||
-0.01
|
||
};
|
||
let next = ((volume + delta) * 100.0).round() / 100.0;
|
||
actions.push(AppAction::SetVolume(next.clamp(0.0, 1.0)));
|
||
}
|
||
let mut keep_open = true;
|
||
ctx.with_layer(ZLayer::Popover, |ctx| {
|
||
let cur_v = if muted { 0.0 } else { volume };
|
||
let s_resp = ym_volume_capsule(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vb_vol_vslider"),
|
||
vol_slider_box,
|
||
cur_v,
|
||
true,
|
||
Color::WHITE,
|
||
);
|
||
if let Some(v) = s_resp.value {
|
||
actions.push(AppAction::SetVolume(v));
|
||
}
|
||
if !s_resp.dragging && !vol_hovered {
|
||
keep_open = false;
|
||
}
|
||
});
|
||
if !keep_open {
|
||
shell.vibe_vol_open = false;
|
||
}
|
||
}
|
||
|
||
// 6b. Dislike Button
|
||
if draw_vibe_circle_btn(
|
||
ctx,
|
||
Pos2::new(capsule_r.left() - 28.0, btn_y),
|
||
"vb_dis",
|
||
if is_disliked {
|
||
Icon::Disliked
|
||
} else {
|
||
Icon::Dislike
|
||
},
|
||
if is_disliked {
|
||
pal.accent_coral
|
||
} else {
|
||
col_side_lo
|
||
},
|
||
) {
|
||
if let Some(ref tr) = current_track {
|
||
actions.push(AppAction::ToggleDislike(tr.clone()));
|
||
}
|
||
}
|
||
|
||
// 6c. Like Button (darker contrast backing when liked over bright playing orange/red gradient!)
|
||
let like_center = Pos2::new(capsule_r.right() + 28.0, btn_y);
|
||
if is_liked && play_fade_t > 0.1 {
|
||
ctx.dl().push_circle(
|
||
like_center,
|
||
24.0,
|
||
css_rgba(0, 0, 0, (56.0 * play_fade_t).round() as u8),
|
||
);
|
||
}
|
||
if draw_vibe_circle_btn(
|
||
ctx,
|
||
like_center,
|
||
"vb_like",
|
||
if is_liked { Icon::Liked } else { Icon::Like },
|
||
if is_liked {
|
||
if play_fade_t > 0.1 {
|
||
Color::rgb(0xFF, 0x3B, 0x30)
|
||
} else {
|
||
pal.accent_coral
|
||
}
|
||
} else {
|
||
col_side_lo
|
||
},
|
||
) {
|
||
if let Some(ref tr) = current_track {
|
||
actions.push(AppAction::ToggleLike(tr.clone()));
|
||
}
|
||
}
|
||
|
||
// 6d. More (`•••`) Button -> Exact 5.129.0 `VibeContextMenu` with real submenus!
|
||
let more_center = Pos2::new(capsule_r.right() + 80.0, btn_y);
|
||
let more_r = Rect::from_center_size(more_center, Vec2::splat(48.0));
|
||
if draw_vibe_circle_btn(ctx, more_center, "vb_more", Icon::More, col_side_hi) {
|
||
let next = !shell.vibe_menu_open;
|
||
shell.close_all_menus();
|
||
shell.vibe_menu_open = next;
|
||
VIBE_LOCAL.with(|s| {
|
||
s.borrow_mut().submenu = VibeSubmenu::None;
|
||
});
|
||
}
|
||
|
||
// 7. TRANSPORT ROW (Prev / 64px Play-Pause / Next)
|
||
let tr_y = pill_y + 84.0;
|
||
let prev_r = Rect::from_center_size(Pos2::new(cx - 76.0, tr_y), Vec2::splat(40.0));
|
||
let prev_resp = ctx.interact(WidgetId::new("vb_prev"), prev_r);
|
||
ctx.draw_icon(
|
||
Icon::Previous,
|
||
Rect::from_center_size(prev_r.center(), Vec2::splat(24.0)),
|
||
if prev_resp.hovered {
|
||
pal.text_bright
|
||
} else {
|
||
col_side_lo
|
||
},
|
||
);
|
||
if prev_resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if prev_resp.clicked {
|
||
actions.push(AppAction::Prev);
|
||
}
|
||
|
||
let play_r = Rect::from_center_size(Pos2::new(cx, tr_y), Vec2::splat(64.0));
|
||
let play_id = WidgetId::new("vb_play");
|
||
let play_resp = ctx.interact(play_id, play_r);
|
||
let play_hov = ctx.animate_bool(play_id.with("hov"), play_resp.hovered, 0.20);
|
||
let (play_bg, play_fg) = if is_playing {
|
||
let base = if pal.is_dark {
|
||
css_rgba(255, 255, 255, 48)
|
||
} else {
|
||
css_rgba(0, 0, 0, 28)
|
||
};
|
||
let hov = if pal.is_dark {
|
||
css_rgba(255, 255, 255, 68)
|
||
} else {
|
||
css_rgba(0, 0, 0, 44)
|
||
};
|
||
(base.lerp(hov, play_hov), pal.text_bright)
|
||
} else {
|
||
(pal.yellow.lerp(pal.yellow_hover, play_hov), pal.on_yellow)
|
||
};
|
||
ctx.dl()
|
||
.push_circle(play_r.center(), 32.0 + 1.2 * play_hov, play_bg);
|
||
ctx.draw_icon(
|
||
if is_playing {
|
||
Icon::PauseLarge
|
||
} else {
|
||
Icon::PlayLarge
|
||
},
|
||
Rect::from_center_size(play_r.center(), Vec2::splat(30.0)),
|
||
play_fg,
|
||
);
|
||
if play_resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if play_resp.clicked {
|
||
actions.push(AppAction::TogglePlay);
|
||
}
|
||
|
||
let next_r = Rect::from_center_size(Pos2::new(cx + 76.0, tr_y), Vec2::splat(40.0));
|
||
let next_resp = ctx.interact(WidgetId::new("vb_next"), next_r);
|
||
ctx.draw_icon(
|
||
Icon::Next,
|
||
Rect::from_center_size(next_r.center(), Vec2::splat(24.0)),
|
||
if next_resp.hovered {
|
||
pal.text_bright
|
||
} else {
|
||
col_side_lo
|
||
},
|
||
);
|
||
if next_resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if next_resp.clicked {
|
||
actions.push(AppAction::Next);
|
||
}
|
||
|
||
// 8. OFFICIAL 5.129.0 `WordsCard` (AI Track Facts / Replies — `4874` mod `78572`, `5b3a6ee99e2bd1b8.css`)
|
||
// `.AiBadge_root__EfKG1 { width: 48px; height: 48px; }`
|
||
// `.AiBadge_glow__R6cQa { opacity: 0.65; transform: translate3d(-25%, -43%, 0); }`
|
||
let ai_y = (tr_y + 100.0).min(rect.bottom() - 68.0);
|
||
let meteor_tex = ctx.icons.get_official_meteor_glow(&mut ctx.textures);
|
||
// Exact 180px base size at t=0 (matches lossless CDP reference) with gentle 1.25s alternate breathing
|
||
let pulse_t = 0.5 - 0.5 * ((ctx.input.time as f32) * (std::f32::consts::TAU / 2.5)).cos();
|
||
let glow_sz = 180.0_f32 * (1.0 + 0.04 * pulse_t);
|
||
|
||
let active_words_card: Option<WordsCard> = app.current_words_card().cloned();
|
||
let feedback_msg: Option<String> = app.current_words_feedback_message().map(str::to_string);
|
||
let current_tid = current_track.as_ref().map(|tr| tr.id.as_str()).unwrap_or("");
|
||
let words_is_empty = !current_tid.is_empty() && app.words_empty_tracks.contains(current_tid);
|
||
|
||
// Auto-close WordsCard popover whenever the active track changes or feedback toast activates
|
||
VIBE_LOCAL.with(|s| {
|
||
let mut st = s.borrow_mut();
|
||
if st.words_popover_open && (st.words_popover_track_id != current_tid || feedback_msg.is_some()) {
|
||
st.words_popover_open = false;
|
||
}
|
||
});
|
||
|
||
let mut words_popover_anchor: Option<(Rect, WordsCard)> = None;
|
||
|
||
if let Some(ref msg) = feedback_msg {
|
||
// State A — Feedback toast active (< 3s): sparkle + centered feedback message (non-clickable)
|
||
let msg_style = TextStyle::medium(14.0, pal.text_primary);
|
||
let msg_w = ctx
|
||
.measure_text(msg, msg_style, None)
|
||
.x
|
||
.min((hero_rect.width() - 120.0).max(160.0));
|
||
let block_w = 44.0 + msg_w;
|
||
let block_l = cx - block_w * 0.5;
|
||
let sp_c = Pos2::new(block_l + 18.0, ai_y);
|
||
let badge_tl = Pos2::new(sp_c.x - 24.0, sp_c.y - 24.0);
|
||
let meteor_r = Rect::from_xywh(
|
||
badge_tl.x - glow_sz * 0.25,
|
||
badge_tl.y - glow_sz * 0.43,
|
||
glow_sz,
|
||
glow_sz,
|
||
);
|
||
ctx.dl()
|
||
.push_image(meteor_r, meteor_tex, 0.0, Color::WHITE.with_alpha(166));
|
||
ctx.draw_icon(
|
||
Icon::AiSparkles,
|
||
Rect::from_center_size(sp_c, Vec2::splat(24.0)),
|
||
pal.text_bright,
|
||
);
|
||
ctx.draw_text_ellipsis(
|
||
msg,
|
||
msg_style,
|
||
Rect::from_xywh(block_l + 40.0, ai_y - 16.0, msg_w + 8.0, 32.0),
|
||
TextAlign::Left,
|
||
);
|
||
ctx.request_repaint_after(std::time::Duration::from_millis(250));
|
||
} else if let Some(ref card) = active_words_card.as_ref().filter(|c| !c.is_disliked()) {
|
||
// State B — Real `WordsCard` loaded for current track & not disliked!
|
||
let max_card_w = (hero_rect.width() - 64.0).clamp(320.0, 480.0);
|
||
let text_max_w = (max_card_w - 60.0).max(200.0);
|
||
let text_style_base = TextStyle::medium(14.0, pal.text_primary).with_line_height(19.0);
|
||
let measured_text = ctx.measure_text(&card.text, text_style_base, Some(text_max_w));
|
||
let text_h = measured_text.y.clamp(20.0, 58.0);
|
||
let has_action = card.action.is_some();
|
||
let action_h = if has_action { 22.0 } else { 0.0 };
|
||
let card_h = (text_h + action_h + 10.0).clamp(48.0, 92.0);
|
||
let card_w = (measured_text.x + 64.0).clamp(240.0, max_card_w);
|
||
let card_cy = ai_y.min(rect.bottom() - card_h * 0.5 - 12.0);
|
||
let card_r = Rect::from_center_size(Pos2::new(cx, card_cy), Vec2::new(card_w, card_h));
|
||
|
||
let card_resp = ctx.interact(WidgetId::new("vb_words_card"), card_r);
|
||
let ai_hov = ctx.animate_bool(WidgetId::new("vb_words_hov"), card_resp.hovered, 0.18);
|
||
let ai_scale = 1.0 + 0.02 * ai_hov;
|
||
|
||
let sp_c = Pos2::new(card_r.left() + 24.0, card_r.center_y());
|
||
let badge_tl = Pos2::new(sp_c.x - 24.0, sp_c.y - 24.0);
|
||
let meteor_r = Rect::from_xywh(
|
||
badge_tl.x - glow_sz * 0.25,
|
||
badge_tl.y - glow_sz * 0.43,
|
||
glow_sz,
|
||
glow_sz,
|
||
);
|
||
ctx.dl()
|
||
.push_image(meteor_r, meteor_tex, 0.0, Color::WHITE.with_alpha(166));
|
||
ctx.draw_icon(
|
||
Icon::AiSparkles,
|
||
Rect::from_center_size(sp_c, Vec2::splat(24.0 * ai_scale)),
|
||
pal.text_bright,
|
||
);
|
||
|
||
let text_x = card_r.left() + 50.0;
|
||
let text_w = (card_r.right() - text_x - 8.0).max(120.0);
|
||
let text_top = card_r.center_y() - (text_h + action_h) * 0.5;
|
||
let card_text_col = if card_resp.hovered {
|
||
pal.text_bright
|
||
} else {
|
||
pal.text_primary
|
||
};
|
||
let card_text_style = TextStyle::medium(14.0 * ai_scale, card_text_col)
|
||
.with_line_height(19.0 * ai_scale);
|
||
ctx.draw_text_wrapped(
|
||
&card.text,
|
||
card_text_style,
|
||
Rect::from_xywh(text_x, text_top, text_w, text_h + 4.0),
|
||
Some(3),
|
||
TextAlign::Left,
|
||
);
|
||
|
||
let mut action_clicked = false;
|
||
if let Some(ref act) = card.action {
|
||
let act_r = Rect::from_xywh(text_x, text_top + text_h + 2.0, text_w, 20.0);
|
||
let act_resp = ctx.interact(WidgetId::new("vb_words_action"), act_r);
|
||
ctx.draw_text_ellipsis(
|
||
&act.title,
|
||
TextStyle::medium(
|
||
13.0,
|
||
if act_resp.hovered {
|
||
pal.text_bright
|
||
} else {
|
||
pal.logo_text
|
||
},
|
||
),
|
||
act_r,
|
||
TextAlign::Left,
|
||
);
|
||
if act_resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if act_resp.clicked && !act.url.is_empty() {
|
||
actions.push(AppAction::OpenUrl(act.url.clone()));
|
||
action_clicked = true;
|
||
}
|
||
}
|
||
|
||
if card_resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if card_resp.clicked && !action_clicked {
|
||
if card.has_big_card() {
|
||
VIBE_LOCAL.with(|s| s.borrow_mut().words_popover_open = false);
|
||
actions.push(AppAction::OpenWordsBigCard {
|
||
track_id: card.track_id.clone(),
|
||
});
|
||
} else {
|
||
shell.close_all_menus();
|
||
VIBE_LOCAL.with(|s| {
|
||
let mut st = s.borrow_mut();
|
||
st.words_popover_open = !st.words_popover_open;
|
||
st.words_popover_track_id = card.track_id.clone();
|
||
});
|
||
}
|
||
}
|
||
|
||
words_popover_anchor = Some((card_r, (*card).clone()));
|
||
} else if words_is_empty || active_words_card.as_ref().map_or(false, |c| c.is_disliked()) {
|
||
// State C — Resolved empty OR card disliked: centered dimmed sparkle badge (opacity 0.50, non-clickable)
|
||
let sp_c = Pos2::new(cx, ai_y);
|
||
let badge_tl = Pos2::new(sp_c.x - 24.0, sp_c.y - 24.0);
|
||
let meteor_r = Rect::from_xywh(
|
||
badge_tl.x - glow_sz * 0.25,
|
||
badge_tl.y - glow_sz * 0.43,
|
||
glow_sz,
|
||
glow_sz,
|
||
);
|
||
ctx.dl()
|
||
.push_image(meteor_r, meteor_tex, 0.0, Color::WHITE.with_alpha(72));
|
||
ctx.draw_icon(
|
||
Icon::AiSparkles,
|
||
Rect::from_center_size(sp_c, Vec2::splat(24.0)),
|
||
pal.text_bright.scale_alpha(0.50),
|
||
);
|
||
} else {
|
||
// State D — Loading OR offline visual fixture: official rotating 5.129.0 `words.loading-phrase-*`
|
||
// (Index 0 at `t == 0.0` matches `my_vibe.jpg` & lossless CDP `test_ext_02` pixel-for-pixel;
|
||
// clicking while loading does NOTHING — zero fake Vibe-settings modal!)
|
||
let ai_rect = Rect::from_center_size(Pos2::new(cx, ai_y), Vec2::new(380.0, 48.0));
|
||
let sp_c = Pos2::new(ai_rect.left() + 29.0, ai_y);
|
||
let badge_tl = Pos2::new(sp_c.x - 24.0, sp_c.y - 24.0);
|
||
let meteor_r = Rect::from_xywh(
|
||
badge_tl.x - glow_sz * 0.25,
|
||
badge_tl.y - glow_sz * 0.43,
|
||
glow_sz,
|
||
glow_sz,
|
||
);
|
||
ctx.dl()
|
||
.push_image(meteor_r, meteor_tex, 0.0, Color::WHITE.with_alpha(166));
|
||
ctx.draw_icon(
|
||
Icon::AiSparkles,
|
||
Rect::from_center_size(sp_c, Vec2::splat(24.0)),
|
||
pal.text_bright,
|
||
);
|
||
let phrases = if ru {
|
||
WORDS_LOADING_PHRASES_RU
|
||
} else {
|
||
WORDS_LOADING_PHRASES_EN
|
||
};
|
||
let phrase_idx = if ctx.input.time <= 0.001 {
|
||
0
|
||
} else {
|
||
((ctx.input.time / 2.5).floor() as usize) % phrases.len()
|
||
};
|
||
let ai_text_r = Rect::from_xywh(
|
||
ai_rect.left() + 56.0,
|
||
ai_rect.top(),
|
||
ai_rect.width() - 60.0,
|
||
ai_rect.height(),
|
||
);
|
||
if phrase_idx == 0 {
|
||
let (lead, rest) = if ru {
|
||
("Собираю ", "интересное силой ИИ")
|
||
} else {
|
||
("Using the ", "AI power to collect interesting stuff")
|
||
};
|
||
let ai_spans = [
|
||
RichSpan::new(lead, TextStyle::medium(14.0, pal.text_secondary)),
|
||
RichSpan::new(rest, TextStyle::medium(14.0, pal.text_primary)),
|
||
];
|
||
ctx.draw_rich_text(&ai_spans, ai_text_r, Some(1), TextAlign::Left);
|
||
} else {
|
||
ctx.draw_text_ellipsis(
|
||
phrases[phrase_idx],
|
||
TextStyle::medium(14.0, pal.text_primary),
|
||
ai_text_r,
|
||
TextAlign::Left,
|
||
);
|
||
}
|
||
if ctx.input.time > 0.001 && !current_tid.is_empty() && app.words_loading_tracks.contains(current_tid) {
|
||
ctx.request_repaint_after(std::time::Duration::from_millis(80));
|
||
}
|
||
}
|
||
|
||
// 9. BOTTOM-RIGHT VERSION BADGE (`APP_VERSION` = `0.1.0`, or `0.1.0 → {ver}` when update available!)
|
||
let (ver_label, ver_col) = if let Some((ref new_ver, _)) = app.available_update {
|
||
(
|
||
format!("{} → {}", APP_VERSION, new_ver),
|
||
if pal.is_dark {
|
||
pal.yellow
|
||
} else {
|
||
pal.outline_selected
|
||
},
|
||
)
|
||
} else {
|
||
(APP_VERSION.to_string(), pal.text_secondary)
|
||
};
|
||
let ver_style = TextStyle::medium(13.0, ver_col);
|
||
let ver_w = (ctx.measure_text(&ver_label, ver_style, None).x + 22.0)
|
||
.max(68.0)
|
||
.ceil();
|
||
let ver_r = Rect::from_xywh(
|
||
(rect.right() - ver_w - 16.0).floor(),
|
||
(rect.bottom() - 38.0).floor(),
|
||
ver_w,
|
||
26.0,
|
||
);
|
||
let ver_resp = ctx.interact(WidgetId::new("vb_version_badge"), ver_r);
|
||
ctx.dl().push_rect(
|
||
ver_r,
|
||
13.0,
|
||
if ver_resp.hovered {
|
||
pal.surface_hover
|
||
} else {
|
||
pal.surface_secondary
|
||
},
|
||
);
|
||
ctx.draw_text_ellipsis(&ver_label, ver_style, ver_r, TextAlign::Center);
|
||
if ver_resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if ver_resp.clicked {
|
||
actions.push(AppAction::CheckForUpdates);
|
||
}
|
||
|
||
// 10. LEFT CURVED-ARC WHEEL CAROUSEL (`WheelDesktop` exact math from `vibe_wheel_foryou_spec.md` §2.1)
|
||
if left_w > 0.0 {
|
||
let fallback_stations = if app.wheel_stations.is_empty() {
|
||
YandexApiClient::official_pumpkin_wheel_for(ru)
|
||
} else {
|
||
Vec::new()
|
||
};
|
||
let active_stations: &[VibeStationSummary] = if !app.wheel_stations.is_empty() {
|
||
&app.wheel_stations
|
||
} else {
|
||
&fallback_stations
|
||
};
|
||
|
||
if !active_stations.is_empty() {
|
||
let n = active_stations.len();
|
||
let wheel_rect = Rect::from_min_max(
|
||
rect.min(),
|
||
Pos2::new(rect.left() + left_w + 76.0, rect.bottom()),
|
||
);
|
||
|
||
let dt = ctx.input.dt.clamp(0.001, 0.05);
|
||
let wheel_hovered = ctx.is_hovered(wheel_rect);
|
||
let wheel_dy = if wheel_hovered {
|
||
ctx.input.wheel_delta.y
|
||
} else {
|
||
0.0
|
||
};
|
||
|
||
let (scroll_pos, animating) = VIBE_LOCAL.with(|s| {
|
||
let mut st = s.borrow_mut();
|
||
let mut pos = st.wheel_scroll_pos.unwrap_or_else(|| n.min(3) as f32);
|
||
let mut anim = false;
|
||
|
||
if wheel_dy.abs() > 0.1 {
|
||
st.wheel_scroll_vel -= (wheel_dy / 120.0) * 3.8;
|
||
st.wheel_scroll_target = None;
|
||
}
|
||
|
||
if let Some(target) = st.wheel_scroll_target {
|
||
let diff = target - pos;
|
||
if diff.abs() < 0.005 {
|
||
pos = target;
|
||
st.wheel_scroll_target = None;
|
||
} else {
|
||
pos += diff * (1.0 - (-dt * 10.0).exp());
|
||
anim = true;
|
||
}
|
||
} else if st.wheel_scroll_vel.abs() > 0.004 {
|
||
pos += st.wheel_scroll_vel * dt;
|
||
st.wheel_scroll_vel *= (-dt * 6.5).exp();
|
||
anim = true;
|
||
} else {
|
||
st.wheel_scroll_vel = 0.0;
|
||
}
|
||
|
||
pos = pos.rem_euclid(n as f32);
|
||
st.wheel_scroll_pos = Some(pos);
|
||
(pos, anim)
|
||
});
|
||
if animating {
|
||
ctx.request_repaint();
|
||
}
|
||
|
||
let slides_per_view = (rect.height() / 106.0).floor().clamp(4.0, 9.0);
|
||
let slide_step = ((rect.height() - 12.0) / slides_per_view).max(106.0);
|
||
let wheel_cy = rect.center_y() + 9.0;
|
||
let half_slots = (slides_per_view * 0.5).ceil() as i32 + 2;
|
||
let base_slot = scroll_pos.round() as i32;
|
||
let time_s = ctx.input.time as f32;
|
||
|
||
ctx.push_clip(wheel_rect, 0.0);
|
||
for offset in -half_slots..=half_slots {
|
||
let slot_idx = base_slot + offset;
|
||
let progress = slot_idx as f32 - scroll_pos;
|
||
let item_idx = (slot_idx.rem_euclid(n as i32)) as usize;
|
||
let st = &active_stations[item_idx];
|
||
|
||
// Verbatim `WheelDesktop` curve & opacity math from `1631.1d3ade3cea83d910.js`
|
||
let norm_t = progress.abs() / 4.0;
|
||
let a = (norm_t * 0.5).min(1.0);
|
||
let theta = if norm_t <= 1.0 {
|
||
std::f32::consts::PI - norm_t * std::f32::consts::FRAC_PI_2
|
||
} else if norm_t <= 2.0 {
|
||
std::f32::consts::FRAC_PI_2 - (norm_t - 1.0) * std::f32::consts::FRAC_PI_2
|
||
} else {
|
||
0.0
|
||
};
|
||
let translate_x = 120.0 * (1.0 + theta.cos());
|
||
let arc_x = rect.left() + 123.0 + translate_x;
|
||
let row_cy = wheel_cy + progress * slide_step;
|
||
if row_cy < rect.top() - 70.0 || row_cy > rect.bottom() + 70.0 {
|
||
continue;
|
||
}
|
||
|
||
let u = ((a - 0.42) / 0.58).clamp(0.0, 1.0);
|
||
let smooth = u * u * (3.0 - 2.0 * u);
|
||
let arc_fade = (1.0 - 0.86 * smooth).clamp(0.14, 1.0);
|
||
let fade_h = (rect.height() * 0.15).clamp(56.0, 130.0);
|
||
let dist_top = (row_cy - rect.top()).max(0.0);
|
||
let dist_bot = (rect.bottom() - row_cy).max(0.0);
|
||
let y_edge = (dist_top.min(dist_bot) / fade_h).clamp(0.0, 1.0);
|
||
let y_smooth = y_edge * y_edge * (3.0 - 2.0 * y_edge);
|
||
let edge_fade = (arc_fade * y_smooth).clamp(0.0, 1.0);
|
||
|
||
// Uniform 80x80 cover (`5rem x 5rem`)
|
||
let icon_sz = 80.0;
|
||
let circle_c = Pos2::new(arc_x, row_cy);
|
||
let icon_rect = Rect::from_center_size(circle_c, Vec2::splat(icon_sz));
|
||
let row_rect = Rect::from_xywh(
|
||
icon_rect.left(),
|
||
row_cy - 44.0,
|
||
(wheel_rect.right() - icon_rect.left() - 16.0).max(160.0),
|
||
88.0,
|
||
);
|
||
let slot_wid = WidgetId::from_pair("vb_wheel_slot", slot_idx);
|
||
let resp = ctx.interact(slot_wid, row_rect);
|
||
let hovered = resp.hovered;
|
||
|
||
let is_setting = st.item_type == "SETTING"
|
||
|| st.title.eq_ignore_ascii_case("settings")
|
||
|| st.title.eq_ignore_ascii_case("настройки")
|
||
|| st.title.to_lowercase().contains("настро");
|
||
let is_reshuffle = st.is_reshuffle
|
||
|| st.item_type == "RESHUFFLE"
|
||
|| st.title.to_lowercase().contains("shake")
|
||
|| st.title.to_lowercase().contains("встряхн");
|
||
let is_promo = st.item_type == "PROMO_LINK" || st.has_link_arrow;
|
||
let is_playable = !is_setting && !is_reshuffle && !is_promo;
|
||
let is_current_station =
|
||
app.active_vibe_title.eq_ignore_ascii_case(&st.title) && is_playing;
|
||
|
||
let cr = if st.is_artist {
|
||
CornerRadii::same(40.0)
|
||
} else if st.item_type == "ALBUM" || st.item_type == "NON_MUSIC" {
|
||
CornerRadii::same(6.0)
|
||
} else {
|
||
CornerRadii::ZERO
|
||
};
|
||
let tint_alpha = if hovered { 1.0 } else { edge_fade };
|
||
let mut drew_tex = false;
|
||
if let Some(ref uri) = st.cover_uri {
|
||
if let Some((tex_id, _, _)) = covers.get_or_fetch(uri, 200) {
|
||
ctx.dl()
|
||
.push_image(icon_rect, tex_id, cr, Color::WHITE.with_alpha_f32(tint_alpha));
|
||
drew_tex = true;
|
||
}
|
||
}
|
||
if !drew_tex {
|
||
let placeholder_bg = if pal.is_dark {
|
||
Color::rgb(0x1C, 0x1C, 0x1C)
|
||
} else {
|
||
Color::rgb(0xE2, 0xE2, 0xE2)
|
||
};
|
||
ctx.dl()
|
||
.push_rect(icon_rect, cr, placeholder_bg.with_alpha_f32(0.88 * edge_fade));
|
||
let glyph = if st.is_artist {
|
||
Icon::Note
|
||
} else {
|
||
Icon::MyVibe
|
||
};
|
||
ctx.draw_icon(
|
||
glyph,
|
||
Rect::from_center_size(circle_c, Vec2::splat(26.0)),
|
||
pal.text_secondary.scale_alpha(edge_fade),
|
||
);
|
||
}
|
||
|
||
// Glassy inset white rim on circular artist covers
|
||
if st.is_artist {
|
||
ctx.dl().push_circle_stroke(
|
||
circle_c,
|
||
39.5,
|
||
1.0,
|
||
css_rgba(255, 255, 255, (128.0 * edge_fade).round() as u8),
|
||
);
|
||
}
|
||
|
||
// Hover Play/Pause overlay OR pulsing 8px yellow dot when playing
|
||
if is_playable && hovered {
|
||
if st.is_artist {
|
||
ctx.dl()
|
||
.push_circle(circle_c, 40.0, css_rgba(0, 0, 0, 120));
|
||
} else {
|
||
ctx.dl()
|
||
.push_rect(icon_rect, cr, css_rgba(0, 0, 0, 110));
|
||
}
|
||
let icon_hovered = ctx
|
||
.input
|
||
.pointer_pos
|
||
.map_or(false, |pos| icon_rect.contains(pos));
|
||
let play_ic_sz = if icon_hovered { 42.0 } else { 40.0 };
|
||
ctx.draw_icon(
|
||
if is_current_station {
|
||
Icon::PauseFilled
|
||
} else {
|
||
Icon::PlayFilled
|
||
},
|
||
Rect::from_center_size(circle_c, Vec2::splat(play_ic_sz)),
|
||
Color::WHITE,
|
||
);
|
||
} else if is_current_station {
|
||
let pulse = 0.5 + 0.5 * (time_s * 9.0).sin();
|
||
let dot_r = 3.5 + 1.5 * pulse;
|
||
ctx.dl().push_circle(circle_c, dot_r, pal.yellow);
|
||
ctx.request_repaint_after(std::time::Duration::from_millis(40));
|
||
}
|
||
|
||
// Typography: 16px gap, subtitle 14px Medium secondary, title 16px Medium bright (or accent yellow for Reshuffle)
|
||
let tx = icon_rect.right() + 16.0;
|
||
let max_tw = (wheel_rect.right() - tx - 16.0).clamp(180.0, 210.0);
|
||
let title_alpha = if hovered { 1.0 } else { 0.96 * edge_fade };
|
||
let title_col = if is_reshuffle {
|
||
pal.logo_variant.with_alpha_f32(title_alpha)
|
||
} else {
|
||
pal.text_bright.with_alpha_f32(title_alpha)
|
||
};
|
||
|
||
let title_style = TextStyle::medium(16.0, title_col).with_line_height(20.0);
|
||
let single_w = ctx.measure_text(&st.title, title_style, None).x;
|
||
let is_multiline = single_w > max_tw + 1.0;
|
||
let title_text_end_x;
|
||
if let Some(ref sub) = st.subtitle {
|
||
if is_multiline {
|
||
let sub_r = Rect::from_xywh(tx, row_cy - 30.0, max_tw, 18.0);
|
||
ctx.draw_text_ellipsis(
|
||
sub,
|
||
TextStyle::medium(14.0, pal.text_secondary.scale_alpha(edge_fade)),
|
||
sub_r,
|
||
TextAlign::Left,
|
||
);
|
||
let t_r = Rect::from_xywh(tx, row_cy - 10.0, max_tw, 42.0);
|
||
let measured = ctx.draw_text_wrapped(
|
||
&st.title,
|
||
title_style,
|
||
t_r,
|
||
Some(2),
|
||
TextAlign::Left,
|
||
);
|
||
title_text_end_x = tx + measured.x.min(max_tw);
|
||
} else {
|
||
let sub_r = Rect::from_xywh(tx, row_cy - 22.0, max_tw, 20.0);
|
||
ctx.draw_text_ellipsis(
|
||
sub,
|
||
TextStyle::medium(14.0, pal.text_secondary.scale_alpha(edge_fade)),
|
||
sub_r,
|
||
TextAlign::Left,
|
||
);
|
||
let t_r = Rect::from_xywh(tx, row_cy - 1.0, max_tw, 22.0);
|
||
let measured = ctx.draw_text_ellipsis(
|
||
&st.title,
|
||
title_style,
|
||
t_r,
|
||
TextAlign::Left,
|
||
);
|
||
title_text_end_x = tx + measured.x.min(max_tw);
|
||
}
|
||
} else if is_multiline {
|
||
let t_r = Rect::from_xywh(tx, row_cy - 19.0, max_tw, 42.0);
|
||
let measured = ctx.draw_text_wrapped(
|
||
&st.title,
|
||
title_style,
|
||
t_r,
|
||
Some(2),
|
||
TextAlign::Left,
|
||
);
|
||
title_text_end_x = tx + measured.x.min(max_tw);
|
||
} else {
|
||
let t_r = Rect::from_xywh(tx, row_cy - 11.0, max_tw, 22.0);
|
||
let measured = ctx.draw_text_ellipsis(
|
||
&st.title,
|
||
title_style,
|
||
t_r,
|
||
TextAlign::Left,
|
||
);
|
||
title_text_end_x = tx + measured.x.min(max_tw);
|
||
}
|
||
|
||
// Inline 20px `link_rounded` icon ONLY for external `http(s)://` promo links
|
||
// (omitted on standard promo slides without external URL matching `my_vibe.jpg`)
|
||
let has_external_link = st
|
||
.promo_url
|
||
.as_deref()
|
||
.map_or(false, |u| u.starts_with("http://") || u.starts_with("https://"));
|
||
if is_promo && has_external_link {
|
||
let arrow_c =
|
||
Pos2::new((title_text_end_x + 14.0).min(wheel_rect.right() - 18.0), row_cy);
|
||
ctx.draw_icon(
|
||
Icon::LinkRounded,
|
||
Rect::from_center_size(arrow_c, Vec2::splat(20.0)),
|
||
if hovered {
|
||
pal.text_bright
|
||
} else {
|
||
pal.text_secondary.scale_alpha(edge_fade)
|
||
},
|
||
);
|
||
}
|
||
|
||
if hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if resp.clicked {
|
||
if progress.abs() >= 2.8 {
|
||
// Exact `WheelDesktop`: clicking outer items smoothly scrolls them toward center
|
||
VIBE_LOCAL.with(|s| {
|
||
s.borrow_mut().wheel_scroll_target = Some(scroll_pos + progress);
|
||
});
|
||
ctx.request_repaint();
|
||
} else if is_setting {
|
||
actions.push(AppAction::SetVibeModalOpen(true));
|
||
} else if is_reshuffle {
|
||
actions.push(AppAction::ReshuffleWheel);
|
||
} else if is_promo {
|
||
actions.push(AppAction::ActivateWheelItem(st.clone()));
|
||
} else if is_current_station {
|
||
actions.push(AppAction::TogglePlay);
|
||
} else {
|
||
actions.push(AppAction::ActivateWheelItem(st.clone()));
|
||
}
|
||
}
|
||
}
|
||
ctx.pop_clip();
|
||
}
|
||
}
|
||
|
||
ctx.pop_clip();
|
||
|
||
// 11. EXACT 5.129.0 `VibeContextMenu` (`vibe_wheel_foryou_spec.md` §3) on `ZLayer::Popover`
|
||
if shell.vibe_menu_open {
|
||
render_vibe_context_menu(
|
||
ctx,
|
||
pal,
|
||
app,
|
||
shell,
|
||
rect,
|
||
more_r,
|
||
current_track.as_ref(),
|
||
is_liked,
|
||
actions,
|
||
);
|
||
}
|
||
|
||
// 12. OFFICIAL 5.129.0 `WordsCardPopoverDesktop` (floating 12px above `WordsCard`, `ZLayer::Popover`)
|
||
let words_pop_open = VIBE_LOCAL.with(|s| s.borrow().words_popover_open);
|
||
if words_pop_open {
|
||
if let Some((anchor_r, ref card)) = words_popover_anchor {
|
||
render_words_card_popover(ctx, pal, ru, anchor_r, card, actions);
|
||
} else {
|
||
VIBE_LOCAL.with(|s| s.borrow_mut().words_popover_open = false);
|
||
}
|
||
}
|
||
|
||
// 13. OFFICIAL 5.129.0 `WordsCardFullscreen` (`ZLayer::Modal` when `app.words_big_card_open`)
|
||
if app.words_big_card_open {
|
||
render_words_card_fullscreen(ctx, pal, covers, app, ru, active_words_card.as_ref(), actions);
|
||
}
|
||
}
|
||
|
||
fn render_words_card_popover(
|
||
ctx: &mut UiContext,
|
||
pal: &YmPalette,
|
||
ru: bool,
|
||
anchor_rect: Rect,
|
||
card: &WordsCard,
|
||
actions: &mut Vec<AppAction>,
|
||
) {
|
||
let pop_w = 260.0_f32;
|
||
let item_h = 36.0_f32;
|
||
let div_h = 13.0_f32;
|
||
let src_count = card.actions.len().min(5);
|
||
let mut pop_h = 16.0 + 2.0 * item_h;
|
||
if src_count > 0 {
|
||
pop_h += src_count as f32 * item_h + div_h;
|
||
}
|
||
let disclaimer_text = if ru {
|
||
"AI может ошибаться, проверяйте важное"
|
||
} else {
|
||
"AI may make mistakes, be sure to double-check important information"
|
||
};
|
||
let disclaimer_h = if card.is_fact() {
|
||
let mh = ctx
|
||
.measure_text(
|
||
disclaimer_text,
|
||
TextStyle::regular(12.0, pal.text_secondary).with_line_height(16.0),
|
||
Some(pop_w - 32.0),
|
||
)
|
||
.y
|
||
.clamp(18.0, 40.0);
|
||
pop_h += div_h + mh + 8.0;
|
||
mh
|
||
} else {
|
||
0.0
|
||
};
|
||
|
||
let screen = ctx.screen_rect();
|
||
let pop_x = (anchor_rect.center_x() - pop_w * 0.5)
|
||
.clamp(screen.left() + 12.0, (screen.right() - pop_w - 12.0).max(screen.left() + 12.0));
|
||
let pop_y = (anchor_rect.top() - pop_h - 12.0).clamp(40.0, (screen.bottom() - pop_h - 12.0).max(40.0));
|
||
let pop_rect = Rect::from_xywh(pop_x, pop_y, pop_w, pop_h);
|
||
|
||
let mut close_pop = false;
|
||
ctx.with_layer(ZLayer::Popover, |ctx| {
|
||
let inner = ym_menu_frame(ctx, pal, pop_rect);
|
||
let mut y = inner.top();
|
||
let w = inner.width();
|
||
|
||
if src_count > 0 {
|
||
for (idx, src) in card.actions.iter().take(src_count).enumerate() {
|
||
let r = Rect::from_xywh(inner.left(), y, w, item_h);
|
||
y += item_h;
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::from_pair("wcp_src", idx),
|
||
r,
|
||
Icon::LinkXxs,
|
||
&src.title,
|
||
false,
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
if !src.url.is_empty() {
|
||
actions.push(AppAction::OpenUrl(src.url.clone()));
|
||
}
|
||
close_pop = true;
|
||
}
|
||
}
|
||
ym_menu_divider(ctx, pal, Rect::from_xywh(inner.left(), y, w, div_h));
|
||
y += div_h;
|
||
}
|
||
|
||
let like_lbl = if ru {
|
||
"Больше такого"
|
||
} else {
|
||
"More similar replies"
|
||
};
|
||
let dislike_lbl = if ru { "Мимо" } else { "Not cool" };
|
||
|
||
let r_like = Rect::from_xywh(inner.left(), y, w, item_h);
|
||
y += item_h;
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("wcp_like"),
|
||
r_like,
|
||
Icon::ThumbUpXxs,
|
||
like_lbl,
|
||
card.is_liked(),
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::SendWordsFeedback {
|
||
track_id: card.track_id.clone(),
|
||
card_id: card.id.clone(),
|
||
state: if card.is_liked() {
|
||
"neutral".into()
|
||
} else {
|
||
"like".into()
|
||
},
|
||
});
|
||
close_pop = true;
|
||
}
|
||
|
||
let r_dislike = Rect::from_xywh(inner.left(), y, w, item_h);
|
||
y += item_h;
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("wcp_dislike"),
|
||
r_dislike,
|
||
Icon::ThumbDownXxs,
|
||
dislike_lbl,
|
||
card.is_disliked(),
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::SendWordsFeedback {
|
||
track_id: card.track_id.clone(),
|
||
card_id: card.id.clone(),
|
||
state: "dislike".into(),
|
||
});
|
||
close_pop = true;
|
||
}
|
||
|
||
if card.is_fact() {
|
||
ym_menu_divider(ctx, pal, Rect::from_xywh(inner.left(), y, w, div_h));
|
||
y += div_h + 2.0;
|
||
ctx.draw_text_wrapped(
|
||
disclaimer_text,
|
||
TextStyle::regular(12.0, pal.text_secondary).with_line_height(16.0),
|
||
Rect::from_xywh(inner.left() + 8.0, y, w - 16.0, disclaimer_h + 4.0),
|
||
Some(3),
|
||
TextAlign::Center,
|
||
);
|
||
}
|
||
|
||
if ctx.input.clicked_outside_any(&[pop_rect, anchor_rect])
|
||
|| ctx.input.key_pressed(Key::Escape)
|
||
{
|
||
close_pop = true;
|
||
}
|
||
});
|
||
|
||
if close_pop {
|
||
VIBE_LOCAL.with(|s| s.borrow_mut().words_popover_open = false);
|
||
}
|
||
}
|
||
|
||
fn render_words_card_fullscreen(
|
||
ctx: &mut UiContext,
|
||
pal: &YmPalette,
|
||
covers: &mut CoverCache,
|
||
app: &AppState,
|
||
ru: bool,
|
||
fallback_card: Option<&WordsCard>,
|
||
actions: &mut Vec<AppAction>,
|
||
) {
|
||
let screen = ctx.screen_rect();
|
||
let mut should_close = false;
|
||
|
||
ctx.with_layer(ZLayer::Modal, |ctx| {
|
||
ctx.register_blocker(screen);
|
||
ctx.dl().push_backdrop_blur(
|
||
screen,
|
||
0.0,
|
||
4.0,
|
||
pal.bg_overlay,
|
||
0.0,
|
||
Color::TRANSPARENT,
|
||
);
|
||
|
||
// Top-right circular Close `×` button
|
||
let close_r = Rect::from_center_size(
|
||
Pos2::new(screen.right() - 40.0, screen.top() + 56.0),
|
||
Vec2::splat(40.0),
|
||
);
|
||
let close_resp = ctx.interact(WidgetId::new("wcf_close"), close_r);
|
||
ctx.dl().push_circle(
|
||
close_r.center(),
|
||
20.0,
|
||
if close_resp.hovered {
|
||
pal.surface_hover
|
||
} else {
|
||
pal.surface_secondary
|
||
},
|
||
);
|
||
ctx.draw_icon(
|
||
Icon::Close,
|
||
Rect::from_center_size(close_r.center(), Vec2::splat(18.0)),
|
||
if close_resp.hovered {
|
||
pal.text_bright
|
||
} else {
|
||
pal.text_primary
|
||
},
|
||
);
|
||
if close_resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if close_resp.clicked {
|
||
should_close = true;
|
||
}
|
||
|
||
let col_w = (screen.width() - 96.0).clamp(300.0, 560.0);
|
||
let col_x = screen.center_x() - col_w * 0.5;
|
||
let disclaimer = if ru {
|
||
"AI может ошибаться, проверяйте важное"
|
||
} else {
|
||
"AI may make mistakes, be sure to double-check important information"
|
||
};
|
||
let disclaimer_y = screen.bottom() - 38.0;
|
||
let content_rect = Rect::from_min_max(
|
||
Pos2::new(col_x - 24.0, screen.top() + 92.0),
|
||
Pos2::new(col_x + col_w + 24.0, disclaimer_y - 12.0),
|
||
);
|
||
|
||
if app.words_big_card_loading {
|
||
// 3 subtle animated shimmer bars centered vertically while `POST /words/big-cards` loads
|
||
let shimmer = 0.5 + 0.5 * ((ctx.input.time as f32) * 3.2).sin();
|
||
let a = (28.0 + 36.0 * shimmer).round() as u8;
|
||
let bar_col = if pal.is_dark {
|
||
css_rgba(255, 255, 255, a)
|
||
} else {
|
||
css_rgba(0, 0, 0, a)
|
||
};
|
||
let sy = content_rect.center_y() - 40.0;
|
||
for (i, frac) in [0.88_f32, 1.0_f32, 0.64_f32].iter().enumerate() {
|
||
let bw = col_w * frac;
|
||
let br = Rect::from_xywh(
|
||
screen.center_x() - bw * 0.5,
|
||
sy + i as f32 * 30.0,
|
||
bw,
|
||
18.0,
|
||
);
|
||
ctx.dl().push_rect(br, 9.0, bar_col);
|
||
}
|
||
ctx.request_repaint();
|
||
} else {
|
||
let full_text = app
|
||
.words_big_card
|
||
.as_ref()
|
||
.map(|b| b.text.as_str())
|
||
.filter(|s| !s.is_empty())
|
||
.or_else(|| fallback_card.map(|c| c.text.as_str()))
|
||
.unwrap_or("");
|
||
let sources = app
|
||
.words_big_card
|
||
.as_ref()
|
||
.filter(|b| !b.actions.is_empty())
|
||
.map(|b| b.actions.as_slice())
|
||
.or_else(|| fallback_card.map(|c| c.actions.as_slice()))
|
||
.unwrap_or(&[]);
|
||
|
||
let text_style = TextStyle::bold(20.0, pal.text_bright).with_line_height(28.0);
|
||
let measured = ctx.measure_text(full_text, text_style, Some(col_w));
|
||
let src_count = sources.len().min(2);
|
||
let src_block_h = if src_count > 0 {
|
||
28.0 + src_count as f32 * 46.0 - 8.0
|
||
} else {
|
||
0.0
|
||
};
|
||
let fb_block_h = if fallback_card.is_some() { 22.0 + 32.0 } else { 0.0 };
|
||
let max_text_h = (content_rect.height() - src_block_h - fb_block_h - 16.0).max(110.0);
|
||
let used_text_h = measured.y.min(max_text_h);
|
||
let total_stack_h = used_text_h + src_block_h + fb_block_h;
|
||
let mut y = (content_rect.center_y() - total_stack_h * 0.5).max(content_rect.top());
|
||
|
||
// 1. Centered 20px bold story text (scrollable if longer than viewport, ZERO floating sparkle!)
|
||
let text_vp = Rect::from_xywh(col_x, y, col_w, used_text_h + 6.0);
|
||
if measured.y > max_text_h {
|
||
let scroll_id = WidgetId::new("wcf_text_scroll");
|
||
let scroll_y = ctx.begin_scroll_v(scroll_id, text_vp, 0.0);
|
||
ctx.draw_text_wrapped(
|
||
full_text,
|
||
text_style,
|
||
Rect::from_xywh(col_x, text_vp.top() - scroll_y, col_w, measured.y + 12.0),
|
||
None,
|
||
TextAlign::Center,
|
||
);
|
||
ctx.end_scroll_v(scroll_id, pal, measured.y + 16.0, false);
|
||
} else {
|
||
ctx.draw_text_wrapped(
|
||
full_text,
|
||
text_style,
|
||
Rect::from_xywh(col_x, y, col_w, measured.y + 12.0),
|
||
None,
|
||
TextAlign::Center,
|
||
);
|
||
}
|
||
y += used_text_h;
|
||
|
||
// 2. Centered full-width-fitted source/Alice glass pill(s) (28px below text, NEVER truncates!)
|
||
if src_count > 0 {
|
||
y += 28.0;
|
||
let max_pill_w = (screen.width() - 64.0).min(520.0);
|
||
for (idx, src) in sources.iter().take(src_count).enumerate() {
|
||
let lbl_style = TextStyle::medium(14.0, pal.text_bright);
|
||
let tw = ctx.measure_text(&src.title, lbl_style, None).x;
|
||
let pill_w = (tw + 54.0).clamp(160.0, max_pill_w);
|
||
let pill_r = Rect::from_xywh(
|
||
screen.center_x() - pill_w * 0.5,
|
||
y,
|
||
pill_w,
|
||
38.0,
|
||
);
|
||
let resp = ctx.interact(WidgetId::from_pair("wcf_src_pill", idx), pill_r);
|
||
let bg = if pal.is_dark {
|
||
css_rgba(255, 255, 255, if resp.hovered { 32 } else { 18 })
|
||
} else if resp.hovered {
|
||
pal.surface_hover
|
||
} else {
|
||
pal.surface_secondary
|
||
};
|
||
let border = if pal.is_dark {
|
||
css_rgba(255, 255, 255, 28)
|
||
} else {
|
||
pal.border_subtle
|
||
};
|
||
ctx.dl().push_rect_bordered(pill_r, 19.0, bg, 1.0, border);
|
||
|
||
// Left 18x18 icon: favicon_url -> Alice purple ring -> LinkRounded
|
||
let ic_center = Pos2::new(pill_r.left() + 22.0, pill_r.center_y());
|
||
let ic_rect = Rect::from_center_size(ic_center, Vec2::splat(18.0));
|
||
let mut drew_fav = false;
|
||
if let Some(ref fav) = src.favicon_url {
|
||
if let Some((tex_id, _, _)) = covers.get_or_fetch(fav, 64) {
|
||
ctx.dl().push_image(ic_rect, tex_id, 9.0, Color::WHITE);
|
||
drew_fav = true;
|
||
}
|
||
}
|
||
if !drew_fav {
|
||
let tl = src.title.to_lowercase();
|
||
if tl.contains("алис") || tl.contains("alice") {
|
||
ctx.dl()
|
||
.push_circle(ic_center, 9.0, Color::rgb(0x18, 0x13, 0x26));
|
||
ctx.dl().push_circle_stroke(
|
||
ic_center,
|
||
8.0,
|
||
2.2,
|
||
Color::rgb(0x8B, 0x5C, 0xF6),
|
||
);
|
||
ctx.dl()
|
||
.push_circle(ic_center, 2.6, Color::rgb(0xC4, 0xB5, 0xFD));
|
||
} else {
|
||
ctx.draw_icon(
|
||
Icon::LinkRounded,
|
||
Rect::from_center_size(ic_center, Vec2::splat(16.0)),
|
||
pal.text_bright,
|
||
);
|
||
}
|
||
}
|
||
|
||
ctx.draw_text_ellipsis(
|
||
&src.title,
|
||
lbl_style,
|
||
Rect::from_xywh(
|
||
pill_r.left() + 38.0,
|
||
pill_r.top(),
|
||
(pill_r.width() - 52.0).max(40.0),
|
||
pill_r.height(),
|
||
),
|
||
TextAlign::Left,
|
||
);
|
||
if resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if resp.clicked && !src.url.is_empty() {
|
||
actions.push(AppAction::OpenUrl(src.url.clone()));
|
||
}
|
||
y += 46.0;
|
||
}
|
||
y -= 8.0;
|
||
}
|
||
|
||
// 3. BORDERLESS TEXT-ONLY feedback buttons (22px below source pill, 28px gap, ZERO boxes!)
|
||
if let Some(card) = fallback_card {
|
||
y += 22.0;
|
||
let like_lbl = if ru {
|
||
"Больше такого"
|
||
} else {
|
||
"More similar replies"
|
||
};
|
||
let dislike_lbl = if ru { "Мимо" } else { "Not cool" };
|
||
let muted = if pal.is_dark {
|
||
css_rgba(255, 255, 255, 148)
|
||
} else {
|
||
pal.text_secondary
|
||
};
|
||
let lbl_style = TextStyle::medium(14.0, muted);
|
||
let like_tw = ctx.measure_text(like_lbl, lbl_style, None).x;
|
||
let dislike_tw = ctx.measure_text(dislike_lbl, lbl_style, None).x;
|
||
let like_w = 16.0 + 7.0 + like_tw + 8.0;
|
||
let dislike_w = 16.0 + 7.0 + dislike_tw + 8.0;
|
||
let gap = 28.0_f32;
|
||
let total_w = like_w + gap + dislike_w;
|
||
let start_x = screen.center_x() - total_w * 0.5;
|
||
let btn_h = 32.0;
|
||
|
||
let like_r = Rect::from_xywh(start_x, y, like_w, btn_h);
|
||
let like_resp = ctx.interact(WidgetId::new("wcf_like"), like_r);
|
||
let like_fg = if card.is_liked() || like_resp.hovered {
|
||
pal.text_bright
|
||
} else {
|
||
muted
|
||
};
|
||
ctx.draw_icon(
|
||
Icon::ThumbUpXxs,
|
||
Rect::from_center_size(
|
||
Pos2::new(like_r.left() + 10.0, like_r.center_y()),
|
||
Vec2::splat(16.0),
|
||
),
|
||
like_fg,
|
||
);
|
||
ctx.draw_text_ellipsis(
|
||
like_lbl,
|
||
TextStyle::medium(14.0, like_fg),
|
||
Rect::from_xywh(like_r.left() + 24.0, like_r.top(), like_tw + 8.0, btn_h),
|
||
TextAlign::Left,
|
||
);
|
||
if like_resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if like_resp.clicked {
|
||
actions.push(AppAction::SendWordsFeedback {
|
||
track_id: card.track_id.clone(),
|
||
card_id: card.id.clone(),
|
||
state: if card.is_liked() {
|
||
"neutral".into()
|
||
} else {
|
||
"like".into()
|
||
},
|
||
});
|
||
}
|
||
|
||
let dislike_r = Rect::from_xywh(like_r.right() + gap, y, dislike_w, btn_h);
|
||
let dislike_resp = ctx.interact(WidgetId::new("wcf_dislike"), dislike_r);
|
||
let dislike_fg = if card.is_disliked() || dislike_resp.hovered {
|
||
pal.text_bright
|
||
} else {
|
||
muted
|
||
};
|
||
ctx.draw_icon(
|
||
Icon::ThumbDownXxs,
|
||
Rect::from_center_size(
|
||
Pos2::new(dislike_r.left() + 10.0, dislike_r.center_y()),
|
||
Vec2::splat(16.0),
|
||
),
|
||
dislike_fg,
|
||
);
|
||
ctx.draw_text_ellipsis(
|
||
dislike_lbl,
|
||
TextStyle::medium(14.0, dislike_fg),
|
||
Rect::from_xywh(
|
||
dislike_r.left() + 24.0,
|
||
dislike_r.top(),
|
||
dislike_tw + 8.0,
|
||
btn_h,
|
||
),
|
||
TextAlign::Left,
|
||
);
|
||
if dislike_resp.hovered {
|
||
ctx.set_cursor(CursorKind::Pointer);
|
||
}
|
||
if dislike_resp.clicked {
|
||
actions.push(AppAction::SendWordsFeedback {
|
||
track_id: card.track_id.clone(),
|
||
card_id: card.id.clone(),
|
||
state: "dislike".into(),
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
// 4. Disclaimer pinned cleanly near the bottom (`screen.bottom() - 32.0`)
|
||
let disc_col = if pal.is_dark {
|
||
css_rgba(255, 255, 255, 96)
|
||
} else {
|
||
pal.text_secondary
|
||
};
|
||
ctx.draw_text_ellipsis(
|
||
disclaimer,
|
||
TextStyle::regular(12.0, disc_col),
|
||
Rect::from_center_size(
|
||
Pos2::new(screen.center_x(), screen.bottom() - 32.0),
|
||
Vec2::new((screen.width() - 64.0).max(200.0), 22.0),
|
||
),
|
||
TextAlign::Center,
|
||
);
|
||
|
||
if ctx.input.key_pressed(Key::Escape)
|
||
|| ctx.input.clicked_outside_any(&[content_rect, close_r])
|
||
{
|
||
should_close = true;
|
||
}
|
||
});
|
||
|
||
if should_close {
|
||
actions.push(AppAction::CloseWordsBigCard);
|
||
}
|
||
}
|
||
|
||
#[allow(clippy::too_many_arguments)]
|
||
fn render_vibe_context_menu(
|
||
ctx: &mut UiContext,
|
||
pal: &YmPalette,
|
||
app: &AppState,
|
||
shell: &mut ShellUiState,
|
||
stage_rect: Rect,
|
||
anchor_btn: Rect,
|
||
current_track: Option<&Track>,
|
||
is_liked: bool,
|
||
actions: &mut Vec<AppAction>,
|
||
) {
|
||
let t = app.i18n();
|
||
let item_h = 36.0;
|
||
let div_h = 13.0;
|
||
let menu_w = 275.0;
|
||
|
||
let is_custom_vibe = app.is_vibe_active
|
||
&& !app.active_vibe_title.is_empty()
|
||
&& !app.active_vibe_title.eq_ignore_ascii_case("My Vibe")
|
||
&& !app.active_vibe_title.eq_ignore_ascii_case("Моя волна");
|
||
let show_shuffle = !app.is_vibe_active;
|
||
let show_lyrics = current_track.map_or(false, |tr| {
|
||
tr.has_lyrics
|
||
|| app
|
||
.current_lyrics
|
||
.as_ref()
|
||
.map_or(false, |l| l.track_id == tr.id && !l.lines.is_empty())
|
||
});
|
||
let has_album = current_track.and_then(|tr| tr.album_id.as_ref()).is_some();
|
||
let has_artists = current_track.map_or(false, |tr| !tr.artists.is_empty());
|
||
|
||
// Exact height calculation for dynamic item count
|
||
let mut rows_h = 16.0; // top+bottom frame padding
|
||
if is_custom_vibe {
|
||
rows_h += item_h;
|
||
}
|
||
rows_h += item_h; // Vibe by track OR My Vibe settings
|
||
rows_h += div_h;
|
||
if show_shuffle {
|
||
rows_h += item_h;
|
||
}
|
||
rows_h += item_h; // Repeat
|
||
if show_lyrics {
|
||
rows_h += item_h;
|
||
}
|
||
rows_h += item_h; // Open queue
|
||
rows_h += item_h; // Sound settings
|
||
if current_track.is_some() {
|
||
rows_h += div_h;
|
||
rows_h += item_h; // Add to playlist >
|
||
rows_h += item_h; // Share >
|
||
rows_h += item_h; // Go to track
|
||
if has_album {
|
||
rows_h += item_h;
|
||
}
|
||
if has_artists {
|
||
rows_h += item_h;
|
||
}
|
||
}
|
||
|
||
let screen = ctx.screen_rect();
|
||
let menu_x = (anchor_btn.right() - menu_w)
|
||
.clamp(stage_rect.left() + 12.0, screen.right() - menu_w - 12.0);
|
||
let menu_y = (anchor_btn.top() - rows_h - 10.0)
|
||
.clamp(38.0, (screen.bottom() - rows_h - 12.0).max(38.0));
|
||
let menu_rect = Rect::from_xywh(menu_x, menu_y, menu_w, rows_h);
|
||
|
||
let mut close_menu = false;
|
||
let mut open_rects = vec![menu_rect, anchor_btn];
|
||
|
||
ctx.with_layer(ZLayer::Popover, |ctx| {
|
||
let inner = ym_menu_frame(ctx, pal, menu_rect);
|
||
let mut y = inner.top();
|
||
let w = inner.width();
|
||
|
||
let next_row = |y: &mut f32| -> Rect {
|
||
let r = Rect::from_xywh(inner.left(), *y, w, item_h);
|
||
*y += item_h;
|
||
r
|
||
};
|
||
let next_div = |y: &mut f32| -> Rect {
|
||
let r = Rect::from_xywh(inner.left(), *y, w, div_h);
|
||
*y += div_h;
|
||
r
|
||
};
|
||
|
||
// Group 1: Pin My Vibe (if custom vibe) + My Vibe by track
|
||
if is_custom_vibe {
|
||
let seeds_id = app
|
||
.active_rotor_session
|
||
.as_ref()
|
||
.map(|s| s.seeds.join(","))
|
||
.unwrap_or_else(|| "user:onyourwave".into());
|
||
let pinned = app.is_pinned("wave", &seeds_id);
|
||
let r = next_row(&mut y);
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_pin_vibe"),
|
||
r,
|
||
if pinned {
|
||
Icon::PinFilledXxs
|
||
} else {
|
||
Icon::PinXxs
|
||
},
|
||
if pinned {
|
||
t.unpin_my_vibe()
|
||
} else {
|
||
t.pin_my_vibe()
|
||
},
|
||
pinned,
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::TogglePin {
|
||
kind: "wave".into(),
|
||
id: seeds_id,
|
||
title: app.active_vibe_title.clone(),
|
||
subtitle: t.my_vibe().into(),
|
||
cover_uri: current_track.and_then(|tr| tr.cover_uri.clone()),
|
||
owner_uid: None,
|
||
});
|
||
close_menu = true;
|
||
}
|
||
}
|
||
|
||
if let Some(tr) = current_track {
|
||
let r = next_row(&mut y);
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_vibe_track"),
|
||
r,
|
||
Icon::VibeXxs,
|
||
t.vibe_by_track(),
|
||
false,
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::StartVibeBySeeds {
|
||
title: tr.title.clone(),
|
||
seeds: vec![format!("track:{}", tr.id)],
|
||
});
|
||
close_menu = true;
|
||
}
|
||
} else {
|
||
let r = next_row(&mut y);
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_vibe_settings"),
|
||
r,
|
||
Icon::VibeXxs,
|
||
if t.is_ru() {
|
||
"Настроить Мою волну"
|
||
} else {
|
||
"My Vibe settings"
|
||
},
|
||
false,
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::SetVibeModalOpen(true));
|
||
close_menu = true;
|
||
}
|
||
}
|
||
|
||
ym_menu_divider(ctx, pal, next_div(&mut y));
|
||
|
||
// Group 2: Shuffle (when not Vibe), Repeat (active state + stays open!), Show lyrics, Open queue, Sound settings
|
||
if show_shuffle {
|
||
let r = next_row(&mut y);
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_shuffle"),
|
||
r,
|
||
Icon::ShuffleXxs,
|
||
t.shuffle(),
|
||
app.shuffle,
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::ToggleShuffle);
|
||
}
|
||
}
|
||
|
||
{
|
||
let r = next_row(&mut y);
|
||
let rep_active = app.repeat != RepeatMode::Off;
|
||
let rep_icon = if app.repeat == RepeatMode::One {
|
||
Icon::RepeatOneXxs
|
||
} else {
|
||
Icon::RepeatXxs
|
||
};
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_repeat"),
|
||
r,
|
||
rep_icon,
|
||
t.repeat(),
|
||
rep_active,
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::CycleRepeat);
|
||
// Exact 5.129.0 spec §3.2: Repeat keeps menu open so user sees toggled active state!
|
||
}
|
||
}
|
||
|
||
if show_lyrics {
|
||
let r = next_row(&mut y);
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_lyrics"),
|
||
r,
|
||
Icon::SyncLyricsXxs,
|
||
t.show_lyrics(),
|
||
app.fullscreen_open && app.fullscreen_lyrics_open,
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::OpenFullscreenSyncLyrics);
|
||
close_menu = true;
|
||
}
|
||
}
|
||
|
||
{
|
||
let r = next_row(&mut y);
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_queue"),
|
||
r,
|
||
Icon::PlayQueueXxs,
|
||
t.open_queue(),
|
||
app.fullscreen_open && app.fullscreen_queue_open,
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::OpenFullscreenQueue);
|
||
close_menu = true;
|
||
}
|
||
}
|
||
|
||
{
|
||
let r = next_row(&mut y);
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_sound"),
|
||
r,
|
||
Icon::SettingsXxs,
|
||
t.sound_settings(),
|
||
false,
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::SetEqPopoverOpen(true));
|
||
close_menu = true;
|
||
}
|
||
}
|
||
|
||
// Group 3: Add to playlist >, Share >, Go to track (TrackModal!), View album, Go to artist(s)
|
||
if let Some(tr) = current_track {
|
||
ym_menu_divider(ctx, pal, next_div(&mut y));
|
||
|
||
let add_r = next_row(&mut y);
|
||
let add_resp = ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_add_playlist"),
|
||
add_r,
|
||
Icon::AddToPlaylistXxs,
|
||
t.add_to_playlist(),
|
||
VIBE_LOCAL.with(|s| s.borrow().submenu == VibeSubmenu::AddToPlaylist),
|
||
true,
|
||
);
|
||
if add_resp.hovered || add_resp.clicked {
|
||
VIBE_LOCAL.with(|s| {
|
||
let mut st = s.borrow_mut();
|
||
st.submenu = VibeSubmenu::AddToPlaylist;
|
||
st.submenu_anchor_y = add_r.top();
|
||
});
|
||
}
|
||
|
||
let share_r = next_row(&mut y);
|
||
let share_resp = ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_share"),
|
||
share_r,
|
||
Icon::Share,
|
||
t.share(),
|
||
VIBE_LOCAL.with(|s| s.borrow().submenu == VibeSubmenu::Share),
|
||
true,
|
||
);
|
||
if share_resp.hovered || share_resp.clicked {
|
||
VIBE_LOCAL.with(|s| {
|
||
let mut st = s.borrow_mut();
|
||
st.submenu = VibeSubmenu::Share;
|
||
st.submenu_anchor_y = share_r.top();
|
||
});
|
||
}
|
||
|
||
let goto_tr = next_row(&mut y);
|
||
let goto_resp = ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_goto_track"),
|
||
goto_tr,
|
||
Icon::NoteXxs,
|
||
t.go_to_track(),
|
||
false,
|
||
false,
|
||
);
|
||
if goto_resp.hovered {
|
||
VIBE_LOCAL.with(|s| s.borrow_mut().submenu = VibeSubmenu::None);
|
||
}
|
||
if goto_resp.clicked {
|
||
// Exact official 5.129.0: navigate directly to full Album page (with bottom PlayerBar),
|
||
// falling back to Fullscreen player when album_id is unavailable.
|
||
if let Some(ref aid) = tr.album_id {
|
||
actions.push(AppAction::Navigate(Route::Album {
|
||
id: aid.clone(),
|
||
title: tr
|
||
.album_title
|
||
.clone()
|
||
.unwrap_or_else(|| t.album().to_string()),
|
||
}));
|
||
} else {
|
||
actions.push(AppAction::SetFullscreen(true));
|
||
}
|
||
close_menu = true;
|
||
}
|
||
|
||
if let Some(ref aid) = tr.album_id {
|
||
let alb_r = next_row(&mut y);
|
||
let alb_resp = ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_goto_album"),
|
||
alb_r,
|
||
Icon::AlbumXxs,
|
||
t.view_album(),
|
||
false,
|
||
false,
|
||
);
|
||
if alb_resp.hovered {
|
||
VIBE_LOCAL.with(|s| s.borrow_mut().submenu = VibeSubmenu::None);
|
||
}
|
||
if alb_resp.clicked {
|
||
actions.push(AppAction::Navigate(Route::Album {
|
||
id: aid.clone(),
|
||
title: tr
|
||
.album_title
|
||
.clone()
|
||
.unwrap_or_else(|| t.album().to_string()),
|
||
}));
|
||
close_menu = true;
|
||
}
|
||
}
|
||
|
||
if !tr.artists.is_empty() {
|
||
let art_r = next_row(&mut y);
|
||
let multi = tr.artists.len() > 1;
|
||
let art_resp = ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_goto_artist"),
|
||
art_r,
|
||
Icon::ArtistXxs,
|
||
if multi {
|
||
t.go_to_artists()
|
||
} else {
|
||
t.go_to_artist()
|
||
},
|
||
multi && VIBE_LOCAL.with(|s| s.borrow().submenu == VibeSubmenu::Artists),
|
||
multi,
|
||
);
|
||
if multi {
|
||
if art_resp.hovered || art_resp.clicked {
|
||
VIBE_LOCAL.with(|s| {
|
||
let mut st = s.borrow_mut();
|
||
st.submenu = VibeSubmenu::Artists;
|
||
st.submenu_anchor_y = art_r.top();
|
||
});
|
||
}
|
||
} else {
|
||
if art_resp.hovered {
|
||
VIBE_LOCAL.with(|s| s.borrow_mut().submenu = VibeSubmenu::None);
|
||
}
|
||
if art_resp.clicked {
|
||
if let Some(first) = tr.artists.first() {
|
||
actions.push(AppAction::Navigate(Route::Artist {
|
||
id: first.id.clone(),
|
||
name: first.name.clone(),
|
||
}));
|
||
close_menu = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// Render active Submenu (Add to playlist / Share / Artists)
|
||
let (active_sub, sub_anchor_y) =
|
||
VIBE_LOCAL.with(|s| (s.borrow().submenu, s.borrow().submenu_anchor_y));
|
||
if active_sub != VibeSubmenu::None {
|
||
let sub_w = 248.0;
|
||
let sub_h = match active_sub {
|
||
VibeSubmenu::AddToPlaylist => {
|
||
let pl_count = app.user_playlists.len().min(8);
|
||
16.0 + item_h * (2 + pl_count) as f32 + div_h
|
||
}
|
||
VibeSubmenu::Share => 16.0 + item_h * 2.0,
|
||
VibeSubmenu::Artists => 16.0 + item_h * tr.artists.len().min(8) as f32,
|
||
VibeSubmenu::None => 0.0,
|
||
};
|
||
// Place submenu to the right if room, else to the left of main menu
|
||
let sub_x = if menu_rect.right() + sub_w + 10.0 <= screen.right() {
|
||
menu_rect.right() + 4.0
|
||
} else {
|
||
(menu_rect.left() - sub_w - 4.0).max(12.0)
|
||
};
|
||
let sub_y = sub_anchor_y
|
||
.clamp(38.0, (screen.bottom() - sub_h - 12.0).max(38.0));
|
||
let sub_rect = Rect::from_xywh(sub_x, sub_y, sub_w, sub_h);
|
||
open_rects.push(sub_rect);
|
||
|
||
let sub_inner = ym_menu_frame(ctx, pal, sub_rect);
|
||
let mut sy = sub_inner.top();
|
||
let sw = sub_inner.width();
|
||
|
||
match active_sub {
|
||
VibeSubmenu::AddToPlaylist => {
|
||
let r_create = Rect::from_xywh(sub_inner.left(), sy, sw, item_h);
|
||
sy += item_h;
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_sub_create_pl"),
|
||
r_create,
|
||
Icon::AddXxs,
|
||
t.create_playlist(),
|
||
false,
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::OpenCreatePlaylistModal {
|
||
initial_track: Some(tr.clone()),
|
||
});
|
||
close_menu = true;
|
||
}
|
||
|
||
ym_menu_divider(ctx, pal, Rect::from_xywh(sub_inner.left(), sy, sw, div_h));
|
||
sy += div_h;
|
||
|
||
let r_fav = Rect::from_xywh(sub_inner.left(), sy, sw, item_h);
|
||
sy += item_h;
|
||
if ym_menu_item_ex(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_sub_fav"),
|
||
r_fav,
|
||
if is_liked {
|
||
Icon::LikedXxs
|
||
} else {
|
||
Icon::LikeXxs
|
||
},
|
||
t.liked_playlist(),
|
||
false,
|
||
is_liked,
|
||
false,
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::ToggleLike(tr.clone()));
|
||
close_menu = true;
|
||
}
|
||
|
||
for (idx, pl) in app.user_playlists.iter().take(8).enumerate() {
|
||
let r_pl = Rect::from_xywh(sub_inner.left(), sy, sw, item_h);
|
||
sy += item_h;
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::from_pair("vcm_sub_pl", idx),
|
||
r_pl,
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
VibeSubmenu::Share => {
|
||
let r_link = Rect::from_xywh(sub_inner.left(), sy, sw, item_h);
|
||
sy += item_h;
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_sub_copy_link"),
|
||
r_link,
|
||
Icon::ChainXxs,
|
||
t.copy_link(),
|
||
false,
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::CopyTrackLink(tr.clone()));
|
||
close_menu = true;
|
||
}
|
||
|
||
let r_embed = Rect::from_xywh(sub_inner.left(), sy, sw, item_h);
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::new("vcm_sub_copy_embed"),
|
||
r_embed,
|
||
Icon::CodeXxs,
|
||
t.html_code(),
|
||
false,
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::CopyTrackEmbed(tr.clone()));
|
||
close_menu = true;
|
||
}
|
||
}
|
||
VibeSubmenu::Artists => {
|
||
for (idx, art) in tr.artists.iter().take(8).enumerate() {
|
||
let r_a = Rect::from_xywh(sub_inner.left(), sy, sw, item_h);
|
||
sy += item_h;
|
||
if ym_menu_item(
|
||
ctx,
|
||
pal,
|
||
WidgetId::from_pair("vcm_sub_art", idx),
|
||
r_a,
|
||
Icon::ArtistXxs,
|
||
&art.name,
|
||
false,
|
||
false,
|
||
)
|
||
.clicked
|
||
{
|
||
actions.push(AppAction::Navigate(Route::Artist {
|
||
id: art.id.clone(),
|
||
name: art.name.clone(),
|
||
}));
|
||
close_menu = true;
|
||
}
|
||
}
|
||
}
|
||
VibeSubmenu::None => {}
|
||
}
|
||
}
|
||
}
|
||
|
||
if ctx.input.clicked_outside_any(&open_rects) || ctx.input.key_pressed(Key::Escape) {
|
||
close_menu = true;
|
||
}
|
||
});
|
||
|
||
if close_menu {
|
||
shell.vibe_menu_open = false;
|
||
VIBE_LOCAL.with(|s| {
|
||
s.borrow_mut().submenu = VibeSubmenu::None;
|
||
});
|
||
}
|
||
}
|