PadXcode-iPad/Theme/PadXcodeTheme.swift
2026-04-12 22:07:35 -07:00

268 lines
7.5 KiB
Swift

import UIKit
import Runestone
// MARK: - Xcode Default Dark Theme
final class PadXcodeTheme: Theme {
let fontSize: CGFloat
init(fontSize: CGFloat = 14) { self.fontSize = fontSize }
// MARK: Required visual properties
var font: UIFont {
UIFont.monospacedSystemFont(ofSize: fontSize, weight: .regular)
}
var textColor: UIColor {
UIColor(r: 212, g: 212, b: 212)
}
var backgroundColor: UIColor {
UIColor(r: 30, g: 30, b: 30)
}
var userInterfaceStyle: UIUserInterfaceStyle {
.dark
}
var gutterBackgroundColor: UIColor {
UIColor(r: 37, g: 37, b: 38)
}
var gutterHairlineColor: UIColor {
UIColor(r: 60, g: 60, b: 60)
}
var lineNumberColor: UIColor {
UIColor(r: 110, g: 118, b: 129)
}
var lineNumberFont: UIFont {
UIFont.monospacedSystemFont(ofSize: 12, weight: .regular)
}
var selectedLineBackgroundColor: UIColor {
UIColor(r: 42, g: 45, b: 46)
}
var selectedLinesLineNumberColor: UIColor {
UIColor(r: 200, g: 200, b: 200)
}
var selectedLinesGutterBackgroundColor: UIColor {
UIColor(r: 42, g: 45, b: 46)
}
var markedTextBackgroundColor: UIColor {
UIColor(r: 38, g: 79, b: 120, alpha: 0.4)
}
var markedTextBackgroundCornerRadius: CGFloat {
2
}
var invisibleCharactersColor: UIColor {
UIColor(r: 64, g: 64, b: 64)
}
var pageGuideHairlineColor: UIColor {
UIColor(r: 64, g: 64, b: 64)
}
var pageGuideBackgroundColor: UIColor {
UIColor(r: 26, g: 26, b: 26)
}
// MARK: Syntax token colours (required by Theme protocol)
func textColor(for highlightName: String) -> UIColor? {
switch highlightName {
case "keyword", "keyword.control", "keyword.operator",
"keyword.other", "keyword.declaration", "storage.type",
"storage.modifier":
return UIColor(r: 255, g: 122, b: 178) // pink
case "type", "type.builtin", "entity.name.type",
"entity.name.type.class", "entity.name.type.struct",
"entity.name.type.enum", "entity.name.type.protocol":
return UIColor(r: 218, g: 186, b: 255) // lavender
case "type.parameter":
return UIColor(r: 107, g: 223, b: 255) // light blue
case "function", "entity.name.function",
"meta.function-call", "function.method", "function.builtin":
return UIColor(r: 103, g: 183, b: 251) // blue
case "property", "variable.other.property":
return UIColor(r: 114, g: 185, b: 213) // teal
case "variable.builtin":
return UIColor(r: 255, g: 122, b: 178) // pink (self, super)
case "constant", "constant.builtin":
return UIColor(r: 217, g: 201, b: 124) // gold bold
case "constant.numeric", "number":
return UIColor(r: 217, g: 201, b: 124) // gold
case "string", "string.special":
return UIColor(r: 255, g: 129, b: 112) // salmon
case "string.escape":
return UIColor(r: 255, g: 129, b: 112) // salmon
case "comment", "comment.line", "comment.block",
"comment.block.documentation":
return UIColor(r: 127, g: 140, b: 152) // grey
case "attribute":
return UIColor(r: 191, g: 134, b: 200) // purple
case "operator", "punctuation.operator",
"punctuation.bracket", "punctuation.delimiter":
return UIColor(r: 212, g: 212, b: 212) // default text
default:
return nil
}
}
}
// MARK: - Xcode Default Light Theme
final class PadXcodeLightTheme: Theme {
let fontSize: CGFloat
init(fontSize: CGFloat = 14) { self.fontSize = fontSize }
// MARK: Required visual properties
var font: UIFont {
UIFont.monospacedSystemFont(ofSize: fontSize, weight: .regular)
}
var textColor: UIColor {
UIColor(r: 0, g: 0, b: 0)
}
var backgroundColor: UIColor {
UIColor(r: 255, g: 255, b: 255)
}
var userInterfaceStyle: UIUserInterfaceStyle {
.light
}
var gutterBackgroundColor: UIColor {
UIColor(r: 242, g: 242, b: 242)
}
var gutterHairlineColor: UIColor {
UIColor(r: 216, g: 216, b: 216)
}
var lineNumberColor: UIColor {
UIColor(r: 160, g: 160, b: 160)
}
var lineNumberFont: UIFont {
UIFont.monospacedSystemFont(ofSize: 12, weight: .regular)
}
var selectedLineBackgroundColor: UIColor {
UIColor(r: 236, g: 245, b: 255)
}
var selectedLinesLineNumberColor: UIColor {
UIColor(r: 58, g: 58, b: 58)
}
var selectedLinesGutterBackgroundColor: UIColor {
UIColor(r: 232, g: 240, b: 250)
}
var markedTextBackgroundColor: UIColor {
UIColor(r: 181, g: 208, b: 247, alpha: 0.4)
}
var markedTextBackgroundCornerRadius: CGFloat {
2
}
var invisibleCharactersColor: UIColor {
UIColor(r: 204, g: 204, b: 204)
}
var pageGuideHairlineColor: UIColor {
UIColor(r: 221, g: 221, b: 221)
}
var pageGuideBackgroundColor: UIColor {
UIColor(r: 249, g: 249, b: 249)
}
// MARK: Syntax token colours (required by Theme protocol)
func textColor(for highlightName: String) -> UIColor? {
switch highlightName {
case "keyword", "keyword.control", "keyword.operator",
"keyword.other", "keyword.declaration", "storage.type",
"storage.modifier":
return UIColor(r: 173, g: 61, b: 164) // purple
case "type", "type.builtin", "entity.name.type",
"entity.name.type.class", "entity.name.type.struct",
"entity.name.type.enum", "entity.name.type.protocol":
return UIColor(r: 112, g: 61, b: 170) // dark purple
case "type.parameter":
return UIColor(r: 4, g: 124, b: 176) // blue
case "function", "entity.name.function",
"meta.function-call", "function.method", "function.builtin":
return UIColor(r: 57, g: 0, b: 160) // indigo
case "property", "variable.other.property":
return UIColor(r: 4, g: 124, b: 176) // blue
case "variable.builtin":
return UIColor(r: 173, g: 61, b: 164) // purple (self, super)
case "constant", "constant.builtin":
return UIColor(r: 39, g: 42, b: 216) // blue bold
case "constant.numeric", "number":
return UIColor(r: 39, g: 42, b: 216) // blue
case "string", "string.special":
return UIColor(r: 196, g: 26, b: 22) // red
case "string.escape":
return UIColor(r: 196, g: 26, b: 22) // red
case "comment", "comment.line", "comment.block",
"comment.block.documentation":
return UIColor(r: 93, g: 108, b: 121) // grey
case "attribute":
return UIColor(r: 108, g: 54, b: 169) // purple
case "operator", "punctuation.operator",
"punctuation.bracket", "punctuation.delimiter":
return nil // inherits default textColor
default:
return nil
}
}
}
// MARK: - UIColor RGB convenience (private to this file)
private extension UIColor {
convenience init(r: CGFloat, g: CGFloat, b: CGFloat, alpha: CGFloat = 1.0) {
self.init(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: alpha)
}
}