feat(player): add category and category selector
cargo devel CI / cargo CI (push) Successful in 3m28s Details

This commit is contained in:
Christoph J. Scherr 2024-08-23 10:23:54 +02:00
parent 3dd949e9a5
commit af3135462a
5 changed files with 74 additions and 25 deletions

View File

@ -29,6 +29,7 @@ image = { version = "0.25.2", default-features = true, features = [
] } ] }
libpt = { version = "0.6.0", features = ["cli", "full"] } libpt = { version = "0.6.0", features = ["cli", "full"] }
strum = { version = "0.26.3", features = ["derive"] }
thiserror = "1.0.63" thiserror = "1.0.63"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

View File

@ -5,7 +5,7 @@ use libpt::log::{debug, info};
use crate::error::Error; use crate::error::Error;
use self::ui::entry::Entry; use self::ui::entry::{Entry, Kind};
pub mod ui; pub mod ui;
@ -21,6 +21,9 @@ pub struct Player {
#[clap(skip)] #[clap(skip)]
show_info_window: bool, show_info_window: bool,
#[clap(skip)]
kind: Kind,
} }
impl Player { impl Player {
@ -59,17 +62,29 @@ impl Player {
// we can use the creation context to do some customizing, but idc right now // we can use the creation context to do some customizing, but idc right now
} }
fn set_category(&mut self, kind: Kind) {
self.kind = kind;
}
fn category(&self) -> Kind {
self.kind
}
fn open(&mut self, entry: &Entry) {
todo!()
}
fn entries(&self) -> Vec<Entry> { fn entries(&self) -> Vec<Entry> {
let e = Entry::new( let mut v = Vec::new();
ui::entry::Kind::Album, match self.category() {
"boom boom boom.", Kind::Album => {
"boomerboom", let e = Entry::new(Kind::Album, "boom boom boom", "boomerboom", None);
None,
);
let mut v = vec![e.clone()];
for _ in 0..100 { for _ in 0..100 {
v.push(e.clone()); v.push(e.clone());
} }
}
_ => todo!("not all categories are implemented yet"),
}
v v
} }
} }

View File

@ -1,8 +1,10 @@
use egui::ImageSource; use egui::ImageSource;
use strum::EnumIter;
#[derive(Hash, Debug, Clone, PartialEq, Eq)] #[derive(Hash, Debug, Clone, PartialEq, Eq, Copy, Default, EnumIter)]
pub enum Kind { pub enum Kind {
Playlist, Playlist,
#[default]
Album, Album,
Song, Song,
Artist, Artist,
@ -37,3 +39,24 @@ impl Entry {
} }
} }
} }
impl std::fmt::Display for Entry {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.title)
}
}
impl std::fmt::Display for Kind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Self::Song => "Song",
Self::Album => "Album",
Self::Playlist => "Playlist",
Self::Artist => "Artist",
}
)
}
}

View File

@ -1,6 +1,7 @@
use egui::IconData; use egui::{IconData, Sense};
use egui_extras::{Column, TableBuilder}; use egui_extras::{Column, TableBuilder};
use libpt::log::trace; use libpt::log::{trace, warn};
use strum::IntoEnumIterator;
pub mod entry; pub mod entry;
pub mod showbox; pub mod showbox;
@ -114,7 +115,13 @@ impl Player {
body.row(240.0, |mut row| { body.row(240.0, |mut row| {
for e in line { for e in line {
row.col(|ui| { row.col(|ui| {
ui.add(ShowBox::new(e)); let shobo = ui.add(ShowBox::new(e));
let shobo = shobo.interact(Sense::click());
if shobo.clicked() {
debug!("showbox \"{:#?}\" was clicked", shobo);
warn!("clicking for showbox not defined yet");
self.open(e);
}
}); });
} }
}); });
@ -123,19 +130,14 @@ impl Player {
} }
fn meta_panel(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) { fn meta_panel(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) {
egui::menu::bar(ui, |ui| { ui.horizontal_centered(|ui| {
// NOTE: no File->Quit on web pages! for category in Kind::iter() {
ui.menu_button("File", |ui| { let sl = ui.selectable_label(self.category() == category, category.to_string());
if ui.button("Info").clicked() { if sl.clicked() {
self.show_info_window = true; self.set_category(category);
} }
ui.separator();
if ui.button("Quit").clicked() {
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
} }
}); });
ui.add_space(16.0);
});
} }
pub(crate) fn load_icon() -> IconData { pub(crate) fn load_icon() -> IconData {

View File

@ -47,3 +47,11 @@ impl egui::Widget for ShowBox {
.response .response
} }
} }
impl std::fmt::Debug for ShowBox {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ShowBox")
.field("entry", &self.entry)
.finish()
}
}