more highlights, prevent overscroll

This commit is contained in:
🪞👃🪞 2025-03-03 18:39:21 +02:00
parent 2b855f43d7
commit b3a52c171b
3 changed files with 61 additions and 31 deletions

View file

@ -1,25 +1,44 @@
use crate::*;
use tek_tui::ratatui::{style::{Color, Style}, prelude::Stylize};
use pad::PadStr;
fn table_row (label: &str, artist: &str, album: &str, title: &str) -> String {
format!("{label:60} {artist:20} {album:20} {title:20}")
}
impl Content<TuiOut> for Taggart {
fn layout (&self, area: [u16;4]) -> [u16;4] {
[area.x(), area.y(), 20, area.h()]
fn content (&self) -> impl Render<TuiOut> {
let sizer = Fill::xy(&self.size);
let size = format!("{}x{}", self.size.w(), self.size.h());
let size_bar = Fill::x(Align::e(Tui::bold(true, Tui::fg_bg(Color::Rgb(0,0,0), Color::Rgb(255,255,255), size))));
let titlebar = Fill::x(Align::w(Tui::bold(true, Tui::fg_bg(Color::Rgb(0,0,0), Color::Rgb(255,255,255), table_row("FILE", "ARTIST", "ALBUM", "TITLE")))));
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<TuiOut> for TreeTable<'a> {
fn render (&self, to: &mut TuiOut) {
let area = to.area();
let Taggart { offset, paths, cursor, .. } = self.0;
for (i, y) in area.iter_y().enumerate() {
let i_offset = i + self.offset;
if let Some(entry) = self.paths.get(i_offset) {
if entry.depth > 0 {
for (index, fragment) in entry.path.iter().enumerate() {
if index == entry.depth - 1 {
let cursor = if self.cursor == i_offset { ">" } else { " " };
let icon = if entry.is_dir {"+"} else {" "};
let name = fragment.display();
let indent = "".pad_to_width((entry.depth - 1) * 2);
let label = format!("{cursor} {indent}{icon} {name}");
let label = format!("{label:80} ARTIST ALBUM TITLE");
to.blit(&label, area.x(), y, None);
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 = if entry.is_dir {"+"} else {" "};
let name = fragment.display();
let indent = "".pad_to_width((entry.depth - 1) * 2);
let label = table_row(&format!("{cursor} {indent}{icon} {name}"), "", "", "");
to.blit(&label, area.x(), y, if entry.is_dir { None } else {
Some(Style::default().bold())
});
if selected {
to.fill_bg([area.x(), y, area.w(), 1], Color::Rgb(0, 0, 0));
}
}
}
@ -29,11 +48,3 @@ impl Content<TuiOut> for Taggart {
}
}
}
fn depth_of (path: &PathBuf) -> usize {
let mut depth = 0;
for _ in path.iter() {
depth += 1;
}
depth
}