From 006586ada6c8fabe2ac4df937ac2f3fec861dda4 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 19 Nov 2020 13:44:08 -0600 Subject: [PATCH] Correctly align separator with contents of cell. Issue #2592 --- .../Timeline/TimelineTableRowView.swift | 37 +++++++++++++++++++ .../Timeline/TimelineViewController.swift | 5 --- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Mac/MainWindow/Timeline/TimelineTableRowView.swift b/Mac/MainWindow/Timeline/TimelineTableRowView.swift index aafd39689..f02ca3fde 100644 --- a/Mac/MainWindow/Timeline/TimelineTableRowView.swift +++ b/Mac/MainWindow/Timeline/TimelineTableRowView.swift @@ -10,6 +10,8 @@ import AppKit class TimelineTableRowView : NSTableRowView { + private var separator: NSView? + override var isOpaque: Bool { return true } @@ -23,6 +25,7 @@ class TimelineTableRowView : NSTableRowView { override var isSelected: Bool { didSet { cellView?.isSelected = isSelected + separator?.isHidden = isSelected } } @@ -43,4 +46,38 @@ class TimelineTableRowView : NSTableRowView { 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) + ]) + } + } + } diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 2d248c447..115a921f9 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -209,11 +209,6 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr if #available(macOS 11.0, *) { tableView.style = .inset - tableView.gridStyleMask = .solidHorizontalGridLineMask - } else { - if AppDefaults.shared.timelineShowsSeparators { - tableView.gridStyleMask = .solidHorizontalGridLineMask - } } if !didRegisterForNotifications {