Struct fltk::dialog::FileChooser

source ·
pub struct FileChooser { /* private fields */ }
Expand description

FLTK’s own FileChooser. Which differs for the Native FileDialog Example:

use fltk::{prelude::*, *};
fn main() {
    let app = app::App::default();
    let mut win = window::Window::default().with_size(900, 300);
    let mut chooser = dialog::FileChooser::new(
        ".",                    // directory
        "*",                    // filter or pattern
        dialog::FileChooserType::Multi, // chooser type
        "Title Of Chooser",     // title
    );
    chooser.show();
    chooser.window().set_pos(300, 300);
    // Block until user picks something.
    //     (The other way to do this is to use a callback())
    //
    while chooser.shown() {
        app::wait();
    }
    // User hit cancel?
    if chooser.value(1).is_none() {
        println!("(User hit 'Cancel')");
        return;
    }
    // Print what the user picked
    println!("--------------------");
    println!("DIRECTORY: '{}'", chooser.directory().unwrap());
    println!("    VALUE: '{}'", chooser.value(1).unwrap()); // value starts at 1!
    println!("    COUNT: {} files selected", chooser.count());
    // Multiple files? Show all of them
    if chooser.count() > 1 {
        for t in 1..=chooser.count() {
            println!(" VALUE[{}]: '{}'", t, chooser.value(t).unwrap());
        }
    }
    win.end();
    win.show();
    app.run().unwrap();
}

Implementations§

source§

impl FileChooser

source

pub fn new<P: AsRef<Path>>( dir: P, pattern: &str, typ: FileChooserType, title: &str ) -> FileChooser

Instantiates a new FileChooser

source

pub unsafe fn delete(dlg: Self)

Deletes a FileChooser

Safety

Can invalidate the underlying pointer

source

pub fn new_button(&self) -> Option<impl ButtonExt>

Gets the new button of the FileChooser

source

pub fn preview_button(&self) -> Option<impl ButtonExt>

Gets the preview button of the FileChooser

source

pub fn show_hidden_button(&self) -> Option<impl ButtonExt>

Gets the show hidden button of the FileChooser

source

pub fn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)

Sets the callback of the FileChooser

source

pub fn set_color(&mut self, c: Color)

Sets the color of the FileChooser

source

pub fn color(&self) -> Color

Gets the color of the FileChooser

source

pub fn count(&self) -> i32

Gets the count of chosen items

source

pub fn set_directory<P: AsRef<Path>>(&mut self, dir: P)

Sets the directory of the FileChooser

source

pub fn directory(&self) -> Option<String>

Gets the directory of the FileChooser

source

pub fn set_filter(&mut self, pattern: &str)

Sets the filter for the dialog, can be: Multiple patterns can be used by separating them with tabs, like “.jpg\t.png\t*.gif\t*”. In addition, you can provide human-readable labels with the patterns inside parenthesis, like “JPEG Files (.jpg)\tPNG Files (.png)\tGIF Files (.gif)\tAll Files () And “Rust Files (*.{rs,txt,toml})”

source

pub fn filter(&self) -> Option<String>

Gets the filter of the FileChooser

source

pub fn filter_value(&self) -> i32

Gets the current filename filter selection

source

pub fn set_filter_value(&mut self, f: i32)

Sets the filter value using an index to the ’\t’separated filters

source

pub fn hide(&mut self)

Hides the file chooser

source

pub fn set_icon_size(&mut self, s: u8)

Sets the icon size of the FileChooser

source

pub fn icon_size(&self) -> u8

Gets the icon size of the FileChooser

source

pub fn set_label(&mut self, l: &str)

Sets the label of the FileChooser

source

pub fn label(&self) -> String

Gets the label of the FileChooser

source

pub fn set_ok_label(&mut self, l: &'static str)

Sets the label of the Ok button

source

pub fn ok_label(&self) -> String

Gets the label of the Ok button

source

pub fn set_preview(&mut self, e: bool)

Add preview to the FileChooser

source

pub fn preview(&self) -> bool

Returns whether preview is enabled for the FileChooser

source

pub fn rescan(&mut self)

Rescan the directory

source

pub fn rescan_keep_filename(&mut self)

Rescan the directory while keeping the file name

source

pub fn show(&mut self)

Shows the File Chooser

source

pub fn shown(&self) -> bool

Returns whether the file chooser is shown

source

pub fn set_text_color(&mut self, c: Color)

Sets the text color of the file chooser

source

pub fn text_color(&self) -> Color

Gets the text color of the file chooser

source

pub fn set_text_font(&mut self, f: Font)

Sets the text font of the file chooser

source

pub fn text_font(&self) -> Font

Gets the text font of the file chooser

source

pub fn set_text_size(&mut self, s: i32)

Sets the text size of the file chooser

source

pub fn text_size(&self) -> i32

Gets the text size of the file chooser

source

pub fn set_type(&mut self, t: FileChooserType)

Sets the type of the FileChooser

source

pub fn get_type(&self) -> FileChooserType

Gets the type of the FileChooser

source

pub unsafe fn user_data(&self) -> Option<Box<dyn FnMut()>>

Gets the user data of the FileChooser

Safety

Can invalidate the user data while the FileChooser is in use

source

pub fn value(&mut self, f: i32) -> Option<String>

Gets the file or dir name chosen by the FileChooser

source

pub fn set_value(&mut self, filename: &str)

Sets the file or dir name chosen by the FileChooser

source

pub fn visible(&self) -> bool

Returns whether the FileChooser is visible or not

source

pub fn window(&self) -> impl WindowExt

Return dialog window

source

pub fn set_add_favorites_label(msg: &'static str)

Set “Add favorites” label

source

pub fn set_all_files_label(msg: &'static str)

Set “All Files” label

source

pub fn set_custom_filter_label(msg: &'static str)

Set “Custom Filter” label

source

pub fn set_existing_file_label(msg: &'static str)

Set “Existing file” label

source

pub fn set_favorites_label(msg: &'static str)

Set “Favorites” label

source

pub fn set_filename_label(msg: &'static str)

Set “Filename” label

source

pub fn set_filesystems_label(msg: &'static str)

Set “Filesystems” label

source

pub fn set_manage_favorites_label(msg: &'static str)

Set “Manage favorites” label

source

pub fn set_new_directory_label(msg: &'static str)

Set “New directory” label

source

pub fn set_new_directory_tooltip(msg: &'static str)

Set “New directory” tooltip

source

pub fn set_preview_label(msg: &'static str)

Set “Preview” label

source

pub fn set_save_label(msg: &'static str)

Set “Save” label

source

pub fn set_show_label(msg: &'static str)

Set “Show” label

source

pub fn set_hidden_label(msg: &'static str)

Set “hidden” label

source

pub fn set_position(&mut self, x: i32, y: i32)

Set the position of the file chooser

source

pub fn set_size(&mut self, w: i32, h: i32)

Set the size of the file chooser

source

pub fn x(&self) -> i32

Get the x pos of the file chooser

source

pub fn y(&self) -> i32

Get the y pos of the file chooser

source

pub fn w(&self) -> i32

Get the width of the file chooser

source

pub fn h(&self) -> i32

Get the width of the file chooser

source

pub fn size(&self) -> (i32, i32)

Get the size of the file chooser

source

pub fn pos(&self) -> (i32, i32)

Get the position of the file chooser

Trait Implementations§

source§

impl Drop for FileChooser

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.