Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Merge branch 'main' into fix/2095-android-menus

Michael Higginse9c1232ce7f8
diff --cc apps/photocraft-web/src/web.rs
index b855befb8,6fd362048..07cd79b6b
--- a/apps/photocraft-web/src/web.rs
+++ b/apps/photocraft-web/src/web.rs
@@@ -283,25 -322,28 +322,34 @@@ impl WebShell
}
impl eframe::App for WebShell {
+ fn raw_input_hook(&mut self, ctx: &egui::Context, raw_input: &mut egui::RawInput) {
+ // A tap reaches eframe as Pointer Events and Touch Events: keep one press per tap, or the
+ // twin press closes the menu the first one opened (#2095).
+ photocraft_ui_egui::touch_twins::drop_twins(ctx, raw_input);
+ }
+
fn logic(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
let dropped = ctx.input_mut(|i| std::mem::take(&mut i.raw.dropped_files));
- for f in dropped {
- let inbox = self.inbox.clone();
+ if !dropped.is_empty() {
+ let names: Vec<String> =
+ dropped.iter().map(|f| f.path().file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_else(|| "dropped".into())).collect();
+ // Decided now, where the drop landed: on the document's canvas the files are placed
+ // as layers (as on the desktop), elsewhere opened.
+ let places = self.app.dropped_on_canvas(ctx, &names);
+ let files: Vec<_> = dropped.into_iter().zip(names).zip(places).collect();
+ let (inbox, place_inbox) = (self.inbox.clone(), self.place_inbox.clone());
let ctx = ctx.clone();
+ // One after another, so they open or place in the order they were dropped.
wasm_bindgen_futures::spawn_local(async move {
- let name = f.path().file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_else(|| "dropped".into());
- match f.bytes_async().await {
- Ok(bytes) => {
- inbox.lock().unwrap_or_else(|e| e.into_inner()).push((name, bytes));
- ctx.request_repaint();
+ for ((f, name), place) in files {
+ match f.bytes_async().await {
+ Ok(bytes) => {
+ let queue = if place { &place_inbox } else { &inbox };
+ queue.lock().unwrap_or_else(|e| e.into_inner()).push((name, bytes));
+ ctx.request_repaint();
+ }
+ Err(e) => log::error!("couldn't read dropped file {name}: {e}"),
}
- Err(e) => log::error!("couldn't read dropped file {name}: {e}"),
}
});
}