mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 17:46:42 +01:00
highlight selected column
This commit is contained in:
parent
b3a52c171b
commit
01bc1b7b47
3 changed files with 53 additions and 11 deletions
35
src/view.rs
35
src/view.rs
|
|
@ -2,16 +2,25 @@ 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}")
|
||||
|
||||
fn table_row (label: &str, artist: &str, album: &str, track: &str, title: &str) -> String {
|
||||
let label = label.pad_to_width(COLUMN_WIDTHS[0] as usize);
|
||||
let artist = artist.pad_to_width(COLUMN_WIDTHS[1] as usize);
|
||||
let album = album.pad_to_width(COLUMN_WIDTHS[2] as usize);
|
||||
let track = track.pad_to_width(COLUMN_WIDTHS[3] as usize);
|
||||
let title = title.pad_to_width(COLUMN_WIDTHS[4] as usize);
|
||||
format!("{label}│{artist}╎{album}╎{track}╎{title}")
|
||||
}
|
||||
fn status_bar (content: impl Content<TuiOut>) -> impl Content<TuiOut> {
|
||||
Fixed::y(1, Fill::x(Tui::bold(true, Tui::fg_bg(Color::Rgb(0,0,0), Color::Rgb(255,255,255), content))))
|
||||
}
|
||||
|
||||
impl Content<TuiOut> for Taggart {
|
||||
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 size_bar = status_bar(Align::e(size));
|
||||
let titlebar = status_bar(Align::w(table_row("FILE", "ARTIST", "RELEASE", "TRACK", "TITLE")));
|
||||
let table = Fill::xy(TreeTable(self));
|
||||
Bsp::n(size_bar, Bsp::s(titlebar, Bsp::b(sizer, table)))
|
||||
}
|
||||
|
|
@ -22,7 +31,17 @@ 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;
|
||||
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;
|
||||
|
|
@ -33,12 +52,14 @@ impl<'a> Content<TuiOut> for TreeTable<'a> {
|
|||
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}"), "", "", "");
|
||||
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));
|
||||
let fill = [area.x(), y, area.w(), 1];
|
||||
to.fill_bg(fill, Color::Rgb(48, 48, 48));
|
||||
to.fill_fg(fill, Color::Rgb(224, 192, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue