Use an NSTextField to draw the title in the timeline.

This commit is contained in:
Brent Simmons 2018-02-19 21:26:15 -08:00
parent 83f97cf118
commit 12575901ec
1 changed files with 19 additions and 4 deletions

View File

@ -11,7 +11,7 @@ import RSTextDrawing
class TimelineTableCellView: NSTableCellView { class TimelineTableCellView: NSTableCellView {
private let titleView = RSMultiLineView(frame: NSZeroRect) private let titleView = TimelineTableCellView.multiLineTextField()
private let unreadIndicatorView = UnreadIndicatorView(frame: NSZeroRect) private let unreadIndicatorView = UnreadIndicatorView(frame: NSZeroRect)
private let dateView = TimelineTableCellView.singleLineTextField() private let dateView = TimelineTableCellView.singleLineTextField()
private let feedNameView = TimelineTableCellView.singleLineTextField() private let feedNameView = TimelineTableCellView.singleLineTextField()
@ -19,7 +19,7 @@ class TimelineTableCellView: NSTableCellView {
private let starView = TimelineTableCellView.imageView(with: AppImages.timelineStar, scaling: .scaleNone) private let starView = TimelineTableCellView.imageView(with: AppImages.timelineStar, scaling: .scaleNone)
private lazy var textFields = { private lazy var textFields = {
return [self.dateView, self.feedNameView] return [self.dateView, self.feedNameView, self.titleView]
}() }()
var cellAppearance: TimelineCellAppearance! { var cellAppearance: TimelineCellAppearance! {
@ -49,7 +49,7 @@ class TimelineTableCellView: NSTableCellView {
var isEmphasized = false { var isEmphasized = false {
didSet { didSet {
titleView.emphasized = isEmphasized // titleView.emphasized = isEmphasized
unreadIndicatorView.isEmphasized = isEmphasized unreadIndicatorView.isEmphasized = isEmphasized
updateTextFieldColors() updateTextFieldColors()
needsDisplay = true needsDisplay = true
@ -58,7 +58,7 @@ class TimelineTableCellView: NSTableCellView {
var isSelected = false { var isSelected = false {
didSet { didSet {
titleView.selected = isSelected // titleView.selected = isSelected
unreadIndicatorView.isSelected = isSelected unreadIndicatorView.isSelected = isSelected
updateTextFieldColors() updateTextFieldColors()
needsDisplay = true needsDisplay = true
@ -139,6 +139,17 @@ private extension TimelineTableCellView {
return textField return textField
} }
static func multiLineTextField() -> NSTextField {
let textField = NSTextField(wrappingLabelWithString: "")
textField.usesSingleLineMode = false
textField.maximumNumberOfLines = 2
textField.isEditable = false
textField.lineBreakMode = .byTruncatingTail
textField.cell?.truncatesLastVisibleLine = true
return textField
}
static func imageView(with image: NSImage?, scaling: NSImageScaling) -> NSImageView { static func imageView(with image: NSImage?, scaling: NSImageScaling) -> NSImageView {
let imageView = image != nil ? NSImageView(image: image!) : NSImageView(frame: NSRect.zero) let imageView = image != nil ? NSImageView(image: image!) : NSImageView(frame: NSRect.zero)
@ -156,6 +167,10 @@ private extension TimelineTableCellView {
else { else {
feedNameView.textColor = cellAppearance.feedNameColor feedNameView.textColor = cellAppearance.feedNameColor
dateView.textColor = cellAppearance.dateColor dateView.textColor = cellAppearance.dateColor
if let attributedTitle = cellData?.attributedTitle {
titleView.attributedStringValue = attributedTitle
}
} }
} }