From 8f6c6b594f79a71f819d2780bf5c141bb47acf6e Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 23 Aug 2024 09:43:16 +0200 Subject: [PATCH] feat(player): imrpove album view --- src/player/mod.rs | 7 ++++++- src/player/ui/entry.rs | 4 +++- src/player/ui/mod.rs | 1 - src/player/ui/showbox.rs | 18 ++++++++++++++---- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/player/mod.rs b/src/player/mod.rs index 644b51c..d01a441 100644 --- a/src/player/mod.rs +++ b/src/player/mod.rs @@ -60,7 +60,12 @@ impl Player { } fn entries(&self) -> Vec { - let e = Entry::new(ui::entry::Kind::Album, "boom boom boom.", None); + let e = Entry::new( + ui::entry::Kind::Album, + "boom boom boom.", + "boomerboom", + None, + ); let mut v = vec![e.clone()]; for _ in 0..100 { v.push(e.clone()); diff --git a/src/player/ui/entry.rs b/src/player/ui/entry.rs index 81c6525..a7b9415 100644 --- a/src/player/ui/entry.rs +++ b/src/player/ui/entry.rs @@ -12,15 +12,17 @@ pub enum Kind { pub struct Entry { pub kind: Kind, pub title: String, + pub subtitle: String, /// image url because I can't be bothered to use lifetimes everywhere pub img_url: Option, } impl Entry { - pub fn new(kind: Kind, title: &str, img: Option) -> Self { + pub fn new(kind: Kind, title: &str, subtitle: &str, img: Option) -> Self { Self { kind, title: title.to_owned(), + subtitle: subtitle.to_owned(), img_url: img, } } diff --git a/src/player/ui/mod.rs b/src/player/ui/mod.rs index 87f2a19..9ad512f 100644 --- a/src/player/ui/mod.rs +++ b/src/player/ui/mod.rs @@ -9,7 +9,6 @@ use self::showbox::ShowBox; use super::*; -const ICON_RAW_PATH: &str = "file://../../../assets/img/icon-512.jpg"; const ICON_RAW: &[u8; 36525] = include_bytes!("../../../assets/img/icon-512.jpg"); impl Player { diff --git a/src/player/ui/showbox.rs b/src/player/ui/showbox.rs index 5e8f8ae..becb61e 100644 --- a/src/player/ui/showbox.rs +++ b/src/player/ui/showbox.rs @@ -1,4 +1,5 @@ -use egui::{Color32, ImageSource}; +use egui::text::LayoutJob; +use egui::{Color32, FontFamily, FontId, ImageSource, Label, TextFormat}; use super::{Entry, ICON_RAW}; @@ -22,16 +23,25 @@ impl egui::Widget for ShowBox { egui::Frame::none() // .fill(Color32::DARK_GRAY) .show(ui, |ui| { - ui.label("Label with red background"); ui.vertical_centered(|ui| { - ui.add( + let mut r = ui.add( egui::Image::new(self.entry.img()) .rounding(5.0) .bg_fill(Color32::DARK_GRAY) .shrink_to_fit() .maintain_aspect_ratio(true), ); - ui.button("i dont get it").union(ui.label("caption")) + let mut job = LayoutJob::default(); + job.append( + &self.entry.title, + 0.0, + TextFormat { + font_id: FontId::new(14.0, FontFamily::Proportional), + ..Default::default() + }, + ); + r.union(ui.add(Label::new(job))); + r.union(ui.label(&self.entry.subtitle)); }) }) .response