App/Sources/DiagramCanvas.swift
27 lines · 809 bytes
1 symbol in this file
1import Notation
2import SwiftUI
3
4/// A step's diagram, drawn by Notation's `drawDiagram` on a white ground.
5struct DiagramCanvas: View {
6 let diagram: Diagram
7 let style: DiagramStyle
8
9 init(diagram: Diagram, style: DiagramStyle) {
10 self.diagram = diagram
11 self.style = style
12 }
13
14 var body: some View {
15 Canvas { context, size in
16 context.fill(Path(CGRect(origin: .zero, size: size)), with: .color(.white))
17 context.withCGContext { cg in
18 cg.translateBy(x: 0, y: size.height)
19 cg.scaleBy(x: 1, y: -1)
20 drawDiagram(diagram, style: style, in: cg, size: size)
21 }
22 }
23 .accessibilityElement()
24 .accessibilityAddTraits(.isImage)
25 .accessibilityIdentifier("diagram")
26 }
27}