diff --git a/src/api-wrappers/HelperExtensions.swift b/src/api-wrappers/HelperExtensions.swift index 0f289482..7018c7e2 100644 --- a/src/api-wrappers/HelperExtensions.swift +++ b/src/api-wrappers/HelperExtensions.swift @@ -123,27 +123,16 @@ extension NSView { } func setSubviews(_ views: [NSView]) { - for view in views { - normalizeSubview(view) - } subviews = views } func addSubviews(_ views: [NSView]) { - for view in views { - normalizeSubview(view) - } subviews = subviews + views } func setSubviewAbove(_ view: NSView) { - normalizeSubview(view) addSubview(view, positioned: .above, relativeTo: nil) } - - private func normalizeSubview(_ view: NSView) { - view.translatesAutoresizingMaskIntoConstraints = false - } } extension Collection { diff --git a/src/ui/FeedbackWindow.swift b/src/ui/FeedbackWindow.swift index c4175293..8b6e50ed 100644 --- a/src/ui/FeedbackWindow.swift +++ b/src/ui/FeedbackWindow.swift @@ -29,6 +29,7 @@ class FeedbackWindow: NSWindow { private func setupView() { let appIcon = LightImageView() + appIcon.translatesAutoresizingMaskIntoConstraints = false appIcon.updateContents(.cgImage(App.appIcon), NSSize(width: 80, height: 80)) appIcon.fit(80, 80) let appText = StackView([ diff --git a/src/ui/generic-components/LightImageView.swift b/src/ui/generic-components/LightImageView.swift index f7f7a493..c126263f 100644 --- a/src/ui/generic-components/LightImageView.swift +++ b/src/ui/generic-components/LightImageView.swift @@ -14,7 +14,6 @@ class LightImageView: NSView { init(frame frameRect: NSRect = .zero, withTransparencyChecks: Bool = false) { self.withTransparencyChecks = withTransparencyChecks super.init(frame: frameRect) - translatesAutoresizingMaskIntoConstraints = false wantsLayer = true // configure the layer for efficient GPU-scaling layer!.contentsGravity = .resize diff --git a/src/ui/generic-components/TrafficLightButton.swift b/src/ui/generic-components/TrafficLightButton.swift index 055cd015..e54a518c 100644 --- a/src/ui/generic-components/TrafficLightButton.swift +++ b/src/ui/generic-components/TrafficLightButton.swift @@ -13,7 +13,6 @@ class TrafficLightButton: NSButton { self.type = type target = self action = #selector(onClick) - fit(TrafficLightButton.size, TrafficLightButton.size) addTrackingArea(NSTrackingArea(rect: bounds, options: [.mouseEnteredAndExited, .activeInKeyWindow], owner: self, userInfo: nil)) toolTip = tooltip appearance = NSAppearance(named: .aqua) diff --git a/src/ui/main-window/ThumbnailFontIconView.swift b/src/ui/main-window/ThumbnailFontIconView.swift index 29967087..5f214aaf 100644 --- a/src/ui/main-window/ThumbnailFontIconView.swift +++ b/src/ui/main-window/ThumbnailFontIconView.swift @@ -32,7 +32,7 @@ class ThumbnailFontIconView: ThumbnailTitleView { attributedStringValue = initialAttributedString textColor = color toolTip = tooltip - addOrUpdateConstraint(widthAnchor, cell!.cellSize.width) + frame.size = cell!.cellSize } // number should be in the interval [0-50] @@ -69,14 +69,14 @@ class ThumbnailFontIconView: ThumbnailTitleView { class ThumbnailFilledFontIconView: NSView { convenience init(_ thumbnailFontIconView: ThumbnailFontIconView, backgroundColor: NSColor, size: CGFloat) { self.init(frame: .zero) - translatesAutoresizingMaskIntoConstraints = false let backgroundView = ThumbnailFontIconView(symbol: .filledCircled, size: size - 3, color: backgroundColor) addSubview(backgroundView) addSubview(thumbnailFontIconView, positioned: .above, relativeTo: nil) - backgroundView.centerXAnchor.constraint(equalTo: thumbnailFontIconView.centerXAnchor).isActive = true - let offset = ((thumbnailFontIconView.cell!.cellSize.width - backgroundView.cell!.cellSize.width) / 2).rounded() - backgroundView.topAnchor.constraint(equalTo: thumbnailFontIconView.topAnchor, constant: offset).isActive = true - widthAnchor.constraint(equalTo: thumbnailFontIconView.widthAnchor).isActive = true - heightAnchor.constraint(equalTo: thumbnailFontIconView.heightAnchor).isActive = true + let fgSize = thumbnailFontIconView.frame.size + let bgSize = backgroundView.frame.size + let offset = ((fgSize.width - bgSize.width) / 2).rounded() + thumbnailFontIconView.frame.origin = .zero + backgroundView.frame.origin = NSPoint(x: (fgSize.width - bgSize.width) / 2, y: offset) + frame.size = fgSize } } diff --git a/src/ui/main-window/ThumbnailTitleView.swift b/src/ui/main-window/ThumbnailTitleView.swift index a259b972..edbfebb7 100644 --- a/src/ui/main-window/ThumbnailTitleView.swift +++ b/src/ui/main-window/ThumbnailTitleView.swift @@ -2,7 +2,6 @@ import Cocoa class ThumbnailTitleView: NSTextField { private var currentWidth: CGFloat = -1 - private var widthConstraint: NSLayoutConstraint? // we set their size manually; override this to remove wasteful appkit-side work override var intrinsicContentSize: NSSize { @@ -10,30 +9,26 @@ class ThumbnailTitleView: NSTextField { } convenience init(font: NSFont) { - self.init(labelWithString: "") + self.init(frame: .zero) + stringValue = "" + isEditable = false + isSelectable = false + isBezeled = false + drawsBackground = false self.font = font textColor = Appearance.fontColor - // drawsBackground = true - // backgroundColor = .red + lineBreakMode = .byTruncatingTail allowsDefaultTighteningForTruncation = false - translatesAutoresizingMaskIntoConstraints = false } func fixHeight() { - heightAnchor.constraint(equalToConstant: fittingSize.height).isActive = true + frame.size.height = cell!.cellSize.height } func setWidth(_ width: CGFloat) { guard currentWidth != width else { return } currentWidth = width frame.size.width = width - if let widthConstraint { - widthConstraint.constant = width - } else { - let constraint = widthAnchor.constraint(equalToConstant: width) - constraint.isActive = true - widthConstraint = constraint - } } override func mouseMoved(with event: NSEvent) { diff --git a/src/ui/main-window/ThumbnailView.swift b/src/ui/main-window/ThumbnailView.swift index b48ec8b2..afbe006f 100644 --- a/src/ui/main-window/ThumbnailView.swift +++ b/src/ui/main-window/ThumbnailView.swift @@ -182,7 +182,6 @@ class ThumbnailView: FlippedView { } private func setupView() { - translatesAutoresizingMaskIntoConstraints = false setAccessibilityChildren([]) wantsLayer = true layer!.masksToBounds = false // without this, label will be clipped in app-icons style since its larger than its parentView @@ -196,7 +195,6 @@ class ThumbnailView: FlippedView { thumbnail.shadow = shadow appIcon.shadow = shadow dockLabelIcon.shadow = shadow - appIcon.translatesAutoresizingMaskIntoConstraints = false appIcon.setSubviewAbove(dockLabelIcon) label.fixHeight() vStackView.wantsLayer = true @@ -552,7 +550,7 @@ class ThumbnailView: FlippedView { static func widthOfComfortableReadability() -> CGFloat? { let labTitleView = ThumbnailTitleView(font: Appearance.font) labTitleView.stringValue = "abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz" + extraTextForPadding - return labTitleView.fittingSize.width + return labTitleView.cell!.cellSize.width } static func widthOfLongestTitle() -> CGFloat? { @@ -561,7 +559,7 @@ class ThumbnailView: FlippedView { for window in Windows.list { guard window.shouldShowTheUser else { continue } labTitleView.stringValue = window.title + extraTextForPadding - let width = labTitleView.fittingSize.width + let width = labTitleView.cell!.cellSize.width if width > maxWidth { maxWidth = width } diff --git a/src/ui/main-window/ThumbnailsView.swift b/src/ui/main-window/ThumbnailsView.swift index 59b53878..7355d333 100644 --- a/src/ui/main-window/ThumbnailsView.swift +++ b/src/ui/main-window/ThumbnailsView.swift @@ -19,11 +19,11 @@ class ThumbnailsView { static func updateCachedSizes() { guard let firstView = ThumbnailsView.recycledViews.first else { return } - layoutCache.labelHeight = firstView.label.fittingSize.height - let iconFittingSize = firstView.windowIndicatorIcons.first!.fittingSize - layoutCache.iconWidth = iconFittingSize.width - layoutCache.iconHeight = iconFittingSize.height - layoutCache.dockLabelSize = firstView.dockLabelIcon.fittingSize + layoutCache.labelHeight = firstView.label.cell!.cellSize.height + let iconCellSize = firstView.windowIndicatorIcons.first!.cell!.cellSize + layoutCache.iconWidth = iconCellSize.width + layoutCache.iconHeight = iconCellSize.height + layoutCache.dockLabelSize = firstView.dockLabelIcon.frame.size layoutCache.comfortableReadabilityWidth = ThumbnailView.widthOfComfortableReadability() } diff --git a/src/ui/permission-window/PermissionsWindow.swift b/src/ui/permission-window/PermissionsWindow.swift index 04145a30..aba359dc 100644 --- a/src/ui/permission-window/PermissionsWindow.swift +++ b/src/ui/permission-window/PermissionsWindow.swift @@ -38,6 +38,7 @@ class PermissionsWindow: NSWindow { private func setupView() { let appIcon = LightImageView() + appIcon.translatesAutoresizingMaskIntoConstraints = false appIcon.updateContents(.cgImage(App.appIcon), NSSize(width: 80, height: 80)) appIcon.fit(80, 80) let appText = TitleLabel(NSLocalizedString("AltTab needs some permissions", comment: "")) diff --git a/src/ui/preferences-window/LabelAndControl.swift b/src/ui/preferences-window/LabelAndControl.swift index 0a8bb88c..1755fc1e 100644 --- a/src/ui/preferences-window/LabelAndControl.swift +++ b/src/ui/preferences-window/LabelAndControl.swift @@ -134,6 +134,7 @@ class LabelAndControl: NSObject { onMouseEntered: EventClosure? = nil, onMouseExited: EventClosure? = nil) -> ClickHoverImageView { let imageView = ThumbnailFontIconView(symbol: .circledInfo, size: size, color: .labelColor) + imageView.translatesAutoresizingMaskIntoConstraints = false let view = ClickHoverImageView(infoCircle: imageView) view.onClick = onClick view.onMouseEntered = onMouseEntered diff --git a/src/ui/preferences-window/tabs/AboutTab.swift b/src/ui/preferences-window/tabs/AboutTab.swift index 599ea863..6a01c91d 100644 --- a/src/ui/preferences-window/tabs/AboutTab.swift +++ b/src/ui/preferences-window/tabs/AboutTab.swift @@ -3,6 +3,7 @@ import Cocoa class AboutTab { static func initTab() -> NSView { let appIcon = LightImageView() + appIcon.translatesAutoresizingMaskIntoConstraints = false appIcon.updateContents(.cgImage(App.appIcon), NSSize(width: 256, height: 256)) appIcon.fit(256, 256) let appText = StackView([