Skip to content

Commit

Permalink
Deprecate standard and swatches styles in favor of default and …
Browse files Browse the repository at this point in the history
…`minimal` to align with Apple API
  • Loading branch information
jordanbaird committed Nov 18, 2023
1 parent adcf565 commit a6f3ffd
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ If the specified raw value does not correspond to any of the existing color well

```swift
print(Style(rawValue: 0))
// Prints "Optional(Style.standard)"
// Prints "Optional(Style.default)"

print(Style(rawValue: 1))
// Prints "Optional(Style.swatches)"
// Prints "Optional(Style.minimal)"

print(Style(rawValue: 2))
// Prints "Optional(Style.expanded)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

### Getting the available styles

- ``standard``
- ``swatches``
- ``default``
- ``minimal``
- ``expanded``

### Creating a style from a raw value

- ``init(rawValue:)``

### Deprecated styles

- ``standard``
- ``swatches``
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

### Types of styles

- ``StandardColorWellStyle``
- ``SwatchesColorWellStyle``
- ``DefaultColorWellStyle``
- ``MinimalColorWellStyle``
- ``ExpandedColorWellStyle``

### Creating a color well style

- ``ColorWellStyle/default``
- ``ColorWellStyle/minimal``
- ``ColorWellStyle/expanded``

### Deprecated styles

- ``StandardColorWellStyle``
- ``SwatchesColorWellStyle``
- ``ColorWellStyle/standard``
- ``ColorWellStyle/swatches``
- ``ColorWellStyle/expanded``
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ``ColorWellKit/DefaultColorWellStyle``

## Topics

### Getting the style

- ``ColorWellStyle/default``

### Creating a default color well style

- ``init()``
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ``ColorWellKit/MinimalColorWellStyle``

## Topics

### Getting the style

- ``ColorWellStyle/minimal``

### Creating a minimal color well style

- ``init()``
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct TextFormatter: View {
}
```

![Two color wells, both displayed in the standard style](standard-style)
![Two color wells, both displayed in the default style](default-style)

### Styling color wells

