mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-06 04:07:54 +00:00
Make timeline text size work on Mac.
This commit is contained in:
1 parent
0a1d847376
commit
e75176c3f6
8 files changed
+109
-91
No files matched your search
@@ -9,13 +9,6 @@
|
||||
import AppKit
|
||||
import Images
|
||||
|
||||
enum FontSize: Int {
|
||||
case small = 0
|
||||
case medium = 1
|
||||
case large = 2
|
||||
case veryLarge = 3
|
||||
}
|
||||
|
||||
/// What the status bar’s count text shows. Clicking the text cycles through them.
|
||||
enum StatusBarCountMode: Int {
|
||||
case unreadCount = 0
|
||||
@@ -38,13 +31,10 @@ enum StatusBarCountMode: Int {
|
||||
extension AppDefaults.Key {
|
||||
static let legacyWindowState = "windowState"
|
||||
static let secureWindowState = "secureWindowState"
|
||||
static let sidebarFontSize = "sidebarFontSize"
|
||||
static let timelineFontSize = "timelineFontSize"
|
||||
static let useColumnLayout = "useColumnLayout"
|
||||
static let showStatusBar = "showStatusBar"
|
||||
static let showStatusBarThemeMenu = "showStatusBarThemeMenu"
|
||||
static let statusBarCountMode = "statusBarCountMode"
|
||||
static let detailFontSize = "detailFontSize"
|
||||
static let openInBrowserInBackground = "openInBrowserInBackground"
|
||||
static let subscribeToFeedsInDefaultBrowser = "subscribeToFeedsInDefaultBrowser"
|
||||
static let articleTextSize = "articleTextSize"
|
||||
@@ -65,9 +55,6 @@ extension AppDefaults.Key {
|
||||
|
||||
extension AppDefaults {
|
||||
|
||||
private static let smallestFontSizeRawValue = FontSize.small.rawValue
|
||||
private static let largestFontSizeRawValue = FontSize.veryLarge.rawValue
|
||||
|
||||
/// Stores window state prior to switching to secure state restoration.
|
||||
///
|
||||
/// This is referenced temporarily, only to be able to provide migration from legacy to secure window state.
|
||||
@@ -118,33 +105,6 @@ extension AppDefaults {
|
||||
}
|
||||
}
|
||||
|
||||
static var sidebarFontSize: FontSize {
|
||||
get {
|
||||
fontSize(for: Key.sidebarFontSize)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setFontSize(for: Key.sidebarFontSize, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
static var timelineFontSize: FontSize {
|
||||
get {
|
||||
fontSize(for: Key.timelineFontSize)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setFontSize(for: Key.timelineFontSize, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
static var detailFontSize: FontSize {
|
||||
get {
|
||||
fontSize(for: Key.detailFontSize)
|
||||
}
|
||||
set {
|
||||
AppDefaults.setFontSize(for: Key.detailFontSize, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
static var importOPMLAccountID: String? {
|
||||
get {
|
||||
UserDefaults.standard.string(forKey: Key.importOPMLAccountID)
|
||||
@@ -316,9 +276,6 @@ extension AppDefaults {
|
||||
#endif
|
||||
|
||||
let platformDefaults: [String: Any] = [
|
||||
Key.sidebarFontSize: FontSize.medium.rawValue,
|
||||
Key.timelineFontSize: FontSize.medium.rawValue,
|
||||
Key.detailFontSize: FontSize.medium.rawValue,
|
||||
Key.useColumnLayout: false,
|
||||
Key.showStatusBar: Self.showStatusBarDefault,
|
||||
Key.showStatusBarThemeMenu: true,
|
||||
@@ -333,38 +290,4 @@ extension AppDefaults {
|
||||
let defaults = commonRegisteredDefaults.merging(platformDefaults) { _, platformValue in platformValue }
|
||||
UserDefaults.standard.register(defaults: defaults)
|
||||
}
|
||||
|
||||
static func actualFontSize(for fontSize: FontSize) -> CGFloat {
|
||||
switch fontSize {
|
||||
case .small:
|
||||
NSFont.systemFontSize
|
||||
case .medium:
|
||||
actualFontSize(for: .small) + 1.0
|
||||
case .large:
|
||||
actualFontSize(for: .medium) + 4.0
|
||||
case .veryLarge:
|
||||
actualFontSize(for: .large) + 8.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension AppDefaults {
|
||||
|
||||
static func fontSize(for key: String) -> FontSize {
|
||||
// Punted till after 1.0.
|
||||
.medium
|
||||
|
||||
// var rawFontSize = UserDefaults.standard.integer(forKey: key)
|
||||
// if rawFontSize < smallestFontSizeRawValue {
|
||||
// rawFontSize = smallestFontSizeRawValue
|
||||
// }
|
||||
// if rawFontSize > largestFontSizeRawValue {
|
||||
// rawFontSize = largestFontSizeRawValue
|
||||
// }
|
||||
// return FontSize(rawValue: rawFontSize)!
|
||||
}
|
||||
|
||||
static func setFontSize(for key: String, _ fontSize: FontSize) {
|
||||
UserDefaults.standard.set(fontSize.rawValue, forKey: key)
|
||||
}
|
||||
}
|
||||
@@ -50,11 +50,10 @@ struct TimelineCellAppearance: Equatable {
|
||||
|
||||
let boxLeftMargin: CGFloat
|
||||
|
||||
init(showIcon: Bool, fontSize: FontSize, iconSize: IconSize, showsLargeThumbnails: Bool) {
|
||||
init(showIcon: Bool, textSize: TimelineTextSize, iconSize: IconSize, showsLargeThumbnails: Bool) {
|
||||
|
||||
let actualFontSize = AppDefaults.actualFontSize(for: fontSize)
|
||||
let smallItemFontSize = floor(actualFontSize * 0.90)
|
||||
let largeItemFontSize = actualFontSize
|
||||
let largeItemFontSize = textSize.pointSize
|
||||
let smallItemFontSize = floor(largeItemFontSize * 0.90)
|
||||
|
||||
self.feedNameFont = NSFont.systemFont(ofSize: smallItemFontSize, weight: NSFont.Weight.bold)
|
||||
self.dateFont = NSFont.systemFont(ofSize: smallItemFontSize, weight: NSFont.Weight.bold)
|
||||
@@ -73,6 +72,30 @@ struct TimelineCellAppearance: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
extension TimelineTextSize {
|
||||
|
||||
private static let smallPointSize: CGFloat = 12
|
||||
private static let mediumPointSize: CGFloat = 14
|
||||
private static let largePointSize: CGFloat = 16
|
||||
private static let extraLargePointSize: CGFloat = 19
|
||||
private static let extraExtraLargePointSize: CGFloat = 22
|
||||
|
||||
var pointSize: CGFloat {
|
||||
switch self {
|
||||
case .small:
|
||||
Self.smallPointSize
|
||||
case .medium:
|
||||
Self.mediumPointSize
|
||||
case .large:
|
||||
Self.largePointSize
|
||||
case .extraLarge:
|
||||
Self.extraLargePointSize
|
||||
case .extraExtraLarge:
|
||||
Self.extraExtraLargePointSize
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension NSEdgeInsets: @retroactive Equatable {
|
||||
|
||||
public static func ==(lhs: NSEdgeInsets, rhs: NSEdgeInsets) -> Bool {
|
||||
|
||||
@@ -27,12 +27,12 @@ extension TimelineViewController {
|
||||
}
|
||||
|
||||
var columnFont: NSFont {
|
||||
NSFont.systemFont(ofSize: AppDefaults.actualFontSize(for: AppDefaults.timelineFontSize))
|
||||
NSFont.systemFont(ofSize: AppDefaults.timelineTextSize.pointSize)
|
||||
}
|
||||
|
||||
// Unread rows are bold, like Mail.
|
||||
var boldColumnFont: NSFont {
|
||||
NSFont.boldSystemFont(ofSize: AppDefaults.actualFontSize(for: AppDefaults.timelineFontSize))
|
||||
NSFont.boldSystemFont(ofSize: AppDefaults.timelineTextSize.pointSize)
|
||||
}
|
||||
|
||||
func columnRowHeight() -> CGFloat {
|
||||
|
||||
@@ -236,10 +236,10 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
var standardColumn: NSTableColumn?
|
||||
// Set while columns are added and autosaved state is restored, which fires sortDescriptorsDidChange.
|
||||
var isConfiguringTableColumns = false
|
||||
private var fontSize: FontSize = AppDefaults.timelineFontSize {
|
||||
private var textSize = AppDefaults.timelineTextSize {
|
||||
didSet {
|
||||
if fontSize != oldValue {
|
||||
fontSizeDidChange()
|
||||
if textSize != oldValue {
|
||||
textSizeDidChange()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -300,6 +300,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineThumbnailsDisplayDidChange(_:)), name: .timelineThumbnailsDisplayDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineFeedIconsDisplayDidChange(_:)), name: .timelineFeedIconsDisplayDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineIconSizeDidChange(_:)), name: .timelineIconSizeDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineTextSizeDidChange(_:)), name: .timelineTextSizeDidChange, object: nil)
|
||||
didRegisterForNotifications = true
|
||||
}
|
||||
|
||||
@@ -803,6 +804,10 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
}
|
||||
|
||||
@objc func handleTimelineTextSizeDidChange(_ notification: Notification) {
|
||||
textSize = AppDefaults.timelineTextSize
|
||||
}
|
||||
|
||||
@objc func handleTimelineIconSizeDidChange(_ notification: Notification) {
|
||||
updateCellAppearances()
|
||||
performBlockAndRestoreSelection {
|
||||
@@ -856,7 +861,6 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
|
||||
private func userDefaultsDidChange() {
|
||||
fontSize = AppDefaults.timelineFontSize
|
||||
updateGridStyle()
|
||||
}
|
||||
|
||||
@@ -1459,11 +1463,11 @@ private extension TimelineViewController {
|
||||
|
||||
private func updateCellAppearances() {
|
||||
let iconSize = AppDefaults.timelineIconSize
|
||||
cellAppearance = TimelineCellAppearance(showIcon: false, fontSize: fontSize, iconSize: iconSize, showsLargeThumbnails: thumbnailsDisplay == .large)
|
||||
cellAppearanceWithIcon = TimelineCellAppearance(showIcon: true, fontSize: fontSize, iconSize: iconSize, showsLargeThumbnails: thumbnailsDisplay == .large)
|
||||
cellAppearance = TimelineCellAppearance(showIcon: false, textSize: textSize, iconSize: iconSize, showsLargeThumbnails: thumbnailsDisplay == .large)
|
||||
cellAppearanceWithIcon = TimelineCellAppearance(showIcon: true, textSize: textSize, iconSize: iconSize, showsLargeThumbnails: thumbnailsDisplay == .large)
|
||||
}
|
||||
|
||||
private func fontSizeDidChange() {
|
||||
private func textSizeDidChange() {
|
||||
updateCellAppearances()
|
||||
updateRowHeights()
|
||||
performBlockAndRestoreSelection {
|
||||
|
||||
@@ -59,6 +59,7 @@ final class AppearancePreferencesViewController: NSViewController {
|
||||
updateTimelineFeedIconsPopup()
|
||||
updateTimelineIconSizePopup()
|
||||
updateTimelineThumbnailsPopup()
|
||||
updateTimelineTextSizePopup()
|
||||
updateArticleThemePopup()
|
||||
}
|
||||
|
||||
@@ -100,6 +101,10 @@ final class AppearancePreferencesViewController: NSViewController {
|
||||
updateTimelineThumbnailsPopup()
|
||||
}
|
||||
|
||||
@objc func handleTimelineTextSizeDidChange(_ notification: Notification) {
|
||||
updateTimelineTextSizePopup()
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction func appearancePopUpDidChange(_ sender: Any) {
|
||||
@@ -153,6 +158,13 @@ final class AppearancePreferencesViewController: NSViewController {
|
||||
AppDefaults.timelineThumbnailsDisplay = thumbnailsDisplay
|
||||
}
|
||||
|
||||
@IBAction func timelineTextSizePopUpDidChange(_ sender: Any) {
|
||||
guard let tag = timelineTextSizePopup?.selectedTag(), let textSize = TimelineTextSize(rawValue: tag) else {
|
||||
return
|
||||
}
|
||||
AppDefaults.timelineTextSize = textSize
|
||||
}
|
||||
|
||||
@IBAction func showThemesFolder(_ sender: Any) {
|
||||
let url = URL(fileURLWithPath: ArticleThemesManager.shared.folderPath)
|
||||
NSWorkspace.shared.open(url)
|
||||
@@ -181,6 +193,7 @@ private extension AppearancePreferencesViewController {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineFeedIconsDisplayDidChange(_:)), name: .timelineFeedIconsDisplayDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineIconSizeDidChange(_:)), name: .timelineIconSizeDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineThumbnailsDisplayDidChange(_:)), name: .timelineThumbnailsDisplayDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineTextSizeDidChange(_:)), name: .timelineTextSizeDidChange, object: nil)
|
||||
}
|
||||
|
||||
/// On macOS 15 the "Article Text Size:" label is vertically misaligned
|
||||
@@ -244,6 +257,10 @@ private extension AppearancePreferencesViewController {
|
||||
timelineThumbnailsPopup?.selectItem(withTag: AppDefaults.timelineThumbnailsDisplay.rawValue)
|
||||
}
|
||||
|
||||
func updateTimelineTextSizePopup() {
|
||||
timelineTextSizePopup?.selectItem(withTag: AppDefaults.timelineTextSize.rawValue)
|
||||
}
|
||||
|
||||
func updateArticleThemePopup() {
|
||||
guard let articleThemePopup, let menu = articleThemePopup.menu else {
|
||||
return
|
||||
|
||||
@@ -267,6 +267,9 @@
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="200" id="tlK-00-0k1"/>
|
||||
</constraints>
|
||||
<connections>
|
||||
<action selector="timelineTextSizePopUpDidChange:" target="-2" id="tlA-tX-0a1"/>
|
||||
</connections>
|
||||
</popUpButton>
|
||||
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="tlL-nL-0l1">
|
||||
<rect key="frame" x="-2" y="225" width="151" height="16"/>
|
||||
|
||||
@@ -32,6 +32,7 @@ enum AppDefaults {
|
||||
static let showUnreadFeed = "showUnreadFeed"
|
||||
static let showStarredFeed = "showStarredFeed"
|
||||
static let timelineIconDimension = "timelineIconSize"
|
||||
static let timelineTextSize = "timelineTextSize"
|
||||
}
|
||||
|
||||
/// Registered by both platforms. Each platform’s registerDefaults adds its own.
|
||||
@@ -48,7 +49,8 @@ enum AppDefaults {
|
||||
Key.sidebarTextSize: SidebarTextSize.system.rawValue,
|
||||
Key.showTodayFeed: true,
|
||||
Key.showUnreadFeed: true,
|
||||
Key.showStarredFeed: true
|
||||
Key.showStarredFeed: true,
|
||||
Key.timelineTextSize: TimelineTextSize.medium.rawValue
|
||||
]
|
||||
}
|
||||
|
||||
@@ -212,6 +214,16 @@ enum AppDefaults {
|
||||
NotificationCenter.default.post(name: .timelineIconSizeDidChange, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
static var timelineTextSize: TimelineTextSize {
|
||||
get {
|
||||
TimelineTextSize(rawValue: UserDefaults.standard.integer(forKey: Key.timelineTextSize)) ?? .medium
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue.rawValue, forKey: Key.timelineTextSize)
|
||||
NotificationCenter.default.post(name: .timelineTextSizeDidChange, object: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// TimelineTextSize.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Brent Simmons on 11/7/26.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Notification.Name {
|
||||
static let timelineTextSizeDidChange = Notification.Name("TimelineTextSizeDidChangeNotification")
|
||||
}
|
||||
|
||||
/// Text size in the timeline.
|
||||
enum TimelineTextSize: Int, CaseIterable, CustomStringConvertible {
|
||||
case small = 1
|
||||
case medium = 2
|
||||
case large = 3
|
||||
case extraLarge = 4
|
||||
case extraExtraLarge = 5
|
||||
|
||||
var description: String {
|
||||
switch self {
|
||||
case .small:
|
||||
NSLocalizedString("Small", comment: "Small")
|
||||
case .medium:
|
||||
NSLocalizedString("Medium", comment: "Medium")
|
||||
case .large:
|
||||
NSLocalizedString("Large", comment: "Large")
|
||||
case .extraLarge:
|
||||
NSLocalizedString("Extra Large", comment: "X-Large")
|
||||
case .extraExtraLarge:
|
||||
NSLocalizedString("Extra Extra Large", comment: "XX-Large")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user