mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Add clipboard image paste support (Event::PasteImage) (#8472)
Adds `egui::Event::PasteImage`, emitted on Ctrl+V/Cmd+V when the clipboard holds an image with no usable text representation (mirrors `OutputCommand::CopyImage` for the opposite direction). `egui-winit::Clipboard` gains `get_image()`, backed by `arboard::Clipboard::get_image()` — the symmetric counterpart to the `set_image()` already used for copy. Wired in the winit keyboard-shortcut path and in both the glow and wgpu eframe backends' AccessKit-driven paste action. Straight (unmultiplied) alpha from the OS clipboard is converted via the existing `ColorImage::from_rgba_unmultiplied` helper rather than reinterpreting bytes directly, since the two aren't bit-compatible for translucent pixels. Not covered here: the web (wasm32) target — browser clipboard image reads are inherently async (`Blob::array_buffer` returns a Promise), while `Event::PasteImage` as designed here carries an already-decoded `ColorImage`. Bridging that needs either an async event payload or a deferred/queued event on `AppRunner` — more of a design decision than a small mirrored addition, flagging it rather than guessing. * Related: #2108 (not fixed: web) --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
@@ -831,6 +831,11 @@ impl GlowWinitRunning<'_> {
|
||||
.events
|
||||
.push(egui::Event::Paste(contents));
|
||||
}
|
||||
} else if let Some(image) = egui_winit.clipboard_image() {
|
||||
egui_winit
|
||||
.egui_input_mut()
|
||||
.events
|
||||
.push(egui::Event::PasteImage(std::sync::Arc::new(image)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -838,6 +838,11 @@ impl WgpuWinitRunning<'_> {
|
||||
.events
|
||||
.push(egui::Event::Paste(contents));
|
||||
}
|
||||
} else if let Some(image) = egui_winit.clipboard_image() {
|
||||
egui_winit
|
||||
.egui_input_mut()
|
||||
.events
|
||||
.push(egui::Event::PasteImage(std::sync::Arc::new(image)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user