Skip to content

Commit

Permalink
Address PR comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
borut-t committed Nov 12, 2024
1 parent 029f995 commit 6c0450a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Sources/UI/SwiftUI/Views/SimpleColorPicker/SimpleColorPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ import SwiftUI
import Combine

/// SwiftUI wrapper for NSColorWell, allowing the selection of colors with a customizable size.
struct SimpleColorPicker: NSViewRepresentable {
public struct SimpleColorPicker: NSViewRepresentable {
@Binding var selection: Color
var size: CGSize?

func makeNSView(context: Context) -> NSColorWell {
public init(selection: Binding<Color>, size: CGSize? = nil) {
self._selection = selection
self.size = size
}

public func makeNSView(context: Context) -> NSColorWell {
let colorWell: NSColorWell
if #available(macOS 13.0, *) {
colorWell = NSColorWell(style: .minimal)
Expand All @@ -38,7 +43,7 @@ struct SimpleColorPicker: NSViewRepresentable {
return colorWell
}

func updateNSView(_ nsView: NSColorWell, context: Context) {
public func updateNSView(_ nsView: NSColorWell, context: Context) {
context.coordinator.colorDidChange = {
selection = Color(nsColor: $0)
}
Expand All @@ -54,12 +59,12 @@ struct SimpleColorPicker: NSViewRepresentable {
}
}

func makeCoordinator() -> Coordinator {
public func makeCoordinator() -> Coordinator {
Coordinator()
}

@MainActor
class Coordinator: NSObject {
public class Coordinator: NSObject {
var colorDidChange: ((NSColor) -> Void)?

private var cancellable: AnyCancellable?
Expand Down

0 comments on commit 6c0450a

Please sign in to comment.