mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
Add Context::copy_image (#5533)
* Closes https://github.com/emilk/egui/issues/5424 This adds support for copying images to the system clipboard on native and on web using `Context::copy_image`.
This commit is contained in:
@@ -1439,13 +1439,22 @@ impl Context {
|
||||
|
||||
/// Copy the given text to the system clipboard.
|
||||
///
|
||||
/// Note that in wasm applications, the clipboard is only accessible in secure contexts (e.g.,
|
||||
/// Note that in web applications, the clipboard is only accessible in secure contexts (e.g.,
|
||||
/// HTTPS or localhost). If this method is used outside of a secure context, it will log an
|
||||
/// error and do nothing. See <https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts>.
|
||||
pub fn copy_text(&self, text: String) {
|
||||
self.send_cmd(crate::OutputCommand::CopyText(text));
|
||||
}
|
||||
|
||||
/// Copy the given image to the system clipboard.
|
||||
///
|
||||
/// Note that in web applications, the clipboard is only accessible in secure contexts (e.g.,
|
||||
/// HTTPS or localhost). If this method is used outside of a secure context, it will log an
|
||||
/// error and do nothing. See <https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts>.
|
||||
pub fn copy_image(&self, image: crate::ColorImage) {
|
||||
self.send_cmd(crate::OutputCommand::CopyImage(image));
|
||||
}
|
||||
|
||||
/// Format the given shortcut in a human-readable way (e.g. `Ctrl+Shift+X`).
|
||||
///
|
||||
/// Can be used to get the text for [`crate::Button::shortcut_text`].
|
||||
|
||||
@@ -85,11 +85,14 @@ pub struct IMEOutput {
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||
pub enum OutputCommand {
|
||||
/// Put this text in the system clipboard.
|
||||
/// Put this text to the system clipboard.
|
||||
///
|
||||
/// This is often a response to [`crate::Event::Copy`] or [`crate::Event::Cut`].
|
||||
CopyText(String),
|
||||
|
||||
/// Put this image to the system clipboard.
|
||||
CopyImage(crate::ColorImage),
|
||||
|
||||
/// Open this url in a browser.
|
||||
OpenUrl(OpenUrl),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user