pub struct FilePicker<'a, Msg> { /* private fields */ }Expand description
Browses folders and chooses a file or a folder.
The picker is built from framework widgets: a clickable path, a name filter, a list of the
folder’s entries (folders first, a parent row on top), and a footer with a hidden-files
switch and the choose button. The application owns a FileBrowser and passes it every
FilePickerMsg; folders are read on a background thread, and a folder that cannot be opened
shows a readable message at once.
While a folder is read the picker keeps showing the folder it was on, unchanged and usable, and switches to the new one in a single frame when it has been read. A read that takes longer than about 300 ms shows a small spinner right after the path, which then stays at least about 500 ms, so quick reads never flash a loading state and slow ones never blink one.
use qframe::prelude::*;
use qframe::widgets::{FileBrowser, FilePicker, FilePickerMsg, PickMode};
struct Open {
browser: FileBrowser,
chosen: Option<std::path::PathBuf>,
}
#[derive(Clone)]
enum Msg {
Picker(FilePickerMsg),
}
impl App for Open {
type Msg = Msg;
fn update(&mut self, msg: Msg) -> Command<Msg> {
match msg {
Msg::Picker(FilePickerMsg::Chosen(path)) => self.chosen = Some(path),
Msg::Picker(message) => return self.browser.update(message, Msg::Picker),
}
Command::none()
}
fn view(&self, ui: &mut View<'_, Msg>) {
FilePicker::new(&self.browser, Msg::Picker).show(ui).fill();
}
}Keys: the list’s keys (↑/↓, Enter opens a folder or chooses a file) and Tab between the
filter, the list, the switch and the button. Style keys: path-segment (fg, bg) with
hover and selected for the current folder; path-separator; spinner and
spinner-label for the reading indicator; the styles of List, TextInput, Switch and
Button. Icons: folder, file, arrow-up,
path-separator, error. Framework strings under quvyta.file-picker.
Implementations§
Source§impl<'a, Msg: Clone + Send + 'static> FilePicker<'a, Msg>
impl<'a, Msg: Clone + Send + 'static> FilePicker<'a, Msg>
Sourcepub fn new(
browser: &'a FileBrowser,
wrap: impl Fn(FilePickerMsg) -> Msg + 'static,
) -> Self
pub fn new( browser: &'a FileBrowser, wrap: impl Fn(FilePickerMsg) -> Msg + 'static, ) -> Self
A picker showing browser; wrap turns picker messages into application messages.
wrap is a function such as Msg::Picker, or a closure that captures what it needs,
e.g. a screen’s own conversion: move |message| wrap(screen::Msg::Picker(message)). It
runs while events are handled on the drawing thread, so it need not be Send, and the
picker shares it among its widgets, so it need not be Clone.
Auto Trait Implementations§
impl<'a, Msg> !RefUnwindSafe for FilePicker<'a, Msg>
impl<'a, Msg> !Send for FilePicker<'a, Msg>
impl<'a, Msg> !Sync for FilePicker<'a, Msg>
impl<'a, Msg> !UnwindSafe for FilePicker<'a, Msg>
impl<'a, Msg> Freeze for FilePicker<'a, Msg>
impl<'a, Msg> Unpin for FilePicker<'a, Msg>
impl<'a, Msg> UnsafeUnpin for FilePicker<'a, Msg>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more