Rework cell background selection and separators to remove separator drawing artifacts and use the inset table style. Fixes #2579, #2580 and #2584

This commit is contained in:
Maurice Parker 2020-11-18 22:02:54 -06:00
parent eb5e85cbcf
commit 8fd3cd2cde
5 changed files with 14 additions and 96 deletions

View File

@ -389,16 +389,3 @@ private extension AppDefaults {
}
}
}
// MARK: -
extension UserDefaults {
/// This property exists so that it can conveniently be observed via KVO
@objc var CorreiaSeparators: Bool {
get {
return bool(forKey: AppDefaults.Key.timelineShowsSeparators)
}
set {
set(newValue, forKey: AppDefaults.Key.timelineShowsSeparators)
}
}
}

View File

@ -12,7 +12,7 @@ struct TimelineCellAppearance: Equatable {
let showIcon: Bool
let cellPadding = NSEdgeInsets(top: 8.0, left: 18.0, bottom: 10.0, right: 18.0)
let cellPadding: NSEdgeInsets
let feedNameFont: NSFont
@ -55,6 +55,12 @@ struct TimelineCellAppearance: Equatable {
self.textOnlyFont = NSFont.systemFont(ofSize: largeItemFontSize)
self.showIcon = showIcon
if #available(macOS 11.0, *) {
cellPadding = NSEdgeInsets(top: 8.0, left: 4.0, bottom: 10.0, right: 4.0)
} else {
cellPadding = NSEdgeInsets(top: 8.0, left: 18.0, bottom: 10.0, right: 18.0)
}
let margin = self.cellPadding.left + self.unreadCircleDimension + self.unreadCircleMarginRight
self.boxLeftMargin = margin

View File

@ -6,7 +6,7 @@
// Copyright © 2015 Ranchero Software, LLC. All rights reserved.
//
import Foundation
import AppKit
import RSCore
class TimelineTableCellView: NSTableCellView {
@ -21,18 +21,11 @@ class TimelineTableCellView: NSTableCellView {
private lazy var iconView = IconView()
private var starView = TimelineTableCellView.imageView(with: AppAssets.timelineStarUnselected, scaling: .scaleNone)
private let separatorView = TimelineTableCellView.separatorView()
private lazy var textFields = {
return [self.dateView, self.feedNameView, self.titleView, self.summaryView, self.textView]
}()
private var showsSeparator: Bool = AppDefaults.shared.timelineShowsSeparators {
didSet {
separatorView.isHidden = !showsSeparator
}
}
var cellAppearance: TimelineCellAppearance! {
didSet {
if cellAppearance != oldValue {
@ -81,15 +74,6 @@ class TimelineTableCellView: NSTableCellView {
self.init(frame: NSRect.zero)
}
override func prepareForReuse() {
super.prepareForReuse()
separatorView.isHidden = !showsSeparator
}
func timelineShowsSeparatorsDefaultDidChange() {
showsSeparator = AppDefaults.shared.timelineShowsSeparators
}
override func setFrameSize(_ newSize: NSSize) {
if newSize == self.frame.size {
@ -123,7 +107,6 @@ class TimelineTableCellView: NSTableCellView {
feedNameView.setFrame(ifNotEqualTo: layoutRects.feedNameRect)
iconView.setFrame(ifNotEqualTo: layoutRects.iconImageRect)
starView.setFrame(ifNotEqualTo: layoutRects.starRect)
separatorView.setFrame(ifNotEqualTo: layoutRects.separatorRect)
}
}
@ -162,11 +145,6 @@ private extension TimelineTableCellView {
return imageView
}
static func separatorView() -> NSView {
return TimelineSeparatorView(frame: .zero)
}
func setFrame(for textField: NSTextField, rect: NSRect) {
if Int(floor(rect.height)) == 0 || Int(floor(rect.width)) == 0 {
@ -211,7 +189,6 @@ private extension TimelineTableCellView {
addSubviewAtInit(feedNameView, hidden: true)
addSubviewAtInit(iconView, hidden: true)
addSubviewAtInit(starView, hidden: true)
addSubviewAtInit(separatorView, hidden: !AppDefaults.shared.timelineShowsSeparators)
makeTextFieldColorsNormal()
}
@ -337,32 +314,3 @@ private extension TimelineTableCellView {
updateIcon()
}
}
// MARK: -
private class TimelineSeparatorView: NSView {
private static let backgroundColor = NSColor(named: "timelineSeparatorColor")!
override init(frame: NSRect) {
super.init(frame: frame)
self.wantsLayer = true
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidChangeEffectiveAppearance() {
super.viewDidChangeEffectiveAppearance()
needsDisplay = true
}
override var wantsUpdateLayer: Bool {
return true
}
override func updateLayer() {
super.updateLayer()
layer?.backgroundColor = TimelineSeparatorView.backgroundColor.cgColor
}
}

View File

@ -34,21 +34,6 @@ class TimelineTableRowView : NSTableRowView {
super.init(coder: coder)
}
override func drawBackground(in dirtyRect: NSRect) {
NSColor.alternatingContentBackgroundColors[0].setFill()
dirtyRect.fill()
}
override func drawSelection(in dirtyRect: NSRect) {
if isEmphasized {
NSColor.selectedContentBackgroundColor.setFill()
dirtyRect.fill()
} else {
NSColor.unemphasizedSelectedContentBackgroundColor.setFill()
dirtyRect.fill()
}
}
private var cellView: TimelineTableCellView? {
for oneSubview in subviews {
if let foundView = oneSubview as? TimelineTableCellView {

View File

@ -194,7 +194,6 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
convenience init(delegate: TimelineDelegate) {
self.init(nibName: "TimelineTableView", bundle: nil)
self.delegate = delegate
self.startObservingUserDefaults()
}
override func viewDidLoad() {
@ -209,7 +208,12 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
tableView.keyboardDelegate = keyboardDelegate
if #available(macOS 11.0, *) {
tableView.style = .plain
tableView.style = .inset
tableView.gridStyleMask = .solidHorizontalGridLineMask
} else {
if AppDefaults.shared.timelineShowsSeparators {
tableView.gridStyleMask = .solidHorizontalGridLineMask
}
}
if !didRegisterForNotifications {
@ -969,18 +973,6 @@ extension TimelineViewController: NSTableViewDelegate {
// MARK: - Private
private extension TimelineViewController {
func startObservingUserDefaults() {
assert(timelineShowsSeparatorsObserver == nil)
timelineShowsSeparatorsObserver = UserDefaults.standard.observe(\UserDefaults.CorreiaSeparators) { [weak self] (_, _) in
guard let self = self, self.isViewLoaded else { return }
self.tableView.enumerateAvailableRowViews { (rowView, index) in
if let cellView = rowView.view(atColumn: 0) as? TimelineTableCellView {
cellView.timelineShowsSeparatorsDefaultDidChange()
}
}
}
}
func fetchAndReplacePreservingSelection() {
if let article = oneSelectedArticle, let account = article.account {