mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 00:04:25 +00:00
Remove unused code.
This commit is contained in:
1 parent
69bebf67af
commit
cfe748eef7
2 files changed
+6
-59
No files matched your search
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in new issue
Block a user