diff --git a/Sources/ColorWellKit/Views/Cocoa/ColorWell.swift b/Sources/ColorWellKit/Views/Cocoa/ColorWell.swift index 60938d2..e8a167f 100644 --- a/Sources/ColorWellKit/Views/Cocoa/ColorWell.swift +++ b/Sources/ColorWellKit/Views/Cocoa/ColorWell.swift @@ -18,6 +18,8 @@ public class ColorWell: _ColorWellBaseControl { private var isExclusive = true + var _popoverConfiguration: _PopoverConfiguration? = .default + /// The color well's delegate object. public weak var delegate: ColorWellDelegate? @@ -32,20 +34,6 @@ public class ColorWell: _ColorWellBaseControl { @objc dynamic public var allowsMultipleSelection: Bool = true - /// A configuration that specifies the appearance of the user-selectable - /// swatches in the color well’s popover. - /// - /// If the ``secondaryAction`` and ``secondaryTarget`` properties have - /// been set, the action specified by those properties will be invoked - /// instead of the popover being shown. - /// - /// If this value is `nil`, and the secondary action and target properties - /// have not been set, the color well will not show its popover, and will - /// instead defer to opening the system color panel. - /// - /// The default value of this property is ``PopoverConfiguration-swift.struct/default``. - public var popoverConfiguration: PopoverConfiguration? = .default - /// The action to perform when the color area of the color well is pressed. /// /// By default, color wells with the ``Style-swift.enum/minimal`` or @@ -215,7 +203,7 @@ public class ColorWell: _ColorWellBaseControl { return false } guard - let popoverConfiguration, + let popoverConfiguration = _popoverConfiguration, layoutView.segments.contains(segment) else { return false @@ -289,3 +277,24 @@ public class ColorWell: _ColorWellBaseControl { } } } + +// MARK: Deprecated +extension ColorWell { + /// A configuration that specifies the appearance of the user-selectable + /// swatches in the color well’s popover. + /// + /// If the ``secondaryAction`` and ``secondaryTarget`` properties have + /// been set, the action specified by those properties will be invoked + /// instead of the popover being shown. + /// + /// If this value is `nil`, and the secondary action and target properties + /// have not been set, the color well will not show its popover, and will + /// instead defer to opening the system color panel. + /// + /// The default value of this property is ``PopoverConfiguration-swift.struct/default``. + @available(*, deprecated, message: "Use the color well's 'secondaryAction' to create a custom popover.") + public var popoverConfiguration: PopoverConfiguration? { + get { _popoverConfiguration } + set { _popoverConfiguration = newValue } + } +} diff --git a/Sources/ColorWellKit/Views/Cocoa/Layout/Segments/ColorWellPullDownSwatchSegment.swift b/Sources/ColorWellKit/Views/Cocoa/Layout/Segments/ColorWellPullDownSwatchSegment.swift index e184437..3997abb 100644 --- a/Sources/ColorWellKit/Views/Cocoa/Layout/Segments/ColorWellPullDownSwatchSegment.swift +++ b/Sources/ColorWellKit/Views/Cocoa/Layout/Segments/ColorWellPullDownSwatchSegment.swift @@ -23,7 +23,7 @@ class ColorWellPullDownSwatchSegment: ColorWellSwatchSegment { // perform further checks return true } - if let popoverConfiguration = colorWell.popoverConfiguration { + if let popoverConfiguration = colorWell._popoverConfiguration { // we have a configuration; make sure it has colors return !popoverConfiguration.colors.isEmpty } diff --git a/Sources/ColorWellKit/Views/Cocoa/Popover/ColorWellPopover+Layout.swift b/Sources/ColorWellKit/Views/Cocoa/Popover/ColorWellPopover+Layout.swift index 9c49e6b..066f906 100644 --- a/Sources/ColorWellKit/Views/Cocoa/Popover/ColorWellPopover+Layout.swift +++ b/Sources/ColorWellKit/Views/Cocoa/Popover/ColorWellPopover+Layout.swift @@ -72,7 +72,7 @@ extension ColorWellPopover.LayoutView { class SwatchLayout: NSGridView { // swiftlint:disable:next nesting - typealias Configuration = ColorWell.PopoverConfiguration + typealias Configuration = ColorWell._PopoverConfiguration // swiftlint:disable:next nesting typealias ColorSwatch = ColorWellPopover.ColorSwatch @@ -255,7 +255,7 @@ extension ColorWellPopover.LayoutView.SwatchLayout { class SelectionIndicator: NSView { // swiftlint:disable:next nesting - typealias SwatchShape = ColorWell.PopoverConfiguration.SwatchShape + typealias SwatchShape = ColorWell._PopoverConfiguration.SwatchShape fileprivate var borderWidth: CGFloat = 0 { didSet { diff --git a/Sources/ColorWellKit/Views/Cocoa/Popover/ColorWellPopover.swift b/Sources/ColorWellKit/Views/Cocoa/Popover/ColorWellPopover.swift index cea8d22..56782c6 100644 --- a/Sources/ColorWellKit/Views/Cocoa/Popover/ColorWellPopover.swift +++ b/Sources/ColorWellKit/Views/Cocoa/Popover/ColorWellPopover.swift @@ -7,7 +7,7 @@ import AppKit /// A popover that contains a grid of selectable color swatches. class ColorWellPopover: NSPopover { - typealias Configuration = ColorWell.PopoverConfiguration + typealias Configuration = ColorWell._PopoverConfiguration private weak var colorWell: ColorWell? diff --git a/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/ContentLayout.swift b/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/ContentLayout.swift index b5b80f8..891d502 100644 --- a/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/ContentLayout.swift +++ b/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/ContentLayout.swift @@ -5,7 +5,7 @@ import CoreGraphics -extension ColorWell.PopoverConfiguration { +extension ColorWell._PopoverConfiguration { /// A type that configures the layout of a popover's content view. public struct ContentLayout { // swiftlint:disable:next nesting @@ -162,13 +162,13 @@ extension ColorWell.PopoverConfiguration { } // MARK: ContentLayout: Equatable -extension ColorWell.PopoverConfiguration.ContentLayout: Equatable { } +extension ColorWell._PopoverConfiguration.ContentLayout: Equatable { } // MARK: ContentLayout: Hashable -extension ColorWell.PopoverConfiguration.ContentLayout: Hashable { } +extension ColorWell._PopoverConfiguration.ContentLayout: Hashable { } // MARK: Deprecated -extension ColorWell.PopoverConfiguration { +extension ColorWell._PopoverConfiguration { /// A type that configures the layout of a popover's content view. @available(*, deprecated, renamed: "ContentLayout") public typealias Layout = ContentLayout diff --git a/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/PopoverConfiguration.swift b/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/PopoverConfiguration.swift index 957b0e9..4723b5f 100644 --- a/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/PopoverConfiguration.swift +++ b/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/PopoverConfiguration.swift @@ -8,7 +8,10 @@ import AppKit extension ColorWell { /// A type that specifies the appearance and behavior of /// a color well's popover. - public struct PopoverConfiguration { + @available(*, deprecated, message: "Use the color well's 'secondaryAction' to create a custom popover.") + public typealias PopoverConfiguration = _PopoverConfiguration + + public struct _PopoverConfiguration { /// The colors that are displayed as swatches inside /// the popover. public var colors: [NSColor] @@ -95,14 +98,14 @@ extension ColorWell { swatchSize: NSSize? = nil, swatchShape: SwatchShape = .rectangle, borderEffect: SwatchBorderEffect = .default - ) -> PopoverConfiguration { + ) -> Self { guard let path = bundle.path(forResource: name, ofType: "clr"), let colorList = NSColorList(name: name, fromFile: path) else { preconditionFailure("Failed to load color list resource.") } - return PopoverConfiguration( + return Self( colorList: colorList, contentLayout: contentLayout, swatchSize: swatchSize, @@ -115,7 +118,7 @@ extension ColorWell { /// /// This configuration specifies a small grid of color swatches with 6 /// columns of colors across the color spectrum. - public static let `default`: PopoverConfiguration = _loadColorListResource( + public static let `default`: Self = _loadColorListResource( name: "DefaultColors", bundle: .module, contentLayout: .grid(columnCount: 6).padding(minLength: 7.5, maxLength: 10), @@ -126,7 +129,7 @@ extension ColorWell { /// A configuration that specifies a grid of color swatches with 12 columns /// of colors across the color spectrum, and a row of common colors across /// the top. - public static let standard: PopoverConfiguration = _loadColorListResource( + public static let standard: Self = _loadColorListResource( name: "StandardColors", bundle: .module, contentLayout: .grid(columnCount: 12, topRowSpacing: 4), @@ -135,7 +138,7 @@ extension ColorWell { /// A configuration that specifies a single row of color swatches consisting /// of some of the most common colors. - public static let simple: PopoverConfiguration = { + public static let simple: Self = { let hexStrings = [ "FF0000", // red "FF8000", // orange @@ -153,7 +156,7 @@ extension ColorWell { let colors = hexStrings.compactMap { string in NSColor(hexString: string) } - return PopoverConfiguration( + return Self( colors: colors, contentLayout: .grid(columnCount: 12, horizontalSpacing: 2.5), swatchSize: NSSize(width: 20, height: 20), @@ -221,7 +224,7 @@ extension ColorWell { } // MARK: PopoverConfiguration: Equatable -extension ColorWell.PopoverConfiguration: Equatable { +extension ColorWell._PopoverConfiguration: Equatable { public static func == (lhs: Self, rhs: Self) -> Bool { lhs.colors == rhs.colors && lhs.contentLayout == rhs.contentLayout && @@ -233,7 +236,7 @@ extension ColorWell.PopoverConfiguration: Equatable { } // MARK: PopoverConfiguration: Hashable -extension ColorWell.PopoverConfiguration: Hashable { +extension ColorWell._PopoverConfiguration: Hashable { public func hash(into hasher: inout Hasher) { hasher.combine(colors) hasher.combine(contentLayout) @@ -245,7 +248,7 @@ extension ColorWell.PopoverConfiguration: Hashable { } // MARK: Deprecated -extension ColorWell.PopoverConfiguration { +extension ColorWell._PopoverConfiguration { /// The layout of the popover's content view. @available(*, deprecated, renamed: "contentLayout") public var layout: Layout { diff --git a/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/SwatchBorderEffect.swift b/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/SwatchBorderEffect.swift index 25a1f10..a87ca2e 100644 --- a/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/SwatchBorderEffect.swift +++ b/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/SwatchBorderEffect.swift @@ -5,7 +5,7 @@ import AppKit -extension ColorWell.PopoverConfiguration { +extension ColorWell._PopoverConfiguration { /// A type that applies an effect to the border color of a swatch. public struct SwatchBorderEffect { @@ -159,7 +159,7 @@ extension ColorWell.PopoverConfiguration { } // MARK: SwatchBorderEffect: Equatable -extension ColorWell.PopoverConfiguration.SwatchBorderEffect: Equatable { } +extension ColorWell._PopoverConfiguration.SwatchBorderEffect: Equatable { } // MARK: SwatchBorderEffect: Hashable -extension ColorWell.PopoverConfiguration.SwatchBorderEffect: Hashable { } +extension ColorWell._PopoverConfiguration.SwatchBorderEffect: Hashable { } diff --git a/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/SwatchShape.swift b/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/SwatchShape.swift index c0f77ee..2ca532c 100644 --- a/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/SwatchShape.swift +++ b/Sources/ColorWellKit/Views/Cocoa/PopoverConfiguration/SwatchShape.swift @@ -5,7 +5,7 @@ import CoreGraphics -extension ColorWell.PopoverConfiguration { +extension ColorWell._PopoverConfiguration { /// An algorithm that specifies the shape for swatches displayed inside /// a color well's popover. public struct SwatchShape { @@ -115,7 +115,7 @@ extension ColorWell.PopoverConfiguration { } // MARK: SwatchShape: Equatable -extension ColorWell.PopoverConfiguration.SwatchShape: Equatable { } +extension ColorWell._PopoverConfiguration.SwatchShape: Equatable { } // MARK: SwatchShape: Hashable -extension ColorWell.PopoverConfiguration.SwatchShape: Hashable { } +extension ColorWell._PopoverConfiguration.SwatchShape: Hashable { } diff --git a/Sources/ColorWellKit/Views/SwiftUI/ColorWellRepresentable.swift b/Sources/ColorWellKit/Views/SwiftUI/ColorWellRepresentable.swift index 8335612..b203e19 100644 --- a/Sources/ColorWellKit/Views/SwiftUI/ColorWellRepresentable.swift +++ b/Sources/ColorWellKit/Views/SwiftUI/ColorWellRepresentable.swift @@ -180,8 +180,8 @@ struct ColorWellRepresentable: NSViewRepresentable { if colorWell.style != context.environment.colorWellStyleConfiguration.style { colorWell.style = context.environment.colorWellStyleConfiguration.style } - if colorWell.popoverConfiguration != context.environment.colorWellPopoverConfiguration { - colorWell.popoverConfiguration = context.environment.colorWellPopoverConfiguration + if colorWell._popoverConfiguration != context.environment.colorWellPopoverConfiguration { + colorWell._popoverConfiguration = context.environment.colorWellPopoverConfiguration } } diff --git a/Sources/ColorWellKit/Views/SwiftUI/EnvironmentValues.swift b/Sources/ColorWellKit/Views/SwiftUI/EnvironmentValues.swift index c3146dd..1e12eb9 100644 --- a/Sources/ColorWellKit/Views/SwiftUI/EnvironmentValues.swift +++ b/Sources/ColorWellKit/Views/SwiftUI/EnvironmentValues.swift @@ -13,7 +13,7 @@ private struct ColorWellStyleConfigurationKey: EnvironmentKey { @available(macOS 10.15, *) private struct ColorWellPopoverConfigurationKey: EnvironmentKey { - static let defaultValue = ColorWell.PopoverConfiguration.default + static let defaultValue = ColorWell._PopoverConfiguration.default } @available(macOS 10.15, *) @@ -26,7 +26,7 @@ extension EnvironmentValues { @available(macOS 10.15, *) extension EnvironmentValues { - var colorWellPopoverConfiguration: ColorWell.PopoverConfiguration { + var colorWellPopoverConfiguration: ColorWell._PopoverConfiguration { get { self[ColorWellPopoverConfigurationKey.self] } set { self[ColorWellPopoverConfigurationKey.self] = newValue } }