From cbfe1909e6d16e60acba326c3f5b811e7fdbcd39 Mon Sep 17 00:00:00 2001 From: Gnohz Gniy <0x00eeee@gmail.com> Date: Mon, 18 Nov 2024 19:03:19 +0800 Subject: [PATCH] Improve overall readability (#74) --- .../Modules/Sources/AppKitControls/ImageButton.swift | 2 +- .../Sources/AppKitExtensions/NSColor+Extension.swift | 6 ++++++ LunarBarMac/Sources/Shared/AppDefinitions.swift | 1 - LunarBarMac/Sources/Views/DateGridCell.swift | 2 +- LunarBarMac/Sources/Views/DateGridView.swift | 6 ++---- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/LunarBarMac/Modules/Sources/AppKitControls/ImageButton.swift b/LunarBarMac/Modules/Sources/AppKitControls/ImageButton.swift index d1e8a81..744ee2e 100644 --- a/LunarBarMac/Modules/Sources/AppKitControls/ImageButton.swift +++ b/LunarBarMac/Modules/Sources/AppKitControls/ImageButton.swift @@ -58,7 +58,7 @@ public final class ImageButton: CustomButton { override public func layout() { super.layout() - highlightView.layerBackgroundColor = .systemGray.withAlphaComponent(0.15) + highlightView.layerBackgroundColor = .highlightedBackground highlightView.frame = bounds.insetBy( dx: Constants.highlightViewInset, dy: Constants.highlightViewInset diff --git a/LunarBarMac/Modules/Sources/AppKitExtensions/NSColor+Extension.swift b/LunarBarMac/Modules/Sources/AppKitExtensions/NSColor+Extension.swift index 323bea7..04d1b1a 100644 --- a/LunarBarMac/Modules/Sources/AppKitExtensions/NSColor+Extension.swift +++ b/LunarBarMac/Modules/Sources/AppKitExtensions/NSColor+Extension.swift @@ -7,6 +7,12 @@ import AppKit public extension NSColor { + static var highlightedBackground: NSColor { + NSColor(name: nil) { + ($0.isDarkMode ? NSColor.white : NSColor.black).withAlphaComponent(0.06) + } + } + @MainActor func resolvedColor(with appearance: NSAppearance = NSApp.effectiveAppearance) -> NSColor { var cgColor: CGColor? diff --git a/LunarBarMac/Sources/Shared/AppDefinitions.swift b/LunarBarMac/Sources/Shared/AppDefinitions.swift index 5dcdda3..e9954ff 100644 --- a/LunarBarMac/Sources/Shared/AppDefinitions.swift +++ b/LunarBarMac/Sources/Shared/AppDefinitions.swift @@ -177,7 +177,6 @@ enum Colors { static let controlAccent: NSColor = .controlAccentColor static let darkGray: NSColor = .darkGray static let primaryLabel: NSColor = .labelColor - static let systemGray: NSColor = .systemGray static let systemTeal: NSColor = .systemTeal static let systemOrange: NSColor = .systemOrange } diff --git a/LunarBarMac/Sources/Views/DateGridCell.swift b/LunarBarMac/Sources/Views/DateGridCell.swift index 8327b44..479321d 100644 --- a/LunarBarMac/Sources/Views/DateGridCell.swift +++ b/LunarBarMac/Sources/Views/DateGridCell.swift @@ -109,7 +109,7 @@ extension DateGridCell { super.viewDidLayout() containerView.frame = view.bounds - highlightView.layerBackgroundColor = Colors.systemGray.withAlphaComponent(0.15) + highlightView.layerBackgroundColor = .highlightedBackground focusRingView.layer?.borderColor = Colors.controlAccent.cgColor } } diff --git a/LunarBarMac/Sources/Views/DateGridView.swift b/LunarBarMac/Sources/Views/DateGridView.swift index 293c9a4..7c31312 100644 --- a/LunarBarMac/Sources/Views/DateGridView.swift +++ b/LunarBarMac/Sources/Views/DateGridView.swift @@ -178,10 +178,8 @@ private extension DateGridView { dataSource?.apply(snapshot, animatingDifferences: animated) // Force update of certain properties that are not part of the diffable model - if !diffable { - visibleCells.forEach { - $0.updateOpacity(monthDate: monthDate) - } + visibleCells.forEach { + $0.updateOpacity(monthDate: monthDate) } } }