diff --git a/Sources/AquaKit/Controls and Views/AquaDragHandle.swift b/Sources/AquaKit/Controls and Views/AquaDragHandle.swift new file mode 100644 index 0000000..e664b73 --- /dev/null +++ b/Sources/AquaKit/Controls and Views/AquaDragHandle.swift @@ -0,0 +1,51 @@ +import AppKit + +/// This is an abstract superclass that draws nothing but handles drag functionality. +open class AquaDragHandle: NSControl { + public struct Drag { + public var initialLocation: NSPoint = .zero + public var finalLocation: NSPoint = .zero + } + + override open var mouseDownCanMoveWindow: Bool { false } + public private(set) var activeDrag: Drag? + + public override init(frame frameRect: NSRect) { + super.init(frame: frameRect) + + addTrackingArea( + NSTrackingArea( + rect: .zero, + options: [ + .mouseEnteredAndExited, + .mouseMoved, + .cursorUpdate, + .activeInKeyWindow, + .inVisibleRect, + ], + owner: self, + userInfo: nil + ) + ) + } + + public required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override open func mouseDown(with event: NSEvent) { + activeDrag = Drag(initialLocation: convert(event.locationInWindow, from: nil)) + } + + override open func mouseDragged(with event: NSEvent) { + guard var drag = activeDrag else { return } + drag.finalLocation = convert(event.locationInWindow, from: nil) + activeDrag = drag + sendAction(action, to: target) + } + + override open func acceptsFirstMouse(for event: NSEvent?) -> Bool { + true + } +} + diff --git a/Sources/AquaKit/Controls and Views/AquaSplitViewResizeHandle.swift b/Sources/AquaKit/Controls and Views/AquaSplitViewResizeHandle.swift index aaa1040..9f9d1fc 100644 --- a/Sources/AquaKit/Controls and Views/AquaSplitViewResizeHandle.swift +++ b/Sources/AquaKit/Controls and Views/AquaSplitViewResizeHandle.swift @@ -1,60 +1,23 @@ import AppKit -open class AquaSplitViewResizeHandle: NSControl { - public struct Drag { - public var initialLocation: NSPoint = .zero - public var finalLocation: NSPoint = .zero - } - - override open var mouseDownCanMoveWindow: Bool { false } - public private(set) var activeDrag: Drag? - +open class AquaSplitViewResizeHandle: AquaDragHandle { public override init(frame frameRect: NSRect) { - super.init(frame: frameRect) - - addTrackingArea( - NSTrackingArea( - rect: .zero, - options: [ - .mouseEnteredAndExited, - .mouseMoved, - .cursorUpdate, - .activeInKeyWindow, - .inVisibleRect, - ], - owner: self, - userInfo: nil - ) - ) - + super.init(frame: frameRect ) + + translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ widthAnchor.constraint(equalToConstant: 16) ]) } - + public required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - - override open func mouseDown(with event: NSEvent) { - activeDrag = Drag(initialLocation: convert(event.locationInWindow, from: nil)) - } - - override open func mouseDragged(with event: NSEvent) { - guard var drag = activeDrag else { return } - drag.finalLocation = convert(event.locationInWindow, from: nil) - activeDrag = drag - sendAction(action, to: target) - } - + override open func cursorUpdate(with event: NSEvent) { NSCursor.columnResize(directions: [.all]).set() } - override open func acceptsFirstMouse(for event: NSEvent?) -> Bool { - true - } - override open func draw(_ dirtyRect: NSRect) { let path = NSBezierPath() let bounds = bounds.insetBy(dx: 4, dy: 0) diff --git a/Sources/AquaKit/Controls and Views/AquaWindowResizeHandle.swift b/Sources/AquaKit/Controls and Views/AquaWindowResizeHandle.swift new file mode 100644 index 0000000..c06d8d3 --- /dev/null +++ b/Sources/AquaKit/Controls and Views/AquaWindowResizeHandle.swift @@ -0,0 +1,51 @@ +import AppKit + +class AquaWindowResizeHandle: AquaDragHandle { + var cornerInset: CGFloat = 12 + var lineSpacing: CGFloat = 2 + var lineCount: Int = 3 + + public override init(frame frameRect: NSRect) { + super.init(frame: frameRect) + + translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([ + widthAnchor.constraint(equalToConstant: AquaWindow.bottomBarThickness - 8), + heightAnchor.constraint(equalToConstant: AquaWindow.bottomBarThickness - 8), + ]) + } + + public required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func mouseMoved(with event: NSEvent) { + NSCursor.frameResize(position: .bottomRight, directions: .all).set() + } + + override func draw(_ dirtyRect: NSRect) { + let cx = bounds.maxX - cornerInset + let cy = bounds.minY + cornerInset + + let gripPath = NSBezierPath() + + for i in 0..