From 9ee6669f8fa160eaee5ee7568e95bdc425197b19 Mon Sep 17 00:00:00 2001 From: Chris Cate <3527720+chriscate@users.noreply.github.com> Date: Fri, 10 Nov 2023 04:49:05 -0600 Subject: [PATCH] Fix rounding of `ImageButton` (#3531) * ImageButton rounding fix * remove unnecessary struct creation * added rounding method for ImageButton * grammar fix * simplify the code slightly --------- Co-authored-by: Emil Ernerfeldt --- crates/egui/src/widgets/button.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/egui/src/widgets/button.rs b/crates/egui/src/widgets/button.rs index 4c94cc9d..e11a33b1 100644 --- a/crates/egui/src/widgets/button.rs +++ b/crates/egui/src/widgets/button.rs @@ -594,6 +594,14 @@ impl<'a> ImageButton<'a> { self.sense = sense; self } + + /// Set rounding for the `ImageButton`. + /// If the underlying image already has rounding, this + /// will override that value. + pub fn rounding(mut self, rounding: impl Into) -> Self { + self.image = self.image.rounding(rounding.into()); + self + } } impl<'a> Widget for ImageButton<'a> { @@ -621,7 +629,7 @@ impl<'a> Widget for ImageButton<'a> { let selection = ui.visuals().selection; ( Vec2::ZERO, - Rounding::ZERO, + self.image.image_options().rounding, selection.bg_fill, selection.stroke, ) @@ -630,7 +638,7 @@ impl<'a> Widget for ImageButton<'a> { let expansion = Vec2::splat(visuals.expansion); ( expansion, - visuals.rounding, + self.image.image_options().rounding, visuals.weak_bg_fill, visuals.bg_stroke, ) @@ -646,10 +654,8 @@ impl<'a> Widget for ImageButton<'a> { .layout() .align_size_within_rect(image_size, rect.shrink2(padding)); // let image_rect = image_rect.expand2(expansion); // can make it blurry, so let's not - let image_options = ImageOptions { - rounding, // apply rounding to the image - ..self.image.image_options().clone() - }; + let image_options = self.image.image_options().clone(); + widgets::image::paint_texture_load_result(ui, &tlr, image_rect, None, &image_options); // Draw frame outline: