Skip to main content

DropZone

Struct DropZone 

Source
pub struct DropZone<C> { /* private fields */ }
Expand description

A dashed area around any content, which takes files dropped on it and shows when they are over the window. Unlike FileUpload it keeps no list: the files go to DropZone::on_files, and what it holds and how it looks are up to the content.

A dropped file lands in the zone under the pointer. While it is being dragged, every zone on the screen lights up, because the platforms say only that files are over the window, and not where. A keyboard cannot drop anything, so DropZone::choosable is there for that.

use ravenrs_widgets::{DropZone, Text, Ui};

let zone = DropZone::new(Text::new("Photos of the session"))
    .accept(["jpg", "png"])
    .on_files(|files| println!("{} files", files.len()));
let mut ui = Ui::new(zone, ravenrs_style::Theme::raven_dark());
ui.update();

Implementations§

Source§

impl<C: View> DropZone<C>

Source

pub fn new(content: C) -> Self

A zone around content, taking any file.

Source

pub fn on_files(self, handler: impl Fn(Vec<PickedFile>) + 'static) -> Self

Called with the files it took. It is not called when all of them were refused.

Source

pub fn on_refused(self, handler: impl Fn(Vec<String>) + 'static) -> Self

Called with one sentence for each refused file, in the words of crate::Labels, for showing them elsewhere. Without it they show inside the zone, under the content.

Source

pub fn accept( self, extensions: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Only these extensions, such as ["pdf", "png"]. Any file by default.

Source

pub fn most_bytes(self, bytes: u64) -> Self

The largest file taken, in bytes. 100 MiB by default.

Source

pub fn most_files(self, files: usize) -> Self

The most files taken from one drop. No limit by default.

Source

pub fn label(self, label: impl Into<String>) -> Self

The name screen readers announce. By default, the words of the hint.

Source

pub fn hint(self, hint: impl Into<String>) -> Self

What shows over the content while files are over the window. By default, file_drop of the labels.

Source

pub fn no_hint(self) -> Self

Shows nothing over the content while files are over the window, only the stronger edge.

Source

pub fn choosable(self) -> Self

Makes the whole zone a button that opens the system’s chooser, with a click, Enter or Space, so that the keyboard can bring files too. Leave it off when the content has its own way of choosing.

Source

pub fn quiet(self) -> Self

Draws the dashes only while files are over the window, for a zone that is a whole screen and should not look like one until then.

Source

pub fn padding(self, padding: f32) -> Self

The space around the content, in logical pixels (space-4 by default).

Source

pub fn min_height(self, height: f32) -> Self

The shortest it gets, in logical pixels.

Source

pub fn fill(self) -> Self

Takes the free space of the parent, for a zone that is a whole screen.

Source

pub fn disabled(self, disabled: bool) -> Self

Turns it off: it takes no files and does not react to them.

Trait Implementations§

Source§

impl<C> Debug for DropZone<C>

Source§

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

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

impl<C: View> View for DropZone<C>

Source§

fn build(&self, cx: &mut BuildCx<'_>) -> NodeId

Creates this view’s node for the current build.
Source§

fn type_name(&self) -> &'static str

The name the diagnostics panel shows this view’s cost under.

Auto Trait Implementations§

§

impl<C> !RefUnwindSafe for DropZone<C>

§

impl<C> !Send for DropZone<C>

§

impl<C> !Sync for DropZone<C>

§

impl<C> !UnwindSafe for DropZone<C>

§

impl<C> Freeze for DropZone<C>
where C: Freeze,

§

impl<C> Unpin for DropZone<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for DropZone<C>
where C: 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
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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, 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<V> ViewExt for V
where V: View,

Source§

fn padding(self, padding: impl Into<Insets>) -> Styled<Self>

Adds padding inside the box, in logical pixels.
Source§

fn background(self, fill: impl Into<Fill>) -> Styled<Self>

Paints a background behind the content.
Source§

fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>

Fixes the width and/or height in logical pixels; None keeps the content size.
Source§

fn width(self, width: f32) -> Styled<Self>

Fixes the width in logical pixels.
Source§

fn height(self, height: f32) -> Styled<Self>

Fixes the height in logical pixels.
Source§

fn grow(self, grow: f32) -> Styled<Self>

Takes a share of the free space in the parent stack.
Source§

fn stretch(self) -> Styled<Self>

Stretches across the parent stack’s cross axis.
Source§

fn centered(self) -> Styled<Self>

Centers the content inside the box.
Source§

fn tooltip(self, text: impl Into<String>) -> Tooltip<Self>

Shows text above the view while the pointer is over it; see Tooltip.
Source§

fn opacity(self, opacity: f32) -> Faded<Self>

Draws the view and everything in it at this opacity, from 0.0 to 1.0, easing to it when it changes. Layout and input stay as they are; see Faded.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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