.
This commit is contained in:
parent
53e03dcc1d
commit
a41e1f2a79
2 changed files with 14 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::{DevicePixels, Result, SharedString, Size, size};
|
||||
use crate::{DevicePixels, Pixels, Result, SharedString, Size, size};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use image::{Delay, Frame};
|
||||
|
@ -80,6 +80,12 @@ impl RenderImage {
|
|||
size(width.into(), height.into())
|
||||
}
|
||||
|
||||
/// Get the size of this image, in pixels for display, adjusted for the scale factor.
|
||||
pub(crate) fn render_size(&self, frame_index: usize) -> Size<Pixels> {
|
||||
self.size(frame_index)
|
||||
.map(|v| (v.0 as f32 / self.scale_factor).into())
|
||||
}
|
||||
|
||||
/// Get the delay of this frame from the previous
|
||||
pub fn delay(&self, frame_index: usize) -> Delay {
|
||||
self.data[frame_index].delay()
|
||||
|
|
|
@ -332,9 +332,7 @@ impl Element for Img {
|
|||
state.started_loading = None;
|
||||
}
|
||||
|
||||
let image_size = data
|
||||
.size(frame_index)
|
||||
.map(|n| n.0 as f32 / data.scale_factor);
|
||||
let image_size = data.render_size(frame_index);
|
||||
style.aspect_ratio = Some(image_size.width / image_size.height);
|
||||
|
||||
if let Length::Auto = style.size.width {
|
||||
|
@ -342,9 +340,10 @@ impl Element for Img {
|
|||
Length::Definite(DefiniteLength::Absolute(
|
||||
AbsoluteLength::Pixels(height),
|
||||
)) => Length::Definite(
|
||||
px(image_size.width * height.0 / image_size.height).into(),
|
||||
px(image_size.width.0 * height.0 / image_size.height.0)
|
||||
.into(),
|
||||
),
|
||||
_ => Length::Definite(px(image_size.width).into()),
|
||||
_ => Length::Definite(image_size.width.into()),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -353,9 +352,10 @@ impl Element for Img {
|
|||
Length::Definite(DefiniteLength::Absolute(
|
||||
AbsoluteLength::Pixels(width),
|
||||
)) => Length::Definite(
|
||||
px(image_size.height * width.0 / image_size.width).into(),
|
||||
px(image_size.height.0 * width.0 / image_size.width.0)
|
||||
.into(),
|
||||
),
|
||||
_ => Length::Definite(px(image_size.height).into()),
|
||||
_ => Length::Definite(image_size.height.into()),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue