Git Product home page Git Product logo

Comments (4)

lucasmerlin avatar lucasmerlin commented on June 2, 2024 2

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.

imxood avatar imxood commented on June 2, 2024 1

It is good, thanks very much~

from hello_egui.

lucasmerlin avatar lucasmerlin commented on June 2, 2024

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.

imxood avatar imxood commented on June 2, 2024

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).

image

egui-pnp测试

from hello_egui.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.