Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions Demos/Cube/VisionOS/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,36 @@ final class MetalHostView: UIView {

struct ContentView: View {
var body: some View {
CubeHostView()
.ignoresSafeArea()
ZStack(alignment: .bottom) {
// 1. The 3D Vulkan Content Layer
CubeHostView()
.ignoresSafeArea()

// 2. The 2D Spatial UI Layer
VStack(spacing: 20) {
Text("Vulkan Live on visionOS")
.font(.largeTitle)
.fontWeight(.bold)
.foregroundColor(.white)
.padding()
.background(Color.black.opacity(0.5))
.cornerRadius(15)

Button(action: {
// Triggers the C-function to re-initialize swapchain logic
cube_runner_resize()
}) {
Label("Reset View", systemImage: "arrow.counterclockwise")
.font(.headline)
.padding()
.frame(minWidth: 200)
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
}
.padding(.bottom, 50)
}
}
}
}

Expand All @@ -57,16 +85,16 @@ struct CubeHostView: UIViewRepresentable {
view.metalLayer.presentsWithTransaction = false

// Drive rendering
let cADisplayLink = CADisplayLink(target: context.coordinator, selector: #selector(Coordinator.tick))
cADisplayLink.preferredFrameRateRange = CAFrameRateRange(minimum: 30, maximum: 60, preferred: 60)
cADisplayLink.add(to: .main, forMode: .default)
context.coordinator.displayLink = cADisplayLink
let displayLink = CADisplayLink(target: context.coordinator, selector: #selector(Coordinator.tick))
displayLink.preferredFrameRateRange = CAFrameRateRange(minimum: 30, maximum: 60, preferred: 60)
displayLink.add(to: .main, forMode: .default)
context.coordinator.displayLink = displayLink

return view
}

func updateUIView(_ uiView: MetalHostView, context: Context) {
uiView.setNeedsLayout() // layoutSubviews will size & start/resize
uiView.setNeedsLayout()
}

static func dismantleUIView(_ uiView: MetalHostView, coordinator: Coordinator) {
Expand Down