feat(player): load img or default
cargo devel CI / cargo CI (push) Successful in 3m20s Details

This commit is contained in:
Christoph J. Scherr 2024-08-23 01:28:43 +02:00
parent 29b6c10fd1
commit c7b6917af2
3 changed files with 29 additions and 18 deletions

View File

@ -1,4 +1,6 @@
#[derive(Hash, Clone, PartialEq, Eq)] use egui::ImageSource;
#[derive(Hash, Debug, Clone, PartialEq, Eq)]
pub enum Kind { pub enum Kind {
Playlist, Playlist,
Album, Album,
@ -6,19 +8,30 @@ pub enum Kind {
Artist, Artist,
} }
#[derive(Hash, Clone, PartialEq, Eq)] #[derive(Clone, Debug)]
pub struct Entry { pub struct Entry {
kind: Kind, pub kind: Kind,
title: String, pub title: String,
image: Option<()>, /// image url because I can't be bothered to use lifetimes everywhere
pub img_url: Option<String>,
} }
impl Entry { impl Entry {
pub fn new(kind: Kind, title: &str, img: Option<()>) -> Self { pub fn new(kind: Kind, title: &str, img: Option<String>) -> Self {
Self { Self {
kind, kind,
title: title.to_owned(), title: title.to_owned(),
image: img, img_url: img,
}
}
pub fn img(&self) -> ImageSource {
if let Some(url) = &self.img_url {
ImageSource::Uri(std::borrow::Cow::from(url))
} else {
ImageSource::Bytes {
uri: std::borrow::Cow::Borrowed("builtin://icon_256.jpg"),
bytes: egui::load::Bytes::Static(super::ICON_RAW),
}
} }
} }
} }

View File

@ -9,6 +9,7 @@ use self::showbox::ShowBox;
use super::*; 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"); const ICON_RAW: &[u8; 36525] = include_bytes!("../../../assets/img/icon-512.jpg");
impl Player { impl Player {

View File

@ -1,4 +1,4 @@
use egui::ImageSource; use egui::{Color32, ImageSource};
use super::{Entry, ICON_RAW}; use super::{Entry, ICON_RAW};
@ -18,21 +18,18 @@ impl ShowBox {
} }
impl egui::Widget for ShowBox { impl egui::Widget for ShowBox {
fn ui(mut self, ui: &mut egui::Ui) -> egui::Response { fn ui(self, ui: &mut egui::Ui) -> egui::Response {
egui::Frame::none() egui::Frame::none()
.fill(Color32::GRAY) // .fill(Color32::DARK_GRAY)
.show(ui, |ui| { .show(ui, |ui| {
ui.label("Label with red background"); ui.label("Label with red background");
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {
ui.add( ui.add(
egui::Image::new(ImageSource::Bytes { egui::Image::new(self.entry.img())
uri: std::borrow::Cow::Borrowed("fuck you"), .rounding(5.0)
bytes: egui::load::Bytes::Static(ICON_RAW), .bg_fill(Color32::DARK_GRAY)
}) .shrink_to_fit()
.rounding(5.0) .maintain_aspect_ratio(true),
.bg_fill(Color32::DARK_GRAY)
.shrink_to_fit()
.maintain_aspect_ratio(true),
); );
ui.button("i dont get it").union(ui.label("caption")) ui.button("i dont get it").union(ui.label("caption"))
}) })