From 33eec3926810b421135235da19eae104d5e546a0 Mon Sep 17 00:00:00 2001 From: Ashley Wulber <48420062+wash2@users.noreply.github.com> Date: Sat, 15 Jun 2024 16:04:42 -0400 Subject: [PATCH] fix: border artifacts in button and input --- src/widget/button/widget.rs | 61 +++++++++++++++++++--------------- src/widget/text_input/input.rs | 1 + 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/widget/button/widget.rs b/src/widget/button/widget.rs index 427a1917..49f0677b 100644 --- a/src/widget/button/widget.rs +++ b/src/widget/button/widget.rs @@ -388,21 +388,27 @@ impl<'a, Message: 'a + Clone> Widget text_color.a = alpha; } - draw::<_, crate::Theme>(renderer, bounds, &styling, |renderer, _styling| { - self.content.as_widget().draw( - &tree.children[0], - renderer, - theme, - &renderer::Style { - icon_color, - text_color, - scale_factor: renderer_style.scale_factor, - }, - content_layout, - cursor, - &bounds, - ); - }); + draw::<_, crate::Theme>( + renderer, + bounds, + &styling, + |renderer, _styling| { + self.content.as_widget().draw( + &tree.children[0], + renderer, + theme, + &renderer::Style { + icon_color, + text_color, + scale_factor: renderer_style.scale_factor, + }, + content_layout, + cursor, + &bounds, + ); + }, + matches!(self.variant, Variant::Image { .. }), + ); if let Variant::Image { close_icon, @@ -744,6 +750,7 @@ pub fn draw( bounds: Rectangle, styling: &super::style::Appearance, draw_contents: impl FnOnce(&mut Renderer, &Appearance), + is_image: bool, ) where Theme: super::style::StyleSheet, { @@ -814,18 +821,20 @@ pub fn draw( renderer.with_layer(clipped_bounds, |renderer| { // NOTE: Workaround to round the border of the hovered/selected image. - renderer.fill_quad( - renderer::Quad { - bounds, - border: Border { - width: styling.border_width, - color: crate::theme::active().current_container().base.into(), - radius: 0.0.into(), + if is_image { + renderer.fill_quad( + renderer::Quad { + bounds, + border: Border { + width: styling.border_width, + color: crate::theme::active().current_container().base.into(), + radius: 0.0.into(), + }, + shadow: Shadow::default(), }, - shadow: Shadow::default(), - }, - Color::TRANSPARENT, - ); + Color::TRANSPARENT, + ); + } // Finish by drawing the border above the contents. renderer.fill_quad( diff --git a/src/widget/text_input/input.rs b/src/widget/text_input/input.rs index 2917ce6d..96930791 100644 --- a/src/widget/text_input/input.rs +++ b/src/widget/text_input/input.rs @@ -2071,6 +2071,7 @@ pub fn draw<'a, Message>( renderer::Quad { bounds, border: Border { + radius: appearance.border_radius, width: appearance.border_width, ..Default::default() },