style(menubar): 将底部操作改为一体式液态玻璃胶囊
This commit is contained in:
@@ -196,29 +196,34 @@ struct MenuPanelView: View {
|
||||
.font(.system(size: 9)).foregroundStyle(.tertiary)
|
||||
}
|
||||
Spacer()
|
||||
Button { keepAwake.toggle() } label: {
|
||||
Image(systemName: keepAwake.isEnabled ? "cup.and.saucer.fill" : "cup.and.saucer")
|
||||
.frame(width: 20, height: 20)
|
||||
.foregroundStyle(keepAwake.isEnabled ? preferences.tintColor : Color.primary)
|
||||
HStack(spacing: 2) {
|
||||
Button { keepAwake.toggle() } label: {
|
||||
Image(systemName: keepAwake.isEnabled ? "cup.and.saucer.fill" : "cup.and.saucer")
|
||||
.frame(width: 20, height: 20)
|
||||
.foregroundStyle(keepAwake.isEnabled ? preferences.tintColor : Color.primary)
|
||||
}
|
||||
.help(keepAwake.didFail ? Text("awake.failed") : (keepAwake.isEnabled ? Text("awake.disable") : Text("awake.enable")))
|
||||
.accessibilityLabel(keepAwake.isEnabled ? Text("awake.disable") : Text("awake.enable"))
|
||||
.accessibilityValue(keepAwake.isEnabled ? Text("awake.on") : Text("awake.off"))
|
||||
Button { metrics.togglePause() } label: {
|
||||
Image(systemName: metrics.isPaused ? "play.fill" : "pause.fill").frame(width: 20, height: 20)
|
||||
}
|
||||
.help(metrics.isPaused ? Text("action.resume") : Text("action.pause"))
|
||||
.accessibilityLabel(metrics.isPaused ? Text("action.resume") : Text("action.pause"))
|
||||
Button { NSApp.activate(); openSettings() } label: {
|
||||
Image(systemName: "gearshape").frame(width: 20, height: 20)
|
||||
}
|
||||
.help(Text("action.settings")).accessibilityLabel(Text("action.settings"))
|
||||
Divider().frame(height: 18).padding(.horizontal, 3)
|
||||
Button { NSApp.terminate(nil) } label: {
|
||||
Image(systemName: "power").frame(width: 20, height: 20)
|
||||
}
|
||||
.help(Text("action.quit")).accessibilityLabel(Text("action.quit"))
|
||||
}
|
||||
.help(keepAwake.didFail ? Text("awake.failed") : (keepAwake.isEnabled ? Text("awake.disable") : Text("awake.enable")))
|
||||
.accessibilityLabel(keepAwake.isEnabled ? Text("awake.disable") : Text("awake.enable"))
|
||||
.accessibilityValue(keepAwake.isEnabled ? Text("awake.on") : Text("awake.off"))
|
||||
Button { metrics.togglePause() } label: {
|
||||
Image(systemName: metrics.isPaused ? "play.fill" : "pause.fill").frame(width: 20, height: 20)
|
||||
}
|
||||
.help(metrics.isPaused ? Text("action.resume") : Text("action.pause"))
|
||||
.accessibilityLabel(metrics.isPaused ? Text("action.resume") : Text("action.pause"))
|
||||
Button { NSApp.activate(); openSettings() } label: {
|
||||
Image(systemName: "gearshape").frame(width: 20, height: 20)
|
||||
}
|
||||
.help(Text("action.settings")).accessibilityLabel(Text("action.settings"))
|
||||
Button { NSApp.terminate(nil) } label: {
|
||||
Image(systemName: "power").frame(width: 20, height: 20)
|
||||
}
|
||||
.help(Text("action.quit")).accessibilityLabel(Text("action.quit"))
|
||||
.buttonStyle(FooterButtonStyle())
|
||||
.padding(4)
|
||||
.glassEffect(.regular, in: .capsule)
|
||||
}
|
||||
.buttonStyle(FooterButtonStyle())
|
||||
.controlSize(.small)
|
||||
.padding(.horizontal, 8).padding(.vertical, 6)
|
||||
}
|
||||
@@ -227,13 +232,24 @@ struct MenuPanelView: View {
|
||||
|
||||
private struct FooterButtonStyle: ButtonStyle {
|
||||
func makeBody(configuration: Configuration) -> some View {
|
||||
configuration.label
|
||||
.padding(.horizontal, 9).padding(.vertical, 6)
|
||||
.contentShape(RoundedRectangle(cornerRadius: 6))
|
||||
.overlay {
|
||||
RoundedRectangle(cornerRadius: 6)
|
||||
.strokeBorder(.primary.opacity(configuration.isPressed ? 0.5 : 0.18), lineWidth: 1)
|
||||
FooterButtonBody(isPressed: configuration.isPressed) {
|
||||
configuration.label
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct FooterButtonBody<Content: View>: View {
|
||||
let isPressed: Bool
|
||||
@ViewBuilder var content: () -> Content
|
||||
@State private var isHovered = false
|
||||
|
||||
var body: some View {
|
||||
content()
|
||||
.frame(width: 34, height: 34)
|
||||
.background {
|
||||
Circle().fill(.primary.opacity(isPressed ? 0.16 : (isHovered ? 0.08 : 0)))
|
||||
}
|
||||
.opacity(configuration.isPressed ? 0.6 : 1)
|
||||
.contentShape(Circle())
|
||||
.onHover { isHovered = $0 }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user