diff options
author | 2024-05-23 13:29:45 +0200 | |
---|---|---|
committer | 2024-05-23 13:29:45 +0200 | |
commit | d8ba6b0673a33724a177f3a1ba59705527280142 (patch) | |
tree | 89482c8d1e3a03e00b3a8151abbb81e30ae5898c /runtime/src/window | |
parent | 72ed8bcc8def9956e25f3720a3095fc96bb2eef0 (diff) | |
parent | 468794d918eb06c1dbebb33c32b10017ad335f05 (diff) | |
download | iced-d8ba6b0673a33724a177f3a1ba59705527280142.tar.gz iced-d8ba6b0673a33724a177f3a1ba59705527280142.tar.bz2 iced-d8ba6b0673a33724a177f3a1ba59705527280142.zip |
Merge branch 'master' into feat/text-macro
Diffstat (limited to 'runtime/src/window')
-rw-r--r-- | runtime/src/window/action.rs | 2 | ||||
-rw-r--r-- | runtime/src/window/screenshot.rs | 16 |
2 files changed, 12 insertions, 6 deletions
diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index e44ff5a6..07e77872 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -106,7 +106,7 @@ pub enum Action<T> { /// said, it's usually in the same ballpark as on Windows. ChangeIcon(Id, Icon), /// Runs the closure with the native window handle of the window with the given [`Id`]. - RunWithHandle(Id, Box<dyn FnOnce(&WindowHandle<'_>) -> T + 'static>), + RunWithHandle(Id, Box<dyn FnOnce(WindowHandle<'_>) -> T + 'static>), /// Screenshot the viewport of the window. Screenshot(Id, Box<dyn FnOnce(Screenshot) -> T + 'static>), } diff --git a/runtime/src/window/screenshot.rs b/runtime/src/window/screenshot.rs index 21e04718..fb318110 100644 --- a/runtime/src/window/screenshot.rs +++ b/runtime/src/window/screenshot.rs @@ -1,8 +1,8 @@ //! Take screenshots of a window. use crate::core::{Rectangle, Size}; +use bytes::Bytes; use std::fmt::{Debug, Formatter}; -use std::sync::Arc; /// Data of a screenshot, captured with `window::screenshot()`. /// @@ -10,7 +10,7 @@ use std::sync::Arc; #[derive(Clone)] pub struct Screenshot { /// The bytes of the [`Screenshot`]. - pub bytes: Arc<Vec<u8>>, + pub bytes: Bytes, /// The size of the [`Screenshot`]. pub size: Size<u32>, } @@ -28,9 +28,9 @@ impl Debug for Screenshot { impl Screenshot { /// Creates a new [`Screenshot`]. - pub fn new(bytes: Vec<u8>, size: Size<u32>) -> Self { + pub fn new(bytes: impl Into<Bytes>, size: Size<u32>) -> Self { Self { - bytes: Arc::new(bytes), + bytes: bytes.into(), size, } } @@ -68,7 +68,7 @@ impl Screenshot { ); Ok(Self { - bytes: Arc::new(chopped), + bytes: Bytes::from(chopped), size: Size::new(region.width, region.height), }) } @@ -80,6 +80,12 @@ impl AsRef<[u8]> for Screenshot { } } +impl From<Screenshot> for Bytes { + fn from(screenshot: Screenshot) -> Self { + screenshot.bytes + } +} + #[derive(Debug, thiserror::Error)] /// Errors that can occur when cropping a [`Screenshot`]. pub enum CropError { |