[][src]Struct dragula::Options

pub struct Options {
    pub is_container: Box<dyn FnMut(JsValue) -> bool>,
    pub moves: Box<dyn FnMut(JsValue, JsValue, JsValue, JsValue) -> bool>,
    pub accepts: Box<dyn FnMut(JsValue, JsValue, JsValue, JsValue) -> bool>,
    pub invalid: Box<dyn FnMut(JsValue, JsValue) -> bool>,
    pub copy: CopyValue,
    pub copy_sort_source: bool,
    pub revert_on_spill: bool,
    pub remove_on_spill: bool,
    pub direction: Direction,
    pub mirror_container: JsValue,
    pub ignore_input_text_selection: bool,
    pub slide_factor_x: i32,
    pub slide_factor_y: i32,
}

Used to pass options when activating Dragula

When passed to the dragula_options function, this struct can be used to specify options to control the behaviour of the drag-and-drop functionality.

For example:

use dragula::*;
use dragula::options::CopyValue;
use web_sys::Element;

//--snip--

let options = Options {
    invalid: Box::new(|el, _handle| {
        Element::from(el).tag_name() == String::from("A")
    }),
    copy: CopyValue::Bool(true),
    copy_sort_source: true,
    remove_on_spill: true,
    slide_factor_x: 10,
    slide_factor_y: 10,
    ..Options::default()
};

let drake = dragula_options(&[element], options);

//--snip--

Fields

is_container: Box<dyn FnMut(JsValue) -> bool>

Besides the containers that you pass to dragula, or the containers you dynamically add, you can also use this closure to specify any sort of logic that defines what is a container for this particular Drake instance.

This closure will be invoked with the element that is being checked for whether it is a container.

moves: Box<dyn FnMut(JsValue, JsValue, JsValue, JsValue) -> bool>

You can define a moves closure which will be invoked with (el, source, handle, sibling) whenever an element is clicked. If this closure returns false, a drag event won't begin, and the event won't be prevented either. The handle element will be the original click target, which comes in handy to test if that element is an expected "drag handle".

accepts: Box<dyn FnMut(JsValue, JsValue, JsValue, JsValue) -> bool>

You can set accepts to a closure with the following signature: (el, target, source, sibling). It'll be called to make sure that an element el, that came from container source, can be dropped on container target before a sibling element. The sibling can be null, which would mean that the element would be placed as the last element in the container. Note that if copy is set to true, el will be set to the copy, instead of the originally dragged element.

invalid: Box<dyn FnMut(JsValue, JsValue) -> bool>

You can provide an invalid closure with a (el, handle) signature. This closure should return true for elements that shouldn't trigger a drag. The handle argument is the element that was clicked, while el is the item that would be dragged.

copy: CopyValue

If copy is set to true (or a closure that returns true), items will be copied rather than moved. This implies the following differences:

EventMoveCopy
dragElement will be concealed from sourceNothing happens
dropElement will be moved into targetElement will be cloned into target
removeElement will be removed from DOMNothing happens
cancelElement will stay in sourceNothing happens

If a closure is passed, it'll be called whenever an element starts being dragged in order to decide whether it should follow copy behavior or not. This closure will be passed the element to be dragged as well as its source container, in other words, the signature is (el, handle).

false by default.

copy_sort_source: bool

If copy is set to true (or a closure that returns true) and copy_sort_source is true as well, users will be able to sort elements in copy-source containers.

false by default.

revert_on_spill: bool

By default, spilling an element outside of any containers will move the element back to the drop position previewed by the feedback shadow. Setting revert_on_spill to true will ensure elements dropped outside of any approved containers are moved back to the source element where the drag event began, rather than stay at the drop position previewed by the feedback shadow.

false by default.

remove_on_spill: bool

By default, spilling an element outside of any containers will move the element back to the drop position previewed by the feedback shadow. Setting remove_on_spill to true will ensure elements dropped outside of any approved containers are removed from the DOM. Note that remove events won't fire if copy is set to true.

false by default.

direction: Direction

When an element is dropped onto a container, it'll be placed near the point where the mouse was released. If the direction is Vertical, the default value, the Y axis will be considered. Otherwise, if the direction is Horizontal, the X axis will be considered.

Vertical, by default.

mirror_container: JsValue

The DOM element where the mirror element displayed while dragging will be appended to.

document.body by default.

ignore_input_text_selection: bool

When this option is enabled, if the user clicks on an input element the drag won't start until their mouse pointer exits the input. This translates into the user being able to select text in inputs contained inside draggable elements, and still drag the element by moving their mouse outside of the input -- so you get the best of both worlds.

true by default.

slide_factor_x: i32

The amount of horizontal movement (in pixels) for a click to be considered a drag

0 by default.

slide_factor_y: i32

The amount of vertical movement (in pixels) for a click to be considered a drag

0 by default.

Trait Implementations

impl Default for Options[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.