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
impl FileChooser
sourcepub fn new<P: AsRef<Path>>(
dir: P,
pattern: &str,
typ: FileChooserType,
title: &str
) -> FileChooser
pub fn new<P: AsRef<Path>>( dir: P, pattern: &str, typ: FileChooserType, title: &str ) -> FileChooser
Instantiates a new FileChooser
Gets the new button of the FileChooser
Gets the preview button of the FileChooser
Gets the show hidden button of the FileChooser
sourcepub fn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
pub fn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
Sets the callback of the FileChooser
sourcepub fn set_directory<P: AsRef<Path>>(&mut self, dir: P)
pub fn set_directory<P: AsRef<Path>>(&mut self, dir: P)
Sets the directory of the FileChooser
sourcepub fn set_filter(&mut self, pattern: &str)
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})”
sourcepub fn filter_value(&self) -> i32
pub fn filter_value(&self) -> i32
Gets the current filename filter selection
sourcepub fn set_filter_value(&mut self, f: i32)
pub fn set_filter_value(&mut self, f: i32)
Sets the filter value using an index to the ’\t’separated filters
sourcepub fn set_icon_size(&mut self, s: u8)
pub fn set_icon_size(&mut self, s: u8)
Sets the icon size of the FileChooser
sourcepub fn set_ok_label(&mut self, l: &'static str)
pub fn set_ok_label(&mut self, l: &'static str)
Sets the label of the Ok button
sourcepub fn set_preview(&mut self, e: bool)
pub fn set_preview(&mut self, e: bool)
Add preview to the FileChooser
sourcepub fn rescan_keep_filename(&mut self)
pub fn rescan_keep_filename(&mut self)
Rescan the directory while keeping the file name
sourcepub fn set_text_color(&mut self, c: Color)
pub fn set_text_color(&mut self, c: Color)
Sets the text color of the file chooser
sourcepub fn text_color(&self) -> Color
pub fn text_color(&self) -> Color
Gets the text color of the file chooser
sourcepub fn set_text_font(&mut self, f: Font)
pub fn set_text_font(&mut self, f: Font)
Sets the text font of the file chooser
sourcepub fn set_text_size(&mut self, s: i32)
pub fn set_text_size(&mut self, s: i32)
Sets the text size of the file chooser
sourcepub fn set_type(&mut self, t: FileChooserType)
pub fn set_type(&mut self, t: FileChooserType)
Sets the type of the FileChooser
sourcepub fn get_type(&self) -> FileChooserType
pub fn get_type(&self) -> FileChooserType
Gets the type of the FileChooser
sourcepub unsafe fn user_data(&self) -> Option<Box<dyn FnMut()>>
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
sourcepub fn value(&mut self, f: i32) -> Option<String>
pub fn value(&mut self, f: i32) -> Option<String>
Gets the file or dir name chosen by the FileChooser
sourcepub fn set_value(&mut self, filename: &str)
pub fn set_value(&mut self, filename: &str)
Sets the file or dir name chosen by the FileChooser
sourcepub fn set_add_favorites_label(msg: &'static str)
pub fn set_add_favorites_label(msg: &'static str)
Set “Add favorites” label
sourcepub fn set_all_files_label(msg: &'static str)
pub fn set_all_files_label(msg: &'static str)
Set “All Files” label
sourcepub fn set_custom_filter_label(msg: &'static str)
pub fn set_custom_filter_label(msg: &'static str)
Set “Custom Filter” label
sourcepub fn set_existing_file_label(msg: &'static str)
pub fn set_existing_file_label(msg: &'static str)
Set “Existing file” label
sourcepub fn set_favorites_label(msg: &'static str)
pub fn set_favorites_label(msg: &'static str)
Set “Favorites” label
sourcepub fn set_filename_label(msg: &'static str)
pub fn set_filename_label(msg: &'static str)
Set “Filename” label
sourcepub fn set_filesystems_label(msg: &'static str)
pub fn set_filesystems_label(msg: &'static str)
Set “Filesystems” label
sourcepub fn set_manage_favorites_label(msg: &'static str)
pub fn set_manage_favorites_label(msg: &'static str)
Set “Manage favorites” label
sourcepub fn set_new_directory_label(msg: &'static str)
pub fn set_new_directory_label(msg: &'static str)
Set “New directory” label
sourcepub fn set_new_directory_tooltip(msg: &'static str)
pub fn set_new_directory_tooltip(msg: &'static str)
Set “New directory” tooltip
sourcepub fn set_preview_label(msg: &'static str)
pub fn set_preview_label(msg: &'static str)
Set “Preview” label
sourcepub fn set_save_label(msg: &'static str)
pub fn set_save_label(msg: &'static str)
Set “Save” label
sourcepub fn set_show_label(msg: &'static str)
pub fn set_show_label(msg: &'static str)
Set “Show” label
Set “hidden” label
sourcepub fn set_position(&mut self, x: i32, y: i32)
pub fn set_position(&mut self, x: i32, y: i32)
Set the position of the file chooser