102 lines
3.8 KiB
Swift
102 lines
3.8 KiB
Swift
import SwiftUI
|
|
|
|
/// The Git and Schema views' icons, drawn on Lucide's 24-unit grid at stroke 1.75; the flag is a plain pennant.
|
|
/// Icons with arcs Lucide draws as curves (cloud, eraser, sparkle) use the nearest SF Symbol.
|
|
enum GitIcon {
|
|
case gitBranch, cloud, arrowDownToLine, arrowUpFromLine, minimize, chevronDown, chevronRight, eraser, check, flag
|
|
case database, terminal, search, minus, plus, x, sparkle
|
|
|
|
fileprivate var symbol: String? {
|
|
switch self {
|
|
case .cloud: "cloud"
|
|
case .eraser: "eraser"
|
|
case .sparkle: "sparkle"
|
|
default: nil
|
|
}
|
|
}
|
|
|
|
fileprivate func path(_ k: CGFloat) -> Path {
|
|
func p(_ x: CGFloat, _ y: CGFloat) -> CGPoint { CGPoint(x: x * k, y: y * k) }
|
|
var path = Path()
|
|
func line(_ points: (CGFloat, CGFloat)...) {
|
|
path.move(to: p(points[0].0, points[0].1))
|
|
for point in points.dropFirst() { path.addLine(to: p(point.0, point.1)) }
|
|
}
|
|
switch self {
|
|
case .gitBranch:
|
|
line((6, 3), (6, 15))
|
|
path.addEllipse(in: CGRect(x: 15 * k, y: 3 * k, width: 6 * k, height: 6 * k))
|
|
path.addEllipse(in: CGRect(x: 3 * k, y: 15 * k, width: 6 * k, height: 6 * k))
|
|
path.move(to: p(18, 9))
|
|
path.addQuadCurve(to: p(9, 18), control: p(18, 18))
|
|
case .arrowDownToLine:
|
|
line((12, 17), (12, 3))
|
|
line((6, 11), (12, 17), (18, 11))
|
|
line((19, 21), (5, 21))
|
|
case .arrowUpFromLine:
|
|
line((18, 9), (12, 3), (6, 9))
|
|
line((12, 3), (12, 17))
|
|
line((5, 21), (19, 21))
|
|
case .minimize:
|
|
line((14, 10), (21, 3))
|
|
line((20, 10), (14, 10), (14, 4))
|
|
line((3, 21), (10, 14))
|
|
line((4, 14), (10, 14), (10, 20))
|
|
case .chevronDown:
|
|
line((6, 9), (12, 15), (18, 9))
|
|
case .chevronRight:
|
|
line((9, 18), (15, 12), (9, 6))
|
|
case .check:
|
|
line((20, 6), (9, 17), (4, 12))
|
|
case .flag:
|
|
line((5, 22), (5, 3))
|
|
line((5, 4), (19, 9), (5, 14))
|
|
case .database:
|
|
path.addEllipse(in: CGRect(x: 3 * k, y: 2 * k, width: 18 * k, height: 6 * k))
|
|
line((3, 5), (3, 19))
|
|
line((21, 5), (21, 19))
|
|
for y in [12.0, 19.0] {
|
|
// A lower half-ellipse, 9 wide and 3 deep each side, as two Bézier quarters.
|
|
let c = 0.5523
|
|
path.move(to: p(3, y))
|
|
path.addCurve(to: p(12, y + 3), control1: p(3, y + 3 * c), control2: p(12 - 9 * c, y + 3))
|
|
path.addCurve(to: p(21, y), control1: p(12 + 9 * c, y + 3), control2: p(21, y + 3 * c))
|
|
}
|
|
case .terminal:
|
|
line((4, 17), (10, 11), (4, 5))
|
|
line((12, 19), (20, 19))
|
|
case .search:
|
|
path.addEllipse(in: CGRect(x: 3 * k, y: 3 * k, width: 16 * k, height: 16 * k))
|
|
line((21, 21), (16.65, 16.65))
|
|
case .minus:
|
|
line((5, 12), (19, 12))
|
|
case .plus:
|
|
line((5, 12), (19, 12))
|
|
line((12, 5), (12, 19))
|
|
case .x:
|
|
line((18, 6), (6, 18))
|
|
line((6, 6), (18, 18))
|
|
case .cloud, .eraser, .sparkle:
|
|
break
|
|
}
|
|
return path
|
|
}
|
|
}
|
|
|
|
struct GitIconView: View {
|
|
let icon: GitIcon
|
|
var size: CGFloat = 14
|
|
|
|
var body: some View {
|
|
if let symbol = icon.symbol {
|
|
Image(systemName: symbol)
|
|
.font(.system(size: size * 0.82, weight: .light))
|
|
.frame(width: size, height: size)
|
|
} else {
|
|
icon.path(size / 24)
|
|
.stroke(style: StrokeStyle(lineWidth: 1.75 * size / 24, lineCap: .round, lineJoin: .round))
|
|
.frame(width: size, height: size)
|
|
}
|
|
}
|
|
}
|