From aa25a934d7eb0f746c2c555c9efcc792fbe6cc5b Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Sun, 14 Jul 2024 05:07:18 +0800 Subject: [PATCH 1/2] Consider the pixels per point --- crates/egui/src/widgets/image.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/egui/src/widgets/image.rs b/crates/egui/src/widgets/image.rs index ab2a10bd6ad..2f1fb35d1c0 100644 --- a/crates/egui/src/widgets/image.rs +++ b/crates/egui/src/widgets/image.rs @@ -326,7 +326,7 @@ impl<'a> Image<'a> { /// # Errors /// May fail if they underlying [`Context::try_load_texture`] call fails. pub fn load_for_size(&self, ctx: &Context, available_size: Vec2) -> TextureLoadResult { - let size_hint = self.size.hint(available_size); + let size_hint = self.size.hint(available_size, ctx.pixels_per_point()); self.source(ctx) .clone() .load(ctx, self.texture_options, size_hint) @@ -431,16 +431,14 @@ impl ImageFit { impl ImageSize { /// Size hint for e.g. rasterizing an svg. - pub fn hint(&self, available_size: Vec2) -> SizeHint { + pub fn hint(&self, available_size: Vec2, pixels_per_point: f32) -> SizeHint { let size = match self.fit { ImageFit::Original { scale } => return SizeHint::Scale(scale.ord()), ImageFit::Fraction(fract) => available_size * fract, ImageFit::Exact(size) => size, }; - let size = size.min(self.max_size); - - // TODO(emilk): take pixels_per_point into account here! + let size = size * pixels_per_point; // `inf` on an axis means "any value" match (size.x.is_finite(), size.y.is_finite()) { From 398728d5c2f5119a1fbc4f3690d6feab3d401d86 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Tue, 16 Jul 2024 01:48:12 +0800 Subject: [PATCH 2/2] Update as suggested --- crates/egui/src/load.rs | 1 + crates/egui/src/widgets/image.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/egui/src/load.rs b/crates/egui/src/load.rs index 71d9d086f56..ee12d8de845 100644 --- a/crates/egui/src/load.rs +++ b/crates/egui/src/load.rs @@ -123,6 +123,7 @@ pub type Result = std::result::Result; /// Given as a hint for image loading requests. /// /// Used mostly for rendering SVG:s to a good size. +/// The size is measured in texels, with the pixels per point already factored in. /// /// All variants will preserve the original aspect ratio. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/crates/egui/src/widgets/image.rs b/crates/egui/src/widgets/image.rs index 2f1fb35d1c0..bf44d398896 100644 --- a/crates/egui/src/widgets/image.rs +++ b/crates/egui/src/widgets/image.rs @@ -445,7 +445,7 @@ impl ImageSize { (true, true) => SizeHint::Size(size.x.round() as u32, size.y.round() as u32), (true, false) => SizeHint::Width(size.x.round() as u32), (false, true) => SizeHint::Height(size.y.round() as u32), - (false, false) => SizeHint::Scale(1.0.ord()), + (false, false) => SizeHint::Scale(pixels_per_point.ord()), } }