Skip to content

Commit

Permalink
Style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbaird committed Dec 29, 2023
1 parent 665cc27 commit 57f07e1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Sources/ColorWellKit/Utilities/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Sources/ColorWellKit/Views/Cocoa/CWColorWellPopover.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
53 changes: 19 additions & 34 deletions Sources/ColorWellKit/Views/Cocoa/CWColorWellSegment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -481,7 +472,7 @@ class CWBorderedSwatchSegment: CWSwatchSegment {
}

let clippingPath = NSBezierPath(
roundedRect: bounds.insetBy(inset),
roundedRect: bounds.inset(by: inset),
xRadius: radius,
yRadius: radius
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 57f07e1

Please sign in to comment.