Skip to main content

FilePicker

Struct FilePicker 

Source
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>

Source

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.

Source

pub fn show<'v>(self, ui: &'v mut View<'_, Msg>) -> NodeMut<'v, Msg>

Adds the picker to ui as a column.

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>
where Rc<dyn Fn(FilePickerMsg) -> Msg>: Freeze,

§

impl<'a, Msg> Unpin for FilePicker<'a, Msg>
where Rc<dyn Fn(FilePickerMsg) -> Msg>: Unpin,

§

impl<'a, Msg> UnsafeUnpin for FilePicker<'a, Msg>
where Rc<dyn Fn(FilePickerMsg) -> Msg>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.