2019-04-30 00:19:08 +02:00
|
|
|
//
|
|
|
|
// MasterTimelineDefaultCellLayout.swift
|
|
|
|
// NetNewsWire
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 2/6/16.
|
|
|
|
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import RSCore
|
|
|
|
|
|
|
|
struct MasterTimelineDefaultCellLayout: MasterTimelineCellLayout {
|
|
|
|
|
2019-11-03 02:19:57 +01:00
|
|
|
static let cellPadding = UIEdgeInsets(top: 12, left: 8, bottom: 12, right: 20)
|
2019-04-30 00:19:08 +02:00
|
|
|
|
2019-05-28 01:33:38 +02:00
|
|
|
static let unreadCircleMarginLeft = CGFloat(integerLiteral: 0)
|
|
|
|
static let unreadCircleDimension = CGFloat(integerLiteral: 12)
|
2019-10-16 03:59:42 +02:00
|
|
|
static let unreadCircleSize = CGSize(width: MasterTimelineDefaultCellLayout.unreadCircleDimension, height: MasterTimelineDefaultCellLayout.unreadCircleDimension)
|
2019-04-30 00:19:08 +02:00
|
|
|
static let unreadCircleMarginRight = CGFloat(integerLiteral: 8)
|
|
|
|
|
2019-06-01 00:58:39 +02:00
|
|
|
static let starDimension = CGFloat(integerLiteral: 16)
|
2019-10-16 03:59:42 +02:00
|
|
|
static let starSize = CGSize(width: MasterTimelineDefaultCellLayout.starDimension, height: MasterTimelineDefaultCellLayout.starDimension)
|
2019-04-30 00:19:08 +02:00
|
|
|
|
2019-11-06 01:05:57 +01:00
|
|
|
static let iconMarginRight = CGFloat(integerLiteral: 8)
|
|
|
|
static let iconCornerRadius = CGFloat(integerLiteral: 4)
|
2019-04-30 00:19:08 +02:00
|
|
|
|
|
|
|
static var titleFont: UIFont {
|
|
|
|
return UIFont.preferredFont(forTextStyle: .headline)
|
|
|
|
}
|
|
|
|
static let titleBottomMargin = CGFloat(integerLiteral: 1)
|
|
|
|
|
|
|
|
static var feedNameFont: UIFont {
|
|
|
|
return UIFont.preferredFont(forTextStyle: .footnote)
|
|
|
|
}
|
|
|
|
static let feedRightMargin = CGFloat(integerLiteral: 8)
|
|
|
|
|
|
|
|
static var dateFont: UIFont {
|
|
|
|
return UIFont.preferredFont(forTextStyle: .footnote)
|
|
|
|
}
|
|
|
|
static let dateMarginBottom = CGFloat(integerLiteral: 1)
|
|
|
|
|
|
|
|
static var summaryFont: UIFont {
|
|
|
|
return UIFont.preferredFont(forTextStyle: .body)
|
|
|
|
}
|
|
|
|
|
|
|
|
let height: CGFloat
|
|
|
|
let unreadIndicatorRect: CGRect
|
|
|
|
let starRect: CGRect
|
2019-11-06 01:05:57 +01:00
|
|
|
let iconImageRect: CGRect
|
2019-04-30 00:19:08 +02:00
|
|
|
let titleRect: CGRect
|
|
|
|
let summaryRect: CGRect
|
|
|
|
let feedNameRect: CGRect
|
|
|
|
let dateRect: CGRect
|
|
|
|
|
|
|
|
init(width: CGFloat, insets: UIEdgeInsets, cellData: MasterTimelineCellData) {
|
|
|
|
|
|
|
|
var currentPoint = CGPoint.zero
|
|
|
|
currentPoint.x = MasterTimelineDefaultCellLayout.cellPadding.left + insets.left + MasterTimelineDefaultCellLayout.unreadCircleMarginLeft
|
|
|
|
currentPoint.y = MasterTimelineDefaultCellLayout.cellPadding.top
|
|
|
|
|
|
|
|
// Unread Indicator and Star
|
|
|
|
self.unreadIndicatorRect = MasterTimelineDefaultCellLayout.rectForUnreadIndicator(currentPoint)
|
|
|
|
self.starRect = MasterTimelineDefaultCellLayout.rectForStar(currentPoint)
|
|
|
|
|
|
|
|
// Start the point at the beginning position of the main block
|
|
|
|
currentPoint.x += MasterTimelineDefaultCellLayout.unreadCircleDimension + MasterTimelineDefaultCellLayout.unreadCircleMarginRight
|
|
|
|
|
2019-11-06 01:05:57 +01:00
|
|
|
// Icon Image
|
|
|
|
if cellData.showIcon {
|
2019-11-09 00:16:09 +01:00
|
|
|
self.iconImageRect = MasterTimelineDefaultCellLayout.rectForIconView(currentPoint, iconSize: cellData.iconSize)
|
2019-11-06 01:05:57 +01:00
|
|
|
currentPoint.x = self.iconImageRect.maxX + MasterTimelineDefaultCellLayout.iconMarginRight
|
2019-04-30 00:19:08 +02:00
|
|
|
} else {
|
2019-11-06 01:05:57 +01:00
|
|
|
self.iconImageRect = CGRect.zero
|
2019-04-30 00:19:08 +02:00
|
|
|
}
|
|
|
|
|
2019-09-27 03:01:13 +02:00
|
|
|
let textAreaWidth = width - (currentPoint.x + MasterTimelineDefaultCellLayout.cellPadding.right + insets.right)
|
2019-04-30 00:19:08 +02:00
|
|
|
|
|
|
|
// Title Text Block
|
|
|
|
let (titleRect, numberOfLinesForTitle) = MasterTimelineDefaultCellLayout.rectForTitle(cellData, currentPoint, textAreaWidth)
|
|
|
|
self.titleRect = titleRect
|
|
|
|
|
|
|
|
// Summary Text Block
|
|
|
|
if self.titleRect != CGRect.zero {
|
|
|
|
currentPoint.y = self.titleRect.maxY + MasterTimelineDefaultCellLayout.titleBottomMargin
|
|
|
|
}
|
|
|
|
self.summaryRect = MasterTimelineDefaultCellLayout.rectForSummary(cellData, currentPoint, textAreaWidth, numberOfLinesForTitle)
|
|
|
|
|
2020-03-12 22:57:30 +01:00
|
|
|
var y = [self.titleRect, self.summaryRect].maxY()
|
|
|
|
if y == 0 {
|
|
|
|
y = iconImageRect.origin.y + iconImageRect.height
|
|
|
|
// Necessary calculation of either feed name or date since we are working with dynamic font-sizes
|
|
|
|
let tmp = MasterTimelineDefaultCellLayout.rectForDate(cellData, currentPoint, textAreaWidth)
|
|
|
|
y -= tmp.height
|
|
|
|
}
|
|
|
|
currentPoint.y = y
|
2019-04-30 00:19:08 +02:00
|
|
|
|
|
|
|
// Feed Name and Pub Date
|
|
|
|
self.dateRect = MasterTimelineDefaultCellLayout.rectForDate(cellData, currentPoint, textAreaWidth)
|
|
|
|
|
|
|
|
let feedNameWidth = textAreaWidth - (MasterTimelineDefaultCellLayout.feedRightMargin + self.dateRect.size.width)
|
|
|
|
self.feedNameRect = MasterTimelineDefaultCellLayout.rectForFeedName(cellData, currentPoint, feedNameWidth)
|
|
|
|
|
2019-11-06 01:05:57 +01:00
|
|
|
self.height = [self.iconImageRect, self.feedNameRect].maxY() + MasterTimelineDefaultCellLayout.cellPadding.bottom
|
2019-04-30 00:19:08 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Calculate Rects
|
|
|
|
|
|
|
|
extension MasterTimelineDefaultCellLayout {
|
|
|
|
|
|
|
|
static func rectForDate(_ cellData: MasterTimelineCellData, _ point: CGPoint, _ textAreaWidth: CGFloat) -> CGRect {
|
|
|
|
|
|
|
|
var r = CGRect.zero
|
|
|
|
|
|
|
|
let size = SingleLineUILabelSizer.size(for: cellData.dateString, font: MasterTimelineDefaultCellLayout.dateFont)
|
|
|
|
r.size = size
|
|
|
|
r.origin.x = (point.x + textAreaWidth) - size.width
|
|
|
|
r.origin.y = point.y
|
|
|
|
|
|
|
|
return r
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|