From 7e501a460ab4dc182796f09e40567071cdc7dc20 Mon Sep 17 00:00:00 2001 From: lwouis Date: Sat, 28 Dec 2024 19:13:59 +0100 Subject: [PATCH] fix: improve label display in app-icons style --- src/ui/main-window/ThumbnailFontIconView.swift | 2 +- src/ui/main-window/ThumbnailTitleView.swift | 10 +--------- src/ui/main-window/ThumbnailView.swift | 11 +++++------ src/ui/main-window/ThumbnailsView.swift | 17 +++++++++-------- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/ui/main-window/ThumbnailFontIconView.swift b/src/ui/main-window/ThumbnailFontIconView.swift index dfda7156..070d7b9d 100644 --- a/src/ui/main-window/ThumbnailFontIconView.swift +++ b/src/ui/main-window/ThumbnailFontIconView.swift @@ -21,7 +21,7 @@ class ThumbnailFontIconView: ThumbnailTitleView { color: NSColor = Appearance.fontColor, shadow: NSShadow? = ThumbnailView.makeShadow(Appearance.indicatedIconShadowColor)) { // This helps SF symbols display vertically centered and not clipped at the top - self.init(size, shadow: shadow, font: NSFont(name: "SF Pro Text", size: (size * 0.85).rounded())!) + self.init(shadow: shadow, font: NSFont(name: "SF Pro Text", size: (size * 0.85).rounded())!) stringValue = symbol.rawValue textColor = color addOrUpdateConstraint(widthAnchor, cell!.cellSize.width) diff --git a/src/ui/main-window/ThumbnailTitleView.swift b/src/ui/main-window/ThumbnailTitleView.swift index aba71a38..d7e2fca6 100644 --- a/src/ui/main-window/ThumbnailTitleView.swift +++ b/src/ui/main-window/ThumbnailTitleView.swift @@ -1,7 +1,7 @@ import Cocoa class ThumbnailTitleView: NSTextField { - convenience init(_ height: CGFloat, shadow: NSShadow? = ThumbnailView.makeShadow(Appearance.titleShadowColor), font: NSFont = Appearance.font) { + convenience init(shadow: NSShadow?, font: NSFont) { self.init(labelWithString: "") self.font = font textColor = Appearance.fontColor @@ -28,12 +28,4 @@ class ThumbnailTitleView: NSTextField { } return .byTruncatingHead } - - static func extraLineSpacing(for fontSize: CGFloat) -> CGFloat { - return fontSize * 0.2 - } - - static func maxHeight() -> CGFloat { - return Appearance.fontHeight + extraLineSpacing(for: Appearance.fontHeight) - } } diff --git a/src/ui/main-window/ThumbnailView.swift b/src/ui/main-window/ThumbnailView.swift index ccfa9a17..bac22bdf 100644 --- a/src/ui/main-window/ThumbnailView.swift +++ b/src/ui/main-window/ThumbnailView.swift @@ -7,7 +7,7 @@ class ThumbnailView: NSStackView { var windowlessIcon = NSImageView() var thumbnailContainer: NSStackView! var appIcon = NSImageView() - var label = ThumbnailTitleView(Appearance.fontHeight) + var label = ThumbnailTitleView(shadow: ThumbnailView.makeShadow(Appearance.titleShadowColor), font: Appearance.font) var fullscreenIcon = ThumbnailFontIconView(symbol: .circledPlusSign, tooltip: NSLocalizedString("Window is fullscreen", comment: "")) var minimizedIcon = ThumbnailFontIconView(symbol: .circledMinusSign, tooltip: NSLocalizedString("Window is minimized", comment: "")) var hiddenIcon = ThumbnailFontIconView(symbol: .circledSlashSign, tooltip: NSLocalizedString("App is hidden", comment: "")) @@ -84,8 +84,7 @@ class ThumbnailView: NSStackView { vStackView.leadingAnchor.constraint(equalTo: leadingAnchor), vStackView.trailingAnchor.constraint(equalTo: trailingAnchor), vStackView.topAnchor.constraint(equalTo: topAnchor), - label.topAnchor.constraint(equalTo: vStackView.bottomAnchor, constant: Appearance.intraCellPadding), - bottomAnchor.constraint(equalTo: label.bottomAnchor, constant: Appearance.intraCellPadding) + label.topAnchor.constraint(equalTo: vStackView.bottomAnchor), ]) } else { hStackView = NSStackView(views: [appIcon, label, hiddenIcon, fullscreenIcon, minimizedIcon, spaceIcon]) @@ -579,15 +578,15 @@ class ThumbnailView: NSStackView { return NSSize(width: Appearance.iconSize, height: Appearance.iconSize) } - static func height(_ screen: NSScreen) -> CGFloat { + static func height(_ screen: NSScreen, _ labelHeight: CGFloat) -> CGFloat { let topBottomEdgeInsetsSize = ThumbnailView.getTopBottomEdgeInsetsSize() if Preferences.appearanceStyle == .titles { - return max(ThumbnailView.iconSize(screen).height, ThumbnailTitleView.maxHeight()) + topBottomEdgeInsetsSize + return max(ThumbnailView.iconSize(screen).height, labelHeight) + topBottomEdgeInsetsSize } else if Preferences.appearanceStyle == .appIcons { return ThumbnailView.iconSize(screen).height + topBottomEdgeInsetsSize + Appearance.intraCellPadding - + ThumbnailTitleView.maxHeight() + + labelHeight + Appearance.intraCellPadding } return ThumbnailView.maxThumbnailHeight(screen).rounded(.down) diff --git a/src/ui/main-window/ThumbnailsView.swift b/src/ui/main-window/ThumbnailsView.swift index ab24b4fd..8a02619b 100644 --- a/src/ui/main-window/ThumbnailsView.swift +++ b/src/ui/main-window/ThumbnailsView.swift @@ -99,8 +99,8 @@ class ThumbnailsView: NSVisualEffectView { func updateItemsAndLayout(_ screen: NSScreen) { let widthMax = ThumbnailsPanel.maxThumbnailsWidth(screen).rounded() - if let (maxX, maxY) = layoutThumbnailViews(screen, widthMax) { - layoutParentViews(screen, maxX, widthMax, maxY) + if let (maxX, maxY, labelHeight) = layoutThumbnailViews(screen, widthMax) { + layoutParentViews(screen, maxX, widthMax, maxY, labelHeight) if Preferences.alignThumbnails == .center { centerRows(maxX) } @@ -116,8 +116,9 @@ class ThumbnailsView: NSVisualEffectView { } } - private func layoutThumbnailViews(_ screen: NSScreen, _ widthMax: CGFloat) -> (CGFloat, CGFloat)? { - let height = ThumbnailView.height(screen) + private func layoutThumbnailViews(_ screen: NSScreen, _ widthMax: CGFloat) -> (CGFloat, CGFloat, CGFloat)? { + let labelHeight = ThumbnailsView.recycledViews.first!.label.cell!.cellSize.height + let height = ThumbnailView.height(screen, labelHeight) let isLeftToRight = App.shared.userInterfaceLayoutDirection == .leftToRight let startingX = isLeftToRight ? Appearance.interCellPadding : widthMax - Appearance.interCellPadding var currentX = startingX @@ -151,7 +152,7 @@ class ThumbnailsView: NSVisualEffectView { window.rowIndex = rows.count - 1 } scrollView.documentView!.subviews = newViews - return (maxX, maxY) + return (maxX, maxY, labelHeight) } private func needNewLine(_ projectedX: CGFloat, _ widthMax: CGFloat) -> Bool { @@ -172,7 +173,7 @@ class ThumbnailsView: NSVisualEffectView { App.shared.userInterfaceLayoutDirection == .leftToRight ? currentX : currentX - width } - private func layoutParentViews(_ screen: NSScreen, _ maxX: CGFloat, _ widthMax: CGFloat, _ maxY: CGFloat) { + private func layoutParentViews(_ screen: NSScreen, _ maxX: CGFloat, _ widthMax: CGFloat, _ maxY: CGFloat, _ labelHeight: CGFloat) { let heightMax = ThumbnailsPanel.maxThumbnailsHeight(screen).rounded() ThumbnailsView.thumbnailsWidth = min(maxX, widthMax) @@ -183,8 +184,8 @@ class ThumbnailsView: NSVisualEffectView { var originY = Appearance.windowPadding if Preferences.appearanceStyle == .appIcons { // If there is title under the icon on the last line, the height of the title needs to be subtracted. - frameHeight = frameHeight - Appearance.intraCellPadding - ThumbnailTitleView.maxHeight() - originY = originY - Appearance.intraCellPadding - ThumbnailTitleView.maxHeight() + frameHeight = frameHeight - Appearance.intraCellPadding - labelHeight + originY = originY - Appearance.intraCellPadding - labelHeight } frame.size = NSSize(width: frameWidth, height: frameHeight)