emilk / egui

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
https://www.egui.rs/
Apache License 2.0
21.76k stars 1.57k forks source link

possible regression in 0.28 vs 0.27 in dnd_drag_source #4883

Open 3gx opened 1 month ago

3gx commented 1 month ago

Describe the bug

To Reproduce Steps to reproduce the behavior:

  1. In tutorial https://github.com/emilk/egui/blob/master/crates/egui_demo_lib/src/demo/drag_and_drop.rs#L72C1-L75C1,
    replace
                        let response = ui
                            .dnd_drag_source(item_id, item_location, |ui| {
                                ui.label(item);
                            })
                            .response;

with

                        let response = ui
                            .dnd_drag_source(item_id, item_location, |ui| {
                                ui.vertical(|ui| {
                                  ui.label("--");
                                  ui.label(item);
                                 });
                            })
                            .response;
  1. Click on it

  2. Error

    
    thread 'main' panicked at /Users/egx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/egui-0.28.1/src/widget_rect.rs:142:17:
    Widget changed layer_id during the frame
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    thread 'main' panicked at /Users/egx/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/macos/app_state.rs:387:33:
    called `Result::unwrap()` on an `Err` value: PoisonError { .. }


**Expected behavior**
Can be dragged with 0.27

**Screenshots**
<!-- If applicable, add screenshots to help explain your problem. -->

**Desktop (please complete the following information):**
 - OS: MacOS 14.5
HactarCE commented 1 month ago

I'm experiencing this in my app, but I'm able to use ui.push_id() as a workaround. I can elaborate if anyone would like more details.

3gx commented 3 weeks ago

I'm experiencing this in my app, but I'm able to use ui.push_id() as a workaround. I can elaborate if anyone would like more details.

Yes, I would appreciate if you can share your workaround. Than you.

HactarCE commented 2 weeks ago

@3gx I'm using my own version of egui's drag-and-drop API but the solution can probably be adapted to work. Try ui.dnd_drag_source(item_id, item_location, |ui| ui.push_id(id, |ui| ...)) (with some unique id).