2019-04-15 22:03:05 +02:00
|
|
|
//
|
2024-02-26 17:37:15 +01:00
|
|
|
// TimelineCellLayout.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
|
2024-04-16 07:21:17 +02:00
|
|
|
import Images
|
2019-04-15 22:03:05 +02:00
|
|
|
|
2024-02-26 17:37:15 +01:00
|
|
|
protocol TimelineCellLayout {
|
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}
|
2019-04-15 22:03:05 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-02-26 17:37:15 +01:00
|
|
|
extension TimelineCellLayout {
|
2019-04-30 00:19:08 +02:00
|
|
|
|
2019-04-29 21:40:14 +02:00
|
|
|
static func rectForUnreadIndicator(_ point: CGPoint) -> CGRect {
|
|
|
|
var r = CGRect.zero
|
2024-02-26 17:37:15 +01:00
|
|
|
r.size = CGSize(width: TimelineDefaultCellLayout.unreadCircleDimension, height: TimelineDefaultCellLayout.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
|
2024-02-26 17:37:15 +01:00
|
|
|
r.size.width = TimelineDefaultCellLayout.starDimension
|
|
|
|
r.size.height = TimelineDefaultCellLayout.starDimension
|
|
|
|
r.origin.x = floor(point.x - ((TimelineDefaultCellLayout.starDimension - TimelineDefaultCellLayout.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-17 02:44:01 +01:00
|
|
|
static func rectForIconView(_ point: CGPoint, iconSize: IconSize) -> CGRect {
|
2019-04-29 21:40:14 +02:00
|
|
|
var r = CGRect.zero
|
2019-11-09 00:16:09 +01:00
|
|
|
r.size = iconSize.size
|
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
|
|
|
|
}
|
|
|
|
|
2024-04-21 00:41:34 +02:00
|
|
|
@MainActor static func rectForTitle(_ cellData: TimelineCellData, _ point: CGPoint, _ textAreaWidth: CGFloat) -> (CGRect, Int) {
|
|
|
|
|
2019-04-29 21:40:14 +02:00
|
|
|
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
|
|
|
|
|
2024-02-26 17:37:15 +01:00
|
|
|
let sizeInfo = MultilineUILabelSizer.size(for: cellData.title, font: TimelineDefaultCellLayout.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
|
|
|
|
2024-04-21 00:41:34 +02:00
|
|
|
@MainActor static func rectForSummary(_ cellData: TimelineCellData, _ point: CGPoint, _ textAreaWidth: CGFloat, _ linesUsed: Int) -> CGRect {
|
2019-04-29 21:40:14 +02:00
|
|
|
|
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
|
|
|
|
|
2024-02-26 17:37:15 +01:00
|
|
|
let sizeInfo = MultilineUILabelSizer.size(for: cellData.summary, font: TimelineDefaultCellLayout.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
|
|
|
}
|
|
|
|
|
2024-05-04 07:49:27 +02:00
|
|
|
@MainActor static func rectForFeedName(_ cellData: TimelineCellData, _ 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
|
|
|
|
2020-04-20 00:28:00 +02:00
|
|
|
let feedName = cellData.showFeedName == .feed ? cellData.feedName : cellData.byline
|
2024-02-26 17:37:15 +01:00
|
|
|
let size = SingleLineUILabelSizer.size(for: feedName, font: TimelineDefaultCellLayout.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
|
|
|
}
|