Struct egui_dnd::DragDropUi
source · pub struct DragDropUi { /* private fields */ }
Expand description
Holds the data needed to draw the floating item while it is being dragged
Implementations§
source§impl DragDropUi
impl DragDropUi
DragDropUi stores the state of the Drag & Drop list.
Example
use egui_dnd::DragDropUi;
use eframe::App;
use eframe::egui::Context;
use eframe::Frame;
use eframe::egui::CentralPanel;
use egui_dnd::utils::shift_vec;
struct DnDApp {
items: Vec<String>,
dnd: DragDropUi,
}
impl App for DnDApp {
fn update(&mut self, ctx: &Context, frame: &mut Frame) {
CentralPanel::default().show(ctx, |ui| {
let response = self.dnd.ui(ui, self.items.iter_mut(), |item, ui, handle| {
ui.horizontal(|ui| {
handle.ui(ui, item, |ui| {
ui.label("grab");
});
ui.label(item.clone());
});
});
if let Some(response) = response.completed {
shift_vec(response.from, response.to, &mut self.items);
}
});
}
}
use eframe::NativeOptions;
let dnd = DragDropUi::default();
eframe::run_native("DnD Example", NativeOptions::default(), Box::new(|_| {
Box::new(DnDApp {
dnd: DragDropUi::default(),
items: vec!["a", "b", "c"].into_iter().map(|s| s.to_string()).collect(),
})
}));
Trait Implementations§
source§impl Clone for DragDropUi
impl Clone for DragDropUi
source§fn clone(&self) -> DragDropUi
fn clone(&self) -> DragDropUi
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Default for DragDropUi
impl Default for DragDropUi
source§fn default() -> DragDropUi
fn default() -> DragDropUi
Returns the “default value” for a type. Read more