Expand description
§iced-swdir-tree
A reusable iced widget for displaying a directory tree with lazy
loading, filtering, selection, and asynchronous traversal.
Built on top of swdir’s scan_dir for single-level, non-recursive
directory listings — perfect for GUI trees that expand one folder at a
time.
§Minimal example
use std::path::PathBuf;
use iced::{Element, Task};
use iced_swdir_tree::{DirectoryFilter, DirectoryTree, DirectoryTreeEvent};
#[derive(Debug, Clone)]
enum Message {
Tree(DirectoryTreeEvent),
}
struct App {
tree: DirectoryTree,
}
impl App {
fn new() -> (Self, Task<Message>) {
let tree = DirectoryTree::new(PathBuf::from("."))
.with_filter(DirectoryFilter::FilesAndFolders);
(Self { tree }, Task::none())
}
fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::Tree(event) => {
// Observe app-level side effects BEFORE passing to the widget.
// The third field is the `SelectionMode` (Replace/Toggle/ExtendRange);
// match it with `_` when you only care about which path was clicked.
if let DirectoryTreeEvent::Selected(path, is_dir, _) = &event {
println!("selected {:?} (dir={})", path, is_dir);
}
self.tree.update(event).map(Message::Tree)
}
}
}
fn view(&self) -> Element<'_, Message> {
self.tree.view(Message::Tree)
}
}§Multi-select
Shift/Ctrl-click support is covered in examples/multi_select.rs
— the built-in view always emits SelectionMode::Replace because
iced 0.14’s button on_press can’t observe modifier keys.
Applications that want multi-select track modifier state via a
keyboard subscription and rewrite the mode in their own update
handler using SelectionMode::from_modifiers.
§Drag-and-drop
The widget tracks drag gestures internally and emits a
DragCompleted{ sources, destination } event when the user releases the mouse over a
valid folder row. The widget performs no filesystem
operation — the app reacts to DragCompleted and does move /
copy / symlink / upload however it likes, then re-scans the
affected folders by emitting a Toggled collapse+expand to
refresh. See examples/drag_drop.rs for a worked example that
performs fs::rename on drop.
§Feature flags
icons(off by default) — when enabled, useslucide-iconsfor folder/file graphics. When disabled, icons fall back to short text labels (▸,▾, etc.). The public API is identical either way.
Structs§
- Directory
Tree - A directory tree widget state.
- Icon
Spec - Description of how to render an icon for a particular
IconRole. - Load
Payload - The payload of
DirectoryTreeEvent::Loaded. - Lucide
Theme icons - Stock theme that renders real lucide vector glyphs.
- Thread
Executor - Default executor — one
std::thread::spawnper scan. - Tree
Config - Per-tree configuration.
- Tree
Node - A single node in the directory tree.
- Unicode
Theme - Stock theme that renders short Unicode symbols available in any system font. Always available.
Enums§
- Directory
Filter - Controls which entries the widget displays.
- Directory
Tree Event - A message emitted by or consumed by the
DirectoryTreewidget. - DragMsg
- Opaque drag-machinery event produced by the widget’s internal mouse-area instrumentation.
- Error
- Everything the widget can fail at.
- Icon
Role - Semantic icon identifiers the widget renders.
- Selection
Mode - How an incoming selection event composes with the existing set.
Constants§
- DEFAULT_
PREFETCH_ SKIP - The default set of basenames that
DirectoryTree’s v0.5 prefetch machinery skips, populated intoTreeConfig::prefetch_skipby default. - LUCIDE_
FONT_ BYTES icons - Bytes of the lucide font
Traits§
- Icon
Theme - How to render each
IconRolefor a given visual design. - Scan
Executor - A pluggable executor for blocking
scan_dircalls.
Type Aliases§
- Scan
Future - The future that runs a
ScanJobto completion. - ScanJob
- The job passed to a
ScanExecutor— always just “callswdir::scan_diron this path”.