NetNewsWire/Evergreen/MainWindow/Timeline/TimelineTableRowView.swift

81 lines
1.5 KiB
Swift
Raw Normal View History

2017-05-27 19:43:27 +02:00
//
// TimelineTableRowView.swift
// Evergreen
//
// Created by Brent Simmons on 8/31/15.
// Copyright © 2015 Ranchero Software, LLC. All rights reserved.
//
import AppKit
2017-05-27 19:43:27 +02:00
class TimelineTableRowView : NSTableRowView {
var cellAppearance: TimelineCellAppearance! {
didSet {
if cellAppearance != oldValue {
invalidateGridRect()
}
}
}
2017-05-27 19:43:27 +02:00
// override var interiorBackgroundStyle: NSBackgroundStyle {
// return .Light
// }
2017-05-27 19:43:27 +02:00
private var cellView: TimelineTableCellView? {
for oneSubview in subviews {
if let foundView = oneSubview as? TimelineTableCellView {
return foundView
2017-05-27 19:43:27 +02:00
}
}
return nil
2017-05-27 19:43:27 +02:00
}
override var isEmphasized: Bool {
didSet {
if let cellView = cellView {
cellView.isEmphasized = isEmphasized
}
}
}
override var isSelected: Bool {
didSet {
if let cellView = cellView {
cellView.isSelected = isSelected
}
}
}
var gridRect: NSRect {
return NSMakeRect(0.0, NSMaxY(bounds) - 1.0, NSWidth(bounds), 1)
2017-05-27 19:43:27 +02:00
}
2017-05-27 19:43:27 +02:00
override func drawSeparator(in dirtyRect: NSRect) {
2017-05-27 19:43:27 +02:00
let path = NSBezierPath()
let originX = floor(cellAppearance.boxLeftMargin)
let destinationX = ceil(NSMaxX(bounds))
let y = floor(NSMaxY(bounds)) - 0.5
path.move(to: NSPoint(x: originX, y: y))
path.line(to: NSPoint(x: destinationX, y: y))
2017-05-27 19:43:27 +02:00
cellAppearance.gridColor.set()
path.stroke()
}
2017-05-27 19:43:27 +02:00
override func draw(_ dirtyRect: NSRect) {
2017-05-27 19:43:27 +02:00
super.draw(dirtyRect)
if cellAppearance.drawsGrid && !isSelected && !isNextRowSelected {
2017-05-27 19:43:27 +02:00
drawSeparator(in: dirtyRect)
}
}
2017-05-27 19:43:27 +02:00
func invalidateGridRect() {
setNeedsDisplay(gridRect)
}
}