Feat: begin sample explorer overhaul
All checks were successful
Deploy Website / deploy (push) Has been skipped

This commit is contained in:
2026-03-05 00:42:39 +01:00
parent 2c8a6794a3
commit 4743c33916
5 changed files with 143 additions and 28 deletions

View File

@@ -23,6 +23,7 @@ pub struct TreeLine {
pub label: String,
pub folder: String,
pub index: usize,
pub child_count: usize,
}
/// Tree-view browser for navigating sample folders.
@@ -163,15 +164,43 @@ impl<'a> SampleBrowser<'a> {
Style::new().fg(icon_color)
};
let prefix_width = indent.len() + 2; // indent + icon
let suffix = match entry.kind {
TreeLineKind::File => format!(" {}", entry.index),
TreeLineKind::Root { expanded: false }
| TreeLineKind::Folder { expanded: false }
if entry.child_count > 0 =>
{
format!(" ({})", entry.child_count)
}
_ => String::new(),
};
let max_label = (area.width as usize)
.saturating_sub(prefix_width)
.saturating_sub(suffix.len());
let label: std::borrow::Cow<str> = if entry.label.len() > max_label && max_label > 1 {
let truncated: String = entry.label.chars().take(max_label - 1).collect();
format!("{}\u{2026}", truncated).into()
} else {
(&entry.label).into()
};
let mut spans = vec![
Span::raw(indent),
Span::styled(icon, icon_style),
Span::styled(&entry.label, label_style),
Span::styled(label, label_style),
];
if matches!(entry.kind, TreeLineKind::File) {
let idx_style = Style::new().fg(colors.browser.empty_text);
spans.push(Span::styled(format!(" {}", entry.index), idx_style));
match entry.kind {
TreeLineKind::File => {
let idx_style = Style::new().fg(colors.browser.empty_text);
spans.push(Span::styled(suffix, idx_style));
}
_ if !suffix.is_empty() => {
let dim_style = Style::new().fg(colors.browser.empty_text);
spans.push(Span::styled(suffix, dim_style));
}
_ => {}
}
lines.push(Line::from(spans));