use crate::*; use tek_tui::ratatui::{style::{Color, Style}, prelude::Stylize}; use pad::PadStr; use std::fmt::Display; impl Content for Taggart { fn content (&self) -> impl Render { let sizer = Fill::xy(&self.size); let size = format!("{}x{}", self.size.w(), self.size.h()); let size_bar = status_bar(Align::e(size)); let titlebar = status_bar(Align::w(table_row( Some("HASH".into()), "FILE", Some("ARTIST".into()), Some("RELEASE".into()), "TRACK", Some("TITLE".into()) ))); let table = Fill::xy(TreeTable(self)); Bsp::n(size_bar, Bsp::s(titlebar, Bsp::b(sizer, table))) } } struct TreeTable<'a>(&'a Taggart); impl<'a> Content for TreeTable<'a> { fn render (&self, to: &mut TuiOut) { let area = to.area(); let Taggart { offset, paths, cursor, column, .. } = self.0; let mut x = 0; for (index, _width) in COLUMN_WIDTHS.iter().enumerate() { let w = COLUMN_WIDTHS[index] + 1; if index == *column { to.fill_bg([area.x() + x, area.y(), w, area.h()], Color::Rgb(0, 0, 0)); break } else { x += w; } } for (i, y) in area.iter_y().enumerate() { let i_offset = i + offset; let selected = *cursor == i_offset; if let Some(entry) = paths.get(i_offset) { for (index, fragment) in entry.path.iter().enumerate() { if index == entry.depth - 1 { let cursor = if selected { ">" } else { " " }; let icon = entry.icon(); let style = entry.style(); let label = entry.label(icon, &fragment.display()); to.blit(&label, area.x(), y, style); if selected { let fill = [area.x(), y, area.w(), 1]; to.fill_fg(fill, Color::Rgb(0, 0, 0)); to.fill_bg(fill, Color::Rgb(224, 192, 0)); } } } } else { break } } } } impl Entry { fn icon (&self) -> &'static str { if self.is_dir() { "" //"+" } else if self.is_img() { "" } else if self.is_mus() { "" } else { " " } } fn style (&self) -> Option