summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorLibravatar Shan <shankern@protonmail.com>2024-05-24 19:46:18 -0700
committerLibravatar Shan <shankern@protonmail.com>2024-05-24 19:46:18 -0700
commit647761ad56fbae20c5299296f88c7c88db65c07c (patch)
treefc2f2cda19c503adaff4424fd96a07532ffdc897 /runtime
parent663a081bdd507da0b5ca7d4dc30d78a20b4618af (diff)
downloadiced-647761ad56fbae20c5299296f88c7c88db65c07c.tar.gz
iced-647761ad56fbae20c5299296f88c7c88db65c07c.tar.bz2
iced-647761ad56fbae20c5299296f88c7c88db65c07c.zip
Added scale_factor to `Screenshot` data for use when cropping to widget bounds
Diffstat (limited to 'runtime')
-rw-r--r--runtime/src/window/screenshot.rs16
1 files changed, 13 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,
})
}
}