diff --git a/Sources/ColorWellKit/Utilities/Extensions.swift b/Sources/ColorWellKit/Utilities/Extensions.swift index ba10b31..feb8b71 100644 --- a/Sources/ColorWellKit/Utilities/Extensions.swift +++ b/Sources/ColorWellKit/Utilities/Extensions.swift @@ -20,7 +20,7 @@ extension CGRect { } /// Returns a rectangle that has been inset by the given dimension. - func insetBy(_ dimension: CGFloat) -> CGRect { + func inset(by dimension: CGFloat) -> CGRect { insetBy(dx: dimension, dy: dimension) } } @@ -348,7 +348,7 @@ extension NSImage { /// Returns an image by redrawing the current image with the given opacity. /// /// - Parameter opacity: The opacity of the returned image. - func opacity(_ opacity: CGFloat) -> NSImage { + func withOpacity(_ opacity: CGFloat) -> NSImage { if opacity >= 1 { return self } diff --git a/Sources/ColorWellKit/Views/Cocoa/CWColorWellLayoutView.swift b/Sources/ColorWellKit/Views/Cocoa/CWColorWellLayoutView.swift index d02c94c..f69f365 100644 --- a/Sources/ColorWellKit/Views/Cocoa/CWColorWellLayoutView.swift +++ b/Sources/ColorWellKit/Views/Cocoa/CWColorWellLayoutView.swift @@ -181,7 +181,7 @@ class CWColorWellLayoutView: NSGridView { .nsBezierPath() case .default, .minimal: bezelPath = Path.fullColorWellPath( - rect: bounds.insetBy(lineWidth / 2), + rect: bounds.inset(by: lineWidth / 2), controlSize: colorWell.controlSize ) .stroked(lineWidth: lineWidth) diff --git a/Sources/ColorWellKit/Views/Cocoa/CWColorWellPopover.swift b/Sources/ColorWellKit/Views/Cocoa/CWColorWellPopover.swift index 678d0c1..c8d22b7 100644 --- a/Sources/ColorWellKit/Views/Cocoa/CWColorWellPopover.swift +++ b/Sources/ColorWellKit/Views/Cocoa/CWColorWellPopover.swift @@ -366,7 +366,7 @@ extension CWColorWellPopover { let color = color.usingColorSpace(.displayP3) ?? color color.drawSwatch(in: bounds) NSColor(white: 1 - color.averageBrightness, alpha: 0.3).setStroke() - let path = NSBezierPath(rect: bounds.insetBy(1)) + let path = NSBezierPath(rect: bounds.inset(by: 1)) path.lineWidth = 2 path.stroke() } diff --git a/Sources/ColorWellKit/Views/Cocoa/CWColorWellSegment.swift b/Sources/ColorWellKit/Views/Cocoa/CWColorWellSegment.swift index c1bf4eb..48c53bd 100644 --- a/Sources/ColorWellKit/Views/Cocoa/CWColorWellSegment.swift +++ b/Sources/ColorWellKit/Views/Cocoa/CWColorWellSegment.swift @@ -68,30 +68,24 @@ class CWColorWellSegment: NSView { /// The default fill color for a color well segment. var segmentColor: NSColor { switch ColorScheme.current { - case .light: - return .controlColor - case .dark: - return .selectedControlColor + case .light: .controlColor + case .dark: .selectedControlColor } } /// The fill color for a highlighted color well segment. var highlightedSegmentColor: NSColor { switch ColorScheme.current { - case .light: - return segmentColor.blending(fraction: 0.5, of: .selectedControlColor) - case .dark: - return segmentColor.blending(fraction: 0.2, of: .highlightColor) + case .light: segmentColor.blending(fraction: 0.5, of: .selectedControlColor) + case .dark: segmentColor.blending(fraction: 0.2, of: .highlightColor) } } /// The fill color for a selected color well segment. var selectedSegmentColor: NSColor { switch ColorScheme.current { - case .light: - return .selectedControlColor - case .dark: - return segmentColor.withAlphaComponent(segmentColor.alphaComponent + 0.25) + case .light: .selectedControlColor + case .dark: segmentColor.withAlphaComponent(segmentColor.alphaComponent + 0.25) } } @@ -289,13 +283,12 @@ class CWSwatchSegment: CWColorWellSegment { var draggingInformation = DraggingInformation() var borderColor: NSColor { - with(displayColor) { displayColor in - let component = min(displayColor.averageBrightness, displayColor.alphaComponent) - let limitedComponent = min(component, 0.3) - let white = 1 - limitedComponent - let alpha = min(limitedComponent * 1.3, 0.7) - return NSColor(white: white, alpha: alpha) - } + let displayColor = displayColor + let component = min(displayColor.averageBrightness, displayColor.alphaComponent) + let limitedComponent = min(component, 0.3) + let white = 1 - limitedComponent + let alpha = min(limitedComponent * 1.3, 0.7) + return NSColor(white: white, alpha: alpha) } override var rawColor: NSColor { @@ -440,10 +433,8 @@ class CWBorderedSwatchSegment: CWSwatchSegment { override var borderColor: NSColor { switch ColorScheme.current { - case .light: - super.borderColor.blending(fraction: 0.25, of: .controlTextColor) - case .dark: - super.borderColor + case .light: super.borderColor.blending(fraction: 0.25, of: .controlTextColor) + case .dark: super.borderColor } } @@ -481,7 +472,7 @@ class CWBorderedSwatchSegment: CWSwatchSegment { } let clippingPath = NSBezierPath( - roundedRect: bounds.insetBy(inset), + roundedRect: bounds.inset(by: inset), xRadius: radius, yRadius: radius ) @@ -739,19 +730,13 @@ class CWToggleSegment: CWColorWellSegment { } }() - static let enabledImageForDarkAppearance = defaultImage - .tinted(to: .white, fraction: 1 / 3) + static let enabledImageForDarkAppearance = defaultImage.tinted(to: .white, fraction: 1 / 3) - static let enabledImageForLightAppearance = defaultImage - .tinted(to: .black, fraction: 1 / 5) + static let enabledImageForLightAppearance = defaultImage.tinted(to: .black, fraction: 1 / 5) - static let disabledImageForDarkAppearance = defaultImage - .tinted(to: .gray, fraction: 1 / 3) - .opacity(0.5) + static let disabledImageForDarkAppearance = defaultImage.tinted(to: .gray, fraction: 1 / 3).withOpacity(0.5) - static let disabledImageForLightAppearance = defaultImage - .tinted(to: .gray, fraction: 1 / 5) - .opacity(0.5) + static let disabledImageForLightAppearance = defaultImage.tinted(to: .gray, fraction: 1 / 5).withOpacity(0.5) } static let widthConstant: CGFloat = 20