Struct FileSpec

Source
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

Source

pub const TEXT: FileSpec

Source

pub const JPG: FileSpec

Source

pub const GIF: FileSpec

Source

pub const PNG: FileSpec

Source

pub const PDF: FileSpec

Source

pub const HTML: FileSpec

Source

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§

Source§

impl Clone for FileSpec

Source§

fn clone(&self) -> FileSpec

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FileSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for FileSpec

Source§

fn eq(&self, other: &FileSpec) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for FileSpec

Source§

impl Eq for FileSpec

Source§

impl StructuralPartialEq for FileSpec

Auto Trait Implementations§

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> AnyEq for T
where T: Any + PartialEq,

Source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

Source§

fn as_any(&self) -> &(dyn Any + 'static)

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> RoundFrom<T> for T

Source§

fn round_from(x: T) -> T

Performs the conversion.
Source§

impl<T, U> RoundInto<U> for T
where U: RoundFrom<T>,

Source§

fn round_into(self) -> U

Performs the conversion.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more