💄 Updates unread count text to be subtle (macOS)

This commit is contained in:
Stuart Breckenridge
2025-06-20 16:01:58 +08:00
parent 0dc9ce56ac
commit 00b8affe5f
2 changed files with 24 additions and 8 deletions

View File

@@ -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 {
}
}

View File

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