mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 00:04:25 +00:00
85 lines
1.9 KiB
Swift
85 lines
1.9 KiB
Swift
//
|
||
// TimelineTableRowView.swift
|
||
// NetNewsWire
|
||
//
|
||
// Created by Brent Simmons on 8/31/15.
|
||
// Copyright © 2015 Ranchero Software, LLC. All rights reserved.
|
||
//
|
||
|
||
import AppKit
|
||
|
||
final class TimelineTableRowView: NSTableRowView {
|
||
|
||
private var separator: NSView?
|
||
|
||
var showsSeparator = false {
|
||
didSet {
|
||
if showsSeparator != oldValue {
|
||
updateSeparator()
|
||
}
|
||
}
|
||
}
|
||
|
||
override var isOpaque: Bool {
|
||
return true
|
||
}
|
||
|
||
override var isEmphasized: Bool {
|
||
didSet {
|
||
cellView?.isEmphasized = isEmphasized
|
||
}
|
||
}
|
||
|
||
override var isSelected: Bool {
|
||
didSet {
|
||
cellView?.isSelected = isSelected
|
||
updateSeparator()
|
||
}
|
||
}
|
||
|
||
init() {
|
||
super.init(frame: NSRect.zero)
|
||
}
|
||
|
||
required init?(coder: NSCoder) {
|
||
super.init(coder: coder)
|
||
}
|
||
|
||
private var cellView: TimelineTableCellView? {
|
||
for oneSubview in subviews {
|
||
if let foundView = oneSubview as? TimelineTableCellView {
|
||
return foundView
|
||
}
|
||
}
|
||
return nil
|
||
}
|
||
|
||
override func viewDidMoveToSuperview() {
|
||
updateSeparator()
|
||
}
|
||
|
||
/// The separator is added once the cell view is, since it’s aligned with the cell view.
|
||
private func updateSeparator() {
|
||
if showsSeparator {
|
||
addSeparatorView()
|
||
}
|
||
separator?.isHidden = !showsSeparator || isSelected
|
||
}
|
||
|
||
private func addSeparatorView() {
|
||
guard let cellView = cellView, separator == nil else { return }
|
||
separator = NSView()
|
||
separator!.translatesAutoresizingMaskIntoConstraints = false
|
||
separator!.wantsLayer = true
|
||
separator!.layer?.backgroundColor = Assets.Colors.timelineSeparator.cgColor
|
||
addSubview(separator!)
|
||
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)
|
||
])
|
||
}
|
||
|
||
}
|