diff --git a/Mac/MainWindow/IconView.swift b/Mac/MainWindow/IconView.swift index 0795d8025..8616a9d72 100644 --- a/Mac/MainWindow/IconView.swift +++ b/Mac/MainWindow/IconView.swift @@ -115,21 +115,20 @@ private extension IconView { let imageSize = image.size let viewSize = bounds.size + if imageSize.height == imageSize.width { - if imageSize.height >= viewSize.height * 0.75 { - // Close enough to viewSize to scale up the image. - return NSRect(x: 0.0, y: 0.0, width: viewSize.width, height: viewSize.height) - } - let offset = floor((viewSize.height - imageSize.height) / 2.0) - return NSRect(x: offset, y: offset, width: imageSize.width, height: imageSize.height) - } else if imageSize.height > imageSize.width { + return NSRect(x: 0.0, y: 0.0, width: viewSize.width, height: viewSize.height) + } + + // Non-square: aspect fit — scale to fill one dimension, center in the other + if imageSize.height > imageSize.width { let factor = viewSize.height / imageSize.height let width = imageSize.width * factor let originX = floor((viewSize.width - width) / 2.0) return NSRect(x: originX, y: 0.0, width: width, height: viewSize.height) } - // Wider than tall: imageSize.width > imageSize.height + // Wider than tall let factor = viewSize.width / imageSize.width let height = imageSize.height * factor let originY = floor((viewSize.height - height) / 2.0) diff --git a/iOS/IconView.swift b/iOS/IconView.swift index ef18e6496..9e78f16d0 100644 --- a/iOS/IconView.swift +++ b/iOS/IconView.swift @@ -91,21 +91,20 @@ private extension IconView { let imageSize = image.size let viewSize = bounds.size + if imageSize.height == imageSize.width { - if imageSize.height >= viewSize.height * 0.75 { - // Close enough to viewSize to scale up the image. - return CGRect(x: 0.0, y: 0.0, width: viewSize.width, height: viewSize.height) - } - let offset = floor((viewSize.height - imageSize.height) / 2.0) - return CGRect(x: offset, y: offset, width: imageSize.width, height: imageSize.height) - } else if imageSize.height > imageSize.width { + return CGRect(x: 0.0, y: 0.0, width: viewSize.width, height: viewSize.height) + } + + // Non-square: aspect fit — scale to fill one dimension, center in the other + if imageSize.height > imageSize.width { let factor = viewSize.height / imageSize.height let width = imageSize.width * factor let originX = floor((viewSize.width - width) / 2.0) return CGRect(x: originX, y: 0.0, width: width, height: viewSize.height) } - // Wider than tall: imageSize.width > imageSize.height + // Wider than tall let factor = viewSize.width / imageSize.width let height = imageSize.height * factor let originY = floor((viewSize.height - height) / 2.0)