Make timeline cell height calculation reliable by considering all the rects, instead of assuming that one or another is the determining rect.

This commit is contained in:
Brent Simmons 2017-12-31 12:08:25 -08:00
parent c8a7b39178
commit b35193b823

View File

@ -33,15 +33,13 @@ struct TimelineCellLayout {
self.avatarImageRect = avatarImageRect self.avatarImageRect = avatarImageRect
self.paddingBottom = paddingBottom self.paddingBottom = paddingBottom
var height = NSMaxY(dateRect) var height = max(0, faviconRect.maxY)
if feedNameRect != NSZeroRect { height = max(height, feedNameRect.maxY)
height = NSMaxY(feedNameRect) height = max(height, dateRect.maxY)
} height = max(height, titleRect.maxY)
height = height + paddingBottom height = max(height, unreadIndicatorRect.maxY)
height = max(height, avatarImageRect.maxY)
let heightOfImage = avatarImageRect.maxY + paddingBottom height += paddingBottom
height = max(height, heightOfImage)
self.height = height self.height = height
} }
} }
@ -51,8 +49,6 @@ private func rectForDate(_ cellData: TimelineCellData, _ width: CGFloat, _ appea
let renderer = RSSingleLineRenderer(attributedTitle: cellData.attributedDateString) let renderer = RSSingleLineRenderer(attributedTitle: cellData.attributedDateString)
var r = NSZeroRect var r = NSZeroRect
r.size = renderer.size r.size = renderer.size
// r.origin.y = appearance.cellPadding.top
// r.origin.x = width - (appearance.cellPadding.right + r.size.width)
r.origin.y = NSMaxY(titleRect) + appearance.titleBottomMargin r.origin.y = NSMaxY(titleRect) + appearance.titleBottomMargin
r.origin.x = appearance.boxLeftMargin r.origin.x = appearance.boxLeftMargin
@ -75,15 +71,7 @@ private func rectForFeedName(_ cellData: TimelineCellData, _ width: CGFloat, _ a
r.origin.y = NSMaxY(dateRect) + appearance.titleBottomMargin r.origin.y = NSMaxY(dateRect) + appearance.titleBottomMargin
r.origin.x = appearance.boxLeftMargin r.origin.x = appearance.boxLeftMargin
// if let _ = cellData.favicon { r.size.width = max(0, width - (r.origin.x + appearance.cellPadding.right))
// r.origin.x += appearance.faviconSize.width + appearance.faviconFeedNameSpacing
// }
r.size.width = width - (r.origin.x + appearance.cellPadding.right)
if r.size.width < 15 {
return NSZeroRect
}
return r return r
} }
@ -124,10 +112,6 @@ private func rectsForTitle(_ cellData: TimelineCellData, _ width: CGFloat, _ app
private func rectForUnreadIndicator(_ cellData: TimelineCellData, _ appearance: TimelineCellAppearance, _ titleLine1Rect: NSRect) -> NSRect { private func rectForUnreadIndicator(_ cellData: TimelineCellData, _ appearance: TimelineCellAppearance, _ titleLine1Rect: NSRect) -> NSRect {
// if cellData.read {
// return NSZeroRect
// }
var r = NSZeroRect var r = NSZeroRect
r.size = NSSize(width: appearance.unreadCircleDimension, height: appearance.unreadCircleDimension) r.size = NSSize(width: appearance.unreadCircleDimension, height: appearance.unreadCircleDimension)
r.origin.x = appearance.cellPadding.left r.origin.x = appearance.cellPadding.left
@ -148,7 +132,6 @@ private func rectForAvatar(_ cellData: TimelineCellData, _ appearance: TimelineC
func timelineCellLayout(_ width: CGFloat, cellData: TimelineCellData, appearance: TimelineCellAppearance) -> TimelineCellLayout { func timelineCellLayout(_ width: CGFloat, cellData: TimelineCellData, appearance: TimelineCellAppearance) -> TimelineCellLayout {
// let dateRect = rectForDate(cellData, width, appearance)
let (titleRect, titleLine1Rect) = rectsForTitle(cellData, width, appearance) let (titleRect, titleLine1Rect) = rectsForTitle(cellData, width, appearance)
let dateRect = rectForDate(cellData, width, appearance, titleRect) let dateRect = rectForDate(cellData, width, appearance, titleRect)
let feedNameRect = rectForFeedName(cellData, width, appearance, dateRect) let feedNameRect = rectForFeedName(cellData, width, appearance, dateRect)