A collection of user interface components and drawing routines for building tasteful apps using AppKit.
appkit swift aqua ui mac

swift-format

+122 -42
+77
.swift-format
··· 1 + // SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers 2 + // 3 + // SPDX-License-Identifier: MPL-2.0 4 + { 5 + "fileScopedDeclarationPrivacy" : { 6 + "accessLevel" : "private" 7 + }, 8 + "indentConditionalCompilationBlocks" : true, 9 + "indentSwitchCaseLabels" : false, 10 + "indentation" : { 11 + "tabs" : 1 12 + }, 13 + "lineBreakAroundMultilineExpressionChainComponents" : false, 14 + "lineBreakBeforeControlFlowKeywords" : false, 15 + "lineBreakBeforeEachArgument" : false, 16 + "lineBreakBeforeEachGenericRequirement" : false, 17 + "lineBreakBetweenDeclarationAttributes" : false, 18 + "lineLength" : 200, 19 + "maximumBlankLines" : 10, 20 + "multiElementCollectionTrailingCommas" : false, 21 + "noAssignmentInExpressions" : { 22 + "allowedFunctions" : [ 23 + "XCTAssertNoThrow" 24 + ] 25 + }, 26 + "prioritizeKeepingFunctionOutputTogether" : false, 27 + "reflowMultilineStringLiterals" : "never", 28 + "respectsExistingLineBreaks" : true, 29 + "rules" : { 30 + "AllPublicDeclarationsHaveDocumentation" : false, 31 + "AlwaysUseLiteralForEmptyCollectionInit" : false, 32 + "AlwaysUseLowerCamelCase" : true, 33 + "AmbiguousTrailingClosureOverload" : true, 34 + "AvoidRetroactiveConformances" : true, 35 + "BeginDocumentationCommentWithOneLineSummary" : false, 36 + "DoNotUseSemicolons" : true, 37 + "DontRepeatTypeInStaticProperties" : true, 38 + "FileScopedDeclarationPrivacy" : true, 39 + "FullyIndirectEnum" : true, 40 + "GroupNumericLiterals" : true, 41 + "IdentifiersMustBeASCII" : false, 42 + "NeverForceUnwrap" : false, 43 + "NeverUseForceTry" : false, 44 + "NeverUseImplicitlyUnwrappedOptionals" : false, 45 + "NoAccessLevelOnExtensionDeclaration" : true, 46 + "NoAssignmentInExpressions" : true, 47 + "NoBlockComments" : false, 48 + "NoCasesWithOnlyFallthrough" : true, 49 + "NoEmptyLinesOpeningClosingBraces" : false, 50 + "NoEmptyTrailingClosureParentheses" : true, 51 + "NoLabelsInCasePatterns" : true, 52 + "NoLeadingUnderscores" : false, 53 + "NoParensAroundConditions" : true, 54 + "NoPlaygroundLiterals" : true, 55 + "NoVoidReturnOnFunctionSignature" : true, 56 + "OmitExplicitReturns" : false, 57 + "OneCasePerLine" : true, 58 + "OneVariableDeclarationPerLine" : true, 59 + "OnlyOneTrailingClosureArgument" : true, 60 + "OrderedImports" : true, 61 + "ReplaceForEachWithForLoop" : true, 62 + "ReturnVoidInsteadOfEmptyTuple" : true, 63 + "TypeNamesShouldBeCapitalized" : true, 64 + "UseEarlyExits" : false, 65 + "UseExplicitNilCheckInConditions" : true, 66 + "UseLetInEveryBoundCaseVariable" : false, 67 + "UseShorthandTypeNames" : true, 68 + "UseSingleLinePropertyGetter" : true, 69 + "UseSynthesizedInitializer" : true, 70 + "UseTripleSlashForDocumentationComments" : true, 71 + "UseWhereClausesInForLoops" : false, 72 + "ValidateDocumentationComments" : false 73 + }, 74 + "spacesAroundRangeFormationOperators" : false, 75 + "spacesBeforeEndOfLineComments" : 2, 76 + "version" : 1 77 + }
+2 -3
Sources/AquaKit/Controls and Views/AquaDragHandle.swift
··· 1 1 import AppKit 2 2 3 - /// This is an abstract superclass that draws nothing but handles drag functionality. 3 + /// This is an abstract superclass that draws nothing but handles drag functionality. 4 4 open class AquaDragHandle: NSControl { 5 5 public struct Drag { 6 6 public var initialLocation: NSPoint = .zero ··· 21 21 .mouseMoved, 22 22 .cursorUpdate, 23 23 .activeInKeyWindow, 24 - .inVisibleRect, 24 + .inVisibleRect 25 25 ], 26 26 owner: self, 27 27 userInfo: nil ··· 48 48 true 49 49 } 50 50 } 51 -
+3 -3
Sources/AquaKit/Controls and Views/AquaSplitView.swift
··· 4 4 override open var dividerColor: NSColor { 5 5 .aquaSeparatorColor 6 6 } 7 - 7 + 8 8 public override init(frame frameRect: NSRect) { 9 9 super.init(frame: frameRect) 10 10 dividerStyle = .thin 11 11 } 12 - 12 + 13 13 override open func viewDidChangeEffectiveAppearance() { 14 14 setNeedsDisplay(bounds) 15 15 } 16 - 16 + 17 17 public required init?(coder: NSCoder) { 18 18 fatalError("init(coder:) has not been implemented") 19 19 }
+4 -4
Sources/AquaKit/Controls and Views/AquaSplitViewResizeHandle.swift
··· 2 2 3 3 open class AquaSplitViewResizeHandle: AquaDragHandle { 4 4 public override init(frame frameRect: NSRect) { 5 - super.init(frame: frameRect ) 6 - 5 + super.init(frame: frameRect) 6 + 7 7 translatesAutoresizingMaskIntoConstraints = false 8 8 NSLayoutConstraint.activate([ 9 9 widthAnchor.constraint(equalToConstant: 16) 10 10 ]) 11 11 } 12 - 12 + 13 13 public required init?(coder: NSCoder) { 14 14 fatalError("init(coder:) has not been implemented") 15 15 } 16 - 16 + 17 17 override open func cursorUpdate(with event: NSEvent) { 18 18 NSCursor.columnResize(directions: [.all]).set() 19 19 }
+1 -1
Sources/AquaKit/Controls and Views/AquaWindowResizeHandle.swift
··· 11 11 translatesAutoresizingMaskIntoConstraints = false 12 12 NSLayoutConstraint.activate([ 13 13 widthAnchor.constraint(equalToConstant: AquaWindow.bottomBarThickness - 8), 14 - heightAnchor.constraint(equalToConstant: AquaWindow.bottomBarThickness - 8), 14 + heightAnchor.constraint(equalToConstant: AquaWindow.bottomBarThickness - 8) 15 15 ]) 16 16 } 17 17
+1 -1
Sources/AquaKit/General Purpose/NSColor+Aqua.swift
··· 9 9 public static var graphiteColor: NSColor { 10 10 #colorLiteral(red: 0.4922081232, green: 0.5492551327, blue: 0.632959187, alpha: 1) 11 11 } 12 - 12 + 13 13 public static var pinstripes: Self { 14 14 let stripeThickness = 1.5 15 15 let patternSize = CGSize(width: stripeThickness, height: stripeThickness * 3)
+1 -1
Sources/AquaKit/General Purpose/NSGradient+Aqua.swift
··· 12 12 dark: .graphiteColor.shadow(withLevel: 0.7)!.blended(withFraction: 0.5, of: .windowBackgroundColor)! 13 13 ) 14 14 return Self(colors: [ 15 - primary, secondary, primary, 15 + primary, secondary, primary 16 16 ]) 17 17 } 18 18 }
+1 -1
Sources/AquaKit/General Purpose/NSView+Anchoring.swift
··· 6 6 leadingAnchor.constraint(equalTo: guide.leadingAnchor), 7 7 trailingAnchor.constraint(equalTo: guide.trailingAnchor), 8 8 topAnchor.constraint(equalTo: guide.topAnchor), 9 - bottomAnchor.constraint(equalTo: guide.bottomAnchor), 9 + bottomAnchor.constraint(equalTo: guide.bottomAnchor) 10 10 ] 11 11 } 12 12 }
+1 -1
Sources/AquaKit/General Purpose/Split View Layout/NSSplitViewController+PreferredDividerPosition.swift
··· 26 26 runningPosition += totalExtent * item.preferredThicknessFraction 27 27 splitView.setPosition(runningPosition, ofDividerAt: dividerIndex) 28 28 } 29 - 29 + 30 30 dividerIndex += 1 31 31 } 32 32 }
+1 -1
Sources/AquaKit/General Purpose/WindowStateSentinelView.swift
··· 5 5 NSWindow.didBecomeKeyNotification, 6 6 NSWindow.didResignKeyNotification, 7 7 NSWindow.didBecomeMainNotification, 8 - NSWindow.didResignMainNotification, 8 + NSWindow.didResignMainNotification 9 9 ] 10 10 11 11 public override init(frame frameRect: NSRect) {
+1 -1
Sources/AquaKit/Source Lists/SourceListBottomBarViewController.swift
··· 74 74 NSLayoutConstraint.activate([ 75 75 resizeHandle.centerYAnchor.constraint(equalTo: view.centerYAnchor), 76 76 resizeHandle.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor), 77 - resizeHandle.heightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.heightAnchor, constant: -16), 77 + resizeHandle.heightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.heightAnchor, constant: -16) 78 78 ]) 79 79 80 80 automaticallyAppliesContentInsets = false
-1
Sources/AquaKit/Table Headers/AquaTableHeaderCell.swift
··· 1 1 import AppKit 2 2 3 - 4 3 open class AquaTableHeaderCell: NSTableHeaderCell { 5 4 public static var backgroundFillGradient: NSGradient { 6 5 .smoothAquaBarGradient
+2 -2
Sources/AquaKit/Web Views/AquaWebViewController.swift
··· 40 40 verticalScroller.rightAnchor.constraint(equalTo: view.rightAnchor), 41 41 verticalScroller.topAnchor.constraint(equalTo: view.topAnchor), 42 42 verticalScroller.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor), 43 - verticalScroller.widthAnchor.constraint(equalToConstant: verticalScrollerWidth), 43 + verticalScroller.widthAnchor.constraint(equalToConstant: verticalScrollerWidth) 44 44 ]) 45 45 46 46 NSLayoutConstraint.activate([ 47 47 horizontalScroller.leftAnchor.constraint(equalTo: view.leftAnchor), 48 48 horizontalScroller.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor), 49 49 horizontalScroller.bottomAnchor.constraint(equalTo: view.bottomAnchor), 50 - horizontalScroller.heightAnchor.constraint(equalToConstant: horizontalScrollerWidth), 50 + horizontalScroller.heightAnchor.constraint(equalToConstant: horizontalScrollerWidth) 51 51 ]) 52 52 53 53 view.addSubview(webView)
+5 -4
Sources/AquaKit/Windows/AquaTitlebarBackgroundView.swift
··· 5 5 super.init(frame: frameRect) 6 6 addSubview(WindowStateSentinelView()) 7 7 } 8 - 8 + 9 9 public required init?(coder: NSCoder) { 10 10 fatalError("init(coder:) has not been implemented") 11 11 } 12 - 12 + 13 13 static var gradient: NSGradient! { 14 - let color1 = NSColor(light: #colorLiteral(red: 0.9262896776, green: 0.9262896776, blue: 0.9262896776, alpha: 1), dark: .underPageBackgroundColor.highlight(withLevel: 0.3)!.withAlphaComponent(0.2)) 14 + let color1 = NSColor( 15 + light: #colorLiteral(red: 0.9262896776, green: 0.9262896776, blue: 0.9262896776, alpha: 1), dark: .underPageBackgroundColor.highlight(withLevel: 0.3)!.withAlphaComponent(0.2)) 15 16 let color2 = NSColor(light: #colorLiteral(red: 0.8432617784, green: 0.8432616591, blue: 0.8432617784, alpha: 1), dark: .underPageBackgroundColor.withAlphaComponent(0.2)) 16 17 return NSGradient(colors: [color1, color2])! 17 18 } ··· 29 30 30 31 NSColor.aquaSeparatorColor.setStroke() 31 32 dividerPath.stroke() 32 - 33 + 33 34 if let window, !window.isKeyWindow { 34 35 NSColor.pinstripes.setFill() 35 36 bounds.fill()
+1 -1
Sources/AquaKit/Windows/AquaToolbarToggleButton.swift
··· 5 5 super.init(frame: frameRect) 6 6 NSLayoutConstraint.activate([ 7 7 widthAnchor.constraint(equalToConstant: 30), 8 - heightAnchor.constraint(equalToConstant: Self.windowControlButtonHeight), 8 + heightAnchor.constraint(equalToConstant: Self.windowControlButtonHeight) 9 9 ]) 10 10 } 11 11
+3 -3
Sources/AquaKit/Windows/AquaTrafficLightButton.swift
··· 29 29 30 30 NSLayoutConstraint.activate([ 31 31 widthAnchor.constraint(equalToConstant: Self.windowControlButtonHeight), 32 - heightAnchor.constraint(equalToConstant: Self.windowControlButtonHeight), 32 + heightAnchor.constraint(equalToConstant: Self.windowControlButtonHeight) 33 33 ]) 34 34 35 35 imageView.imageScaling = .scaleProportionallyUpOrDown ··· 45 45 additionalSafeAreaInsets = NSEdgeInsets(top: 4, left: 4, bottom: 4, right: 4) 46 46 NSLayoutConstraint.activate([ 47 47 imageView.centerXAnchor.constraint(equalTo: centerXAnchor), 48 - imageView.centerYAnchor.constraint(equalTo: centerYAnchor), 48 + imageView.centerYAnchor.constraint(equalTo: centerYAnchor) 49 49 ]) 50 50 51 51 let trackingAreaOptions: NSTrackingArea.Options = [ 52 52 .activeAlways, 53 53 .mouseEnteredAndExited, 54 54 .assumeInside, 55 - .inVisibleRect, 55 + .inVisibleRect 56 56 ] 57 57 58 58 let trackingArea = NSTrackingArea(rect: .zero, options: trackingAreaOptions, owner: self)
+1 -1
Sources/AquaKit/Windows/AquaWindow.swift
··· 2 2 3 3 open class AquaWindow: NSWindow { 4 4 public static var bottomBarThickness: CGFloat { 30.0 } 5 - 5 + 6 6 private var _showsToolbarButton: Bool = false 7 7 override open var showsToolbarButton: Bool { 8 8 get { _showsToolbarButton }
+14 -10
Sources/AquaKit/Windows/AquaWindowBottomBarViewController.swift
··· 18 18 dividerPath.lineWidth = 1 19 19 return dividerPath 20 20 } 21 - 21 + 22 22 static var gradient: NSGradient! { 23 - let color1 = NSColor(light: #colorLiteral(red: 0.9262896776, green: 0.9262896776, blue: 0.9262896776, alpha: 1), dark: .underPageBackgroundColor.highlight(withLevel: 0.5)!.withAlphaComponent(0.2)) 24 - let color2 = NSColor(light: #colorLiteral(red: 0.8432617784, green: 0.8432616591, blue: 0.8432617784, alpha: 1), dark: .underPageBackgroundColor.shadow(withLevel: 0.6)!.withAlphaComponent(0.2)) 23 + let color1 = NSColor( 24 + light: #colorLiteral(red: 0.9262896776, green: 0.9262896776, blue: 0.9262896776, alpha: 1), 25 + dark: .underPageBackgroundColor.highlight(withLevel: 0.5)!.withAlphaComponent(0.2)) 26 + let color2 = NSColor( 27 + light: #colorLiteral(red: 0.8432617784, green: 0.8432616591, blue: 0.8432617784, alpha: 1), 28 + dark: .underPageBackgroundColor.shadow(withLevel: 0.6)!.withAlphaComponent(0.2)) 25 29 return NSGradient(colors: [color1, color2])! 26 30 } 27 31 ··· 41 45 open override func loadView() { 42 46 view = View() 43 47 } 44 - 48 + 45 49 open override func viewDidLoad() { 46 50 super.viewDidLoad() 47 - 51 + 48 52 let resizeHandle = AquaWindowResizeHandle() 49 53 resizeHandle.target = self 50 54 resizeHandle.action = #selector(resize(_:)) 51 55 resizeHandle.translatesAutoresizingMaskIntoConstraints = false 52 - 56 + 53 57 view.addSubview(resizeHandle) 54 - 58 + 55 59 NSLayoutConstraint.activate([ 56 60 resizeHandle.rightAnchor.constraint(equalTo: view.rightAnchor), 57 - resizeHandle.bottomAnchor.constraint(equalTo: view.bottomAnchor), 61 + resizeHandle.bottomAnchor.constraint(equalTo: view.bottomAnchor) 58 62 ]) 59 63 } 60 - 64 + 61 65 @objc private func resize(_ sender: AquaWindowResizeHandle) { 62 66 guard let drag = sender.activeDrag, let window = view.window else { return } 63 67 let deltaX = drag.finalLocation.x - drag.initialLocation.x 64 68 let deltaY = drag.initialLocation.y - drag.finalLocation.y 65 - 69 + 66 70 var frame = window.frame 67 71 frame.size.width += deltaX 68 72 frame.size.height += deltaY
+2 -2
Sources/AquaKit/Windows/AquaWindowContainerViewController.swift
··· 11 11 12 12 override open func viewDidLoad() { 13 13 super.viewDidLoad() 14 - 14 + 15 15 let titlebarBackgroundView = AquaTitlebarBackgroundView() 16 16 titlebarBackgroundView.translatesAutoresizingMaskIntoConstraints = false 17 17 ··· 21 21 titlebarBackgroundView.leftAnchor.constraint(equalTo: view.leftAnchor), 22 22 titlebarBackgroundView.rightAnchor.constraint(equalTo: view.rightAnchor), 23 23 titlebarBackgroundView.topAnchor.constraint(equalTo: view.topAnchor), 24 - titlebarBackgroundView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), 24 + titlebarBackgroundView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor) 25 25 ]) 26 26 } 27 27 }
+1 -1
Sources/AquaKit/Windows/AquaWindowControlButton.swift
··· 9 9 10 10 public override init(frame frameRect: NSRect) { 11 11 super.init(frame: frameRect) 12 - 12 + 13 13 addSubview(WindowStateSentinelView()) 14 14 15 15 title = ""