Skip to main content

Crate iced_swdir_tree

Crate iced_swdir_tree 

Source
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, uses lucide-icons for folder/file graphics. When disabled, icons fall back to short text labels (, , etc.). The public API is identical either way.

Structs§

DirectoryTree
A directory tree widget state.
IconSpec
Description of how to render an icon for a particular IconRole.
LoadPayload
The payload of DirectoryTreeEvent::Loaded.
LucideThemeicons
Stock theme that renders real lucide vector glyphs.
ThreadExecutor
Default executor — one std::thread::spawn per scan.
TreeConfig
Per-tree configuration.
TreeNode
A single node in the directory tree.
UnicodeTheme
Stock theme that renders short Unicode symbols available in any system font. Always available.

Enums§

DirectoryFilter
Controls which entries the widget displays.
DirectoryTreeEvent
A message emitted by or consumed by the DirectoryTree widget.
DragMsg
Opaque drag-machinery event produced by the widget’s internal mouse-area instrumentation.
Error
Everything the widget can fail at.
IconRole
Semantic icon identifiers the widget renders.
SelectionMode
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 into TreeConfig::prefetch_skip by default.
LUCIDE_FONT_BYTESicons
Bytes of the lucide font

Traits§

IconTheme
How to render each IconRole for a given visual design.
ScanExecutor
A pluggable executor for blocking scan_dir calls.

Type Aliases§

ScanFuture
The future that runs a ScanJob to completion.
ScanJob
The job passed to a ScanExecutor — always just “call swdir::scan_dir on this path”.