From 00b8affe5f8dc900a5a1190addff4686164b81fd Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Fri, 20 Jun 2025 16:01:58 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20Updates=20unread=20count=20text?= =?UTF-8?q?=20to=20be=20subtle=20(macOS)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mac/MainWindow/Sidebar/Cell/SidebarCell.swift | 2 +- Mac/MainWindow/Sidebar/UnreadCountView.swift | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift b/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift index d3154e2c8..190e48321 100644 --- a/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift +++ b/Mac/MainWindow/Sidebar/Cell/SidebarCell.swift @@ -78,6 +78,7 @@ class SidebarCell : NSTableCellView { override var backgroundStyle: NSView.BackgroundStyle { didSet { updateFaviconImage() + unreadCountView.isSelected = (backgroundStyle != .normal) } } @@ -164,4 +165,3 @@ private extension SidebarCell { } } - diff --git a/Mac/MainWindow/Sidebar/UnreadCountView.swift b/Mac/MainWindow/Sidebar/UnreadCountView.swift index 25ee1c2a4..75ab94e6b 100644 --- a/Mac/MainWindow/Sidebar/UnreadCountView.swift +++ b/Mac/MainWindow/Sidebar/UnreadCountView.swift @@ -13,11 +13,9 @@ class UnreadCountView : NSView { struct Appearance { static let padding = NSEdgeInsets(top: 1.0, left: 7.0, bottom: 1.0, right: 7.0) static let cornerRadius: CGFloat = 8.0 - static let backgroundColor = NSColor(named: "SidebarUnreadCountBackground")! - static let textColor = NSColor(named: "SidebarUnreadCountText")! - static let textSize: CGFloat = 11.0 - static let textFont = NSFont.systemFont(ofSize: textSize, weight: NSFont.Weight.semibold) - static let textAttributes: [NSAttributedString.Key: AnyObject] = [NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.font: textFont, NSAttributedString.Key.kern: NSNull()] + static let backgroundColor = NSColor.clear + static let textSize: CGFloat = 13.0 + static let textFont = NSFont.systemFont(ofSize: textSize, weight: NSFont.Weight.regular) } var unreadCount = 0 { @@ -30,6 +28,24 @@ class UnreadCountView : NSView { return unreadCount < 1 ? "" : "\(unreadCount)" } + var isSelected: Bool = false { + didSet { + needsDisplay = true + } + } + + private var currentTextColor: NSColor { + return isSelected ? NSColor.white : NSColor.tertiaryLabelColor + } + + private var textAttributes: [NSAttributedString.Key: AnyObject] { + return [ + .foregroundColor: currentTextColor, + .font: Appearance.textFont, + .kern: NSNull() + ] + } + private var intrinsicContentSizeIsValid = false private var _intrinsicContentSize = NSZeroSize @@ -66,7 +82,7 @@ class UnreadCountView : NSView { return cachedSize } - var size = unreadCountString.size(withAttributes: Appearance.textAttributes) + var size = unreadCountString.size(withAttributes: textAttributes) size.height = ceil(size.height) size.width = ceil(size.width) @@ -89,7 +105,7 @@ class UnreadCountView : NSView { path.fill() if unreadCount > 0 { - unreadCountString.draw(at: textRect().origin, withAttributes: Appearance.textAttributes) + unreadCountString.draw(at: textRect().origin, withAttributes: textAttributes) } } }