@@ -2,6 +2,8 @@ import Cocoa
22
33class ThumbnailView : FlippedView {
44 static let noOpenWindowToolTip = NSLocalizedString ( " App is running but has no open window " , comment: " " )
5+ // when calculating the width of a nstextfield, somehow we need to add this suffix to get the correct width
6+ static let extraTextForPadding = " lmnopqrstuvw "
57 var window_ : Window ?
68 var thumbnail = LightImageView ( )
79 var windowlessIcon = LightImageView ( )
@@ -276,20 +278,19 @@ class ThumbnailView: FlippedView {
276278 let availableRightWidth = view. isLastInRow ? 0 : CGFloat ( view. numberOfViewsInRow - 1 - view. indexInRow) * viewWidth
277279 let totalWidth = availableLeftWidth + availableRightWidth + viewWidth
278280 let maxLabelWidth = min ( totalWidth, maxAllowedWidth)
279- return maxLabelWidth - Appearance. intraCellPadding * 4
281+ return maxLabelWidth - Appearance. intraCellPadding * 2
280282 }
281283
282284 private func updateAppIconsLabelFrame( _ view: ThumbnailView ) {
283285 let viewWidth = view. frame. width
284- let labelWidth = view. label. fittingSize . width
286+ let labelWidth = view. label. cell! . cellSize . width
285287 let maxAllowedLabelWidth = getMaxAllowedLabelWidth ( view)
286288 let effectiveLabelWidth = max ( min ( labelWidth, maxAllowedLabelWidth) , viewWidth)
287- var leftOffset = CGFloat ( 0 )
288- var effectiveLabelWidth = max ( min ( labelWidth, maxAllowedLabelWidth) , viewWidth)
289+ - ( view. isFirstInRow && view. isLastInRow ? 4 : ( view. isFirstInRow || view. isLastInRow ? 2 : 0 ) ) * Appearance. intraCellPadding
289290 var leftOffset = - Appearance. intraCellPadding * 2
290291 if view. isFirstInRow && view. isLastInRow {
291292 leftOffset = - Appearance. intraCellPadding * 2
292- effectiveLabelWidth -= Appearance . intraCellPadding * 4
293+
293294 } else if view. isLastInRow {
294295 leftOffset = max ( 0 , effectiveLabelWidth - viewWidth + Appearance. intraCellPadding * 2 )
295296 } else if !view. isFirstInRow && !view. isLastInRow {
@@ -547,6 +548,28 @@ class ThumbnailView: FlippedView {
547548 return ThumbnailsPanel . maxThumbnailsWidth ( ) * Appearance. windowMaxWidthInRow - Appearance. interCellPadding * 2
548549 }
549550
551+ static func widthOfComfortableReadability( ) -> CGFloat ? {
552+ let labTitleView = ThumbnailTitleView ( font: Appearance . font)
553+ labTitleView. stringValue = " abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijk " + extraTextForPadding
554+ Logger . error ( labTitleView. font)
555+ return labTitleView. fittingSize. width
556+ }
557+
558+ static func widthOfLongestTitle( ) -> CGFloat ? {
559+ let labTitleView = ThumbnailTitleView ( font: Appearance . font)
560+ var maxWidth = CGFloat ( 0 )
561+ for window in Windows . list {
562+ guard window. shouldShowTheUser else { continue }
563+ labTitleView. stringValue = window. title + extraTextForPadding
564+ let width = labTitleView. fittingSize. width
565+ if width > maxWidth {
566+ maxWidth = width
567+ }
568+ }
569+ guard maxWidth > 0 else { return nil }
570+ return maxWidth
571+ }
572+
550573 static func minThumbnailWidth( ) -> CGFloat {
551574 return ThumbnailsPanel . maxThumbnailsWidth ( ) * Appearance. windowMinWidthInRow - Appearance. interCellPadding * 2
552575 }
0 commit comments