Synced lyrics follow playback, accent-coloured app icon, compact menus, drop redundant items
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
parent
4e3f38c3f1
commit
28b4a9c19a
5 changed files with 75 additions and 16 deletions
13
src/app.rs
13
src/app.rs
|
|
@ -186,6 +186,7 @@ impl App {
|
|||
if settings().get_bool("library/scan_on_start") && !settings().get_list("library/folders").is_empty() {
|
||||
app.lib.scan(false, bus.clone());
|
||||
}
|
||||
app.apply_icon();
|
||||
app.resume_playback();
|
||||
if !args.is_empty() {
|
||||
app.handle_args(args);
|
||||
|
|
@ -281,11 +282,22 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
/// Window and tray icon follow the accent colour.
|
||||
pub fn apply_icon(&mut self) {
|
||||
let t = &self.g.theme;
|
||||
let rgba = util::themed_icon(t.primary, t.on_primary, 256);
|
||||
self.ctx.send_viewport_cmd(egui::ViewportCommand::Icon(Some(Arc::new(egui::IconData { rgba, width: 256, height: 256 }))));
|
||||
if let Some(tray) = &self.tray {
|
||||
tray.set_icon(util::themed_icon(t.primary, t.on_primary, 64));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rebuild_theme(&mut self) {
|
||||
let t = Theme::build(self.album_seed);
|
||||
if !t.same_colors(&self.g.theme) || t.surface_container != self.g.theme.surface_container {
|
||||
apply_visuals(&self.ctx, &t);
|
||||
self.g.theme = t;
|
||||
self.apply_icon();
|
||||
self.hero.bg_dirty = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -977,6 +989,7 @@ impl eframe::App for App {
|
|||
if self.player.song.is_some() {
|
||||
let p = self.player.pos();
|
||||
self.spectrum.set_position(p);
|
||||
self.hero.lyrics.set_position(p);
|
||||
}
|
||||
if self.spectrum.active() {
|
||||
if let Some(strength) = self.spectrum.tick(dt) {
|
||||
|
|
|
|||
13
src/tray.rs
13
src/tray.rs
|
|
@ -9,6 +9,14 @@ struct MbTray {
|
|||
icon: Vec<ksni::Icon>,
|
||||
}
|
||||
|
||||
fn argb(rgba: &[u8], size: i32) -> Vec<ksni::Icon> {
|
||||
let mut data = Vec::with_capacity(rgba.len());
|
||||
for px in rgba.chunks_exact(4) {
|
||||
data.extend_from_slice(&[px[3], px[0], px[1], px[2]]);
|
||||
}
|
||||
vec![ksni::Icon { width: size, height: size, data }]
|
||||
}
|
||||
|
||||
fn icon() -> Vec<ksni::Icon> {
|
||||
let svg = include_str!("../assets/mulberry.svg");
|
||||
let size = 64u32;
|
||||
|
|
@ -79,6 +87,11 @@ impl Tray {
|
|||
t.spawn().ok().map(|handle| Tray { handle })
|
||||
}
|
||||
|
||||
pub fn set_icon(&self, rgba: Vec<u8>) {
|
||||
let icon = argb(&rgba, 64);
|
||||
let _ = self.handle.update(move |t: &mut MbTray| t.icon = icon);
|
||||
}
|
||||
|
||||
pub fn set_playing(&self, playing: bool) {
|
||||
let _ = self.handle.update(move |t: &mut MbTray| t.playing = playing);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ pub fn show(app: &mut App, ctx: &Context) {
|
|||
let area = egui::Area::new(Id::new("popup-menu")).order(Order::Foreground).fixed_pos(m.pos).constrain(true).interactable(true);
|
||||
let inner = area.show(ctx, |ui| {
|
||||
menu_frame(&app.g).show(ui, |ui| {
|
||||
ui.set_min_width(230.0);
|
||||
ui.set_min_width(180.0);
|
||||
ui.spacing_mut().item_spacing = Vec2::ZERO;
|
||||
match &m.kind {
|
||||
MenuKind::Bar(i) => bar_menu(app, ui, *i, &mut act),
|
||||
|
|
@ -233,11 +233,6 @@ fn bar_menu(app: &mut App, ui: &mut Ui, i: usize, act: &mut Option<Act>) {
|
|||
item(ui, g, act, Some("stop_fill"), "Stop", "", Act::Do("stop"), None);
|
||||
item(ui, g, act, Some("stop_circle"), "Stop after this track", "Ctrl+Alt+V", Act::Do("stop_after"), Some(app_stop_after(&app.mgr, &app.player)));
|
||||
item(ui, g, act, Some("skip_next_fill"), "Next", "Ctrl+→", Act::Do("next"), None);
|
||||
item(ui, g, act, None, "Seek forward 10 s", "Alt+→", Act::Do("seek+"), None);
|
||||
item(ui, g, act, None, "Seek back 10 s", "Alt+←", Act::Do("seek-"), None);
|
||||
item(ui, g, act, Some("volume_up"), "Volume up", "Ctrl+↑", Act::Do("vol+"), None);
|
||||
item(ui, g, act, Some("volume_down"), "Volume down", "Ctrl+↓", Act::Do("vol-"), None);
|
||||
item(ui, g, act, Some("volume_off"), "Mute", "Ctrl+M", Act::Do("mute"), None);
|
||||
menu_sep(ui, g);
|
||||
item(ui, g, act, Some("favorite"), "Love current track", "Ctrl+L", Act::Do("love"), None);
|
||||
menu_sep(ui, g);
|
||||
|
|
@ -298,7 +293,6 @@ fn bar_menu(app: &mut App, ui: &mut Ui, i: usize, act: &mut Option<Act>) {
|
|||
item(ui, g, act, Some("menu"), "Show sidebar", "Ctrl+B", Act::Do("sidebar"), Some(app.show_sidebar));
|
||||
item(ui, g, act, Some("graphic_eq"), "Show spectrum analyzer", "", Act::Do("analyzer"), Some(settings().get_bool("appearance/analyzer")));
|
||||
item(ui, g, act, Some("auto_awesome"), "Floating bass shape", "", Act::Do("shape"), Some(settings().get_bool("appearance/floating_shape")));
|
||||
item(ui, g, act, Some("open_in_full"), "Focus mode (cover & lyrics)", "F11", Act::Do("focus"), None);
|
||||
menu_sep(ui, g);
|
||||
item(ui, g, act, Some("palette"), "Theme: follow system colours", "", Act::Theme("kde"), None);
|
||||
item(ui, g, act, Some("image"), "Theme: colours from album art", "", Act::Theme("album"), None);
|
||||
|
|
|
|||
|
|
@ -337,11 +337,11 @@ pub fn menu_frame(g: &Gfx) -> egui::Frame {
|
|||
.fill(g.theme.surface_container)
|
||||
.stroke(Stroke::new(1.0, with_alpha(g.theme.outline_variant, 0.5)))
|
||||
.corner_radius(cr(14.0))
|
||||
.inner_margin(egui::Margin::symmetric(0, 8))
|
||||
.inner_margin(egui::Margin::symmetric(0, 5))
|
||||
}
|
||||
|
||||
pub fn menu_sep(ui: &mut Ui, g: &Gfx) {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::new(ui.available_width(), 13.0), Sense::hover());
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::new(ui.min_size().x.max(180.0), 9.0), Sense::hover());
|
||||
ui.painter().line_segment([Pos2::new(rect.left() + 14.0, rect.center().y), Pos2::new(rect.right() - 14.0, rect.center().y)], Stroke::new(1.0, g.theme.outline_variant));
|
||||
}
|
||||
|
||||
|
|
@ -352,11 +352,12 @@ pub fn menu_item(ui: &mut Ui, g: &mut Gfx, icon: Option<&str>, text: &str, enabl
|
|||
|
||||
/// Menu row with a right-aligned shortcut hint.
|
||||
pub fn menu_item_h(ui: &mut Ui, g: &mut Gfx, icon: Option<&str>, text: &str, hint: &str, enabled: bool, checked: Option<bool>) -> Response {
|
||||
let fnt = font(14.0);
|
||||
let fnt = font(13.5);
|
||||
let tw = ui.painter().layout_no_wrap(text.to_string(), fnt.clone(), Color32::WHITE).size().x;
|
||||
let hw = if hint.is_empty() { 0.0 } else { ui.painter().layout_no_wrap(hint.to_string(), font(12.5), Color32::WHITE).size().x + 28.0 };
|
||||
let want = (tw + 14.0 + 40.0 + 28.0 + hw).max(ui.available_width().min(520.0)).max(230.0);
|
||||
let (rect, resp) = ui.allocate_exact_size(Vec2::new(want.min(ui.available_width().max(230.0).max(want)), 36.0), Sense::click());
|
||||
let want = (tw + 40.0 + 30.0 + hw).max(190.0);
|
||||
let want = want.max(ui.min_size().x);
|
||||
let (rect, resp) = ui.allocate_exact_size(Vec2::new(want, 30.0), Sense::click());
|
||||
let t = &g.theme;
|
||||
let row = rect.shrink2(Vec2::new(6.0, 0.0));
|
||||
if resp.hovered() && enabled {
|
||||
|
|
@ -365,9 +366,9 @@ pub fn menu_item_h(ui: &mut Ui, g: &mut Gfx, icon: Option<&str>, text: &str, hin
|
|||
let fg = if enabled { t.on_surface } else { with_alpha(t.on_surface, 0.38) };
|
||||
let ic = if enabled { t.on_surface_variant } else { with_alpha(t.on_surface, 0.38) };
|
||||
if let Some(name) = icon {
|
||||
g.icon(ui.painter(), Rect::from_center_size(Pos2::new(row.left() + 24.0, row.center().y), Vec2::splat(20.0)), name, ic);
|
||||
g.icon(ui.painter(), Rect::from_center_size(Pos2::new(row.left() + 22.0, row.center().y), Vec2::splat(18.0)), name, ic);
|
||||
}
|
||||
ui.painter().text(Pos2::new(row.left() + 46.0, row.center().y), Align2::LEFT_CENTER, text, fnt, fg);
|
||||
ui.painter().text(Pos2::new(row.left() + 40.0, row.center().y), Align2::LEFT_CENTER, text, fnt, fg);
|
||||
if !hint.is_empty() {
|
||||
ui.painter().text(Pos2::new(row.right() - 14.0, row.center().y), Align2::RIGHT_CENTER, hint, font(12.5), with_alpha(g.theme.on_surface_variant, if enabled { 0.9 } else { 0.4 }));
|
||||
}
|
||||
|
|
@ -385,7 +386,7 @@ pub fn menu_item_h(ui: &mut Ui, g: &mut Gfx, icon: Option<&str>, text: &str, hin
|
|||
/// Submenu row; returns the response of the row (the submenu body is shown by egui).
|
||||
pub fn submenu<R>(ui: &mut Ui, g: &mut Gfx, icon: Option<&str>, text: &str, add: impl FnOnce(&mut Ui, &mut Gfx) -> R) {
|
||||
let fnt = font(14.0);
|
||||
let (rect, resp) = ui.allocate_exact_size(Vec2::new(ui.available_width().max(230.0), 36.0), Sense::click());
|
||||
let (rect, resp) = ui.allocate_exact_size(Vec2::new(ui.min_size().x.max(190.0), 30.0), Sense::click());
|
||||
let row = rect.shrink2(Vec2::new(6.0, 0.0));
|
||||
let open_id = resp.id.with("open");
|
||||
let is_open = ui.ctx().data(|d| d.get_temp::<bool>(open_id)).unwrap_or(false);
|
||||
|
|
@ -395,7 +396,7 @@ pub fn submenu<R>(ui: &mut Ui, g: &mut Gfx, icon: Option<&str>, text: &str, add:
|
|||
if let Some(name) = icon {
|
||||
g.icon(ui.painter(), Rect::from_center_size(Pos2::new(row.left() + 24.0, row.center().y), Vec2::splat(20.0)), name, g.theme.on_surface_variant);
|
||||
}
|
||||
ui.painter().text(Pos2::new(row.left() + 46.0, row.center().y), Align2::LEFT_CENTER, text, fnt, g.theme.on_surface);
|
||||
ui.painter().text(Pos2::new(row.left() + 40.0, row.center().y), Align2::LEFT_CENTER, text, fnt, g.theme.on_surface);
|
||||
g.icon(ui.painter(), Rect::from_center_size(Pos2::new(row.right() - 20.0, row.center().y), Vec2::splat(20.0)), "chevron_right", g.theme.on_surface_variant);
|
||||
// open on hover/click, stay open while the pointer is over the row or the submenu
|
||||
let sub_id = resp.id.with("sub");
|
||||
|
|
|
|||
38
src/util.rs
38
src/util.rs
|
|
@ -55,3 +55,41 @@ pub fn clean_title(s: &str) -> String {
|
|||
pub fn norm(s: &str) -> String {
|
||||
s.chars().filter(|c| c.is_ascii_alphanumeric()).collect::<String>().to_lowercase()
|
||||
}
|
||||
|
||||
/// The cookie-shaped app icon in the current accent colours (RGBA, straight alpha).
|
||||
pub fn themed_icon(bg: eframe::egui::Color32, fg: eframe::egui::Color32, size: u32) -> Vec<u8> {
|
||||
let hex = |c: eframe::egui::Color32| format!("#{:02x}{:02x}{:02x}", c.r(), c.g(), c.b());
|
||||
let c = 128.0f32;
|
||||
let r = 256.0 * 0.47;
|
||||
let pts: Vec<String> = (0..120)
|
||||
.map(|i| {
|
||||
let t = i as f32 / 120.0 * std::f32::consts::TAU;
|
||||
let rr = r * (0.92 + 0.08 * (9.0 * t).cos());
|
||||
format!("{:.2},{:.2}", c + rr * t.cos(), c + rr * t.sin())
|
||||
})
|
||||
.collect();
|
||||
let note = crate::icondata::ICONS.iter().find(|(n, _)| *n == "music_note").map(|x| x.1).unwrap_or("");
|
||||
let s = 256.0 * 0.56 / 960.0;
|
||||
let off = (256.0 - 256.0 * 0.56) / 2.0;
|
||||
let svg = format!(
|
||||
r#"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" width="256" height="256"><polygon fill="{}" points="{}"/><g transform="translate({off},{off}) scale({s}) translate(0,960)"><path fill="{}" d="{note}"/></g></svg>"#,
|
||||
hex(bg),
|
||||
pts.join(" "),
|
||||
hex(fg)
|
||||
);
|
||||
let mut pm = resvg::tiny_skia::Pixmap::new(size, size).unwrap();
|
||||
if let Ok(tree) = resvg::usvg::Tree::from_str(&svg, &resvg::usvg::Options::default()) {
|
||||
let k = size as f32 / 256.0;
|
||||
resvg::render(&tree, resvg::tiny_skia::Transform::from_scale(k, k), &mut pm.as_mut());
|
||||
}
|
||||
let mut rgba = pm.take();
|
||||
for px in rgba.chunks_exact_mut(4) {
|
||||
let a = px[3] as u32;
|
||||
if a > 0 && a < 255 {
|
||||
for ch in &mut px[..3] {
|
||||
*ch = ((*ch as u32 * 255 + a / 2) / a).min(255) as u8;
|
||||
}
|
||||
}
|
||||
}
|
||||
rgba
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue