mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Store web_sys::File inside of DroppedFile (#8354)
* Closes #4654 * Related #4667 * [x] I have followed the instructions in the PR template This PR avoids materializing the contents of a file that was dragged into an egui application on the web. It does so by storing the `web_sys::File` handle directly on WASM. This breaks the existing API of `DroppedFile` on the web, because there is no way to retrieve the bytes synchronously form a `DroppedFile` anymore, forcing handling call sites to become asynchronous. The native API remains the same. --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
@@ -21,6 +21,7 @@ use egui::{Pos2, Rect, Theme, Vec2, ViewportBuilder, ViewportCommand, ViewportId
|
||||
pub use winit;
|
||||
|
||||
pub mod clipboard;
|
||||
mod dropped_file;
|
||||
mod safe_area;
|
||||
mod window_settings;
|
||||
|
||||
@@ -28,6 +29,8 @@ pub use window_settings::WindowSettings;
|
||||
|
||||
use raw_window_handle::HasDisplayHandle;
|
||||
|
||||
use dropped_file::NativeFile;
|
||||
|
||||
use winit::{
|
||||
dpi::{PhysicalPosition, PhysicalSize},
|
||||
event::ElementState,
|
||||
@@ -470,10 +473,9 @@ impl State {
|
||||
}
|
||||
WindowEvent::DroppedFile(path) => {
|
||||
self.egui_input.hovered_files.clear();
|
||||
self.egui_input.dropped_files.push(egui::DroppedFile {
|
||||
path: Some(path.clone()),
|
||||
..Default::default()
|
||||
});
|
||||
self.egui_input
|
||||
.dropped_files
|
||||
.push(std::sync::Arc::new(NativeFile::from(path.clone())));
|
||||
EventResponse {
|
||||
repaint: true,
|
||||
consumed: false,
|
||||
|
||||
Reference in New Issue
Block a user