pub struct Dnd<'a> { /* private fields */ }
Expand description
Helper struct for ease of use.
Implementations§
source§impl<'a> Dnd<'a>
impl<'a> Dnd<'a>
sourcepub fn new(ui: &'a mut Ui, id_source: impl Hash) -> Self
pub fn new(ui: &'a mut Ui, id_source: impl Hash) -> Self
Initialize the drag and drop UI. Same as dnd.
sourcepub fn with_mouse_config(self, config: DragDropConfig) -> Self
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
sourcepub fn with_touch_config(self, config: Option<DragDropConfig>) -> Self
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
sourcepub fn with_return_animation_time(self, animation_time: f32) -> Self
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
sourcepub fn with_swap_animation_time(self, animation_time: f32) -> Self
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
sourcepub fn with_animation_time(self, animation_time: f32) -> Self
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
sourcepub fn show<T: DragDropItem>(
self,
items: impl Iterator<Item = T>,
item_ui: impl FnMut(&mut Ui, T, Handle<'_>, ItemState)
) -> DragDropResponse
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.
sourcepub fn show_sized<T: DragDropItem>(
self,
items: impl Iterator<Item = T>,
size: Vec2,
item_ui: impl FnMut(&mut Ui, T, Handle<'_>, ItemState)
) -> DragDropResponse
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.
sourcepub fn show_vec<T: Hash>(
self,
items: &mut [T],
item_ui: impl FnMut(&mut Ui, &mut T, Handle<'_>, ItemState)
) -> DragDropResponse
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.
sourcepub fn show_vec_sized<T: Hash>(
self,
items: &mut [T],
size: Vec2,
item_ui: impl FnMut(&mut Ui, &mut T, Handle<'_>, ItemState)
) -> DragDropResponse
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.
sourcepub fn show_custom(
self,
f: impl FnOnce(&mut Ui, &mut ItemIterator<'_>)
) -> DragDropResponse
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.
sourcepub fn show_custom_vec<T: Hash>(
self,
items: &mut [T],
f: impl FnOnce(&mut Ui, &mut [T], &mut ItemIterator<'_>)
) -> DragDropResponse
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.