Skip to content

Commit

Permalink
Rework Image::layout
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed Sep 3, 2024
1 parent ee4856f commit 24d19f1
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions masonry/src/widget/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,16 @@ impl Widget for Image {
// If either the width or height is constrained calculate a value so that the image fits
// in the size exactly. If it is unconstrained by both width and height take the size of
// the image.
let max = bc.max();
let image_size = Size::new(self.image_data.width as f64, self.image_data.height as f64);
let size = if bc.is_width_bounded() && !bc.is_height_bounded() {
let ratio = max.width / image_size.width;
Size::new(max.width, ratio * image_size.height)
} else if bc.is_height_bounded() && !bc.is_width_bounded() {
let ratio = max.height / image_size.height;
Size::new(ratio * image_size.width, max.height)
} else {
bc.constrain(image_size)
};
if image_size.is_empty() {
let size = bc.min();
trace!("Computed size: {}", size);
return size;
}
// This size logic has NOT been carefully considered
// TODO: Carefully consider it
let size =
bc.constrain_aspect_ratio(image_size.height / image_size.width, image_size.width);
trace!("Computed size: {}", size);
size
}
Expand Down

0 comments on commit 24d19f1

Please sign in to comment.