You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I'm trying to create some "file drop zone" widgets, like user could drag file into the main window and drop to specified widget.
That means there could be multiple widgets in the window which expect a file drop, and ideally I could use Reponse.hovered() to check which widget is actually get the dropped file.
But once the file is dragged into main window, Response.hovered() will always be false.
Here is a minimal code.
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]// hide console window on Windows in releaseuse eframe::egui;fnmain() -> Result<(), eframe::Error>{let options = eframe::NativeOptions{drag_and_drop_support:true,initial_window_size:Some(egui::vec2(800.0,600.0)),
..Default::default()};
eframe::run_native("Dnd test",
options,Box::new(|_cc| Box::new(MyApp::default())),)}#[derive(Default)]structMyApp{mac_path:String,}impl eframe::AppforMyApp{fnupdate(&mutself,ctx:&egui::Context,_frame:&mut eframe::Frame){
egui::CentralPanel::default().show(ctx, |ui| {
ui.label("Mac Pak File");let resp = ui.text_edit_singleline(&mutself.mac_path);let rect = resp.rect.expand(1.0);if !ctx.input(|i| i.raw.hovered_files.is_empty()){if resp.hovered(){
ui.painter().rect_stroke(rect,1.0, ui.visuals().widgets.active.fg_stroke);}}});}}
To Reproduce
Steps to reproduce the behavior:
Drag a file into main window.
Hover that file on text edit.
Expected behavior
A highlight rect will be drawn.
Desktop (please complete the following information):
OS: macOS v13.1
Version: egui 0.21.3
Rust edition: 2021
The text was updated successfully, but these errors were encountered:
It seems that when the egui window (ie winit) doesn't have focus, there is no way to get a pointer position. There is an open issue for winit suggesting as much: rust-windowing/winit#1550. Looks like there is an open PR that addresses this.
One workaround is to use dropped_files instead of hovered_files. If you use dropped_files there is an instance where winit can read both the pointer position (because the window has become active) and the dropped files. In the above example, this change made the whole thing work but only when the mouse is moving when the files are dropped. Not great.
Another workaround might be to store Vec as soon as the mouse enters the screen, then as soon as we receive a pointer position we assume that is where the user wants to drag and drop those files. Also not great but a little better.
Describe the bug
I'm trying to create some "file drop zone" widgets, like user could drag file into the main window and drop to specified widget.
That means there could be multiple widgets in the window which expect a file drop, and ideally I could use Reponse.hovered() to check which widget is actually get the dropped file.
But once the file is dragged into main window, Response.hovered() will always be false.
Here is a minimal code.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A highlight rect will be drawn.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: