Files
ghostty/macos/Sources/Features/About/CyclingIconView.swift
Lukas 6cf7e0cc54 macOS: fix swiftlint warnings
swiftlint 0.63.3 introduced a new rule called [`legacy_swiftui_aspect_ratio`](76363aa4d7/CHANGELOG.md (L314))
2026-08-24 11:34:38 +02:00

45 lines
1.3 KiB
Swift

import SwiftUI
import GhosttyKit
import Combine
/// A view that cycles through Ghostty's official icon variants.
struct CyclingIconView: View {
@EnvironmentObject var viewModel: AboutViewModel
var body: some View {
ZStack {
iconView(for: viewModel.currentIcon)
.id(viewModel.currentIcon)
}
.animation(.easeInOut(duration: 0.5), value: viewModel.currentIcon)
.frame(height: 128)
.onHover { hovering in
viewModel.isHovering = hovering
}
.onTapGesture {
viewModel.advanceToNextIcon()
}
.contextMenu {
if let currentIcon = viewModel.currentIcon {
Button("Copy Icon Config") {
NSPasteboard.general.setString("macos-icon = \(currentIcon.rawValue)", forType: .string)
}
}
}
.accessibilityLabel("Ghostty Application Icon")
.accessibilityHint("Click to cycle through icon variants")
}
@ViewBuilder
private func iconView(for icon: Ghostty.MacOSIcon?) -> some View {
let iconImage: Image = switch icon?.assetName {
case let assetName?: Image(assetName)
case nil: ghosttyIconImage()
}
iconImage
.resizable()
.scaledToFit()
}
}