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 {
|
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),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use egui::ImageSource;
|
use egui::{Color32, ImageSource};
|
||||||
|
|
||||||
use super::{Entry, ICON_RAW};
|
use super::{Entry, ICON_RAW};
|
||||||
|
|
||||||
|
@ -18,17 +18,14 @@ 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"),
|
|
||||||
bytes: egui::load::Bytes::Static(ICON_RAW),
|
|
||||||
})
|
|
||||||
.rounding(5.0)
|
.rounding(5.0)
|
||||||
.bg_fill(Color32::DARK_GRAY)
|
.bg_fill(Color32::DARK_GRAY)
|
||||||
.shrink_to_fit()
|
.shrink_to_fit()
|
||||||
|
|
Loading…
Reference in New Issue