1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 05:10:03 -04:00

Drag and drop files into egui_glium and egui_web (#637)

* Implement file drag-and-drop for egui_glium

* Implement file drag-and-drop into egui_web

* Cleanup
This commit is contained in:
Emil Ernerfeldt
2021-08-20 22:20:45 +02:00
committed by GitHub
parent 488b1f2462
commit a256ca115b
10 changed files with 239 additions and 6 deletions

View File

@@ -266,10 +266,10 @@ pub fn run(mut app: Box<dyn epi::App>, native_options: epi::NativeOptions) {
} else {
// Winit uses up all the CPU of one core when returning ControlFlow::Wait.
// Sleeping here helps, but still uses 1-3% of CPU :(
if is_focused {
if is_focused || !egui.input_state.raw.hovered_files.is_empty() {
std::thread::sleep(std::time::Duration::from_millis(10));
} else {
std::thread::sleep(std::time::Duration::from_millis(100));
std::thread::sleep(std::time::Duration::from_millis(50));
}
}
}
@@ -287,6 +287,7 @@ pub fn run(mut app: Box<dyn epi::App>, native_options: epi::NativeOptions) {
// TODO: ask egui if the events warrants a repaint instead of repainting on each event.
display.gl_window().window().request_redraw();
repaint_asap = true;
}
glutin::event::Event::UserEvent(RequestRepaintEvent) => {
display.gl_window().window().request_redraw();

View File

@@ -255,6 +255,22 @@ pub fn input_to_egui(
},
});
}
WindowEvent::HoveredFile(path) => {
input_state.raw.hovered_files.push(egui::HoveredFile {
path: Some(path.clone()),
..Default::default()
});
}
WindowEvent::HoveredFileCancelled => {
input_state.raw.hovered_files.clear();
}
WindowEvent::DroppedFile(path) => {
input_state.raw.hovered_files.clear();
input_state.raw.dropped_files.push(egui::DroppedFile {
path: Some(path.clone()),
..Default::default()
});
}
_ => {
// dbg!(event);
}