[−][src]Struct dragula::Options
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:
Event | Move | Copy |
---|---|---|
drag | Element will be concealed from source | Nothing happens |
drop | Element will be moved into target | Element will be cloned into target |
remove | Element will be removed from DOM | Nothing happens |
cancel | Element will stay in source | Nothing 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
Auto Trait Implementations
impl !RefUnwindSafe for Options
[src]
impl !Send for Options
[src]
impl !Sync for Options
[src]
impl Unpin for Options
[src]
impl !UnwindSafe for Options
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,