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) } } }