Files
steipete--codexbar/Sources/CodexBar/MenuHighlightStyle.swift
T
2026-07-13 12:22:33 +08:00

40 lines
1.5 KiB
Swift

import SwiftUI
extension EnvironmentValues {
@Entry var menuItemHighlighted: Bool = false
/// Optional live-refresh monitor injected into menu card views so the provider card
/// subtitle can reflect the in-flight "Refreshing…" state in place while the NSMenu
/// stays open, without rebuilding the menu during AppKit tracking.
@Entry var menuCardRefreshMonitor: MenuCardRefreshMonitor?
}
enum MenuHighlightStyle {
static let selectionText = Color(nsColor: .selectedMenuItemTextColor)
static let normalPrimaryText = Color(nsColor: .controlTextColor)
static let normalSecondaryText = Color(nsColor: .secondaryLabelColor)
static func primary(_ highlighted: Bool) -> Color {
highlighted ? self.selectionText : self.normalPrimaryText
}
static func secondary(_ highlighted: Bool) -> Color {
highlighted ? self.selectionText : self.normalSecondaryText
}
static func error(_ highlighted: Bool) -> Color {
highlighted ? self.selectionText : Color(nsColor: .systemRed)
}
static func progressTrack(_ highlighted: Bool) -> Color {
highlighted ? self.selectionText.opacity(0.22) : Color(nsColor: .tertiaryLabelColor).opacity(0.22)
}
static func progressTint(_ highlighted: Bool, fallback: Color) -> Color {
highlighted ? self.selectionText : fallback
}
static func selectionBackground(_ highlighted: Bool) -> Color {
highlighted ? Color(nsColor: .selectedContentBackgroundColor) : .clear
}
}