generated from PlexSheep/rs-base
feat(player): load img or default
cargo devel CI / cargo CI (push) Successful in 3m20s
Details
cargo devel CI / cargo CI (push) Successful in 3m20s
Details
This commit is contained in:
parent
29b6c10fd1
commit
c7b6917af2
|
@ -1,4 +1,6 @@
|
|||
#[derive(Hash, Clone, PartialEq, Eq)]
|
||||
use egui::ImageSource;
|
||||
|
||||
#[derive(Hash, Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Kind {
|
||||
Playlist,
|
||||
Album,
|
||||
|
@ -6,19 +8,30 @@ pub enum Kind {
|
|||
Artist,
|
||||
}
|
||||
|
||||
#[derive(Hash, Clone, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Entry {
|
||||
kind: Kind,
|
||||
title: String,
|
||||
image: Option<()>,
|
||||
pub kind: Kind,
|
||||
pub title: String,
|
||||
/// image url because I can't be bothered to use lifetimes everywhere
|
||||
pub img_url: Option<String>,
|
||||
}
|
||||
|
||||
impl Entry {
|
||||
pub fn new(kind: Kind, title: &str, img: Option<()>) -> Self {
|
||||
pub fn new(kind: Kind, title: &str, img: Option<String>) -> Self {
|
||||
Self {
|
||||
kind,
|
||||
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),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ 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 {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use egui::ImageSource;
|
||||
use egui::{Color32, ImageSource};
|
||||
|
||||
use super::{Entry, ICON_RAW};
|
||||
|
||||
|
@ -18,17 +18,14 @@ impl 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()
|
||||
.fill(Color32::GRAY)
|
||||
// .fill(Color32::DARK_GRAY)
|
||||
.show(ui, |ui| {
|
||||
ui.label("Label with red background");
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.add(
|
||||
egui::Image::new(ImageSource::Bytes {
|
||||
uri: std::borrow::Cow::Borrowed("fuck you"),
|
||||
bytes: egui::load::Bytes::Static(ICON_RAW),
|
||||
})
|
||||
egui::Image::new(self.entry.img())
|
||||
.rounding(5.0)
|
||||
.bg_fill(Color32::DARK_GRAY)
|
||||
.shrink_to_fit()
|
||||
|
|
Loading…
Reference in New Issue