GPUI Box GitHub

Components / controls

Dropzone builder

An area that accepts a drop.

A builder is RenderOnce. Construct and mount it in one expression.

use gpui_kit::controls::dropzone::Dropzone;

Reviewed in dropzone.

Construct
new(ident: impl Into<Ident>, label: impl Into<SharedString>) -> Self
Options

Chain onto the value.

hint(hint: impl Into<SharedString>) -> Self
refusal(refusal: impl Into<SharedString>) -> Self
accepts<S: Into<SharedString>>(kinds: impl IntoIterator<Item = S>) -> Self
icon(icon: Icon) -> Self
state(state: DropzoneState) -> Self
invalid(invalid: bool) -> Self
on_drop(handler: impl Fn(&DragItem, &mut Window, &mut App) + 'static) -> Self
on_files(handler: impl Fn(&ExternalPaths, &mut Window, &mut App) + 'static) -> Self
Example · dropzone
fn dropzone(_window: &mut Window, cx: &mut App) -> AnyElement {
    let theme = cx.theme().clone();
    // No single pointer position can produce all three states at once, so each
    // zone is pinned to the one it is here to show.
    stack(&theme)
        .w(px(560.0))
        .child(caption(&theme, "idle, accepting, refusing"))
        .child(
            row(&theme)
                .items_stretch()
                .child(
                    div().flex_1().child(
                        Dropzone::new("scene.dropzone.idle", "Drop files to attach")
                            .hint("PDF, PNG, or plain text")
                            .state(DropzoneState::Idle)
                            .on_files(|_, _, _| {}),
                    ),
                )
                .child(
                    div().flex_1().child(
                        Dropzone::new("scene.dropzone.accepting", "Drop files to attach")
                            .hint("PDF, PNG, or plain text")
                            .state(DropzoneState::Accepting)
                            .on_files(|_, _, _| {}),
                    ),
                )
                .child(
                    div().flex_1().child(
                        Dropzone::new("scene.dropzone.refusing", "Drop files to attach")
                            .hint("PDF, PNG, or plain text")
                            .refusal("A folder cannot be attached.")
                            .state(DropzoneState::Refusing)
                            .on_files(|_, _, _| {}),
                    ),
                ),
        )
        .into_any_element()
}

Source: crates/gpui-kit/src/controls/dropzone.rs