Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596import ParcelAnimationimport ParcelConfigimport SwiftUI
struct SettingsPreviewPolicy: Equatable { let motion: MotionConfiguration let reduceMotion: Bool let reduceTransparency: Bool let increaseContrast: Bool
var level: WhimsyLevel { switch motion.level { case .calm: .calm case .playful: .playful case .extra: .extra } }
var spec: MotionSpec? { guard motion.transitions != .snap, MotionPolicy(enabled: motion.enabled, reduceMotion: reduceMotion).behavior(for: .miniMap, level: level) == .animate else { return nil } let token: MotionToken = motion.transitions == .ghost && !reduceTransparency ? .fade : .shuffle return token.spec(settings: MotionSettings(level: level, speedMultiplier: motion.speed)) }
var ghost: Bool { motion.transitions == .ghost && !reduceTransparency && !reduceMotion && motion.enabled } var borderWidth: CGFloat { increaseContrast ? 3 : 1 }}
struct MotionPreview: View, SearchableSettingsPane { let motion: MotionConfiguration
static let searchControls: [SettingsControl] = { [ SettingsControl( "settings.motion.preview", section: .motion, title: SettingsText.string("Preview motion")) ] }() @Environment(\.accessibilityReduceMotion) private var reduceMotion @Environment(\.accessibilityReduceTransparency) private var reduceTransparency @Environment(\.colorSchemeContrast) private var contrast @State private var alternate = false
private var policy: SettingsPreviewPolicy { SettingsPreviewPolicy( motion: motion, reduceMotion: reduceMotion, reduceTransparency: reduceTransparency, increaseContrast: contrast == .increased) }
private var animation: Animation? { guard let spec = policy.spec else { return nil } switch spec.curve { case .spring, .glide: return .spring(duration: spec.duration, bounce: spec.bounce) case .fade: return .easeInOut(duration: spec.duration) } }
var body: some View { VStack(alignment: .leading, spacing: 12) { ZStack { RoundedRectangle(cornerRadius: 12) .fill(Color(nsColor: .controlBackgroundColor)) HStack(spacing: 8) { RoundedRectangle(cornerRadius: 6) .fill(Color.accentColor) .frame(width: alternate ? 110 : 160) RoundedRectangle(cornerRadius: 6) .fill(Color(nsColor: .secondaryLabelColor)) .frame(width: alternate ? 160 : 110) } .opacity(policy.ghost && alternate ? 0.7 : 1) .padding(12) } .overlay(RoundedRectangle(cornerRadius: 12).stroke(Color.primary, lineWidth: policy.borderWidth)) .frame(width: 310, height: 110) .accessibilityHidden(true) Button(Self.control("settings.motion.preview").title) { withAnimation(animation) { alternate.toggle() } } .settingsSearchTarget(Self.control("settings.motion.preview")) } .onChange(of: policy) { old, new in if old.motion.speed != new.motion.speed { withAnimation(animation) { alternate.toggle() } } else { var transaction = Transaction(animation: nil) transaction.disablesAnimations = true withTransaction(transaction) { alternate = false } } } }}