From d727b22c0fab3e695adcb702760659e508245995 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 23 Aug 2024 00:24:27 +0200 Subject: [PATCH] feat(player): somewhat of a grid --- Cargo.toml | 1 + src/player/mod.rs | 11 +++++++++++ src/player/ui/entry.rs | 24 ++++++++++++++++++++++++ src/player/{ui.rs => ui/mod.rs} | 32 +++++++++++++++++++++++++------- src/player/ui/showbox.rs | 25 +++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 src/player/ui/entry.rs rename src/player/{ui.rs => ui/mod.rs} (86%) create mode 100644 src/player/ui/showbox.rs diff --git a/Cargo.toml b/Cargo.toml index 4959c4e..ba1395e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ anyhow = "1.0.86" clap = { version = "4.5.16", features = ["derive"] } eframe = { version = "0.28.1", optional = false } egui = { version = "0.28.1", optional = false } +egui_extras = { version = "0.28.1", features = ["image"] } human-panic = "2.0.1" image = "0.25.2" libpt = { version = "0.6.0", features = ["cli", "full"] } diff --git a/src/player/mod.rs b/src/player/mod.rs index 6f9e43c..0a4c2e9 100644 --- a/src/player/mod.rs +++ b/src/player/mod.rs @@ -5,6 +5,8 @@ use libpt::log::{debug, info, trace}; use crate::error::Error; +use self::ui::entry::Entry; + pub mod ui; pub const TITLE: &str = "Beatbär"; @@ -56,4 +58,13 @@ impl Player { pub fn init(&mut self, _cc: &CreationContext) { // we can use the creation context to do some customizing, but idc right now } + + fn entries(&self) -> Vec { + let e = Entry::new(ui::entry::Kind::Album, "boom boom boom.", None); + let mut v = vec![e.clone()]; + for _ in 0..100 { + v.push(e.clone()); + } + v + } } diff --git a/src/player/ui/entry.rs b/src/player/ui/entry.rs new file mode 100644 index 0000000..60d2fb5 --- /dev/null +++ b/src/player/ui/entry.rs @@ -0,0 +1,24 @@ +#[derive(Hash, Clone, PartialEq, Eq)] +pub enum Kind { + Playlist, + Album, + Song, + Artist, +} + +#[derive(Hash, Clone, PartialEq, Eq)] +pub struct Entry { + kind: Kind, + title: String, + image: Option<()>, +} + +impl Entry { + pub fn new(kind: Kind, title: &str, img: Option<()>) -> Self { + Self { + kind, + title: title.to_owned(), + image: img, + } + } +} diff --git a/src/player/ui.rs b/src/player/ui/mod.rs similarity index 86% rename from src/player/ui.rs rename to src/player/ui/mod.rs index ad92e2b..d3d0fd4 100644 --- a/src/player/ui.rs +++ b/src/player/ui/mod.rs @@ -1,9 +1,15 @@ -use egui::IconData; +use egui::{IconData, ScrollArea}; +use egui_extras::{Column, Table, TableBuilder}; use libpt::log::trace; +pub mod entry; +pub mod showbox; + +use self::showbox::ShowBox; + use super::*; -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 { fn top_panel(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) { @@ -95,11 +101,23 @@ impl Player { } fn main_panel(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) { - ui.vertical_centered(|ui| { - for i in 0..100 { - ui.horizontal_wrapped(|ui| { - for j in 0..10 { - ui.label(format!("foo-{i}-{j}")); + let mut tb = TableBuilder::new(ui) + .column(Column::remainder()) + .column(Column::remainder()) + .column(Column::remainder()) + .column(Column::remainder()) + .column(Column::remainder()) + .column(Column::remainder()) + .column(Column::remainder()) + .column(Column::remainder()); + + tb.body(|mut body| { + for line in self.entries().chunks(8) { + body.row(30.0, |mut row| { + for e in line { + row.col(|ui| { + ui.add(ShowBox::new(e)); + }); } }); } diff --git a/src/player/ui/showbox.rs b/src/player/ui/showbox.rs new file mode 100644 index 0000000..09903cd --- /dev/null +++ b/src/player/ui/showbox.rs @@ -0,0 +1,25 @@ +use egui::Color32; + +use super::Entry; + +pub struct ShowBox { + entry: Entry, + frame: egui::Frame, +} + +impl ShowBox { + pub fn new(entry: &Entry) -> Self { + let frame = egui::Frame::none(); + Self { + entry: entry.to_owned(), + frame, + } + } +} + +impl egui::Widget for ShowBox { + fn ui(mut self, ui: &mut egui::Ui) -> egui::Response { + ui.vertical_centered(|ui| ui.button("i dont get it").union(ui.label("caption"))) + .response + } +}