adds first version of the app
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import AppKit
|
||||
|
||||
/// The colour tokens of the paper look.
|
||||
public enum Theme {
|
||||
/// Window and page background.
|
||||
public static let paper = NSColor(hex: 0xD8D0C0)
|
||||
/// Text.
|
||||
public static let ink = NSColor(hex: 0x2B2621)
|
||||
/// Dates, `image missing`.
|
||||
public static let inkMuted = NSColor(hex: 0x6E655A)
|
||||
/// The caret.
|
||||
public static let accent = NSColor(hex: 0x8A4B2A)
|
||||
/// Selected text, and the save error message.
|
||||
public static let selection = NSColor(hex: 0xB9AE98)
|
||||
}
|
||||
|
||||
public extension NSColor {
|
||||
convenience init(hex: UInt32, alpha: CGFloat = 1) {
|
||||
self.init(
|
||||
srgbRed: CGFloat((hex >> 16) & 0xFF) / 255,
|
||||
green: CGFloat((hex >> 8) & 0xFF) / 255,
|
||||
blue: CGFloat(hex & 0xFF) / 255,
|
||||
alpha: alpha
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// The body text size that ⌘+ / ⌘− / ⌘0 change.
|
||||
public struct TextSize: Equatable, Sendable {
|
||||
public static let standard: CGFloat = 16
|
||||
public static let range: ClosedRange<CGFloat> = 10...32
|
||||
public static let step: CGFloat = 2
|
||||
|
||||
public private(set) var body: CGFloat
|
||||
|
||||
public init(body: CGFloat = TextSize.standard) {
|
||||
self.body = min(max(body, TextSize.range.lowerBound), TextSize.range.upperBound)
|
||||
}
|
||||
|
||||
public mutating func bigger() { self = TextSize(body: body + TextSize.step) }
|
||||
public mutating func smaller() { self = TextSize(body: body - TextSize.step) }
|
||||
public mutating func reset() { self = TextSize() }
|
||||
}
|
||||
|
||||
/// Sizes of the page layout that follow the body size.
|
||||
public enum PageMetrics {
|
||||
public static let columnCharacters = 68
|
||||
public static let lineHeightMultiple: CGFloat = 1.6
|
||||
public static let dateScale: CGFloat = 0.75
|
||||
/// Room under the transparent title bar.
|
||||
public static let topInset: CGFloat = 52
|
||||
public static let sideMargin: CGFloat = 28
|
||||
/// The narrowest left margin that shows created dates.
|
||||
public static let dateMarginMinimum: CGFloat = 120
|
||||
/// Room between a margin date and the column.
|
||||
public static let dateSpacing: CGFloat = 16
|
||||
|
||||
/// The width of about 68 characters of body text.
|
||||
public static func columnWidth(bodySize: CGFloat) -> CGFloat {
|
||||
let sample = String(String(repeating: "the quick brown fox jumps over a lazy dog ", count: 2).prefix(columnCharacters))
|
||||
let width = NSAttributedString(string: sample, attributes: [.font: PlakFonts.body(bodySize)]).size().width
|
||||
return ceil(width)
|
||||
}
|
||||
|
||||
/// The height of one text line: 1.6 times the size, or more when the font needs it.
|
||||
public static func lineHeight(_ font: NSFont) -> CGFloat {
|
||||
max(round(font.pointSize * lineHeightMultiple), PlakFonts.naturalLineHeight(font))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user