perf: remove normalize-subview to avoid appkit work
This commit is contained in:
1 parent
13ed78bc23
commit
ce2dfc1f19
11 files changed
+26
-42
No files matched your search
@@ -123,27 +123,16 @@ extension NSView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setSubviews(_ views: [NSView]) {
|
func setSubviews(_ views: [NSView]) {
|
||||||
for view in views {
|
|
||||||
normalizeSubview(view)
|
|
||||||
}
|
|
||||||
subviews = views
|
subviews = views
|
||||||
}
|
}
|
||||||
|
|
||||||
func addSubviews(_ views: [NSView]) {
|
func addSubviews(_ views: [NSView]) {
|
||||||
for view in views {
|
|
||||||
normalizeSubview(view)
|
|
||||||
}
|
|
||||||
subviews = subviews + views
|
subviews = subviews + views
|
||||||
}
|
}
|
||||||
|
|
||||||
func setSubviewAbove(_ view: NSView) {
|
func setSubviewAbove(_ view: NSView) {
|
||||||
normalizeSubview(view)
|
|
||||||
addSubview(view, positioned: .above, relativeTo: nil)
|
addSubview(view, positioned: .above, relativeTo: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func normalizeSubview(_ view: NSView) {
|
|
||||||
view.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Collection {
|
extension Collection {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class FeedbackWindow: NSWindow {
|
|||||||
|
|
||||||
private func setupView() {
|
private func setupView() {
|
||||||
let appIcon = LightImageView()
|
let appIcon = LightImageView()
|
||||||
|
appIcon.translatesAutoresizingMaskIntoConstraints = false
|
||||||
appIcon.updateContents(.cgImage(App.appIcon), NSSize(width: 80, height: 80))
|
appIcon.updateContents(.cgImage(App.appIcon), NSSize(width: 80, height: 80))
|
||||||
appIcon.fit(80, 80)
|
appIcon.fit(80, 80)
|
||||||
let appText = StackView([
|
let appText = StackView([
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ class LightImageView: NSView {
|
|||||||
init(frame frameRect: NSRect = .zero, withTransparencyChecks: Bool = false) {
|
init(frame frameRect: NSRect = .zero, withTransparencyChecks: Bool = false) {
|
||||||
self.withTransparencyChecks = withTransparencyChecks
|
self.withTransparencyChecks = withTransparencyChecks
|
||||||
super.init(frame: frameRect)
|
super.init(frame: frameRect)
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
wantsLayer = true
|
wantsLayer = true
|
||||||
// configure the layer for efficient GPU-scaling
|
// configure the layer for efficient GPU-scaling
|
||||||
layer!.contentsGravity = .resize
|
layer!.contentsGravity = .resize
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ class TrafficLightButton: NSButton {
|
|||||||
self.type = type
|
self.type = type
|
||||||
target = self
|
target = self
|
||||||
action = #selector(onClick)
|
action = #selector(onClick)
|
||||||
fit(TrafficLightButton.size, TrafficLightButton.size)
|
|
||||||
addTrackingArea(NSTrackingArea(rect: bounds, options: [.mouseEnteredAndExited, .activeInKeyWindow], owner: self, userInfo: nil))
|
addTrackingArea(NSTrackingArea(rect: bounds, options: [.mouseEnteredAndExited, .activeInKeyWindow], owner: self, userInfo: nil))
|
||||||
toolTip = tooltip
|
toolTip = tooltip
|
||||||
appearance = NSAppearance(named: .aqua)
|
appearance = NSAppearance(named: .aqua)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class ThumbnailFontIconView: ThumbnailTitleView {
|
|||||||
attributedStringValue = initialAttributedString
|
attributedStringValue = initialAttributedString
|
||||||
textColor = color
|
textColor = color
|
||||||
toolTip = tooltip
|
toolTip = tooltip
|
||||||
addOrUpdateConstraint(widthAnchor, cell!.cellSize.width)
|
frame.size = cell!.cellSize
|
||||||
}
|
}
|
||||||
|
|
||||||
// number should be in the interval [0-50]
|
// number should be in the interval [0-50]
|
||||||
@@ -69,14 +69,14 @@ class ThumbnailFontIconView: ThumbnailTitleView {
|
|||||||
class ThumbnailFilledFontIconView: NSView {
|
class ThumbnailFilledFontIconView: NSView {
|
||||||
convenience init(_ thumbnailFontIconView: ThumbnailFontIconView, backgroundColor: NSColor, size: CGFloat) {
|
convenience init(_ thumbnailFontIconView: ThumbnailFontIconView, backgroundColor: NSColor, size: CGFloat) {
|
||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
let backgroundView = ThumbnailFontIconView(symbol: .filledCircled, size: size - 3, color: backgroundColor)
|
let backgroundView = ThumbnailFontIconView(symbol: .filledCircled, size: size - 3, color: backgroundColor)
|
||||||
addSubview(backgroundView)
|
addSubview(backgroundView)
|
||||||
addSubview(thumbnailFontIconView, positioned: .above, relativeTo: nil)
|
addSubview(thumbnailFontIconView, positioned: .above, relativeTo: nil)
|
||||||
backgroundView.centerXAnchor.constraint(equalTo: thumbnailFontIconView.centerXAnchor).isActive = true
|
let fgSize = thumbnailFontIconView.frame.size
|
||||||
let offset = ((thumbnailFontIconView.cell!.cellSize.width - backgroundView.cell!.cellSize.width) / 2).rounded()
|
let bgSize = backgroundView.frame.size
|
||||||
backgroundView.topAnchor.constraint(equalTo: thumbnailFontIconView.topAnchor, constant: offset).isActive = true
|
let offset = ((fgSize.width - bgSize.width) / 2).rounded()
|
||||||
widthAnchor.constraint(equalTo: thumbnailFontIconView.widthAnchor).isActive = true
|
thumbnailFontIconView.frame.origin = .zero
|
||||||
heightAnchor.constraint(equalTo: thumbnailFontIconView.heightAnchor).isActive = true
|
backgroundView.frame.origin = NSPoint(x: (fgSize.width - bgSize.width) / 2, y: offset)
|
||||||
|
frame.size = fgSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,6 @@ import Cocoa
|
|||||||
|
|
||||||
class ThumbnailTitleView: NSTextField {
|
class ThumbnailTitleView: NSTextField {
|
||||||
private var currentWidth: CGFloat = -1
|
private var currentWidth: CGFloat = -1
|
||||||
private var widthConstraint: NSLayoutConstraint?
|
|
||||||
|
|
||||||
// we set their size manually; override this to remove wasteful appkit-side work
|
// we set their size manually; override this to remove wasteful appkit-side work
|
||||||
override var intrinsicContentSize: NSSize {
|
override var intrinsicContentSize: NSSize {
|
||||||
@@ -10,30 +9,26 @@ class ThumbnailTitleView: NSTextField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
convenience init(font: NSFont) {
|
convenience init(font: NSFont) {
|
||||||
self.init(labelWithString: "")
|
self.init(frame: .zero)
|
||||||
|
stringValue = ""
|
||||||
|
isEditable = false
|
||||||
|
isSelectable = false
|
||||||
|
isBezeled = false
|
||||||
|
drawsBackground = false
|
||||||
self.font = font
|
self.font = font
|
||||||
textColor = Appearance.fontColor
|
textColor = Appearance.fontColor
|
||||||
// drawsBackground = true
|
lineBreakMode = .byTruncatingTail
|
||||||
// backgroundColor = .red
|
|
||||||
allowsDefaultTighteningForTruncation = false
|
allowsDefaultTighteningForTruncation = false
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func fixHeight() {
|
func fixHeight() {
|
||||||
heightAnchor.constraint(equalToConstant: fittingSize.height).isActive = true
|
frame.size.height = cell!.cellSize.height
|
||||||
}
|
}
|
||||||
|
|
||||||
func setWidth(_ width: CGFloat) {
|
func setWidth(_ width: CGFloat) {
|
||||||
guard currentWidth != width else { return }
|
guard currentWidth != width else { return }
|
||||||
currentWidth = width
|
currentWidth = width
|
||||||
frame.size.width = 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) {
|
override func mouseMoved(with event: NSEvent) {
|
||||||
|
|||||||
@@ -182,7 +182,6 @@ class ThumbnailView: FlippedView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func setupView() {
|
private func setupView() {
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
setAccessibilityChildren([])
|
setAccessibilityChildren([])
|
||||||
wantsLayer = true
|
wantsLayer = true
|
||||||
layer!.masksToBounds = false // without this, label will be clipped in app-icons style since its larger than its parentView
|
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
|
thumbnail.shadow = shadow
|
||||||
appIcon.shadow = shadow
|
appIcon.shadow = shadow
|
||||||
dockLabelIcon.shadow = shadow
|
dockLabelIcon.shadow = shadow
|
||||||
appIcon.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
appIcon.setSubviewAbove(dockLabelIcon)
|
appIcon.setSubviewAbove(dockLabelIcon)
|
||||||
label.fixHeight()
|
label.fixHeight()
|
||||||
vStackView.wantsLayer = true
|
vStackView.wantsLayer = true
|
||||||
@@ -552,7 +550,7 @@ class ThumbnailView: FlippedView {
|
|||||||
static func widthOfComfortableReadability() -> CGFloat? {
|
static func widthOfComfortableReadability() -> CGFloat? {
|
||||||
let labTitleView = ThumbnailTitleView(font: Appearance.font)
|
let labTitleView = ThumbnailTitleView(font: Appearance.font)
|
||||||
labTitleView.stringValue = "abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz" + extraTextForPadding
|
labTitleView.stringValue = "abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz" + extraTextForPadding
|
||||||
return labTitleView.fittingSize.width
|
return labTitleView.cell!.cellSize.width
|
||||||
}
|
}
|
||||||
|
|
||||||
static func widthOfLongestTitle() -> CGFloat? {
|
static func widthOfLongestTitle() -> CGFloat? {
|
||||||
@@ -561,7 +559,7 @@ class ThumbnailView: FlippedView {
|
|||||||
for window in Windows.list {
|
for window in Windows.list {
|
||||||
guard window.shouldShowTheUser else { continue }
|
guard window.shouldShowTheUser else { continue }
|
||||||
labTitleView.stringValue = window.title + extraTextForPadding
|
labTitleView.stringValue = window.title + extraTextForPadding
|
||||||
let width = labTitleView.fittingSize.width
|
let width = labTitleView.cell!.cellSize.width
|
||||||
if width > maxWidth {
|
if width > maxWidth {
|
||||||
maxWidth = width
|
maxWidth = width
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ class ThumbnailsView {
|
|||||||
|
|
||||||
static func updateCachedSizes() {
|
static func updateCachedSizes() {
|
||||||
guard let firstView = ThumbnailsView.recycledViews.first else { return }
|
guard let firstView = ThumbnailsView.recycledViews.first else { return }
|
||||||
layoutCache.labelHeight = firstView.label.fittingSize.height
|
layoutCache.labelHeight = firstView.label.cell!.cellSize.height
|
||||||
let iconFittingSize = firstView.windowIndicatorIcons.first!.fittingSize
|
let iconCellSize = firstView.windowIndicatorIcons.first!.cell!.cellSize
|
||||||
layoutCache.iconWidth = iconFittingSize.width
|
layoutCache.iconWidth = iconCellSize.width
|
||||||
layoutCache.iconHeight = iconFittingSize.height
|
layoutCache.iconHeight = iconCellSize.height
|
||||||
layoutCache.dockLabelSize = firstView.dockLabelIcon.fittingSize
|
layoutCache.dockLabelSize = firstView.dockLabelIcon.frame.size
|
||||||
layoutCache.comfortableReadabilityWidth = ThumbnailView.widthOfComfortableReadability()
|
layoutCache.comfortableReadabilityWidth = ThumbnailView.widthOfComfortableReadability()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class PermissionsWindow: NSWindow {
|
|||||||
|
|
||||||
private func setupView() {
|
private func setupView() {
|
||||||
let appIcon = LightImageView()
|
let appIcon = LightImageView()
|
||||||
|
appIcon.translatesAutoresizingMaskIntoConstraints = false
|
||||||
appIcon.updateContents(.cgImage(App.appIcon), NSSize(width: 80, height: 80))
|
appIcon.updateContents(.cgImage(App.appIcon), NSSize(width: 80, height: 80))
|
||||||
appIcon.fit(80, 80)
|
appIcon.fit(80, 80)
|
||||||
let appText = TitleLabel(NSLocalizedString("AltTab needs some permissions", comment: ""))
|
let appText = TitleLabel(NSLocalizedString("AltTab needs some permissions", comment: ""))
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ class LabelAndControl: NSObject {
|
|||||||
onMouseEntered: EventClosure? = nil,
|
onMouseEntered: EventClosure? = nil,
|
||||||
onMouseExited: EventClosure? = nil) -> ClickHoverImageView {
|
onMouseExited: EventClosure? = nil) -> ClickHoverImageView {
|
||||||
let imageView = ThumbnailFontIconView(symbol: .circledInfo, size: size, color: .labelColor)
|
let imageView = ThumbnailFontIconView(symbol: .circledInfo, size: size, color: .labelColor)
|
||||||
|
imageView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
let view = ClickHoverImageView(infoCircle: imageView)
|
let view = ClickHoverImageView(infoCircle: imageView)
|
||||||
view.onClick = onClick
|
view.onClick = onClick
|
||||||
view.onMouseEntered = onMouseEntered
|
view.onMouseEntered = onMouseEntered
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import Cocoa
|
|||||||
class AboutTab {
|
class AboutTab {
|
||||||
static func initTab() -> NSView {
|
static func initTab() -> NSView {
|
||||||
let appIcon = LightImageView()
|
let appIcon = LightImageView()
|
||||||
|
appIcon.translatesAutoresizingMaskIntoConstraints = false
|
||||||
appIcon.updateContents(.cgImage(App.appIcon), NSSize(width: 256, height: 256))
|
appIcon.updateContents(.cgImage(App.appIcon), NSSize(width: 256, height: 256))
|
||||||
appIcon.fit(256, 256)
|
appIcon.fit(256, 256)
|
||||||
let appText = StackView([
|
let appText = StackView([
|
||||||
|
|||||||
Reference in new issue
Block a user