2019-04-15 22:03:05 +02:00
|
|
|
//
|
|
|
|
// MasterTimelineCellLayout.swift
|
2019-04-30 00:19:08 +02:00
|
|
|
// NetNewsWire-iOS
|
2019-04-15 22:03:05 +02:00
|
|
|
//
|
2019-04-30 00:19:08 +02:00
|
|
|
// Created by Maurice Parker on 4/29/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
2019-04-15 22:03:05 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
2019-04-30 00:19:08 +02:00
|
|
|
protocol MasterTimelineCellLayout {
|
2019-04-29 21:40:14 +02:00
|
|
|
|
2019-04-30 00:19:08 +02:00
|
|
|
var height: CGFloat {get}
|
|
|
|
var unreadIndicatorRect: CGRect {get}
|
|
|
|
var starRect: CGRect {get}
|
2019-11-06 01:05:57 +01:00
|
|
|
var iconImageRect: CGRect {get}
|
2019-04-30 00:19:08 +02:00
|
|
|
var titleRect: CGRect {get}
|
|
|
|
var summaryRect: CGRect {get}
|
|
|
|
var feedNameRect: CGRect {get}
|
|
|
|
var dateRect: CGRect {get}
|
|
|
|
var separatorInsets: UIEdgeInsets {get}
|
2019-04-15 22:03:05 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-04-30 00:19:08 +02:00
|
|
|
extension MasterTimelineCellLayout {
|
|
|
|
|
2019-04-29 21:40:14 +02:00
|
|
|
static func rectForUnreadIndicator(_ point: CGPoint) -> CGRect {
|
|
|
|
var r = CGRect.zero
|
2019-04-30 00:19:08 +02:00
|
|
|
r.size = CGSize(width: MasterTimelineDefaultCellLayout.unreadCircleDimension, height: MasterTimelineDefaultCellLayout.unreadCircleDimension)
|
2019-04-29 21:40:14 +02:00
|
|
|
r.origin.x = point.x
|
2019-06-19 01:31:37 +02:00
|
|
|
r.origin.y = point.y + 5
|
2019-04-29 21:40:14 +02:00
|
|
|
return r
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
2019-04-30 00:19:08 +02:00
|
|
|
|
|
|
|
|
2019-04-29 21:40:14 +02:00
|
|
|
static func rectForStar(_ point: CGPoint) -> CGRect {
|
|
|
|
var r = CGRect.zero
|
2019-04-30 00:19:08 +02:00
|
|
|
r.size.width = MasterTimelineDefaultCellLayout.starDimension
|
|
|
|
r.size.height = MasterTimelineDefaultCellLayout.starDimension
|
|
|
|
r.origin.x = floor(point.x - ((MasterTimelineDefaultCellLayout.starDimension - MasterTimelineDefaultCellLayout.unreadCircleDimension) / 2.0))
|
2019-06-19 01:31:37 +02:00
|
|
|
r.origin.y = point.y + 3
|
2019-04-29 21:40:14 +02:00
|
|
|
return r
|
|
|
|
}
|
2019-04-30 00:19:08 +02:00
|
|
|
|
2019-11-06 01:05:57 +01:00
|
|
|
static func rectForIconView(_ point: CGPoint) -> CGRect {
|
2019-04-29 21:40:14 +02:00
|
|
|
var r = CGRect.zero
|
2019-11-06 01:05:57 +01:00
|
|
|
r.size = MasterTimelineDefaultCellLayout.iconImageSize
|
2019-06-01 00:58:39 +02:00
|
|
|
r.origin.x = point.x
|
|
|
|
r.origin.y = point.y + 4
|
2019-04-29 21:40:14 +02:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
static func rectForTitle(_ cellData: MasterTimelineCellData, _ point: CGPoint, _ textAreaWidth: CGFloat) -> (CGRect, Int) {
|
|
|
|
|
|
|
|
var r = CGRect.zero
|
2019-04-15 22:03:05 +02:00
|
|
|
if cellData.title.isEmpty {
|
|
|
|
return (r, 0)
|
|
|
|
}
|
|
|
|
|
2019-04-29 21:40:14 +02:00
|
|
|
r.origin = point
|
|
|
|
|
2019-04-30 00:19:08 +02:00
|
|
|
let sizeInfo = MultilineUILabelSizer.size(for: cellData.title, font: MasterTimelineDefaultCellLayout.titleFont, numberOfLines: cellData.numberOfLines, width: Int(textAreaWidth))
|
2019-04-29 21:40:14 +02:00
|
|
|
|
|
|
|
r.size.width = textAreaWidth
|
2019-04-15 22:03:05 +02:00
|
|
|
r.size.height = sizeInfo.size.height
|
|
|
|
if sizeInfo.numberOfLinesUsed < 1 {
|
|
|
|
r.size.height = 0
|
|
|
|
}
|
2019-04-29 21:40:14 +02:00
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
return (r, sizeInfo.numberOfLinesUsed)
|
2019-04-29 21:40:14 +02:00
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
2019-04-30 00:19:08 +02:00
|
|
|
|
2019-04-29 21:40:14 +02:00
|
|
|
static func rectForSummary(_ cellData: MasterTimelineCellData, _ point: CGPoint, _ textAreaWidth: CGFloat, _ linesUsed: Int) -> CGRect {
|
|
|
|
|
2019-04-29 22:29:00 +02:00
|
|
|
let linesLeft = cellData.numberOfLines - linesUsed
|
2019-04-29 21:40:14 +02:00
|
|
|
|
|
|
|
var r = CGRect.zero
|
|
|
|
if cellData.summary.isEmpty || linesLeft < 1 {
|
2019-04-15 22:03:05 +02:00
|
|
|
return r
|
|
|
|
}
|
2019-04-29 21:40:14 +02:00
|
|
|
|
|
|
|
r.origin = point
|
|
|
|
|
2019-04-30 00:19:08 +02:00
|
|
|
let sizeInfo = MultilineUILabelSizer.size(for: cellData.summary, font: MasterTimelineDefaultCellLayout.summaryFont, numberOfLines: linesLeft, width: Int(textAreaWidth))
|
2019-04-29 21:40:14 +02:00
|
|
|
|
|
|
|
r.size.width = textAreaWidth
|
2019-04-15 22:03:05 +02:00
|
|
|
r.size.height = sizeInfo.size.height
|
|
|
|
if sizeInfo.numberOfLinesUsed < 1 {
|
|
|
|
r.size.height = 0
|
|
|
|
}
|
2019-04-29 21:40:14 +02:00
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
return r
|
2019-04-29 21:40:14 +02:00
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2019-04-29 21:40:14 +02:00
|
|
|
static func rectForFeedName(_ cellData: MasterTimelineCellData, _ point: CGPoint, _ textAreaWidth: CGFloat) -> CGRect {
|
2019-04-30 00:19:08 +02:00
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
var r = CGRect.zero
|
2019-04-29 21:40:14 +02:00
|
|
|
r.origin = point
|
2019-04-30 00:19:08 +02:00
|
|
|
|
|
|
|
let size = SingleLineUILabelSizer.size(for: cellData.feedName, font: MasterTimelineDefaultCellLayout.feedNameFont)
|
2019-04-29 21:40:14 +02:00
|
|
|
r.size = size
|
|
|
|
|
|
|
|
if r.size.width > textAreaWidth {
|
|
|
|
r.size.width = textAreaWidth
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return r
|
2019-04-29 21:40:14 +02:00
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|
2019-04-29 21:40:14 +02:00
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
}
|