Zum Inhalt

apple/PhysarumApp/Sources/UI/HelpLabel.swift

#if !os(tvOS)
import SwiftUI

/// A control label with an optional inline ⓘ that reveals a help popover on tap
/// (macOS also shows it on hover; VoiceOver reads it as a hint). Empty `help`
/// renders just the label with no ⓘ. Extracted from ParamSlider so any non-scalar
/// control row can carry the same help affordance.
struct HelpLabel: View {
    let label: String
    let help: String
    var font: Font = Theme.Fonts.label

    init(_ label: String, help: String, font: Font = Theme.Fonts.label) {
        self.label = label; self.help = help; self.font = font
    }

    @State private var showHelp = false
    private var hasHelp: Bool { !help.isEmpty }

    var body: some View {
        HStack(spacing: 4) {
            Text(label).font(font).foregroundStyle(Theme.Colors.fgSecondary)
            if hasHelp {
                Image(systemName: "info.circle")
                    .font(.system(size: 10))
                    .foregroundStyle(Theme.Colors.fgTertiary)
            }
        }
        .contentShape(Rectangle())
        .onTapGesture { if hasHelp { showHelp = true } }
        #if os(macOS)
        .help(help)
        #endif
        .popover(isPresented: $showHelp) {
            Text(help)
                .font(.callout)
                .multilineTextAlignment(.leading)
                .frame(width: 260)
                .padding()
                .presentationCompactAdaptation(.popover)
        }
        .accessibilityHint(help)
    }
}
#endif