TokamakUI / Tokamak

SwiftUI-compatible framework for building browser apps with WebAssembly and native apps for other platforms
Apache License 2.0
2.62k stars 111 forks source link

`Canvas` doesn't draw `Path` when `Path.addRect` is called #473

Open Jomy10 opened 2 years ago

Jomy10 commented 2 years ago

Describe the bug Canvas doesn't draw a Path when Path.addRect is called before adding it to the GraphicsContext using GraphicsContext.fill.

(I have not tested this for other functions on Rect)

To Reproduce For the app:

struct TokamakApp: App {
    var body: some Scene {
        WindowGroup("Tokamak App") {
            ContentView()
        }
    }
}

struct ContentView: View {
    var body: some View {
        Canvas(renderer: renderer)
    }
}

Then for our renderer function:

func renderer(gc: inout GraphicsContext, cSizee: CGSize) {
    var path = Path(CGRect(x: 0, y: 0, width: 10, height: 10))
    path.addRect(CGRect(x: 0, y: 15, width: 10, height: 10))
    gc.fill(path, with: .color(.red))
}

This will not draw the path to the screen (see first screenshot)

If we instead have the following renderer function:

func renderer(gc: inout GraphicsContext, cSizee: CGSize) {
    var path = Path(CGRect(x: 0, y: 0, width: 10, height: 10))
    gc.fill(path, with: .color(.red))
}

Then it does draw to the screen (see second screenshot)

Expected behavior Two rectangles should be drawn to the screen (see third screenshot), but none are being drawn.

Screenshots For the first renderer function:

Schermafbeelding 2022-03-13 om 16 28 15

For the second renderer function:

Schermafbeelding 2022-03-13 om 16 29 23

In SwiftUI using the first renderer function (expected output):

Schermafbeelding 2022-03-13 om 16 30 11

Desktop (please complete the following information):

Additional context None I can think of