Closed imxood closed 1 year ago
It was not possible before. I've now added an index property to the state struct. Can you try and see if this works for you?
Thanks~ It's good, but it is the show's sorted item index, and also should add a index(raw data item)
when I want to delete the choosed item, I need the index(raw data item).
This is working for me:
use eframe::egui;
use egui::CentralPanel;
use egui_dnd::dnd;
pub fn main() -> eframe::Result<()> {
let mut items = vec!["alfred", "bernhard", "christian"];
let mut delete_index = None;
eframe::run_simple_native(
"DnD Simple Example",
Default::default(),
move |ctx, _frame| {
CentralPanel::default().show(ctx, |ui| {
dnd(ui, "dnd_example").show_vec(&mut items, |ui, item, handle, state| {
handle.ui(ui, |ui| {
if state.dragged {
ui.label("dragging");
} else {
ui.label("drag");
}
});
ui.label(*item);
if ui.button("delete").clicked() {
delete_index = Some(state.index);
}
});
});
if let Some(index) = delete_index {
items.remove(index);
delete_index = None;
}
},
)
}
With raw data item, do you mean the items original index, before the sort was changed? If you need that, you should add it as a field to your item type. I don't think it makes sense for egui_dnd to keep track of that.
It is good, thanks very much~
How to get the item index in show_vec?