first commit
This commit is contained in:
commit
a408df2a76
218 changed files with 52376 additions and 0 deletions
673
src/views/player_bar.rs
Normal file
673
src/views/player_bar.rs
Normal file
|
|
@ -0,0 +1,673 @@
|
|||
use crate::api::models::format_ms;
|
||||
use crate::app::{AppAction, AppState, RepeatMode, Route};
|
||||
use crate::covers::CoverCache;
|
||||
use crate::engine::widgets::{draw_cover_art, separated_artists, ym_volume_capsule};
|
||||
use crate::engine::{
|
||||
css_rgba, Color, CursorKind, Pos2, Rect, RichSpan, TextAlign, TextStyle, UiContext, Vec2,
|
||||
WidgetId, YmPalette, ZLayer,
|
||||
};
|
||||
use crate::icons::Icon;
|
||||
use crate::views::overlays::ShellUiState;
|
||||
|
||||
/// Exact Yandex Music Desktop 5.129.0 Bottom PlayerBar (`PlayerBarDesktopWithBackgroundProgressBar`):
|
||||
/// - Exact 80px height, `hsl(h, s%, 20%)` track-derived bg (or `pal.bg_player`) in BOTH themes
|
||||
/// - Subtle played split fill + hover top 4px yellow progress bar + 12px thumb + timecode pills
|
||||
/// - Clickable cover (hover scrim + Fullscreen), clickable title (opens album),
|
||||
/// individually clickable multi-artists (`SeparatedArtists`), full `•••` TrackContextMenu
|
||||
/// - Disabled visual states: Shuffle muted (`hsla(0,0%,100%,.08)`) & non-clickable when `is_vibe_active`;
|
||||
/// Lyrics muted (`#4D4D4D`) & non-clickable when `!track.has_lyrics`
|
||||
/// - Right-side `44×216` vertical hover volume popover with real Kawase blur & 1% wheel step
|
||||
pub fn render_player_bar(
|
||||
ctx: &mut UiContext,
|
||||
pal: &YmPalette,
|
||||
covers: &mut CoverCache,
|
||||
app: &AppState,
|
||||
shell: &mut ShellUiState,
|
||||
rect: Rect,
|
||||
actions: &mut Vec<AppAction>,
|
||||
) {
|
||||
let i18n = app.i18n();
|
||||
let current_track = app.current_track();
|
||||
let is_playing = app.is_audio_playing();
|
||||
let is_buffering = app.is_buffering();
|
||||
let position_ms = app.position_ms();
|
||||
let duration_ms = app.duration_ms();
|
||||
let volume = app.config.volume;
|
||||
let muted = app.config.muted;
|
||||
let is_vibe_active = app.is_vibe_active;
|
||||
|
||||
let is_liked = current_track.map_or(false, |t| app.liked_ids.contains(&t.id));
|
||||
let is_disliked = current_track.map_or(false, |t| app.disliked_ids.contains(&t.id));
|
||||
let has_lyrics = current_track.map_or(false, |t| {
|
||||
t.has_lyrics
|
||||
|| app
|
||||
.current_lyrics
|
||||
.as_ref()
|
||||
.map_or(false, |l| l.track_id == t.id && !l.lines.is_empty())
|
||||
});
|
||||
|
||||
let progress = if duration_ms > 0 {
|
||||
(position_ms as f32 / duration_ms as f32).clamp(0.0, 1.0)
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
// 1. Exact 5.129.0 `--player-average-color-background`: `hsl(h, s%, 20%)` in BOTH dark & light themes!
|
||||
// Falls back to `pal.bg_player` (`#141414` dark / `#999999` light) when idle.
|
||||
let track_rgb = current_track.and_then(|tr| {
|
||||
tr.derived_average_hex
|
||||
.as_deref()
|
||||
.and_then(Color::from_hex_str)
|
||||
.or_else(|| tr.derived_accent_hex.as_deref().and_then(Color::from_hex_str))
|
||||
.or_else(|| {
|
||||
tr.cover_uri
|
||||
.as_deref()
|
||||
.and_then(|u| covers.get_or_fetch(u, 100))
|
||||
.map(|(_, dom, _)| dom)
|
||||
})
|
||||
});
|
||||
let base_bg = pal.player_bar_bg(track_rgb);
|
||||
|
||||
// Player bar controls always sit on a dark/mid-grey surface (`hsl(..., 20%)`, `#141414`, or `#999`),
|
||||
// so foreground uses official `--ym-controls-color-secondary-text-*` tokens (light/white in both themes).
|
||||
let fg_bright = Color::WHITE;
|
||||
let fg_muted = css_rgba(255, 255, 255, 148);
|
||||
let fg_disabled_shuffle = if pal.is_dark {
|
||||
css_rgba(255, 255, 255, 20) // hsla(0,0%,100%,.08)
|
||||
} else {
|
||||
css_rgba(255, 255, 255, 26) // hsla(0,0%,100%,.10)
|
||||
};
|
||||
let fg_disabled_lyrics = if pal.is_dark {
|
||||
Color::rgb(0x4D, 0x4D, 0x4D)
|
||||
} else {
|
||||
css_rgba(255, 255, 255, 72)
|
||||
};
|
||||
let btn_hover_bg = css_rgba(255, 255, 255, 31);
|
||||
|
||||
ctx.dl().push_rect(rect, 12.0, base_bg);
|
||||
|
||||
// 2. Top-edge 4px yellow progress bar + 12px thumb + hover timecode pills
|
||||
let bar_hover_zone = rect.expand2(Vec2::new(0.0, 6.0));
|
||||
let bar_hovered = ctx.is_hovered(bar_hover_zone);
|
||||
let scrub_zone = Rect::from_min_max(
|
||||
Pos2::new(rect.left() + 8.0, rect.top() - 6.0),
|
||||
Pos2::new(rect.right() - 8.0, rect.top() + 12.0),
|
||||
);
|
||||
let scrub_resp = ctx.interact(WidgetId::new("pb_top_scrub"), scrub_zone);
|
||||
|
||||
// Smooth drag seeking: preview drag position locally and dispatch SeekFraction ONLY on release/click!
|
||||
if scrub_resp.pressed || scrub_resp.dragged {
|
||||
if let Some(pos) = ctx.input.pointer_pos {
|
||||
let frac = ((pos.x - scrub_zone.left()) / scrub_zone.width().max(1.0)).clamp(0.0, 1.0);
|
||||
shell.pb_scrub_frac = Some(frac);
|
||||
}
|
||||
}
|
||||
if let Some(frac) = shell.pb_scrub_frac {
|
||||
if !ctx.input.left_down || scrub_resp.drag_stopped || scrub_resp.clicked {
|
||||
let commit_frac = ctx
|
||||
.input
|
||||
.pointer_pos
|
||||
.map(|pos| ((pos.x - scrub_zone.left()) / scrub_zone.width().max(1.0)).clamp(0.0, 1.0))
|
||||
.unwrap_or(frac);
|
||||
actions.push(AppAction::SeekFraction(commit_frac));
|
||||
shell.pb_scrub_frac = None;
|
||||
}
|
||||
} else if scrub_resp.clicked {
|
||||
if let Some(pos) = ctx.input.pointer_pos {
|
||||
let frac = ((pos.x - scrub_zone.left()) / scrub_zone.width().max(1.0)).clamp(0.0, 1.0);
|
||||
actions.push(AppAction::SeekFraction(frac));
|
||||
}
|
||||
}
|
||||
|
||||
let display_progress = shell.pb_scrub_frac.unwrap_or(progress);
|
||||
|
||||
// Subtle played split overlay clipped to left progress fraction (exact 5.129.0 `rgba(255,255,255,0.051)`)
|
||||
let prog_x = rect.left() + rect.width() * display_progress;
|
||||
if display_progress > 0.002 {
|
||||
let clip_played = Rect::from_min_max(rect.min(), Pos2::new(prog_x, rect.bottom()));
|
||||
ctx.dl().push_clip(clip_played, 0.0);
|
||||
ctx.dl().push_rect(rect, 12.0, css_rgba(255, 255, 255, 13));
|
||||
ctx.dl().pop_clip();
|
||||
}
|
||||
ctx.dl()
|
||||
.push_rect_bordered(rect, 12.0, Color::TRANSPARENT, 1.0, pal.border_subtle);
|
||||
|
||||
let scrub_active =
|
||||
scrub_resp.hovered || scrub_resp.pressed || scrub_resp.dragged || shell.pb_scrub_frac.is_some();
|
||||
let hover_t = ctx.animate_bool(WidgetId::new("pb_scrub_hover_anim"), bar_hovered || scrub_active, 0.15);
|
||||
|
||||
if hover_t > 0.01 {
|
||||
let display_frac = display_progress;
|
||||
|
||||
ctx.with_layer(ZLayer::Popover, |ctx| {
|
||||
let bar_y = rect.top() + 2.0;
|
||||
let bar_r = Rect::from_min_max(
|
||||
Pos2::new(scrub_zone.left(), bar_y - 2.0),
|
||||
Pos2::new(scrub_zone.right(), bar_y + 2.0),
|
||||
);
|
||||
ctx.dl()
|
||||
.push_rect(bar_r, 2.0, css_rgba(255, 255, 255, (38.0 * hover_t).round() as u8));
|
||||
|
||||
let fill_x = scrub_zone.left() + scrub_zone.width() * display_frac;
|
||||
let fill_r = Rect::from_min_max(bar_r.min(), Pos2::new(fill_x, bar_r.bottom()));
|
||||
let yellow_a = pal.yellow.with_alpha_f32(hover_t);
|
||||
ctx.dl().push_rect(fill_r, 2.0, yellow_a);
|
||||
|
||||
// Exact 12px circular yellow thumb (`radius = 6px`)
|
||||
ctx.dl()
|
||||
.push_circle(Pos2::new(fill_x, bar_y), 6.0 * hover_t, yellow_a);
|
||||
|
||||
// Left & right timecode pills
|
||||
let cur_ms = (display_frac * duration_ms as f32) as u64;
|
||||
let tc_bg = css_rgba(20, 20, 20, (215.0 * hover_t).round() as u8);
|
||||
let tc_fg = Color::rgb(0xE6, 0xE6, 0xE6).with_alpha_f32(hover_t);
|
||||
|
||||
let left_tc_r = Rect::from_xywh(rect.left() + 8.0, rect.top() - 24.0, 44.0, 18.0);
|
||||
ctx.dl().push_rect(left_tc_r, 9.0, tc_bg);
|
||||
ctx.draw_text_ellipsis(
|
||||
&format_ms(cur_ms),
|
||||
TextStyle::medium(11.0, tc_fg),
|
||||
left_tc_r,
|
||||
TextAlign::Center,
|
||||
);
|
||||
|
||||
let right_tc_r = Rect::from_xywh(rect.right() - 52.0, rect.top() - 24.0, 44.0, 18.0);
|
||||
ctx.dl().push_rect(right_tc_r, 9.0, tc_bg);
|
||||
ctx.draw_text_ellipsis(
|
||||
&format_ms(duration_ms),
|
||||
TextStyle::medium(11.0, tc_fg),
|
||||
right_tc_r,
|
||||
TextAlign::Center,
|
||||
);
|
||||
|
||||
// Hover seek cursor timecode tooltip
|
||||
if scrub_active {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
if let Some(pos) = ctx.input.pointer_pos {
|
||||
let frac = ((pos.x - scrub_zone.left()) / scrub_zone.width().max(1.0)).clamp(0.0, 1.0);
|
||||
let hover_ms = (frac * duration_ms as f32) as u64;
|
||||
let tip_x = pos.x.clamp(rect.left() + 78.0, (rect.right() - 78.0).max(rect.left() + 78.0));
|
||||
let tip_r = Rect::from_center_size(Pos2::new(tip_x, rect.top() - 18.0), Vec2::new(50.0, 22.0));
|
||||
ctx.dl().push_rect(tip_r, 11.0, css_rgba(20, 20, 20, 230));
|
||||
ctx.draw_text_ellipsis(
|
||||
&format_ms(hover_ms),
|
||||
TextStyle::medium(12.0, Color::WHITE),
|
||||
tip_r,
|
||||
TextAlign::Center,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let cy = rect.center_y();
|
||||
let cx = rect.center_x() - 12.0;
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
// LEFT: 64×64 Cover + Clickable Title + Explicit + `•••` TrackContextMenu + SeparatedArtists
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
let left_max_x = (cx - 182.0).max(rect.left() + 140.0);
|
||||
if let Some(track) = current_track {
|
||||
let cover_rect = Rect::from_xywh(rect.left() + 8.0, cy - 32.0, 64.0, 64.0);
|
||||
draw_cover_art(
|
||||
ctx,
|
||||
pal,
|
||||
covers,
|
||||
cover_rect,
|
||||
track.cover_uri.as_deref(),
|
||||
&track.id,
|
||||
6.0,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
let cov_resp = ctx.interact(WidgetId::new("pb_cover"), cover_rect);
|
||||
if cov_resp.hovered {
|
||||
ctx.dl().push_rect(cover_rect, 6.0, css_rgba(0, 0, 0, 128));
|
||||
ctx.dl()
|
||||
.push_circle(cover_rect.center(), 22.0, css_rgba(26, 26, 26, 230));
|
||||
ctx.draw_icon(
|
||||
Icon::Fullscreen,
|
||||
Rect::from_center_size(cover_rect.center(), Vec2::splat(24.0)),
|
||||
Color::WHITE,
|
||||
);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(cover_rect, i18n.fullscreen_player());
|
||||
}
|
||||
if cov_resp.clicked {
|
||||
actions.push(AppAction::SetFullscreen(true));
|
||||
}
|
||||
|
||||
let info_x = cover_rect.right() + 10.0;
|
||||
let info_w = (left_max_x - info_x - 50.0).max(70.0);
|
||||
|
||||
// Title + optional version
|
||||
let version_str = track
|
||||
.version
|
||||
.as_deref()
|
||||
.filter(|v| !v.is_empty())
|
||||
.map(|v| format!(" {}", v));
|
||||
let full_text = match &version_str {
|
||||
Some(vs) => format!("{}{}", track.title, vs),
|
||||
None => track.title.clone(),
|
||||
};
|
||||
let measured_w = ctx
|
||||
.measure_text(&full_text, TextStyle::bold(14.0, fg_bright), None)
|
||||
.x
|
||||
.min(info_w);
|
||||
let title_r = Rect::from_xywh(info_x, cy - 19.0, measured_w.max(20.0), 20.0);
|
||||
let title_resp = ctx.interact(WidgetId::new("pb_title_click"), title_r);
|
||||
|
||||
let mut spans = vec![RichSpan::new(&track.title, TextStyle::bold(14.0, fg_bright))];
|
||||
if let Some(ref vs) = version_str {
|
||||
spans.push(RichSpan::new(vs, TextStyle::medium(14.0, fg_muted)));
|
||||
}
|
||||
ctx.draw_rich_text(
|
||||
&spans,
|
||||
Rect::from_xywh(info_x, cy - 19.0, info_w, 20.0),
|
||||
Some(1),
|
||||
TextAlign::Left,
|
||||
);
|
||||
if title_resp.hovered && track.album_id.is_some() {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.dl().push_rect(
|
||||
Rect::from_xywh(title_r.left(), title_r.bottom() - 2.0, title_r.width(), 1.0),
|
||||
0.0,
|
||||
fg_bright.scale_alpha(0.75),
|
||||
);
|
||||
}
|
||||
if title_resp.clicked {
|
||||
if let Some(ref aid) = track.album_id {
|
||||
actions.push(AppAction::Navigate(Route::Album {
|
||||
id: aid.clone(),
|
||||
title: track
|
||||
.album_title
|
||||
.clone()
|
||||
.unwrap_or_else(|| i18n.album().to_string()),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
let mut after_title_x = info_x + measured_w + 4.0;
|
||||
if track.is_explicit && after_title_x + 18.0 < left_max_x - 24.0 {
|
||||
ctx.draw_icon(
|
||||
Icon::Explicit,
|
||||
Rect::from_center_size(Pos2::new(after_title_x + 9.0, cy - 10.0), Vec2::splat(18.0)),
|
||||
fg_muted,
|
||||
);
|
||||
after_title_x += 22.0;
|
||||
}
|
||||
|
||||
// `•••` button opens the full reusable `TrackContextMenu` (player bar mode!)
|
||||
let more_pos = Pos2::new((after_title_x + 16.0).min(left_max_x - 24.0), cy - 10.0);
|
||||
let more_r = Rect::from_center_size(more_pos, Vec2::splat(24.0));
|
||||
let more_resp = ctx.interact(WidgetId::new("pb_more_btn"), more_r);
|
||||
let more_open = shell
|
||||
.track_menu
|
||||
.as_ref()
|
||||
.map_or(false, |m| m.from_player_bar && m.track.id == track.id);
|
||||
if more_resp.hovered || more_open {
|
||||
ctx.dl().push_circle(more_pos, 12.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
ctx.draw_icon(
|
||||
Icon::MoreXxs,
|
||||
Rect::from_center_size(more_pos, Vec2::splat(20.0)),
|
||||
if more_resp.hovered || more_open {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if more_resp.clicked {
|
||||
if more_open {
|
||||
shell.track_menu = None;
|
||||
} else {
|
||||
shell.open_track_menu_player_bar(track.clone(), Pos2::new(more_pos.x, rect.top() - 8.0));
|
||||
}
|
||||
}
|
||||
|
||||
// Individually clickable multi-artists (`SeparatedArtists`)!
|
||||
let artist_r = Rect::from_xywh(info_x, cy + 2.0, info_w, 20.0);
|
||||
if let Some((aid, aname)) = separated_artists(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("pb_artists"),
|
||||
artist_r,
|
||||
&track.artists,
|
||||
14.0,
|
||||
fg_muted,
|
||||
fg_bright,
|
||||
TextAlign::Left,
|
||||
) {
|
||||
actions.push(AppAction::Navigate(Route::Artist { id: aid, name: aname }));
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
// CENTER: [Dislike] [Shuffle] [Prev] [40px Yellow Play] [Next] [Repeat] [Like]
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
|
||||
// Dislike
|
||||
let dis_r = Rect::from_center_size(Pos2::new(cx - 154.0, cy), Vec2::splat(40.0));
|
||||
let dis_resp = ctx.interact(WidgetId::new("pb_dis"), dis_r);
|
||||
if dis_resp.hovered {
|
||||
ctx.dl().push_circle(dis_r.center(), 18.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(dis_r, i18n.dislike());
|
||||
}
|
||||
ctx.draw_icon(
|
||||
if is_disliked { Icon::Disliked } else { Icon::Dislike },
|
||||
Rect::from_center_size(dis_r.center(), Vec2::splat(24.0)),
|
||||
if is_disliked || dis_resp.hovered {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if dis_resp.clicked {
|
||||
if let Some(tr) = current_track {
|
||||
actions.push(AppAction::ToggleDislike(tr.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
// Shuffle — DISABLED & non-clickable when `is_vibe_active` (exact `hsla(0,0%,100%,.08)`)!
|
||||
let shuf_r = Rect::from_center_size(Pos2::new(cx - 100.0, cy), Vec2::splat(32.0));
|
||||
if is_vibe_active {
|
||||
ctx.draw_icon(
|
||||
Icon::Shuffle,
|
||||
Rect::from_center_size(shuf_r.center(), Vec2::splat(24.0)),
|
||||
fg_disabled_shuffle,
|
||||
);
|
||||
} else {
|
||||
let shuf_resp = ctx.interact(WidgetId::new("pb_shuf"), shuf_r);
|
||||
if shuf_resp.hovered {
|
||||
ctx.dl().push_circle(shuf_r.center(), 16.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(shuf_r, i18n.shuffle());
|
||||
}
|
||||
ctx.draw_icon(
|
||||
Icon::Shuffle,
|
||||
Rect::from_center_size(shuf_r.center(), Vec2::splat(24.0)),
|
||||
if app.shuffle {
|
||||
pal.yellow
|
||||
} else if shuf_resp.hovered {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if shuf_resp.clicked {
|
||||
actions.push(AppAction::ToggleShuffle);
|
||||
}
|
||||
}
|
||||
|
||||
// Previous
|
||||
let prev_r = Rect::from_center_size(Pos2::new(cx - 46.0, cy), Vec2::splat(40.0));
|
||||
let prev_resp = ctx.interact(WidgetId::new("pb_prev"), prev_r);
|
||||
if prev_resp.hovered {
|
||||
ctx.dl().push_circle(prev_r.center(), 18.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
ctx.draw_icon(
|
||||
Icon::PreviousXxs,
|
||||
Rect::from_center_size(prev_r.center(), Vec2::splat(20.0)),
|
||||
if prev_resp.hovered { fg_bright } else { fg_muted },
|
||||
);
|
||||
if prev_resp.clicked {
|
||||
actions.push(AppAction::Prev);
|
||||
}
|
||||
|
||||
// 40px Yellow circular Play / Pause button
|
||||
let play_r = Rect::from_center_size(Pos2::new(cx, cy), Vec2::splat(40.0));
|
||||
let play_resp = ctx.interact(WidgetId::new("pb_play"), play_r);
|
||||
let play_col = if play_resp.hovered {
|
||||
pal.yellow_hover
|
||||
} else {
|
||||
pal.yellow
|
||||
};
|
||||
if is_buffering {
|
||||
ctx.dl().push_circle(play_r.center(), 20.0, play_col);
|
||||
ctx.draw_text_ellipsis("···", TextStyle::medium(15.0, pal.on_yellow), play_r, TextAlign::Center);
|
||||
} else {
|
||||
let sz = if play_resp.hovered { 42.0 } else { 40.0 };
|
||||
ctx.draw_icon(
|
||||
if is_playing {
|
||||
Icon::PauseFilled
|
||||
} else {
|
||||
Icon::PlayFilled
|
||||
},
|
||||
Rect::from_center_size(play_r.center(), Vec2::splat(sz)),
|
||||
play_col,
|
||||
);
|
||||
}
|
||||
if play_resp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
if play_resp.clicked {
|
||||
actions.push(AppAction::TogglePlay);
|
||||
}
|
||||
|
||||
// Next
|
||||
let next_r = Rect::from_center_size(Pos2::new(cx + 46.0, cy), Vec2::splat(40.0));
|
||||
let next_resp = ctx.interact(WidgetId::new("pb_next"), next_r);
|
||||
if next_resp.hovered {
|
||||
ctx.dl().push_circle(next_r.center(), 18.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
ctx.draw_icon(
|
||||
Icon::NextXxs,
|
||||
Rect::from_center_size(next_r.center(), Vec2::splat(20.0)),
|
||||
if next_resp.hovered { fg_bright } else { fg_muted },
|
||||
);
|
||||
if next_resp.clicked {
|
||||
actions.push(AppAction::Next);
|
||||
}
|
||||
|
||||
// Repeat
|
||||
let rep_r = Rect::from_center_size(Pos2::new(cx + 100.0, cy), Vec2::splat(32.0));
|
||||
let rep_resp = ctx.interact(WidgetId::new("pb_rep"), rep_r);
|
||||
if rep_resp.hovered {
|
||||
ctx.dl().push_circle(rep_r.center(), 16.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(rep_r, i18n.repeat());
|
||||
}
|
||||
ctx.draw_icon(
|
||||
if app.repeat == RepeatMode::One {
|
||||
Icon::RepeatOne
|
||||
} else {
|
||||
Icon::Repeat
|
||||
},
|
||||
Rect::from_center_size(rep_r.center(), Vec2::splat(24.0)),
|
||||
if app.repeat != RepeatMode::Off {
|
||||
pal.yellow
|
||||
} else if rep_resp.hovered {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if rep_resp.clicked {
|
||||
actions.push(AppAction::CycleRepeat);
|
||||
}
|
||||
|
||||
// Like
|
||||
let like_r = Rect::from_center_size(Pos2::new(cx + 154.0, cy), Vec2::splat(40.0));
|
||||
let like_resp = ctx.interact(WidgetId::new("pb_like"), like_r);
|
||||
if like_resp.hovered {
|
||||
ctx.dl().push_circle(like_r.center(), 18.0, btn_hover_bg);
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(like_r, i18n.like());
|
||||
}
|
||||
ctx.draw_icon(
|
||||
if is_liked { Icon::Liked } else { Icon::Like },
|
||||
Rect::from_center_size(like_r.center(), Vec2::splat(24.0)),
|
||||
if is_liked {
|
||||
pal.accent_coral
|
||||
} else if like_resp.hovered {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if like_resp.clicked {
|
||||
if let Some(tr) = current_track {
|
||||
actions.push(AppAction::ToggleLike(tr.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
// RIGHT: [Lyrics] [Queue] [EQ] [Volume + 44×216 Kawase Popover]
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
let vol_icon_x = rect.right() - 35.0;
|
||||
|
||||
// 1. Lyrics button (disabled muted when `!has_lyrics`!)
|
||||
let lyr_x = vol_icon_x - 135.0;
|
||||
if lyr_x >= cx + 184.0 {
|
||||
let br = Rect::from_center_size(Pos2::new(lyr_x, cy), Vec2::splat(36.0));
|
||||
if !has_lyrics {
|
||||
ctx.draw_icon(
|
||||
Icon::Lyrics,
|
||||
Rect::from_center_size(br.center(), Vec2::splat(24.0)),
|
||||
fg_disabled_lyrics,
|
||||
);
|
||||
} else {
|
||||
let bresp = ctx.interact(WidgetId::new("pb_r_lyr"), br);
|
||||
let active = app.fullscreen_open && app.fullscreen_lyrics_open;
|
||||
let ic_sz = if bresp.hovered { 25.2 } else { 24.0 };
|
||||
if bresp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(br, i18n.lyrics());
|
||||
}
|
||||
ctx.draw_icon(
|
||||
Icon::Lyrics,
|
||||
Rect::from_center_size(br.center(), Vec2::splat(ic_sz)),
|
||||
if active {
|
||||
pal.yellow
|
||||
} else if bresp.hovered {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if bresp.clicked {
|
||||
actions.push(AppAction::OpenFullscreenSyncLyrics);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Queue button
|
||||
let que_x = vol_icon_x - 90.0;
|
||||
if que_x >= cx + 184.0 {
|
||||
let br = Rect::from_center_size(Pos2::new(que_x, cy), Vec2::splat(36.0));
|
||||
let bresp = ctx.interact(WidgetId::new("pb_r_que"), br);
|
||||
let active = app.fullscreen_open && app.fullscreen_queue_open;
|
||||
let ic_sz = if bresp.hovered { 25.2 } else { 24.0 };
|
||||
if bresp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(br, i18n.queue());
|
||||
}
|
||||
ctx.draw_icon(
|
||||
Icon::Queue,
|
||||
Rect::from_center_size(br.center(), Vec2::splat(ic_sz)),
|
||||
if active {
|
||||
pal.yellow
|
||||
} else if bresp.hovered {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if bresp.clicked {
|
||||
actions.push(AppAction::OpenFullscreenQueue);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. EQ / Sound Settings button
|
||||
let eq_x = vol_icon_x - 45.0;
|
||||
if eq_x >= cx + 184.0 {
|
||||
let br = Rect::from_center_size(Pos2::new(eq_x, cy), Vec2::splat(36.0));
|
||||
let bresp = ctx.interact(WidgetId::new("pb_r_eq"), br);
|
||||
let ic_sz = if bresp.hovered { 25.2 } else { 24.0 };
|
||||
if bresp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
ctx.show_tooltip(br, i18n.sound_settings());
|
||||
}
|
||||
ctx.draw_icon(
|
||||
Icon::Settings,
|
||||
Rect::from_center_size(br.center(), Vec2::splat(ic_sz)),
|
||||
if app.eq_popover_open {
|
||||
pal.yellow
|
||||
} else if bresp.hovered {
|
||||
fg_bright
|
||||
} else {
|
||||
fg_muted
|
||||
},
|
||||
);
|
||||
if bresp.clicked {
|
||||
actions.push(AppAction::SetEqPopoverOpen(!app.eq_popover_open));
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Volume button + Exact 44×216 Vertical Hover Popover (Kawase Blur + 1% wheel step)
|
||||
if vol_icon_x >= cx + 184.0 {
|
||||
let vol_btn_r = Rect::from_center_size(Pos2::new(vol_icon_x, cy), Vec2::splat(38.0));
|
||||
let vol_resp = ctx.interact(WidgetId::new("pb_r_vol"), vol_btn_r);
|
||||
let vol_ic = if muted || volume < 0.01 {
|
||||
Icon::VolumeOff
|
||||
} else {
|
||||
Icon::Volume
|
||||
};
|
||||
let ic_sz = if vol_resp.hovered { 25.2 } else { 24.0 };
|
||||
if vol_resp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
ctx.draw_icon(
|
||||
vol_ic,
|
||||
Rect::from_center_size(vol_btn_r.center(), Vec2::splat(ic_sz)),
|
||||
if vol_resp.hovered { fg_bright } else { fg_muted },
|
||||
);
|
||||
if vol_resp.clicked {
|
||||
actions.push(AppAction::ToggleMute);
|
||||
}
|
||||
|
||||
let pop_w = 44.0;
|
||||
let pop_h = 216.0;
|
||||
let pop_rect = Rect::from_xywh(
|
||||
(vol_icon_x - pop_w * 0.5).clamp(8.0, (ctx.screen_rect().right() - pop_w - 8.0).max(8.0)),
|
||||
(rect.top() - pop_h - 4.0).max(36.0),
|
||||
pop_w,
|
||||
pop_h,
|
||||
);
|
||||
let bridge = vol_btn_r.union(pop_rect);
|
||||
let pointer_in_bridge = ctx.input.pointer_pos.map_or(false, |p| bridge.contains(p));
|
||||
let vol_dragging = ctx.input.active_id == Some(WidgetId::new("pb_vol_vslider"));
|
||||
let show_popover = pointer_in_bridge || vol_dragging;
|
||||
shell.pb_vol_hovered = show_popover;
|
||||
|
||||
if show_popover {
|
||||
// Exact 1% (0.01) wheel step per notch
|
||||
let wy = ctx.input.wheel_delta.y;
|
||||
if wy.abs() > 0.1 {
|
||||
let delta = if wy > 0.0 { 0.01 } else { -0.01 };
|
||||
let next = ((volume + delta) * 100.0).round() / 100.0;
|
||||
actions.push(AppAction::SetVolume(next.clamp(0.0, 1.0)));
|
||||
}
|
||||
|
||||
ctx.with_layer(ZLayer::Popover, |ctx| {
|
||||
let cur_v = if muted { 0.0 } else { volume };
|
||||
let sresp = ym_volume_capsule(
|
||||
ctx,
|
||||
pal,
|
||||
WidgetId::new("pb_vol_vslider"),
|
||||
pop_rect,
|
||||
cur_v,
|
||||
false,
|
||||
pal.yellow,
|
||||
);
|
||||
if let Some(new_v) = sresp.value {
|
||||
actions.push(AppAction::SetVolume(new_v));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue