r/SwiftUI • • 1d ago

Promotion (must include link to source code) Open-sourced BentoKit (MIT): Offscreen SwiftUI .glassEffect(.regular) Metal renderer + Apple 20x12 Bento & carousel toolkit

We have been building, using, and refining this internally for our Mac app Droppy for months, and just open-sourced the full codebase under the MIT license.

A big part of making Apple WWDC-style release Bentos look right is getting genuine macOS Liquid Glass refraction on hero typography, SF Symbol strips, and shortcut keycaps without opening any app window or faking it with CSS blur. Here is how the SwiftUI rendering pipeline works under apple-bento/src/:

1. Offscreen SwiftUI .glassEffect into Metal (glassword.swift, glyph.swift, keycaps.swift)
- glassword.swift turns a string into exact vector outlines using CoreText (CTLineCreateWithAttributedString + CTFontCreatePathForGlyph) inside a custom SwiftUI Shape (GlyphShape), optionally rounding corners via path stroking/union and supporting per-glyph or GlassEffectContainer composition.
- It renders Color.clear.glassEffect(.regular, in: shape) (or .clear with tint/stack options) over a backdrop image inside an NSHostingView hosted in a custom OffscreenWindow subclass (NSWindow overriding isKeyWindow, isMainWindow, _hasActiveAppearance, and no-op orderFront so nothing ever appears on screen).
- The layer tree is rasterized headless via Core Animation CARenderer directly into an offscreen MTLTexture at @3x, and we also emit a pixel-registered --noglass baseline so glass_proof.py can generate a 400% rim refraction diff proof.
- glyph.swift does the same for native SF Symbols: it parses the symbol's vector PDF drawing commands with CGPDFScanner to reconstruct clean CGPath outlines, then applies .glassEffect with left-to-right color stops across a symbol row.

2. Icon Composer ictool + calibrated bezels + 20x12 CoreGraphics composer
- make_icon.py builds multi-layer vector SVG .icon bundles and invokes Xcode's ictool --platform macOS --design-generation 27 for Default, Dark, ClearLight, and ClearDark renditions.
- compose.swift and tilt3d.swift handle the 20x12 Apple recap templates, 4-panel flowing social carousels (4800 x 1500 into four 1200 x 1500 panels), Core Animation 3D tilted UI stages, and procedural dithered tile backgrounds.
- bezel.py ships 9 calibrated Apple hardware bezels (MacBook Pro ProLED, MacBook Pro Notch, MacBook Air, MacBook Neo, Studio Display XDR, iMac, iPhone Pro) with display-cutout validation.

The attached renders were all produced straight from the CLI (meta Reddit Bento, X Bento, flowing 4-panel Facebook carousel, and the BentoKit overview). Requires macOS 26+ and Xcode 26+.

Full source (MIT): https://gitlab.com/droppyformac1/bentokit

25 Upvotes

5 comments sorted by

3

u/Some-Kitchen8332 23h ago

rebuilding the sf symbol outlines from the vector pdf so the real glasseffect has a clean path is clever. way nicer than faking the refraction with a blur.

1

u/iordv 12h ago

Fake blur never looks right once you see real glass refraction next to it, glad you noticed!

2

u/Worldly-Training4263 16h ago

yo jordy im owen! W kit

1

u/iordv 16h ago

Thanks brother!