pub struct FileSpec {
pub name: &'static str,
pub extensions: &'static [&'static str],
}
Expand description
A description of a filetype, for specifying allowed types in a file dialog.
§Windows
Each instance of this type is converted to a COMDLG_FILTERSPEC
struct.
§macOS
These file types also apply to directories to define them as packages.
Fields§
§name: &'static str
A human readable name, describing this filetype.
This is used in the Windows file dialog, where the user can select from a dropdown the type of file they would like to choose.
This should not include the file extensions; they will be added automatically. For instance, if we are describing Word documents, the name would be “Word Document”, and the displayed string would be “Word Document (*.doc)”.
extensions: &'static [&'static str]
The file extensions used by this file type.
This should not include the leading ‘.’.
Implementations§
Source§impl FileSpec
impl FileSpec
pub const TEXT: FileSpec
pub const JPG: FileSpec
pub const GIF: FileSpec
pub const PNG: FileSpec
pub const PDF: FileSpec
pub const HTML: FileSpec
Sourcepub const fn new(
name: &'static str,
extensions: &'static [&'static str],
) -> FileSpec
pub const fn new( name: &'static str, extensions: &'static [&'static str], ) -> FileSpec
Create a new FileSpec
.
Examples found in repository?
examples/open_save.rs (line 40)
39fn ui_builder() -> impl Widget<String> {
40 let rs = FileSpec::new("Rust source", &["rs"]);
41 let txt = FileSpec::new("Text file", &["txt"]);
42 let other = FileSpec::new("Bogus file", &["foo", "bar", "baz"]);
43 // The options can also be generated at runtime,
44 // so to show that off we create a String for the default save name.
45 let default_save_name = String::from("MyFile.txt");
46 let save_dialog_options = FileDialogOptions::new()
47 .allowed_types(vec![rs, txt, other])
48 .default_type(txt)
49 .default_name(default_save_name)
50 .name_label("Target")
51 .title("Choose a target for this lovely file")
52 .button_text("Export");
53 let open_dialog_options = save_dialog_options
54 .clone()
55 .default_name("MySavedFile.txt")
56 .name_label("Source")
57 .title("Where did you put that file?")
58 .button_text("Import");
59
60 let input = TextBox::new();
61 let save = Button::new("Save").on_click(move |ctx, _, _| {
62 ctx.submit_command(druid::commands::SHOW_SAVE_PANEL.with(save_dialog_options.clone()))
63 });
64 let open = Button::new("Open").on_click(move |ctx, _, _| {
65 ctx.submit_command(druid::commands::SHOW_OPEN_PANEL.with(open_dialog_options.clone()))
66 });
67
68 let mut col = Flex::column();
69 col.add_child(input);
70 col.add_spacer(8.0);
71 col.add_child(save);
72 col.add_child(open);
73 Align::centered(col)
74}
Trait Implementations§
impl Copy for FileSpec
impl Eq for FileSpec
impl StructuralPartialEq for FileSpec
Auto Trait Implementations§
impl Freeze for FileSpec
impl RefUnwindSafe for FileSpec
impl Send for FileSpec
impl Sync for FileSpec
impl Unpin for FileSpec
impl UnwindSafe for FileSpec
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T, U> RoundInto<U> for Twhere
U: RoundFrom<T>,
impl<T, U> RoundInto<U> for Twhere
U: RoundFrom<T>,
Source§fn round_into(self) -> U
fn round_into(self) -> U
Performs the conversion.