punchnet-macos/punchnet/Views/Common/CustomWindowControls.swift
2026-03-25 11:54:07 +08:00

63 lines
1.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// CustomWindowControls.swift
// punchnet
//
// Created by on 2026/3/25.
//
import SwiftUI
struct CustomWindowControls: View {
@State private var isHovering = false
var body: some View {
HStack(spacing: 8) {
// ()
CircleButton(color: .red, systemName: "xmark", isHovering: isHovering) {
//
if let window = NSApp.keyWindow {
window.close()
}
}
// // ()
// CircleButton(color: .yellow, systemName: "minus", isHovering: isHovering) {
// NSApp.keyWindow?.miniaturize(nil)
// }
//
// // / (绿)
// CircleButton(color: .green, systemName: "arrow.up.left.and.arrow.down.right", isHovering: isHovering) {
// NSApp.keyWindow?.toggleFullScreen(nil)
// }
}
.onHover { hovering in
withAnimation(.easeInOut(duration: 0.1)) {
isHovering = hovering
}
}
}
}
struct CircleButton: View {
let color: Color
let systemName: String
let isHovering: Bool
let action: () -> Void
var body: some View {
Button(action: action) {
ZStack {
Circle()
.fill(color.opacity(0.8))
.frame(width: 12, height: 12)
//
Image(systemName: systemName)
.font(.system(size: 8, weight: .bold))
.foregroundColor(.black.opacity(0.5))
.opacity(isHovering ? 1 : 0)
}
}
.buttonStyle(.plain)
}
}