Correctly align separator with contents of cell. Issue #2592

This commit is contained in:
Maurice Parker 2020-11-19 13:44:08 -06:00
parent 97bbb9d9d9
commit 006586ada6
2 changed files with 37 additions and 5 deletions

View File

@ -10,6 +10,8 @@ import AppKit
class TimelineTableRowView : NSTableRowView { class TimelineTableRowView : NSTableRowView {
private var separator: NSView?
override var isOpaque: Bool { override var isOpaque: Bool {
return true return true
} }
@ -23,6 +25,7 @@ class TimelineTableRowView : NSTableRowView {
override var isSelected: Bool { override var isSelected: Bool {
didSet { didSet {
cellView?.isSelected = isSelected cellView?.isSelected = isSelected
separator?.isHidden = isSelected
} }
} }
@ -43,4 +46,38 @@ class TimelineTableRowView : NSTableRowView {
return nil return nil
} }
override func viewDidMoveToSuperview() {
if #available(macOS 11.0, *) {
addSeparatorView()
} else {
if AppDefaults.shared.timelineShowsSeparators {
addSeparatorView()
}
}
}
private func addSeparatorView() {
guard let cellView = cellView else { return }
separator = NSView()
separator!.translatesAutoresizingMaskIntoConstraints = false
separator!.wantsLayer = true
separator!.layer?.backgroundColor = NSColor.separatorColor.cgColor
addSubview(separator!)
if #available(macOS 11.0, *) {
NSLayoutConstraint.activate([
separator!.leadingAnchor.constraint(equalTo: cellView.leadingAnchor, constant: 20),
separator!.trailingAnchor.constraint(equalTo: cellView.trailingAnchor, constant: -4),
separator!.heightAnchor.constraint(equalToConstant: 1),
separator!.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 0)
])
} else {
NSLayoutConstraint.activate([
separator!.leadingAnchor.constraint(equalTo: cellView.leadingAnchor, constant: 34),
separator!.trailingAnchor.constraint(equalTo: cellView.trailingAnchor, constant: -28),
separator!.heightAnchor.constraint(equalToConstant: 1),
separator!.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 0)
])
}
}
} }

View File

@ -209,11 +209,6 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
if #available(macOS 11.0, *) { if #available(macOS 11.0, *) {
tableView.style = .inset tableView.style = .inset
tableView.gridStyleMask = .solidHorizontalGridLineMask
} else {
if AppDefaults.shared.timelineShowsSeparators {
tableView.gridStyleMask = .solidHorizontalGridLineMask
}
} }
if !didRegisterForNotifications { if !didRegisterForNotifications {