From ced5ee60c13716fd7810fa76a09c13f27484cbbe Mon Sep 17 00:00:00 2001 From: "louis.pontoise" Date: Thu, 16 Jan 2020 14:08:18 +0900 Subject: [PATCH] fix: add rough downscaling when there are many windows (closes #69) --- alt-tab-macos/ui/Cell.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/alt-tab-macos/ui/Cell.swift b/alt-tab-macos/ui/Cell.swift index 01b34a3c..d1d1f18f 100644 --- a/alt-tab-macos/ui/Cell.swift +++ b/alt-tab-macos/ui/Cell.swift @@ -109,16 +109,23 @@ class Cell: NSCollectionViewItem { return vStackView } + static func downscaleFactor() -> CGFloat { + let nCellsBeforePotentialOverflow = Preferences.nCellsRows * Preferences.minCellsPerRow + guard CGFloat(Windows.list.count) > nCellsBeforePotentialOverflow else { return 1 } + // TODO: replace this buggy heuristic with a correct implementation of downscaling + return nCellsBeforePotentialOverflow / (nCellsBeforePotentialOverflow + (sqrt(CGFloat(Windows.list.count) - nCellsBeforePotentialOverflow) * 2)) + } + static func widthMax(_ screen: NSScreen) -> CGFloat { - return ThumbnailsPanel.widthMax(screen) / Preferences.minCellsPerRow - Preferences.cellPadding + return (ThumbnailsPanel.widthMax(screen) / Preferences.minCellsPerRow - Preferences.cellPadding) * Cell.downscaleFactor() } static func widthMin(_ screen: NSScreen) -> CGFloat { - return ThumbnailsPanel.widthMax(screen) / Preferences.maxCellsPerRow - Preferences.cellPadding + return (ThumbnailsPanel.widthMax(screen) / Preferences.maxCellsPerRow - Preferences.cellPadding) * Cell.downscaleFactor() } static func height(_ screen: NSScreen) -> CGFloat { - return ThumbnailsPanel.heightMax(screen) / Preferences.nCellsRows - Preferences.cellPadding + return (ThumbnailsPanel.heightMax(screen) / Preferences.nCellsRows - Preferences.cellPadding) * Cell.downscaleFactor() } static func width(_ image: NSImage?, _ screen: NSScreen) -> CGFloat {