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:
@@ -4,6 +4,14 @@ import OnyxDesign
|
||||
import OnyxWidgetKit
|
||||
|
||||
/// Die Mischpult-Ansicht. Dieselbe im Panel und im Menüleisten-Popover.
|
||||
///
|
||||
/// Die Anordnung folgt SoundSource, weil sie dort gut gelöst ist: eine Zeile je
|
||||
/// Programm, links das Symbol als Kachel, dann ein Stummschalter, dann der
|
||||
/// Regler, rechts der Wert. Nichts steht übereinander, nichts muss man suchen.
|
||||
///
|
||||
/// Die Farben folgen ihr **nicht**. SoundSource färbt jeden Regler grün; in
|
||||
/// Onyx ist Farbe ein Signal — die Verstärkung über 100 % ist eines, eine
|
||||
/// gewöhnliche Lautstärke nicht.
|
||||
public struct MixerView: View {
|
||||
let mixer: AudioMixer
|
||||
/// Im Panel ist es eng, im Popover nicht.
|
||||
@@ -24,8 +32,22 @@ public struct MixerView: View {
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.padding(.vertical, 8)
|
||||
} else {
|
||||
ForEach(mixer.processes.prefix(compact ? 4 : 10)) { process in
|
||||
ProcessRow(mixer: mixer, process: process)
|
||||
// Eine Karte um die Zeilen: sie fasst zusammen, was
|
||||
// zusammengehört, und trennt es vom Ausschalter darunter.
|
||||
VStack(spacing: 0) {
|
||||
ForEach(Array(mixer.processes.prefix(compact ? 4 : 12).enumerated()),
|
||||
id: \.element.id) { index, process in
|
||||
if index > 0 { Divider().overlay(Onyx.Color.hairline) }
|
||||
ProcessRow(mixer: mixer, process: process, compact: compact)
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.vertical, compact ? 7 : 9)
|
||||
}
|
||||
}
|
||||
.background(Onyx.Color.elevated.opacity(0.55),
|
||||
in: .rect(cornerRadius: 10, style: .continuous))
|
||||
.overlay {
|
||||
RoundedRectangle(cornerRadius: 10, style: .continuous)
|
||||
.strokeBorder(Onyx.Color.hairline, lineWidth: 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,15 +116,15 @@ private struct OffState: View {
|
||||
private struct ProcessRow: View {
|
||||
let mixer: AudioMixer
|
||||
let process: AudioProcess
|
||||
@State private var isHovered = false
|
||||
let compact: Bool
|
||||
|
||||
private var managed: Bool { mixer.isManaged(process.bundleID) }
|
||||
private var muted: Bool { mixer.isMuted(process.bundleID) }
|
||||
private var volume: Double { mixer.volume(for: process.bundleID) }
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
HStack(spacing: 7) {
|
||||
VStack(alignment: .leading, spacing: compact ? 5 : 6) {
|
||||
HStack(spacing: 8) {
|
||||
icon
|
||||
Text(process.name)
|
||||
.font(Onyx.Font.caption)
|
||||
@@ -111,22 +133,28 @@ private struct ProcessRow: View {
|
||||
// In der Mitte kürzen statt am Ende: bei zwei ähnlichen
|
||||
// Namen ist das Ende oft das Unterscheidende.
|
||||
.truncationMode(.middle)
|
||||
.layoutPriority(1)
|
||||
|
||||
Spacer(minLength: 4)
|
||||
|
||||
// Die Prozentzahl erscheint erst, wenn sie etwas aussagt.
|
||||
// Bei jedem Programm „100 %" zu zeigen ist Zahlenrauschen.
|
||||
if managed {
|
||||
Text("\(Int(volume * 100)) %")
|
||||
.font(Onyx.Font.metricSmall)
|
||||
.foregroundStyle(volume > 1 ? Onyx.Color.warning : Onyx.Color.textTertiary)
|
||||
.monospacedDigit()
|
||||
.transition(.opacity)
|
||||
if process.isPlaying {
|
||||
Circle().fill(Onyx.Color.positive).frame(width: 5, height: 5)
|
||||
}
|
||||
}
|
||||
|
||||
HStack(spacing: 7) {
|
||||
HStack(spacing: 9) {
|
||||
// Der Stummschalter links vom Regler, wie in SoundSource: er
|
||||
// gehört zur Lautstärke und nicht zu den Zusatzfunktionen.
|
||||
Button {
|
||||
if !managed { mixer.setManaged(true, for: process.bundleID) }
|
||||
mixer.setMuted(!muted, for: process.bundleID)
|
||||
} label: {
|
||||
Image(systemName: muted ? "speaker.slash.fill" : speakerSymbol)
|
||||
.font(.system(size: 11))
|
||||
.frame(width: 15, alignment: .leading)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.foregroundStyle(muted ? Onyx.Color.critical
|
||||
: (managed ? Onyx.Color.textSecondary
|
||||
: Onyx.Color.textTertiary))
|
||||
|
||||
VolumeBar(
|
||||
volume: volume,
|
||||
level: mixer.level(for: process.bundleID),
|
||||
@@ -140,22 +168,16 @@ private struct ProcessRow: View {
|
||||
mixer.setVolume(newValue, for: process.bundleID)
|
||||
})
|
||||
|
||||
Button {
|
||||
if !managed { mixer.setManaged(true, for: process.bundleID) }
|
||||
mixer.setMuted(!muted, for: process.bundleID)
|
||||
} label: {
|
||||
Image(systemName: muted ? "speaker.slash.fill" : "speaker.wave.2.fill")
|
||||
.font(.system(size: 9))
|
||||
.frame(width: 12)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.foregroundStyle(muted ? Onyx.Color.critical
|
||||
: (managed ? Onyx.Color.textTertiary
|
||||
: Onyx.Color.textTertiary.opacity(0.5)))
|
||||
Text(managed ? "\(Int(volume * 100)) %" : "–")
|
||||
.font(Onyx.Font.metricSmall)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(volume > 1 && managed ? Onyx.Color.warning
|
||||
: Onyx.Color.textTertiary)
|
||||
// Feste Breite, sonst wandert der Regler beim Ziehen.
|
||||
.frame(width: 36, alignment: .trailing)
|
||||
}
|
||||
}
|
||||
.contentShape(.rect)
|
||||
.onHover { isHovered = $0 }
|
||||
.contextMenu {
|
||||
if managed {
|
||||
Button {
|
||||
@@ -168,20 +190,36 @@ private struct ProcessRow: View {
|
||||
.animation(Onyx.Motion.value, value: managed)
|
||||
}
|
||||
|
||||
/// Wie viele Wellen am Lautsprecher — folgt der Lautstärke, wie überall
|
||||
/// sonst in macOS auch.
|
||||
private var speakerSymbol: String {
|
||||
switch volume {
|
||||
case ..<0.01: "speaker.fill"
|
||||
case ..<0.5: "speaker.wave.1.fill"
|
||||
case ..<1.2: "speaker.wave.2.fill"
|
||||
default: "speaker.wave.3.fill"
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var icon: some View {
|
||||
// Auch Hilfsprozesse bekommen das Symbol ihres Programms — sonst steht
|
||||
// neben „Google Chrome" ein leerer Platzhalter.
|
||||
if let image = ProcessNaming.icon(bundleID: process.bundleID, pid: process.pid) {
|
||||
Image(nsImage: image)
|
||||
.resizable().frame(width: 15, height: 15)
|
||||
.opacity(managed ? 1 : 0.65)
|
||||
} else {
|
||||
Image(systemName: "app.dashed")
|
||||
.font(.system(size: 11))
|
||||
.foregroundStyle(Onyx.Color.textTertiary)
|
||||
.frame(width: 15, height: 15)
|
||||
// Als Kachel wie in SoundSource: ein freigestelltes Programmsymbol
|
||||
// wirkt neben Text verloren, mit Hintergrund steht es für sich.
|
||||
Group {
|
||||
// Auch Hilfsprozesse bekommen das Symbol ihres Programms — sonst
|
||||
// steht neben „Google Chrome" ein leerer Platzhalter.
|
||||
if let image = ProcessNaming.icon(bundleID: process.bundleID, pid: process.pid) {
|
||||
Image(nsImage: image).resizable().padding(2)
|
||||
} else {
|
||||
Image(systemName: "app.dashed")
|
||||
.font(.system(size: 10))
|
||||
.foregroundStyle(Onyx.Color.textTertiary)
|
||||
}
|
||||
}
|
||||
.frame(width: 20, height: 20)
|
||||
.background(Onyx.Color.surface.opacity(managed ? 0.9 : 0.5),
|
||||
in: .rect(cornerRadius: 5, style: .continuous))
|
||||
.opacity(managed ? 1 : 0.7)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,61 +237,64 @@ private struct VolumeBar: View {
|
||||
|
||||
@State private var isDragging = false
|
||||
|
||||
private let trackHeight: CGFloat = 5
|
||||
private let trackHeight: CGFloat = 6
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { geometry in
|
||||
let width = geometry.size.width
|
||||
let fraction = min(max(volume / Gain.maximumVolume, 0), 1)
|
||||
let fillWidth = width * fraction
|
||||
let knob: CGFloat = isDragging ? 13 : 11
|
||||
// Der Knopf soll an den Enden nicht überstehen.
|
||||
let travel = max(width - knob, 1)
|
||||
let fillWidth = travel * fraction + knob / 2
|
||||
|
||||
ZStack(alignment: .leading) {
|
||||
Capsule()
|
||||
.fill(Onyx.Color.elevated)
|
||||
.fill(Onyx.Color.surface)
|
||||
.frame(height: trackHeight)
|
||||
|
||||
// Markierung bei 100 %: darüber wird verstärkt, und man soll
|
||||
// sehen, wann man diese Grenze überschreitet.
|
||||
Rectangle()
|
||||
.fill(Onyx.Color.hairline)
|
||||
.frame(width: 1, height: trackHeight + 3)
|
||||
.offset(x: width / Gain.maximumVolume)
|
||||
.frame(width: 1, height: trackHeight + 4)
|
||||
.offset(x: knob / 2 + travel / Gain.maximumVolume)
|
||||
|
||||
Capsule()
|
||||
.fill(volume > 1 ? Onyx.Color.warning : Onyx.Color.accent)
|
||||
.frame(width: fillWidth, height: trackHeight)
|
||||
.opacity(isActive ? 1 : 0.28)
|
||||
.opacity(isActive ? 1 : 0.3)
|
||||
|
||||
// Der Pegel läuft **im** Regler mit, nicht daneben: eine
|
||||
// zweite Leiste pro Zeile wäre doppelt so viel Grafik für
|
||||
// dieselbe Auskunft.
|
||||
if isActive, level > 0.001 {
|
||||
Capsule()
|
||||
.fill(.white.opacity(0.35))
|
||||
.fill(.white.opacity(0.4))
|
||||
.frame(width: fillWidth * meterFraction, height: trackHeight)
|
||||
.blendMode(.plusLighter)
|
||||
.allowsHitTesting(false)
|
||||
}
|
||||
|
||||
Circle()
|
||||
.fill(Onyx.Color.textPrimary)
|
||||
.frame(width: isDragging ? 10 : 8, height: isDragging ? 10 : 8)
|
||||
.shadow(color: .black.opacity(0.4), radius: 1, y: 0.5)
|
||||
.offset(x: fillWidth - (isDragging ? 5 : 4))
|
||||
.opacity(isActive ? 1 : 0.5)
|
||||
.fill(.white)
|
||||
.frame(width: knob, height: knob)
|
||||
.shadow(color: .black.opacity(0.45), radius: 1.5, y: 0.5)
|
||||
.offset(x: travel * fraction)
|
||||
.opacity(isActive ? 1 : 0.55)
|
||||
}
|
||||
.frame(height: 14)
|
||||
.frame(height: 16)
|
||||
.contentShape(.rect)
|
||||
.gesture(
|
||||
DragGesture(minimumDistance: 0)
|
||||
.onChanged { value in
|
||||
isDragging = true
|
||||
let position = min(max(value.location.x / width, 0), 1)
|
||||
let position = min(max((value.location.x - knob / 2) / travel, 0), 1)
|
||||
onChange(position * Gain.maximumVolume)
|
||||
}
|
||||
.onEnded { _ in isDragging = false })
|
||||
}
|
||||
.frame(height: 14)
|
||||
.frame(height: 16)
|
||||
.animation(Onyx.Motion.value, value: isDragging)
|
||||
}
|
||||
|
||||
@@ -279,7 +320,7 @@ public struct AudioMixerWidget: OnyxWidget {
|
||||
public func makeView() -> AnyView {
|
||||
AnyView(
|
||||
ScrollView {
|
||||
MixerView(mixer: mixer)
|
||||
MixerView(mixer: mixer, compact: true)
|
||||
}
|
||||
.scrollIndicators(.never)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user