Skip to content

feat(gpui): clip a layer to its element's rounded corners - #84

Merged
nolight132 merged 2 commits into
masterfrom
feat/rounded-layers
Nov 29, 2026
Merged

nolight132 merged 2 commits into
masterfrom
feat/rounded-layers

Conversation

@nolight132

Copy link
Copy Markdown
Member

Summary

  • add clip_corners(), which clips an element and everything inside it to the element's rounded corners through an offscreen layer, so pictures and blurs follow the curve rather than a rectangular content mask
  • apply the corner clip in the layer mask of the wgpu, metal and directx renderers, antialiased over one frame pixel at any layer scale

@github-actions github-actions Bot added macos changes the macOS backend windows changes the Windows backend rendering changes the scene, shaders or a renderer labels Nov 29, 2026
@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 46 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Summary

This change adds the Styled::clip_corners() method. It clips an element and its subtree to the element's rounded corners through an offscreen layer, in the wgpu, Metal, and DirectX renderers.

The change adds rounded-corner clipping for filtered layers. A new Styled::clip_corners method enables the option, and Window::with_clipped_filter passes clip bounds and corner radii into layer filters. Metal, WGPU, and DirectX renderers pass this data to their mask shaders, which combine rounded-rectangle coverage with existing fade coverage.

Merge Risk: Low · previous review dae01

Rounded-corner clipping works, but elements that combine corner smoothing with clip_corners will clip their contents to a circular corner rather than the smoothed curve. This is a minor visual mismatch and does not block merging.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Comment thread crates/gpui_apple/src/shaders.metal Outdated
Corners_ScaledPixels corners = params->corners;
if (corners.top_left > 0.0 || corners.top_right > 0.0 || corners.bottom_right > 0.0 ||
corners.bottom_left > 0.0) {
fade *= saturate(0.5 - quad_sdf(source_point, params->clip, corners, 0.0) * params->scale);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Use the element's corner smoothing in the clip.

When corner_smoothing > 0, the element's background and border use a smoothed corner. The style paint path preserves that smoothing, but the layer parameters omit it. This call then forces a circular corner with 0.0. An opaque child can therefore remain visible outside the smoothed silhouette. Carry the smoothing through the filter parameters and use it here and in the WGPU and DirectX mask paths. Keep 0.0 for unsmoothed elements. (raw.githubusercontent.com)

@nolight132
nolight132 merged commit d5f5fe3 into master Nov 29, 2026
3 checks passed
9Vcc added a commit to 9Vcc/WispMusic that referenced this pull request Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

macos changes the macOS backend rendering changes the scene, shaders or a renderer windows changes the Windows backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant