diff --git a/crates/gpui2/src/geometry.rs b/crates/gpui2/src/geometry.rs index f58435d7b9..6b4d9ae807 100644 --- a/crates/gpui2/src/geometry.rs +++ b/crates/gpui2/src/geometry.rs @@ -1590,6 +1590,15 @@ impl Edges { left: self.left.scale(factor), } } + + /// Returns the maximum value of any edge. + /// + /// # Returns + /// + /// The maximum `Pixels` value among all four edges. + pub fn max(&self) -> Pixels { + self.top.max(self.right).max(self.bottom).max(self.left) + } } impl Into> for f32 { @@ -1740,6 +1749,18 @@ impl Corners { bottom_left: self.bottom_left.scale(factor), } } + + /// Returns the maximum value of any corner. + /// + /// # Returns + /// + /// The maximum `Pixels` value among all four corners. + pub fn max(&self) -> Pixels { + self.top_left + .max(self.top_right) + .max(self.bottom_right) + .max(self.bottom_left) + } } impl Corners { diff --git a/crates/gpui2/src/style.rs b/crates/gpui2/src/style.rs index 3e9593b0fd..de54da79b3 100644 --- a/crates/gpui2/src/style.rs +++ b/crates/gpui2/src/style.rs @@ -402,13 +402,65 @@ impl Style { if self.is_border_visible() { cx.with_z_index(3, |cx| { - cx.paint_quad(quad( + let corner_radii = self.corner_radii.to_pixels(bounds.size, rem_size); + let border_widths = self.border_widths.to_pixels(rem_size); + let max_border_width = border_widths.max(); + let max_corner_radius = corner_radii.max(); + + let top_bounds = Bounds::from_corners( + bounds.origin, + bounds.upper_right() + + point(Pixels::ZERO, max_border_width.max(max_corner_radius)), + ); + let bottom_bounds = Bounds::from_corners( + bounds.lower_left() + - point(Pixels::ZERO, max_border_width.max(max_corner_radius)), + bounds.lower_right(), + ); + let left_bounds = Bounds::from_corners( + top_bounds.lower_left(), + bottom_bounds.origin + point(max_border_width, Pixels::ZERO), + ); + let right_bounds = Bounds::from_corners( + top_bounds.lower_right() - point(max_border_width, Pixels::ZERO), + bottom_bounds.upper_right(), + ); + + let quad = quad( bounds, - self.corner_radii.to_pixels(bounds.size, rem_size), + corner_radii, Hsla::transparent_black(), - self.border_widths.to_pixels(rem_size), + border_widths, self.border_color.unwrap_or_default(), - )); + ); + + cx.with_content_mask(Some(ContentMask { bounds: top_bounds }), |cx| { + cx.paint_quad(quad.clone()); + }); + cx.with_content_mask( + Some(ContentMask { + bounds: right_bounds, + }), + |cx| { + cx.paint_quad(quad.clone()); + }, + ); + cx.with_content_mask( + Some(ContentMask { + bounds: bottom_bounds, + }), + |cx| { + cx.paint_quad(quad.clone()); + }, + ); + cx.with_content_mask( + Some(ContentMask { + bounds: left_bounds, + }), + |cx| { + cx.paint_quad(quad); + }, + ); }); } diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index e57984fa0d..c20e2f7b94 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -3074,6 +3074,7 @@ impl From<(&'static str, u64)> for ElementId { } /// A rectangle, to be rendered on the screen by GPUI at the given position and size. +#[derive(Clone)] pub struct PaintQuad { bounds: Bounds, corner_radii: Corners,