Expand Down
4 changes: 2 additions & 2 deletions Sources/ColorWellKit/Views/Cocoa/ColorWell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ColorWell: _ColorWellBaseControl {

/// The action to perform when the color area of the color well is pressed.
///
/// By default, color wells with the ``Style-swift.enum/swatches`` or
/// By default, color wells with the ``Style-swift.enum/minimal`` or
/// ``Style-swift.enum/expanded`` style display a popover with a grid of
/// color swatches when the color area is pressed. If you specify a value
/// for this property and the ``secondaryTarget`` property, clicks inside
Expand All @@ -58,7 +58,7 @@ public class ColorWell: _ColorWellBaseControl {
/// The target object that defines the action to perform when the color
/// area of the color well is pressed.
///
/// By default, color wells with the ``Style-swift.enum/swatches`` or
/// By default, color wells with the ``Style-swift.enum/minimal`` or
/// ``Style-swift.enum/expanded`` style display a popover with a grid of
/// color swatches when the color area is pressed. If you specify a value
/// for this property and the ``secondaryAction`` property, clicks inside
Expand Down
4 changes: 2 additions & 2 deletions Sources/ColorWellKit/Views/Cocoa/ColorWellBaseControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class _ColorWellBaseControl: NSControl {
struct BackingStorage {
static let defaultColor = NSColor(red: 1, green: 1, blue: 1, alpha: 1)

static let defaultStyle = ColorWell.Style.standard
static let defaultStyle = ColorWell.Style.default

static let defaultSize = NSSize(width: 38, height: 24)

Expand Down Expand Up @@ -144,7 +144,7 @@ public class _ColorWellBaseControl: NSControl {
// this implementation returns the same sizes as NSColorWell
var size = BackingStorage.defaultSize
switch backingStorage.style {
case .standard, .swatches:
case .default, .minimal:
switch controlSize {
case .large:
size.height += 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ class ColorWellLayoutView: NSGridView {
return
}
switch colorWell.style {
case .standard:
case .default:
layer.shadowRadius = 0.5
layer.shadowOpacity = 0.3
layer.shadowOffset = NSSize(width: 0, height: -0.25)
case .swatches:
case .minimal:
layer.shadowRadius = 0
layer.shadowOpacity = 0
layer.shadowOffset = NSSize(width: 0, height: 0)
Expand All @@ -139,10 +139,10 @@ class ColorWellLayoutView: NSGridView {
}
resetLayoutView()
switch colorWell.style {
case .standard:
case .default:
segments.append(ColorWellBorderedSwatchSegment(colorWell: colorWell))
widthConstant = 0
case .swatches:
case .minimal:
segments.append(ColorWellSinglePullDownSwatchSegment(colorWell: colorWell))
widthConstant = 0
case .expanded:
Expand Down Expand Up @@ -179,7 +179,7 @@ class ColorWellLayoutView: NSGridView {
)
.stroked(lineWidth: lineWidth)
.nsBezierPath()
case .standard, .swatches:
case .default, .minimal:
bezelPath = Path.fullColorWellPath(
rect: bounds.insetBy(lineWidth / 2),
controlSize: colorWell.controlSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ extension ColorWellPopover {

let padding = with(colorWell.style) { style in
switch style {
case .standard, .expanded:
case .default, .expanded:
return (
leading: configuration.contentLayout.padding.leading.max ?? fallbackPadding,
trailing: configuration.contentLayout.padding.trailing.max ?? fallbackPadding,
top: configuration.contentLayout.padding.top.max ?? fallbackPadding,
bottom: configuration.contentLayout.padding.bottom.max ?? fallbackPadding
)
case .swatches:
case .minimal:
return (
leading: configuration.contentLayout.padding.leading.min ?? fallbackPadding,
trailing: configuration.contentLayout.padding.trailing.min ?? fallbackPadding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension ColorWellPopover {
addRow(with: [swatchLayout])
swatchLayout.assignLayoutViewIfAble(self)

if colorWell.style == .swatches {
if colorWell.style == .minimal {
let activationButton = NSButton(
title: "Show More Colors…",
target: self,
Expand Down
28 changes: 22 additions & 6 deletions Sources/ColorWellKit/Views/Cocoa/Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ extension ColorWell {
@objc public enum Style: Int {
/// The color well is displayed as a rectangular control that displays
/// the selected color and shows the system color panel when clicked.
case standard = 0
case `default` = 0

/// The color well is displayed as a rectangular control that displays
/// the selected color and shows a popover containing the color well's
/// swatch colors when clicked.
///
/// The popover contains an option to show the system color panel.
case swatches = 1
case minimal = 1

/// The color well is displayed as a segmented control that displays
/// the selected color alongside a dedicated button to show the system
Expand All @@ -33,12 +33,28 @@ extension ColorWell.Style: CustomStringConvertible {
public var description: String {
let prefix = String(describing: Self.self) + "."
switch self {
case .standard:
return prefix + "standard"
case .swatches:
return prefix + "swatches"
case .default:
return prefix + "default"
case .minimal:
return prefix + "minimal"
case .expanded:
return prefix + "expanded"
}
}
}

// MARK: - Deprecated
extension ColorWell.Style {
/// The color well is displayed as a rectangular control that displays
/// the selected color and shows the system color panel when clicked.
@available(*, deprecated, renamed: "default")
public static let standard = Self.default

/// The color well is displayed as a rectangular control that displays
/// the selected color and shows a popover containing the color well's
/// swatch colors when clicked.
///
/// The popover contains an option to show the system color panel.
@available(*, deprecated, renamed: "minimal")
public static let swatches = Self.minimal
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct ColorWellRepresentable: NSViewRepresentable {
override func computeIntrinsicContentSize(for controlSize: ControlSize) -> NSSize {
var size = BackingStorage.defaultSize
switch backingStorage.style {
case .standard, .swatches:
case .default, .minimal:
switch controlSize {
case .large:
size.width += 17
Expand Down
84 changes: 68 additions & 16 deletions Sources/ColorWellKit/Views/SwiftUI/ColorWellStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,47 +33,47 @@ public protocol ColorWellStyle {
var _configuration: _ColorWellStyleConfiguration { get }
}

// MARK: - StandardColorWellStyle
// MARK: - DefaultColorWellStyle

/// A color well style that displays the color well's color inside of a
/// rectangular control, and toggles the system color panel when clicked.
///
/// You can also use ``standard`` to construct this style.
public struct StandardColorWellStyle: ColorWellStyle {
public let _configuration = _ColorWellStyleConfiguration(style: .standard)
/// You can also use ``default`` to construct this style.
public struct DefaultColorWellStyle: ColorWellStyle {
public let _configuration = _ColorWellStyleConfiguration(style: .default)

/// Creates an instance of the standard color well style.
/// Creates an instance of the default color well style.
public init() { }
}

extension ColorWellStyle where Self == StandardColorWellStyle {
extension ColorWellStyle where Self == DefaultColorWellStyle {
/// A color well style that displays the color well's color inside of a
/// rectangular control, and toggles the system color panel when clicked.
public static var standard: StandardColorWellStyle {
StandardColorWellStyle()
public static var `default`: DefaultColorWellStyle {
DefaultColorWellStyle()
}
}

// MARK: - SwatchesColorWellStyle
// MARK: - MinimalColorWellStyle

/// A color well style that displays the color well's color inside of a
/// rectangular control, and shows a popover containing the color well's
/// swatch colors when clicked.
///
/// You can also use ``swatches`` to construct this style.
public struct SwatchesColorWellStyle: ColorWellStyle {
public let _configuration = _ColorWellStyleConfiguration(style: .swatches)
/// You can also use ``minimal`` to construct this style.
public struct MinimalColorWellStyle: ColorWellStyle {
public let _configuration = _ColorWellStyleConfiguration(style: .minimal)

/// Creates an instance of the swatches color well style.
/// Creates an instance of the minimal color well style.
public init() { }
}

extension ColorWellStyle where Self == SwatchesColorWellStyle {
extension ColorWellStyle where Self == MinimalColorWellStyle {
/// A color well style that displays the color well's color inside of a
/// rectangular control, and shows a popover containing the color well's
/// swatch colors when clicked.
public static var swatches: SwatchesColorWellStyle {
SwatchesColorWellStyle()
public static var minimal: MinimalColorWellStyle {
MinimalColorWellStyle()
}
}

Expand Down Expand Up @@ -103,4 +103,56 @@ extension ColorWellStyle where Self == ExpandedColorWellStyle {
ExpandedColorWellStyle()
}
}

// MARK: - Deprecated -

// MARK: - StandardColorWellStyle

/// A color well style that displays the color well's color inside of a
/// rectangular control, and toggles the system color panel when clicked.
///
/// You can also use ``standard`` to construct this style.
@available(*, deprecated, renamed: "DefaultColorWellStyle")
public struct StandardColorWellStyle: ColorWellStyle {
public let _configuration = _ColorWellStyleConfiguration(style: .standard)

/// Creates an instance of the standard color well style.
public init() { }
}

@available(*, deprecated)
extension ColorWellStyle where Self == StandardColorWellStyle {
/// A color well style that displays the color well's color inside of a
/// rectangular control, and toggles the system color panel when clicked.
@available(*, deprecated, renamed: "default")
public static var standard: StandardColorWellStyle {
StandardColorWellStyle()
}
}

// MARK: - SwatchesColorWellStyle

/// A color well style that displays the color well's color inside of a
/// rectangular control, and shows a popover containing the color well's
/// swatch colors when clicked.
///
/// You can also use ``swatches`` to construct this style.
@available(*, deprecated, renamed: "MinimalColorWellStyle")
public struct SwatchesColorWellStyle: ColorWellStyle {
public let _configuration = _ColorWellStyleConfiguration(style: .swatches)

/// Creates an instance of the swatches color well style.
public init() { }
}

@available(*, deprecated)
extension ColorWellStyle where Self == SwatchesColorWellStyle {
/// A color well style that displays the color well's color inside of a
/// rectangular control, and shows a popover containing the color well's
/// swatch colors when clicked.
@available(*, deprecated, renamed: "minimal")
public static var swatches: SwatchesColorWellStyle {
SwatchesColorWellStyle()
}
}
#endif

0 comments on commit a6f3ffd

Please sign in to comment.