diff options
Diffstat (limited to '')
-rw-r--r-- | runtime/src/window/screenshot.rs | 16 | ||||
-rw-r--r-- | winit/src/application.rs | 1 | ||||
-rw-r--r-- | winit/src/multi_window.rs | 1 |
3 files changed, 15 insertions, 3 deletions
diff --git a/runtime/src/window/screenshot.rs b/runtime/src/window/screenshot.rs index fb318110..d9adbc01 100644 --- a/runtime/src/window/screenshot.rs +++ b/runtime/src/window/screenshot.rs @@ -11,16 +11,20 @@ use std::fmt::{Debug, Formatter}; pub struct Screenshot { /// The bytes of the [`Screenshot`]. pub bytes: Bytes, - /// The size of the [`Screenshot`]. + /// The size of the [`Screenshot`] in physical pixels. pub size: Size<u32>, + /// The scale factor of the [`Screenshot`]. This can be useful when converting between widget + /// bounds (which are in logical pixels) to crop screenshots. + pub scale_factor: f64, } impl Debug for Screenshot { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!( f, - "Screenshot: {{ \n bytes: {}\n size: {:?} }}", + "Screenshot: {{ \n bytes: {}\n scale: {}\n size: {:?} }}", self.bytes.len(), + self.scale_factor, self.size ) } @@ -28,10 +32,15 @@ impl Debug for Screenshot { impl Screenshot { /// Creates a new [`Screenshot`]. - pub fn new(bytes: impl Into<Bytes>, size: Size<u32>) -> Self { + pub fn new( + bytes: impl Into<Bytes>, + size: Size<u32>, + scale_factor: f64, + ) -> Self { Self { bytes: bytes.into(), size, + scale_factor, } } @@ -70,6 +79,7 @@ impl Screenshot { Ok(Self { bytes: Bytes::from(chopped), size: Size::new(region.width, region.height), + scale_factor: self.scale_factor, }) } } diff --git a/winit/src/application.rs b/winit/src/application.rs index f7508b4c..4aed1eee 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -1066,6 +1066,7 @@ pub fn run_command<A, C, E>( proxy.send(tag(window::Screenshot::new( bytes, state.physical_size(), + state.viewport().scale_factor(), ))); } }, diff --git a/winit/src/multi_window.rs b/winit/src/multi_window.rs index 95d78b83..74ab64f2 100644 --- a/winit/src/multi_window.rs +++ b/winit/src/multi_window.rs @@ -1239,6 +1239,7 @@ fn run_command<A, C, E>( proxy.send(tag(window::Screenshot::new( bytes, window.state.physical_size(), + window.state.viewport().scale_factor(), ))); } } |