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

@@ -1,3 +1,4 @@
use std::cell::Cell;
use std::fs;
use std::path::{Path, PathBuf};
@@ -62,12 +63,19 @@ impl SampleNode {
SampleNode::Folder { expanded, .. } => TreeLineKind::Folder { expanded: *expanded },
SampleNode::File { .. } => TreeLineKind::File,
};
let child_count = match self {
SampleNode::Root { children, .. } | SampleNode::Folder { children, .. } => {
children.iter().filter(|c| matches!(c, SampleNode::File { .. })).count()
}
SampleNode::File { .. } => 0,
};
out.push(TreeLine {
depth,
kind,
label: self.label().to_string(),
folder: parent_folder.to_string(),
index: file_index,
child_count,
});
if self.expanded() {
let folder_name = self.label();
@@ -321,6 +329,7 @@ impl SampleTree {
expanded,
} if name == target_name => {
let show_children = !collapsed && *expanded;
let file_count = children.iter().filter(|c| matches!(c, SampleNode::File { .. })).count();
out.push(TreeLine {
depth: 0,
kind: TreeLineKind::Folder {
@@ -329,6 +338,7 @@ impl SampleTree {
label: name.clone(),
folder: String::new(),
index: 0,
child_count: file_count,
});
if show_children {
let mut idx = 0;
@@ -340,6 +350,7 @@ impl SampleTree {
label: fname.clone(),
folder: name.clone(),
index: idx,
child_count: 0,
});
idx += 1;
}
@@ -362,6 +373,7 @@ pub struct SampleBrowserState {
pub scroll_offset: usize,
pub search_query: String,
pub search_active: bool,
pub visible_height: Cell<usize>,
filter: Option<Vec<String>>,
}
@@ -373,6 +385,7 @@ impl SampleBrowserState {
scroll_offset: 0,
search_query: String::new(),
search_active: false,
visible_height: Cell::new(20),
filter: None,
}
}
@@ -427,6 +440,10 @@ impl SampleBrowserState {
if self.scroll_offset > self.cursor {
self.scroll_offset = self.cursor;
}
let vh = self.visible_height.get();
if vh > 0 && self.cursor >= self.scroll_offset + vh {
self.scroll_offset = self.cursor - vh + 1;
}
}
pub fn move_up(&mut self) {
@@ -438,15 +455,16 @@ impl SampleBrowserState {
}
}
pub fn move_down(&mut self, visible_height: usize) {
pub fn move_down(&mut self) {
let count = self.visible_count();
if count == 0 {
return;
}
if self.cursor + 1 < count {
self.cursor += 1;
if self.cursor >= self.scroll_offset + visible_height {
self.scroll_offset = self.cursor - visible_height + 1;
let vh = self.visible_height.get();
if vh > 0 && self.cursor >= self.scroll_offset + vh {
self.scroll_offset = self.cursor - vh + 1;
}
}
}