perf: cache expensive layout values 2

This commit is contained in:
lwouis committed 2026-02-11 21:35:27 +01:00
1 parent 904bd17c53
commit 13ed78bc23
4 files changed
+15 -2

No files matched your search

@@ -4,6 +4,11 @@ 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 {
return NSSize(width: NSView.noIntrinsicMetric, height: NSView.noIntrinsicMetric)
}
convenience init(font: NSFont) {
self.init(labelWithString: "")
self.font = font
+7 -1
View File
@@ -114,9 +114,15 @@ class ThumbnailView: FlippedView {
func mouseMoved() {
showOrHideWindowControls(true)
updateLabelTooltipIfNeeded()
mouseMovedCallback()
}
private func updateLabelTooltipIfNeeded() {
guard Preferences.appearanceStyle != .appIcons else { return }
label.toolTip = label.cell!.cellSize.width >= label.frame.size.width ? label.stringValue : nil
}
convenience init() {
self.init(frame: .zero)
setupView()
@@ -125,10 +131,10 @@ class ThumbnailView: FlippedView {
func updateRecycledCellWithNewContent(_ element: Window, _ index: Int, _ newHeight: CGFloat) {
window_ = element
label.toolTip = nil
updateValues(element, index, newHeight)
updateSizes(newHeight)
updatePositions(newHeight)
label.toolTip = label.cell!.cellSize.width >= label.frame.size.width ? label.stringValue : nil
}
func drawHighlight() {
+1 -1
View File
@@ -64,7 +64,7 @@ class ThumbnailsPanel: NSPanel {
static func maxThumbnailsWidth(_ screen: NSScreen = NSScreen.preferred) -> CGFloat {
if Preferences.appearanceStyle == .titles,
let readableWidth = ThumbnailView.widthOfComfortableReadability() {
let readableWidth = ThumbnailsView.layoutCache.comfortableReadabilityWidth {
return (
min(
screen.frame.width * Appearance.maxWidthOnScreen,
+2
View File
@@ -24,6 +24,7 @@ class ThumbnailsView {
layoutCache.iconWidth = iconFittingSize.width
layoutCache.iconHeight = iconFittingSize.height
layoutCache.dockLabelSize = firstView.dockLabelIcon.fittingSize
layoutCache.comfortableReadabilityWidth = ThumbnailView.widthOfComfortableReadability()
}
func updateBackgroundView() {
@@ -265,6 +266,7 @@ class ThumbnailsView {
var iconWidth = CGFloat(0)
var iconHeight = CGFloat(0)
var dockLabelSize = NSSize.zero
var comfortableReadabilityWidth: CGFloat?
}
}