Skip to content

Commit a123167

Browse files
committed
More idiomatic layout for image widgit
1 parent 0c0851f commit a123167

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

druid/src/widget/image.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,11 @@ impl<T: Data> Widget<T> for Image {
193193
// in the size exactly. If it is unconstrained by both width and height take the size of
194194
// the image.
195195
let max = bc.max();
196+
let min = bc.min();
196197
let image_size = self.image_data.size();
197-
let size = if bc.is_width_bounded() && !bc.is_height_bounded() {
198-
let ratio = max.width / image_size.width;
199-
Size::new(max.width, ratio * image_size.height)
200-
} else if bc.is_height_bounded() && !bc.is_width_bounded() {
201-
let ratio = max.height / image_size.height;
202-
Size::new(ratio * image_size.width, max.height)
203-
} else {
204-
bc.constrain(self.image_data.size())
205-
};
198+
let width = image_size.width.max(min.width).min(max.width);
199+
let height = image_size.height.max(min.height).min(max.height);
200+
let size = Size::new(width, height);
206201
trace!("Computed size: {}", size);
207202
size
208203
}

0 commit comments

Comments
 (0)