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

Bringing in some of the infrastructure for AquaWebViewController

+112 -5
+7
Sources/AquaKit/General Purpose/Geometry/NSSize+Plus.swift
··· 1 + import Foundation 2 + 3 + extension NSSize { 4 + public static func + (lhs: NSSize, rhs: NSSize) -> NSSize { 5 + NSSize(width: lhs.width + rhs.width, height: lhs.height + rhs.height) 6 + } 7 + }
+40
Sources/AquaKit/General Purpose/Geometry/Orientation.swift
··· 1 + import AppKit 2 + 3 + public enum Orientation { 4 + case vertical 5 + case horizontal 6 + } 7 + 8 + extension NSSize { 9 + public subscript(orientation: Orientation) -> CGFloat { 10 + get { 11 + switch orientation { 12 + case .vertical: height 13 + case .horizontal: width 14 + } 15 + } 16 + set { 17 + switch orientation { 18 + case .vertical: height = newValue 19 + case .horizontal: width = newValue 20 + } 21 + } 22 + } 23 + } 24 + 25 + extension NSPoint { 26 + public subscript(orientation: Orientation) -> CGFloat { 27 + get { 28 + switch orientation { 29 + case .vertical: y 30 + case .horizontal: x 31 + } 32 + } 33 + set { 34 + switch orientation { 35 + case .vertical: y = newValue 36 + case .horizontal: x = newValue 37 + } 38 + } 39 + } 40 + }
+64
Sources/AquaKit/Scroll Views/AquaScrollState.swift
··· 1 + import Foundation 2 + import AppKit 3 + 4 + public struct AquaScrollState { 5 + public var scrollPosition: NSPoint 6 + public var contentSize: NSSize 7 + public var visibleSize: NSSize 8 + 9 + public init(scrollPosition: NSPoint, contentSize: NSSize, visibleSize: NSSize) { 10 + self.scrollPosition = scrollPosition 11 + self.contentSize = contentSize 12 + self.visibleSize = visibleSize 13 + } 14 + 15 + public var maxOffset: NSSize { 16 + NSSize( 17 + width: max(contentSize.width - visibleSize.width, 0), 18 + height: max(contentSize.height - visibleSize.height, 0) 19 + ) 20 + } 21 + 22 + public var verticalOverscroll: CGFloat { 23 + absoluteExcess(of: scrollPosition.y, in: 0..<maxOffset.height) 24 + } 25 + 26 + public func absoluteExcess(of position: CGFloat, in range: Range<CGFloat>) -> CGFloat { 27 + if position < range.lowerBound { 28 + range.lowerBound - position 29 + } else if position > range.upperBound { 30 + position - range.upperBound 31 + } else { 32 + 0 33 + } 34 + } 35 + 36 + public func absoluteExcess(of point: NSPoint, in size: NSSize) -> NSSize { 37 + NSSize( 38 + width: absoluteExcess(of: point.x, in: 0..<size.width), 39 + height: absoluteExcess(of: point.y, in: 0..<size.height) 40 + ) 41 + } 42 + 43 + public var effectiveContentSize: NSSize { 44 + contentSize + absoluteExcess(of: scrollPosition, in: maxOffset) 45 + } 46 + } 47 + 48 + 49 + extension NSScroller { 50 + public func adopt(state: AquaScrollState, orientation: Orientation) { 51 + let maxOffset = state.maxOffset 52 + let effectiveContentSize = state.effectiveContentSize 53 + knobProportion = min(max(state.visibleSize[orientation] / effectiveContentSize[orientation], 0.0), 1.0) 54 + doubleValue = maxOffset[orientation] > 0 ? min(max(state.scrollPosition[orientation] / maxOffset[orientation], 0.0), 1.0) : 0.0 55 + isEnabled = maxOffset[orientation] > 0 56 + isHidden = maxOffset[orientation] <= 0 57 + } 58 + } 59 + 60 + extension AquaScroller { 61 + public func adopt(state: AquaScrollState) { 62 + adopt(state: state, orientation: orientation) 63 + } 64 + }
+1 -5
Sources/AquaKit/Scroll Views/AquaScroller.swift
··· 2 2 import AquaKit 3 3 4 4 public class AquaScroller: NSScroller { 5 - public enum Orientation { 6 - case vertical, horizontal 7 - } 8 - 9 5 public let orientation: Orientation 10 6 11 7 public override var floatValue: Float { ··· 269 265 } 270 266 } 271 267 272 - extension AquaScroller.Orientation { 268 + fileprivate extension Orientation { 273 269 /// The affine transform that maps between screen space and canonical (vertical) 274 270 /// coordinate space. For vertical this is the identity; for horizontal it swaps 275 271 /// the x and y axes. This transform is its own inverse.