From e068450b6be94d851a22204e6c1e4b25297c9be0 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sat, 24 Aug 2024 01:24:39 +0200 Subject: [PATCH] feat: add a lot of stuff, don't remember what exactly it did lol --- src/player/mod.rs | 19 +++++++++++++ src/player/ui/details.rs | 58 ++++++++++++++++++++++++++++++++++++++ src/player/ui/entry.rs | 4 ++- src/player/ui/mainpanel.rs | 26 +++++++++++++++++ src/player/ui/mod.rs | 39 ++++++++----------------- src/player/ui/overview.rs | 47 ++++++++++++++++++++++++++++++ src/player/ui/showbox.rs | 46 ++++++++++++++---------------- src/store/album.rs | 0 src/store/artist.rs | 0 src/store/genre.rs | 0 src/store/mod.rs | 2 +- src/store/playlist.rs | 1 + src/store/song.rs | 2 ++ 13 files changed, 190 insertions(+), 54 deletions(-) create mode 100644 src/player/ui/details.rs create mode 100644 src/player/ui/mainpanel.rs create mode 100644 src/player/ui/overview.rs create mode 100644 src/store/album.rs create mode 100644 src/store/artist.rs create mode 100644 src/store/genre.rs create mode 100644 src/store/playlist.rs create mode 100644 src/store/song.rs diff --git a/src/player/mod.rs b/src/player/mod.rs index 1218ab8..176a8f5 100644 --- a/src/player/mod.rs +++ b/src/player/mod.rs @@ -7,7 +7,9 @@ use libpt::log::{debug, info}; use crate::error::Error; use crate::store::Store; +use self::ui::details::Details; use self::ui::entry::{Entry, Kind}; +use self::ui::mainpanel::MainPanel; pub mod ui; @@ -29,6 +31,9 @@ pub struct Player { #[clap(skip)] store: Option, + + #[clap(skip)] + active_main_panel: MainPanel, } impl Player { @@ -65,6 +70,8 @@ impl Player { ..Default::default() }; + debug!("main panel on start: {:#?}", app.active_main_panel); + info!("Player ready to start UI"); Ok(app) } @@ -74,6 +81,17 @@ impl Player { fn set_category(&mut self, kind: Kind) { self.kind = kind; + match self.kind { + Kind::Album | Kind::Playlist => { + self.set_active_main_panel(MainPanel::Details(Default::default())) + } + Kind::Genre | Kind::Artist | Kind::Overview => { + self.set_active_main_panel(MainPanel::Overview(Default::default())) + } + Kind::Song => { + unreachable!() + } + } } fn category(&self) -> Kind { @@ -86,6 +104,7 @@ impl Player { fn entries(&self) -> Vec { match self.category() { + Kind::Overview => self.store().albums(), Kind::Album => self.store().albums(), Kind::Song => self.store().songs(), Kind::Playlist => self.store().playlists(), diff --git a/src/player/ui/details.rs b/src/player/ui/details.rs new file mode 100644 index 0000000..039bc3f --- /dev/null +++ b/src/player/ui/details.rs @@ -0,0 +1,58 @@ +use egui::text::LayoutJob; +use egui::{Color32, FontFamily, FontId, Label, TextFormat}; + +use super::Entry; + +#[derive(Clone, Default, PartialEq)] +pub struct Details { + parent: Entry, + frame: egui::Frame, +} + +impl Details { + pub fn new(parent: Entry) -> Self { + let frame = egui::Frame::none(); + Self { + parent: parent.to_owned(), + frame, + } + } + + pub(crate) fn ui(&self, ui: &mut egui::Ui, ctx: &egui::Context, player: &mut super::Player) { + ui.label("todo"); + } +} + +impl egui::Widget for Details { + fn ui(self, ui: &mut egui::Ui) -> egui::Response { + ui.vertical_centered(|ui| { + let r = ui.add( + egui::Image::new(self.parent.img()) + .rounding(5.0) + .bg_fill(Color32::DARK_GRAY) + .shrink_to_fit() + .maintain_aspect_ratio(true), + ); + let mut job = LayoutJob::default(); + job.append( + &self.parent.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.parent.subtitle)); + }) + .response + } +} + +impl std::fmt::Debug for Details { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Details") + .field("parent", &self.parent) + .finish() + } +} diff --git a/src/player/ui/entry.rs b/src/player/ui/entry.rs index 495dae0..385c63c 100644 --- a/src/player/ui/entry.rs +++ b/src/player/ui/entry.rs @@ -9,9 +9,10 @@ pub enum Kind { Song, Artist, Genre, + Overview, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] pub struct Entry { pub kind: Kind, pub title: String, @@ -54,6 +55,7 @@ impl std::fmt::Display for Kind { "{}", match self { Self::Song => "Song", + Self::Overview => "Overview", Self::Genre => "Genre", Self::Album => "Album", Self::Playlist => "Playlist", diff --git a/src/player/ui/mainpanel.rs b/src/player/ui/mainpanel.rs new file mode 100644 index 0000000..f5a15cc --- /dev/null +++ b/src/player/ui/mainpanel.rs @@ -0,0 +1,26 @@ +use egui_extras::{Column, TableBuilder}; + +use super::details::Details; +use super::overview::Overview; +use super::Player; + +#[derive(Clone, PartialEq, Debug)] +pub enum MainPanel { + Details(Details), + Overview(Overview), +} + +impl MainPanel { + pub(crate) fn ui(&self, ui: &mut egui::Ui, ctx: &egui::Context, player: &mut Player) { + match self { + Self::Overview(ov) => ov.ui(ui, ctx, player), + Self::Details(dt) => dt.ui(ui, ctx, player), + } + } +} + +impl Default for MainPanel { + fn default() -> Self { + Self::Overview(Overview::default()) + } +} diff --git a/src/player/ui/mod.rs b/src/player/ui/mod.rs index 4307da9..ec3eb38 100644 --- a/src/player/ui/mod.rs +++ b/src/player/ui/mod.rs @@ -3,11 +3,12 @@ use egui_extras::{Column, TableBuilder}; use libpt::log::{error, trace, warn}; use strum::IntoEnumIterator; +pub mod details; pub mod entry; +pub mod mainpanel; +pub mod overview; pub mod showbox; -use self::showbox::ShowBox; - use super::*; const ICON_RAW: &[u8; 36525] = include_bytes!("../../../assets/img/icon-512.jpg"); @@ -102,36 +103,16 @@ impl Player { } fn main_panel(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) { - let mut tb = TableBuilder::new(ui); - - let entries_per_line: usize = ctx.screen_rect().width() as usize / 256; - - for _ in 0..entries_per_line { - tb = tb.column(Column::remainder()); - } - - tb.body(|mut body| { - for line in self.entries().chunks(entries_per_line) { - body.row(240.0, |mut row| { - for e in line { - row.col(|ui| { - 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); - } - }); - } - }); - } - }); + let bind = self.active_main_panel.clone(); + bind.ui(ui, ctx, self) } fn meta_panel(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) { ui.horizontal_centered(|ui| { for category in Kind::iter() { + if category == Kind::Song { + continue; // no category for songs, that's just clicked and then played + } let sl = ui.selectable_label(self.category() == category, category.to_string()); if sl.clicked() { self.set_category(category); @@ -156,6 +137,10 @@ impl Player { height: icon_height, } } + + pub fn set_active_main_panel(&mut self, mp: MainPanel) { + self.active_main_panel = mp; + } } impl eframe::App for Player { diff --git a/src/player/ui/overview.rs b/src/player/ui/overview.rs new file mode 100644 index 0000000..8169480 --- /dev/null +++ b/src/player/ui/overview.rs @@ -0,0 +1,47 @@ +use egui::Sense; +use egui_extras::{Column, TableBuilder}; +use libpt::log::{debug, warn}; + +use super::showbox::ShowBox; +use super::Player; + +#[derive(Clone, Default, PartialEq)] +pub struct Overview { + frame: egui::Frame, +} + +impl Overview { + pub fn ui(&self, ui: &mut egui::Ui, ctx: &egui::Context, player: &mut Player) { + let mut tb = TableBuilder::new(ui); + + let entries_per_line: usize = ctx.screen_rect().width() as usize / 256; + + for _ in 0..entries_per_line { + tb = tb.column(Column::remainder()); + } + + tb.body(|mut body| { + for line in player.entries().chunks(entries_per_line) { + body.row(240.0, |mut row| { + for e in line { + row.col(|ui| { + 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"); + player.open(e); + } + }); + } + }); + } + }); + } +} + +impl std::fmt::Debug for Overview { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Overview").finish() + } +} diff --git a/src/player/ui/showbox.rs b/src/player/ui/showbox.rs index fa0749d..1c32a59 100644 --- a/src/player/ui/showbox.rs +++ b/src/player/ui/showbox.rs @@ -20,31 +20,27 @@ impl ShowBox { impl egui::Widget for ShowBox { fn ui(self, ui: &mut egui::Ui) -> egui::Response { - egui::Frame::none() - // .fill(Color32::DARK_GRAY) - .show(ui, |ui| { - ui.vertical_centered(|ui| { - let r = ui.add( - egui::Image::new(self.entry.img()) - .rounding(5.0) - .bg_fill(Color32::DARK_GRAY) - .shrink_to_fit() - .maintain_aspect_ratio(true), - ); - 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 + ui.vertical_centered(|ui| { + let r = ui.add( + egui::Image::new(self.entry.img()) + .rounding(5.0) + .bg_fill(Color32::DARK_GRAY) + .shrink_to_fit() + .maintain_aspect_ratio(true), + ); + 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 } } diff --git a/src/store/album.rs b/src/store/album.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/store/artist.rs b/src/store/artist.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/store/genre.rs b/src/store/genre.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/store/mod.rs b/src/store/mod.rs index 0a46662..0c764d8 100644 --- a/src/store/mod.rs +++ b/src/store/mod.rs @@ -98,7 +98,7 @@ impl Store { } else { let e = Error::NoProjDir; error!("{}", e); - std::process::exit(1); + Err(e) } } } diff --git a/src/store/playlist.rs b/src/store/playlist.rs new file mode 100644 index 0000000..0155a84 --- /dev/null +++ b/src/store/playlist.rs @@ -0,0 +1 @@ +pub struct Playlist; diff --git a/src/store/song.rs b/src/store/song.rs new file mode 100644 index 0000000..0763dac --- /dev/null +++ b/src/store/song.rs @@ -0,0 +1,2 @@ +#[derive(Clone, Debug, Hash)] +pub struct Song {}