Skip to content

Commit

Permalink
fix: improve label display in app-icons style
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Dec 28, 2024
1 parent dd05ba2 commit 7e501a4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/ui/main-window/ThumbnailFontIconView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 1 addition & 9 deletions src/ui/main-window/ThumbnailTitleView.swift
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}
11 changes: 5 additions & 6 deletions src/ui/main-window/ThumbnailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""))
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions src/ui/main-window/ThumbnailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 7e501a4

Please sign in to comment.