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 <emil.ernerfeldt@gmail.com>
This commit is contained in:
Chris Cate 2023-11-10 04:49:05 -06:00 committed by GitHub
parent d0ff09ac20
commit 9ee6669f8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 6 deletions

View File

@ -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<Rounding>) -> 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: