mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-08-31 03:13:40 +00:00
macos: MetalView, render an MTKView
This commit is contained in:
33
macos/Sources/Helpers/MetalView.swift
Normal file
33
macos/Sources/Helpers/MetalView.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
import SwiftUI
|
||||
import MetalKit
|
||||
|
||||
/// Implements the logic for a metal view used by MetalView.
|
||||
protocol MetalViewRenderer: MTKViewDelegate {
|
||||
init(metalView: MTKView)
|
||||
}
|
||||
|
||||
/// Renders an MTKView with the given renderer class.
|
||||
struct MetalView<R: MetalViewRenderer>: View {
|
||||
@State private var metalView = MTKView()
|
||||
@State private var renderer: R?
|
||||
|
||||
var body: some View {
|
||||
MetalViewRepresentable(metalView: $metalView)
|
||||
.onAppear { renderer = R(metalView: metalView) }
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate struct MetalViewRepresentable: NSViewRepresentable {
|
||||
@Binding var metalView: MTKView
|
||||
|
||||
func makeNSView(context: Context) -> some NSView {
|
||||
metalView
|
||||
}
|
||||
|
||||
func updateNSView(_ view: NSViewType, context: Context) {
|
||||
updateMetalView()
|
||||
}
|
||||
|
||||
func updateMetalView() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user