Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Use smaller quads to draw borders
Antonio Scandurrac03c0d50d5f2
diff --git a/crates/gpui2/src/geometry.rs b/crates/gpui2/src/geometry.rsindex f58435d7b9a..6b4d9ae807b 100644--- a/crates/gpui2/src/geometry.rs+++ b/crates/gpui2/src/geometry.rs@@ -1590,6 +1590,15 @@ impl Edges<Pixels> {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<Edges<Pixels>> for f32 {@@ -1740,6 +1749,18 @@ impl Corners<Pixels> {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<T: Clone + Default + Debug> Corners<T> {diff --git a/crates/gpui2/src/style.rs b/crates/gpui2/src/style.rsindex 3e9593b0fd6..de54da79b3d 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.rsindex e57984fa0d0..c20e2f7b94a 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<Pixels>,corner_radii: Corners<Pixels>,