Skip to content

Commit

Permalink
fix: using floor() everywhere to avoid blurry rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
louis.pontoise authored and lwouis committed Mar 10, 2020
1 parent e588d55 commit 2a36196
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
19 changes: 12 additions & 7 deletions alt-tab-macos/ui/Cell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,31 +109,36 @@ class Cell: NSCollectionViewItem {
}

static func widthMax(_ screen: NSScreen) -> CGFloat {
return (ThumbnailsPanel.widthMax(screen) / Preferences.minCellsPerRow - Preferences.cellPadding) * Cell.downscaleFactor()
return floor((ThumbnailsPanel.widthMax(screen) / Preferences.minCellsPerRow - Preferences.cellPadding) * Cell.downscaleFactor())
}

static func widthMin(_ screen: NSScreen) -> CGFloat {
return (ThumbnailsPanel.widthMax(screen) / Preferences.maxCellsPerRow - Preferences.cellPadding) * Cell.downscaleFactor()
return floor((ThumbnailsPanel.widthMax(screen) / Preferences.maxCellsPerRow - Preferences.cellPadding) * Cell.downscaleFactor())
}

static func height(_ screen: NSScreen) -> CGFloat {
return (ThumbnailsPanel.heightMax(screen) / Preferences.nCellsRows - Preferences.cellPadding) * Cell.downscaleFactor()
return floor((ThumbnailsPanel.heightMax(screen) / Preferences.nCellsRows - Preferences.cellPadding) * Cell.downscaleFactor())
}

static func width(_ image: NSImage?, _ screen: NSScreen) -> CGFloat {
return max(thumbnailSize(image, screen).width + Preferences.cellPadding * 2, ThumbnailsPanel.widthMin(screen))
return floor(max(thumbnailSize(image, screen).width + Preferences.cellPadding * 2, ThumbnailsPanel.widthMin(screen)))
}

static func thumbnailSize(_ image: NSImage?, _ screen: NSScreen) -> NSSize {
let (width, height) = thumbnailSize_(image, screen)
return NSSize(width: floor(width), height: floor(height))
}

static func thumbnailSize_(_ image: NSImage?, _ screen: NSScreen) -> (CGFloat, CGFloat) {
let thumbnailWidthMin = Cell.widthMin(screen) - Preferences.cellPadding * 2
let thumbnailHeightMax = Cell.height(screen) - Preferences.cellPadding * 3 - Preferences.iconSize
let thumbnailWidthMax = Cell.widthMax(screen) - Preferences.cellPadding * 2
guard let image = image else { return NSSize(width: thumbnailWidthMin, height: thumbnailHeightMax) }
guard let image = image else { return (thumbnailWidthMin, thumbnailHeightMax) }
let imageRatio = image.size.width / image.size.height
let thumbnailRatio = thumbnailWidthMax / thumbnailHeightMax
if thumbnailRatio > imageRatio {
return NSSize(width: image.size.width * thumbnailHeightMax / image.size.height, height: thumbnailHeightMax)
return (image.size.width * thumbnailHeightMax / image.size.height, thumbnailHeightMax)
}
return NSSize(width: thumbnailWidthMax, height: image.size.height * thumbnailWidthMax / image.size.width)
return (thumbnailWidthMax, image.size.height * thumbnailWidthMax / image.size.width)
}
}
8 changes: 4 additions & 4 deletions alt-tab-macos/ui/ThumbnailsPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@ class ThumbnailsPanel: NSPanel, NSCollectionViewDataSource, NSCollectionViewDele
}

static func widthMax(_ screen: NSScreen) -> CGFloat {
return screen.frame.width * Preferences.maxScreenUsage - Preferences.windowPadding * 2
return floor(screen.frame.width * Preferences.maxScreenUsage - Preferences.windowPadding * 2)
}

static func heightMax(_ screen: NSScreen) -> CGFloat {
return screen.frame.height * Preferences.maxScreenUsage - Preferences.windowPadding * 2
return floor(screen.frame.height * Preferences.maxScreenUsage - Preferences.windowPadding * 2)
}

static func widthMin(_ screen: NSScreen) -> CGFloat {
return Cell.widthMin(screen) - Preferences.windowPadding * 2
return floor(Cell.widthMin(screen) - Preferences.windowPadding * 2)
}

static func heightMin(_ screen: NSScreen) -> CGFloat {
return Cell.height(screen) - Preferences.windowPadding * 2
return floor(Cell.height(screen) - Preferences.windowPadding * 2)
}
}

0 comments on commit 2a36196

Please sign in to comment.