diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index 903f03c..1c41f86 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -4931,12 +4931,37 @@ impl Window { continue; } let shadow_bounds = (bounds + shadow.offset).dilate(shadow.spread_radius); + // The spread grows the rounded corners with the box, as CSS does, so a ring drawn + // with a spread keeps one width around the corners. A square corner stays square, + // and a corner rounded less than the spread grows by less, so it does not jump to + // the full spread. + let spread = |radius: Pixels| { + let reach = shadow.spread_radius; + if radius <= Pixels::ZERO { + return radius; + } + if reach <= Pixels::ZERO { + return (radius + reach).max(Pixels::ZERO); + } + let ratio = radius / reach; + let grow = match ratio < 1. { + true => reach * (1. + (ratio - 1.).powi(3)), + false => reach, + }; + radius + grow + }; + let shadow_corner_radii = Corners { + top_left: spread(corner_radii.top_left), + top_right: spread(corner_radii.top_right), + bottom_right: spread(corner_radii.bottom_right), + bottom_left: spread(corner_radii.bottom_left), + }; self.next_frame.scene.insert_primitive(Shadow { order: 0, blur_radius: shadow.blur_radius.scale(scale_factor), bounds: self.cover_bounds(shadow_bounds), content_mask, - corner_radii: corner_radii.scale(scale_factor), + corner_radii: shadow_corner_radii.scale(scale_factor), color: shadow.color.opacity(opacity), element_bounds, element_corner_radii,