From cfe748eef7cc144f7847736d34de233fb381ea38 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 27 Oct 2026 11:26:03 -0700 Subject: [PATCH] Remove unused code. --- .../Timeline/Cell/ThumbnailView.swift | 59 ++----------------- .../Timeline/Cell/TimelineTableCellView.swift | 6 +- 2 files changed, 6 insertions(+), 59 deletions(-) diff --git a/Mac/MainWindow/Timeline/Cell/ThumbnailView.swift b/Mac/MainWindow/Timeline/Cell/ThumbnailView.swift index 643e27154..99a15fc66 100644 --- a/Mac/MainWindow/Timeline/Cell/ThumbnailView.swift +++ b/Mac/MainWindow/Timeline/Cell/ThumbnailView.swift @@ -9,11 +9,7 @@ import AppKit /// An article’s thumbnail in a timeline cell. /// -/// By default the image is cropped to fill the view. Tall images keep their top, -/// where faces usually are. Wide images crop both sides equally. -/// With `fitsImage`, the whole image shows, on the placeholder fill. -/// -/// Shows a placeholder fill until the image arrives. +/// The whole image shows, scaled to fit, on a fill that is also the placeholder until the image arrives. final class ThumbnailView: NSView { var image: NSImage? { @@ -24,15 +20,6 @@ final class ThumbnailView: NSView { } } - var fitsImage = false { - didSet { - if fitsImage != oldValue { - layer?.contentsGravity = fitsImage ? .resizeAspect : .resizeAspectFill - needsDisplay = true - } - } - } - var fillColor = NSColor.systemFill { didSet { if fillColor != oldValue { @@ -69,21 +56,13 @@ final class ThumbnailView: NSView { self.init(frame: NSRect.zero) } - override func setFrameSize(_ newSize: NSSize) { - let oldSize = frame.size - super.setFrameSize(newSize) - if newSize != oldSize { - needsDisplay = true - } - } - override func updateLayer() { guard let layer else { return } - layer.contents = fitsImage ? cgImage() : croppedImage() - // Resolved here so the placeholder follows light and dark mode. - layer.backgroundColor = image == nil || fitsImage ? fillColor.cgColor : nil + layer.contents = image?.cgImage(forProposedRect: nil, context: nil, hints: nil) + // Resolved here so the fill follows light and dark mode. + layer.backgroundColor = fillColor.cgColor } } @@ -92,35 +71,7 @@ private extension ThumbnailView { func commonInit() { wantsLayer = true layerContentsRedrawPolicy = .onSetNeedsDisplay - layer?.contentsGravity = .resizeAspectFill + layer?.contentsGravity = .resizeAspect layer?.masksToBounds = true } - - func cgImage() -> CGImage? { - image?.cgImage(forProposedRect: nil, context: nil, hints: nil) - } - - /// The image cropped to the view’s aspect ratio. Uses `CGImage` coordinates, where the origin is the top left. - func croppedImage() -> CGImage? { - guard let cgImage = cgImage() else { - return nil - } - guard bounds.width > 0.0, bounds.height > 0.0 else { - return cgImage - } - - let imageWidth = CGFloat(cgImage.width) - let imageHeight = CGFloat(cgImage.height) - let viewAspectRatio = bounds.width / bounds.height - - let cropRect: CGRect - if imageWidth / imageHeight > viewAspectRatio { - let croppedWidth = floor(imageHeight * viewAspectRatio) - cropRect = CGRect(x: floor((imageWidth - croppedWidth) / 2.0), y: 0.0, width: croppedWidth, height: imageHeight) - } else { - let croppedHeight = floor(imageWidth / viewAspectRatio) - cropRect = CGRect(x: 0.0, y: 0.0, width: imageWidth, height: croppedHeight) - } - return cgImage.cropping(to: cropRect) ?? cgImage - } } diff --git a/Mac/MainWindow/Timeline/Cell/TimelineTableCellView.swift b/Mac/MainWindow/Timeline/Cell/TimelineTableCellView.swift index 19d905c49..33ea84cc9 100644 --- a/Mac/MainWindow/Timeline/Cell/TimelineTableCellView.swift +++ b/Mac/MainWindow/Timeline/Cell/TimelineTableCellView.swift @@ -19,11 +19,7 @@ final class TimelineTableCellView: NSTableCellView { private let feedNameView = TimelineTableCellView.singleLineTextField() private lazy var iconView = IconView() - private lazy var thumbnailView: ThumbnailView = { - let thumbnailView = ThumbnailView() - thumbnailView.fitsImage = true - return thumbnailView - }() + private let thumbnailView = ThumbnailView() private var starView = TimelineTableCellView.imageView(with: Assets.Images.timelineStar, scaling: .scaleNone)