Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure SVGs are crisp #4823

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions crates/egui/src/widgets/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()) {
Expand Down
Loading