2017-11-25 06:39:59 +01:00
|
|
|
//
|
|
|
|
// SidebarLayout.swift
|
2018-08-29 07:18:24 +02:00
|
|
|
// NetNewsWire
|
2017-11-25 06:39:59 +01:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 11/24/17.
|
|
|
|
// Copyright © 2017 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2018-02-03 07:51:32 +01:00
|
|
|
import AppKit
|
2017-11-25 06:39:59 +01:00
|
|
|
|
|
|
|
// image - title - unreadCount
|
|
|
|
|
2024-03-20 07:05:30 +01:00
|
|
|
@MainActor struct SidebarCellLayout {
|
2017-11-25 06:39:59 +01:00
|
|
|
|
|
|
|
let faviconRect: CGRect
|
|
|
|
let titleRect: CGRect
|
|
|
|
let unreadCountRect: CGRect
|
|
|
|
|
|
|
|
init(appearance: SidebarCellAppearance, cellSize: NSSize, shouldShowImage: Bool, textField: NSTextField, unreadCountView: UnreadCountView) {
|
|
|
|
|
|
|
|
let bounds = NSRect(x: 0.0, y: 0.0, width: floor(cellSize.width), height: floor(cellSize.height))
|
|
|
|
|
|
|
|
var rFavicon = NSRect.zero
|
|
|
|
if shouldShowImage {
|
|
|
|
rFavicon = NSRect(x: 0.0, y: 0.0, width: appearance.imageSize.width, height: appearance.imageSize.height)
|
2020-01-09 06:40:21 +01:00
|
|
|
rFavicon = rFavicon.centeredVertically(in: bounds)
|
2017-11-25 06:39:59 +01:00
|
|
|
}
|
|
|
|
self.faviconRect = rFavicon
|
|
|
|
|
2018-02-20 00:56:15 +01:00
|
|
|
let textFieldSize = SingleLineTextFieldSizer.size(for: textField.stringValue, font: textField.font!)
|
|
|
|
|
2017-11-25 06:39:59 +01:00
|
|
|
var rTextField = NSRect(x: 0.0, y: 0.0, width: textFieldSize.width, height: textFieldSize.height)
|
|
|
|
if shouldShowImage {
|
|
|
|
rTextField.origin.x = NSMaxX(rFavicon) + appearance.imageMarginRight
|
|
|
|
}
|
2020-01-09 06:40:21 +01:00
|
|
|
rTextField = rTextField.centeredVertically(in: bounds)
|
2017-11-25 06:39:59 +01:00
|
|
|
|
|
|
|
let unreadCountSize = unreadCountView.intrinsicContentSize
|
|
|
|
let unreadCountIsHidden = unreadCountView.unreadCount < 1
|
|
|
|
|
|
|
|
var rUnread = NSRect.zero
|
|
|
|
if !unreadCountIsHidden {
|
|
|
|
rUnread.size = unreadCountSize
|
|
|
|
rUnread.origin.x = NSMaxX(bounds) - unreadCountSize.width
|
2020-01-09 06:40:21 +01:00
|
|
|
rUnread = rUnread.centeredVertically(in: bounds)
|
2017-11-25 06:39:59 +01:00
|
|
|
let textFieldMaxX = NSMinX(rUnread) - appearance.unreadCountMarginLeft
|
|
|
|
if NSMaxX(rTextField) > textFieldMaxX {
|
|
|
|
rTextField.size.width = textFieldMaxX - NSMinX(rTextField)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.unreadCountRect = rUnread
|
|
|
|
|
|
|
|
if NSMaxX(rTextField) > NSMaxX(bounds) {
|
|
|
|
rTextField.size.width = NSMaxX(bounds) - NSMinX(rTextField)
|
|
|
|
}
|
|
|
|
self.titleRect = rTextField
|
|
|
|
}
|
|
|
|
}
|