diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2023-05-07 15:22:54 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2023-05-07 15:22:54 +0200 |
| commit | fdb4633d3e9158e457d57e820df6e1efb4df39c2 (patch) | |
| tree | 176cad99cb9befc0a65a7af02561019e811814de /Map/Views/SlowMapRender.swift | |
| parent | 75a0e4509a70055851b085f3f7293ae1cf48164c (diff) | |
Update to support notes + new style2.0.0
Diffstat (limited to 'Map/Views/SlowMapRender.swift')
| -rw-r--r-- | Map/Views/SlowMapRender.swift | 90 |
1 files changed, 0 insertions, 90 deletions
diff --git a/Map/Views/SlowMapRender.swift b/Map/Views/SlowMapRender.swift deleted file mode 100644 index b7cd842..0000000 --- a/Map/Views/SlowMapRender.swift +++ /dev/null @@ -1,90 +0,0 @@ -import Cocoa -import SwiftUI - -class SlowMapRenderController: NSViewController { - - var content: String - private var contentBinding: Binding<String> { - Binding( - get: { self.content }, - set: { content in - self.content = content - } - ) - } - - var evolution: Stage - private var evolutionBinding: Binding<Stage> { - Binding( - get: { self.evolution }, - set: { evolution in - self.evolution = evolution - } - ) - } - private var colorSchemeEnvironment: ObservableColorSchemeEnvironment - - private let debouncer: Debouncer = Debouncer(seconds: 0.1) - - init(content: String, evolution: Stage, colorScheme: ColorScheme) { - - self.content = content - self.evolution = evolution - self.colorSchemeEnvironment = ObservableColorSchemeEnvironment(colorScheme: colorScheme) - super.init(nibName: nil, bundle: nil) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override func loadView() { - - let renderView = MapRenderView(content: self.contentBinding, evolution: self.evolutionBinding) - .environmentObject(self.colorSchemeEnvironment) - let hostingView = NSHostingView(rootView: renderView) - - self.view = hostingView - } - - func update(content: String, evolution: Stage, colorScheme: ColorScheme) { - self.debouncer.debounce { - DispatchQueue.main.async { - print("Updating: START") - self.content = content - self.evolution = evolution - self.colorSchemeEnvironment.colorScheme = colorScheme - print("Updating: END") - } - } - } - - private class ObservableColorSchemeEnvironment: ObservableObject { - @Published var colorScheme: ColorScheme - - init(colorScheme: ColorScheme) { - self.colorScheme = colorScheme - } - } -} - -struct SlowMapRender: NSViewControllerRepresentable { - - var content: String - var evolution: Stage - let colorScheme: ColorScheme - - func makeNSViewController( - context: NSViewControllerRepresentableContext<SlowMapRender> - ) -> SlowMapRenderController { - return SlowMapRenderController(content: content, evolution: evolution, colorScheme: colorScheme) - } - - func updateNSViewController( - _ nsViewController: SlowMapRenderController, - context: NSViewControllerRepresentableContext<SlowMapRender> - ) { - nsViewController.update( - content: content, evolution: evolution, colorScheme: context.environment.colorScheme) - } -} |