feat(player): somewhat of a grid

This commit is contained in:
Christoph J. Scherr 2024-08-23 00:24:27 +02:00
parent a744147355
commit d727b22c0f
5 changed files with 86 additions and 7 deletions

View File

@ -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"] }

View File

@ -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<Entry> {
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
}
}

24
src/player/ui/entry.rs Normal file
View File

@ -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,
}
}
}

View File

@ -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));
});
}
});
}

25
src/player/ui/showbox.rs Normal file
View File

@ -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
}
}