Skip to content

Elliptical Rects - #70

Merged
elcritch merged 9 commits into
mainfrom
ellipsed-rects
Jul 30, 2026
Merged

Elliptical Rects#70
elcritch merged 9 commits into
mainfrom
ellipsed-rects

Conversation

@elcritch

@elcritch elcritch commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Extend the core nkRectangle primitive with independent horizontal and vertical radii for each corner. This allows making "elliptical corners" which generalize the circular corners. They can fallback to previous circle forms and the SDF / Shader code is optimized for that case (e.g. rx == ry).

Changes

  • Add the common cornerRadiiY field and NfEllipticalCorners flag while preserving existing circular-corner behavior.
  • Propagate elliptical corners through Metal, OpenGL/GLES, and Vulkan, including:
    • fills and strokes
    • clipping and rectangle masks
    • drop and inner shadows
    • backdrop blur
  • Reuse elliptical rounded rectangles for drawable ellipses, removing the dedicated ellipse shader modes.
  • Keep the existing circular shader path whenever every rx == ry.
  • Consolidate Metal attribute uploads into reusable aligned upload buffers.
  • Add documentation, examples, transfer support, and renderer/backend tests.

Compatibility

Existing nodes remain circular unless NfEllipticalCorners is set. In elliptical mode, corners supplies the X radii and cornerRadiiY supplies the Y radii:

Fig(
  kind: nkRectangle,
  flags: {NfEllipticalCorners},
  corners: [80'u16, 40'u16, 24'u16, 60'u16],
  cornerRadiiY: [28'u16, 64'u16, 12'u16, 36'u16],
)

Setting every X radius to half the rectangle width and every Y radius to half its height produces a filled ellipse.

Fig is now exactly 256 bytes. Circular backend calls remain source-compatible through automatic promotion to equal X/Y axes.

Validation

  • nim r tests/tfignodes_helpers.nim
  • nim r tests/trenderfragments.nim
  • nim r tests/ttransform.nim
  • nim c examples/siwin_cell_grid.nim
  • siwin_cell_grid measured approximately 119.9 FPS using Metal on an Apple M3 Pro.

@elcritch elcritch changed the title Ellipsed rects Elliptical Rects Jul 30, 2026
@elcritch
elcritch merged commit 6ef00c9 into main Jul 30, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant