Struct egui_dnd::Dnd

source ·
pub struct Dnd<'a> { /* private fields */ }
Expand description

Helper struct for ease of use.

Implementations§

source§

impl<'a> Dnd<'a>

source

pub fn new(ui: &'a mut Ui, id_source: impl Hash) -> Self

Initialize the drag and drop UI. Same as dnd.

source

pub fn with_mouse_config(self, config: DragDropConfig) -> Self

Sets the config used when dragging with the mouse or when no touch config is set

source

pub fn with_touch_config(self, config: Option<DragDropConfig>) -> Self

Sets the config used when dragging with touch If None, the mouse config is used instead Use DragDropConfig::touch or DragDropConfig::touch_scroll to get a config optimized for touch The default is DragDropConfig::touch For dragging in a ScrollArea, use DragDropConfig::touch_scroll

source

pub fn with_return_animation_time(self, animation_time: f32) -> Self

Sets the animation time for the return animation (after dropping an item) The default is the same as the egui animation time If you want to disable the animation, set it to 0

source

pub fn with_swap_animation_time(self, animation_time: f32) -> Self

Sets the animation time for the swap animation (when dragging an item over another item) The default is the same as the egui animation time If you want to disable the animation, set it to 0

source

pub fn with_animation_time(self, animation_time: f32) -> Self

Sets the animation time for all animations The default is the same as the egui animation time If you want to disable all animations, set it to 0

source

pub fn show<T: DragDropItem>( self, items: impl Iterator<Item = T>, item_ui: impl FnMut(&mut Ui, T, Handle<'_>, ItemState) ) -> DragDropResponse

Display the drag and drop UI. items should be an iterator over items that should be sorted.

The items won’t be sorted automatically, but you can use Dnd::show_vec or DragDropResponse::update_vec to do so. If your items aren’t in a vec, you have to sort them yourself.

item_ui is called for each item. Display your item there. item_ui gets a Handle that can be used to display the drag handle. Only the handle can be used to drag the item. If you want the whole item to be draggable, put everything in the handle.

source

pub fn show_sized<T: DragDropItem>( self, items: impl Iterator<Item = T>, size: Vec2, item_ui: impl FnMut(&mut Ui, T, Handle<'_>, ItemState) ) -> DragDropResponse

Same as Dnd::show, but with a fixed size for each item. This allows items to be placed in a horizontal_wrapped ui. For more info, look at the horizontal example. If you need even more control over the size, use Dnd::show_custom instead, where you can individually size each item. See the sort_words example for an example.

source

pub fn show_vec<T: Hash>( self, items: &mut [T], item_ui: impl FnMut(&mut Ui, &mut T, Handle<'_>, ItemState) ) -> DragDropResponse

Same as Dnd::show, but automatically sorts the items.

source

pub fn show_vec_sized<T: Hash>( self, items: &mut [T], size: Vec2, item_ui: impl FnMut(&mut Ui, &mut T, Handle<'_>, ItemState) ) -> DragDropResponse

Same as Dnd::show_sized, but automatically sorts the items.

source

pub fn show_custom( self, f: impl FnOnce(&mut Ui, &mut ItemIterator<'_>) ) -> DragDropResponse

This will allow for very flexible UI. You can use it to e.g. render outlines around items or render items in complex layouts. This is experimental.

source

pub fn show_custom_vec<T: Hash>( self, items: &mut [T], f: impl FnOnce(&mut Ui, &mut [T], &mut ItemIterator<'_>) ) -> DragDropResponse

Same as Dnd::show_custom, but automatically sorts the items.

Auto Trait Implementations§

§

impl<'a> Freeze for Dnd<'a>

§

impl<'a> !RefUnwindSafe for Dnd<'a>

§

impl<'a> Send for Dnd<'a>

§

impl<'a> Sync for Dnd<'a>

§

impl<'a> Unpin for Dnd<'a>

§

impl<'a> !UnwindSafe for Dnd<'a>

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
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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>,

§

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>,

§

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.