Implement DisplayNode drawing

This commit is contained in:
Guille Gonzalez
2026-01-03 20:51:53 +01:00
parent a80b1ea3db
commit 55abc5b2bd
4 changed files with 265 additions and 11 deletions

View File

@@ -0,0 +1,27 @@
import SwiftUI
extension GraphicsContext {
func draw(_ displayNode: Math.DisplayNode, size: CGSize, foregroundColor: Color) {
var context = self
context.translateBy(x: 0, y: size.height)
context.scaleBy(x: 1, y: -1)
let foregroundColor = foregroundColor.resolve(in: environment).cgColor
context.withCGContext { cgContext in
cgContext.draw(displayNode, foregroundColor: foregroundColor)
}
}
func draw(_ displayNode: Math.DisplayNode, size: CGSize, with shading: GraphicsContext.Shading) {
var context = self
context.fill(Path(CGRect(origin: .zero, size: size)), with: shading)
context.blendMode = .destinationIn
context.drawLayer {
$0.draw(displayNode, size: size, foregroundColor: .black)
}
}
}