emilk / emilk/egui

dnd_drag_source zones take priority over interior input widgets

Open
#5,822 2 comments 1 reaction 0 assignees View on GitHub
bug egui
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
72

Description

**Describe the bug**
I am trying to make an application with some widgets that can be dragged to be reordered. I'm using a `dnd_drag_source` to make the element draggable. All of this works as expected.

What doesn't work as expected is that I have some input elements on the draggable widgets. These work as expected except for when inside a `dnd_drag_source` element. When inside, they become very difficult to click, because most of their surface area is seemingly intercepted by the `dnd_drag_source`, with the only exception being the border of the widgets.

Is there a better way to make elements that can be dragged and dropped within a column (similar to the drag and drop demo found [here](https://github.com/emilk/egui/blob/master/crates/egui_demo_lib/src/demo/drag_and_drop.rs) that contain other input elements, or can this be considered a bug? at the very least I think this behavior is surprising/unexpected.

**To Reproduce**
Here is some minimal code that reproduces the behavior:
```rust
use eframe::egui;

#[derive(Debug, Default)]
pub struct DragTest {
my_entry: String,
}

impl eframe::App for DragTest {
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
eframe::egui::CentralPanel::default().show(ctx, |ui| {
ui.dnd_drag_source("drag_id".into(), (), |ui| {
eframe::egui::Frame::new()
.fill(ui.style().visuals.widgets.inactive.bg_fill)
.show(ui, |ui| {
ui.add_space(25.0);
ui.text_edit_singleline(&mut self.my_entry);
ui.add_space(25.0);
if ui.button("click me").clicked() {
println!("clicked!")
}
ui.add_space(25.0);
})
})
});
}
}

fn main() -> Result<(), eframe::Error> {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([640.0, 480.0]),
..Default::default()
};

eframe::run_native(
"Drag Test",
options,
Box::new(|_| Ok(Box::new(DragTest::default()))),
)?;
Ok(())
}
```

**Expected behavior**
The widgets should be draggable when clicked and dragged outside of any interior widget's areas, but clicking on interior widgets should interact with them first/exclusively

**Screenshots**
![Image](https://github.com/user-attachments/assets/c2b33268-e681-40a3-8735-789a67ca2c1d)

**Desktop (please complete the following information):**
- OS: Endeavor OS (reproducible on others)
- Browser N/A
- Version Latest master ([a2afc8d](https://github.com/emilk/egui/commit/a2afc8d092a4e3f0b17675b114db8fad08810947))

**Additional context**
I can make the repo where I discovered this problem public if that would help, but it is currently set to private as it's generally not ready to share yet.

Contributor guide

Open the contributing guide

Research direction

Start with the minimal Rust reproduction in the issue and compare it with crates/egui_demo_lib/src/demo/drag_and_drop.rs. Read the dnd_drag_source input-handling path and verify how interior text fields and buttons compete with the drag zone. Done means interior widgets receive clicks and text input, while dragging still starts from non-widget areas.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.