66 lines
2.2 KiB
Swift
66 lines
2.2 KiB
Swift
import SwiftUI
|
|
|
|
private struct MenuItemHighlightedKey: EnvironmentKey {
|
|
static let defaultValue = false
|
|
}
|
|
|
|
extension EnvironmentValues {
|
|
var menuItemHighlighted: Bool {
|
|
get { self[MenuItemHighlightedKey.self] }
|
|
set { self[MenuItemHighlightedKey.self] = newValue }
|
|
}
|
|
}
|
|
|
|
struct SessionMenuLabelView: View {
|
|
let row: SessionRow
|
|
let width: CGFloat
|
|
@Environment(\.menuItemHighlighted) private var isHighlighted
|
|
private let paddingLeading: CGFloat = 26
|
|
private let paddingTrailing: CGFloat = 18
|
|
private let barHeight: CGFloat = 6
|
|
|
|
private var primaryTextColor: Color {
|
|
self.isHighlighted ? Color(nsColor: .selectedMenuItemTextColor) : .primary
|
|
}
|
|
|
|
private var secondaryTextColor: Color {
|
|
self.isHighlighted ? Color(nsColor: .selectedMenuItemTextColor).opacity(0.85) : .secondary
|
|
}
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
ContextUsageBar(
|
|
usedTokens: self.row.tokens.total,
|
|
contextTokens: self.row.tokens.contextTokens,
|
|
width: max(1, self.width - (self.paddingLeading + self.paddingTrailing)),
|
|
height: self.barHeight)
|
|
|
|
HStack(alignment: .firstTextBaseline, spacing: 8) {
|
|
Text(self.row.key)
|
|
.font(.caption.weight(self.row.key == "main" ? .semibold : .regular))
|
|
.foregroundStyle(self.primaryTextColor)
|
|
.lineLimit(1)
|
|
.truncationMode(.middle)
|
|
.layoutPriority(1)
|
|
|
|
Spacer(minLength: 8)
|
|
|
|
Text(self.row.tokens.contextSummaryShort)
|
|
.font(.caption.monospacedDigit())
|
|
.foregroundStyle(self.secondaryTextColor)
|
|
.lineLimit(1)
|
|
.fixedSize(horizontal: true, vertical: false)
|
|
.layoutPriority(2)
|
|
|
|
Image(systemName: "chevron.right")
|
|
.font(.caption.weight(.semibold))
|
|
.foregroundStyle(self.secondaryTextColor)
|
|
.padding(.leading, 2)
|
|
}
|
|
}
|
|
.padding(.vertical, 10)
|
|
.padding(.leading, self.paddingLeading)
|
|
.padding(.trailing, self.paddingTrailing)
|
|
}
|
|
}
|