Comments (4)
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.
from hello_egui.
It is good, thanks very much~
from hello_egui.
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?
from hello_egui.
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).
from hello_egui.
Related Issues (9)
- Using drag 'n drop with `egui::selectable_value` or the like HOT 11
- Dragging in and out of nested items HOT 1
- egui_dnd: Significant animation jitter HOT 2
- Weird snap animation on drop when using indices as an Id HOT 3
- Drag between two different dnd regions HOT 1
- If the dnd(..).show function chooses to not add a element, the result is a weird gap between list items HOT 4
- Exposing `InfiniteScroll`s `VirtualList` HOT 1
- [egui_dnd] Two elements with same content create conflicts HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hello_egui.