Mixer im Zeilenlayout, Akku zeigt „am Netz, lädt nicht"

Am Netz und trotzdem kein Blitz sah aus wie Akkubetrieb — dabei ist es der
Normalfall, sobald das Ladelimit greift. Jetzt steht in diesem Zustand ein
Stecker im Akku, ausgestanzt wie der Blitz. Drei Zustände, drei Zeichen:
lädt, hängt am Netz, läuft auf Akku.

Der Mixer folgt jetzt der Anordnung von SoundSource, weil sie dort gut
gelöst ist: eine Zeile je Programm, links das Symbol als Kachel, dann der
Stummschalter, dann der Regler, rechts der Wert. Vorher stand der
Stummschalter rechts zwischen den Zusatzelementen, obwohl er zur Lautstärke
gehört, und die Prozentzahl sprang zwischen zwei Zeilen.

Die Farben folgen SoundSource **nicht**. Dort ist jeder Regler grün; in Onyx
ist Farbe ein Signal — die Verstärkung über 100 % ist eines, eine
gewöhnliche Lautstärke nicht.

Nebenbei zwei Fehler im Regler: der Knopf stand an den Enden über die Bahn
hinaus, und die Ziehposition rechnete ohne seine Breite. Am rechten Anschlag
ließen sich die letzten Prozent deshalb nicht einstellen.

Das Popover ist die Hauptfläche und jetzt 330 statt 280 Punkte breit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Scarriffle
2026-08-11 16:05:37 +02:00
parent 9968236a37
commit eff3c30a71
6 changed files with 195 additions and 80 deletions

View File

@@ -25,6 +25,30 @@ public enum BatteryGlyph {
return min(max(inner * clamped, minimumFill), inner)
}
/// Was mitten im Akku steht.
public enum Indicator: CaseIterable, Sendable {
case none
/// Lädt.
case bolt
/// Am Netz, aber es fließt nichts meist, weil das Ladelimit erreicht
/// ist. Ohne eigenes Zeichen sieht das aus wie Akkubetrieb, und man
/// fragt sich, ob das Kabel wirklich steckt.
case plug
public var symbolName: String? {
switch self {
case .none: nil
case .bolt: "bolt.fill"
case .plug: "powerplug.fill"
}
}
}
public static func indicator(isCharging: Bool, isPluggedIn: Bool) -> Indicator {
if isCharging { return .bolt }
return isPluggedIn ? .plug : .none
}
public static func isLow(charge: Double, isCharging: Bool = false) -> Bool {
// Ein roter Akku, der gerade lädt, wäre eine Warnung vor etwas, das
// sich schon erledigt.
@@ -36,7 +60,7 @@ public enum BatteryGlyph {
/// - Parameter color: die Vordergrundfarbe der Menüleiste. Nur bei
/// kritischem Ladestand weicht die Füllung davon ab Farbe ist in der
/// Menüleiste ein Signal, keine Dekoration.
public static func draw(charge: Double, isCharging: Bool,
public static func draw(charge: Double, isCharging: Bool, isPluggedIn: Bool = false,
color: NSColor, in rect: CGRect) {
let capWidth: CGFloat = 2
let body = CGRect(x: rect.minX, y: rect.minY,
@@ -65,23 +89,24 @@ public enum BatteryGlyph {
NSBezierPath(roundedRect: fill, xRadius: 1.5, yRadius: 1.5).fill()
}
guard isCharging else { return }
// Der Blitz wird **ausgestanzt**, nicht daraufgelegt.
// Das Zeichen wird **ausgestanzt**, nicht daraufgelegt.
//
// `destinationOut` nimmt weg, was vorher gezeichnet wurde Füllung und
// Rahmen. Übrig bleibt ein Loch in Blitzform, durch das die Menüleiste
// scheint. Genau so sieht der von macOS aus, und es funktioniert auf
// hellem wie dunklem Grund, ohne die Hintergrundfarbe zu kennen.
guard let bolt = NSImage(systemSymbolName: "bolt.fill",
accessibilityDescription: nil) else { return }
let boltHeight = rect.height - 1
let boltWidth = (bolt.size.width / bolt.size.height) * boltHeight
let boltRect = CGRect(x: body.midX - boltWidth / 2,
y: rect.midY - boltHeight / 2,
width: boltWidth, height: boltHeight)
// Rahmen. Übrig bleibt ein Loch in Blitz- bzw. Steckerform, durch das
// die Menüleiste scheint. Genau so sieht der von macOS aus, und es
// funktioniert auf hellem wie dunklem Grund, ohne die Hintergrundfarbe
// zu kennen.
guard let name = indicator(isCharging: isCharging,
isPluggedIn: isPluggedIn).symbolName,
let glyph = NSImage(systemSymbolName: name, accessibilityDescription: nil)
else { return }
let glyphHeight = rect.height - 1
let glyphWidth = (glyph.size.width / glyph.size.height) * glyphHeight
let glyphRect = CGRect(x: body.midX - glyphWidth / 2,
y: rect.midY - glyphHeight / 2,
width: glyphWidth, height: glyphHeight)
NSGraphicsContext.saveGraphicsState()
bolt.draw(in: boltRect, from: .zero, operation: .destinationOut, fraction: 1)
glyph.draw(in: glyphRect, from: .zero, operation: .destinationOut, fraction: 1)
NSGraphicsContext.restoreGraphicsState()
}
}
@@ -101,9 +126,13 @@ public struct BatteryGlyphView: View {
private let isCharging: Bool
private let height: CGFloat
public init(charge: Double, isCharging: Bool, height: CGFloat = 14) {
private let isPluggedIn: Bool
public init(charge: Double, isCharging: Bool, isPluggedIn: Bool = false,
height: CGFloat = 14) {
self.charge = charge
self.isCharging = isCharging
self.isPluggedIn = isPluggedIn
self.height = height
}
@@ -126,9 +155,10 @@ public struct BatteryGlyphView: View {
}
.frame(width: (BatteryGlyph.size.width - 3) * scale, height: height)
.overlay {
if isCharging {
Image(systemName: "bolt.fill")
.font(.system(size: height * 0.72))
if let name = BatteryGlyph.indicator(isCharging: isCharging,
isPluggedIn: isPluggedIn).symbolName {
Image(systemName: name)
.font(.system(size: height * 0.68))
.blendMode(.destinationOut)
}
}

View File

@@ -250,7 +250,7 @@ final class MetricStatusView: NSView, WidthReporting {
return
}
BatteryGlyph.draw(charge: battery.charge, isCharging: battery.isCharging,
color: color,
isPluggedIn: battery.isPluggedIn, color: color,
in: CGRect(origin: origin, size: BatteryGlyph.size))
}

View File

@@ -341,7 +341,8 @@ private struct BatteryTile: View {
// dasselbe wie bei 95 % und trägt nichts bei.
if let battery {
BatteryGlyphView(charge: battery.charge,
isCharging: battery.isCharging, height: 15)
isCharging: battery.isCharging,
isPluggedIn: battery.isPluggedIn, height: 15)
.foregroundStyle(tint(battery))
} else {
Image(systemName: BatterySymbol.unavailable)