Files
Memola/Memola/Canvas/View/Bridge/Views/CenterClipView.swift
T
2024-07-06 20:44:19 +07:00

26 lines
712 B
Swift

//
// CenterClipView.swift
// Memola
//
// Created by Dscyre Scotti on 7/6/24.
//
#if canImport(AppKit)
import AppKit
class CenterClipView: NSClipView {
override func constrainBoundsRect(_ proposedBounds: NSRect) -> NSRect {
var rect = super.constrainBoundsRect(proposedBounds)
if let containerView = self.documentView {
if (rect.size.width > containerView.frame.size.width) {
rect.origin.x = (containerView.frame.width - rect.width) / 2
}
if(rect.size.height > containerView.frame.size.height) {
rect.origin.y = (containerView.frame.height - rect.height) / 2
}
}
return rect
}
}
#endif