Files
helder/Sources/HelderUI/GitView/GitView.swift
T

120 lines
4.1 KiB
Swift

import HelderCore
import SwiftUI
/// ⌘G: the full-screen Git view over the title bar, the columns and the status bar.
struct GitView: View {
let model: WorkspaceModel
var body: some View {
Group {
if let store = model.sourceControl {
VStack(spacing: 0) {
GitTopBar(model: model, store: store)
GitCommitBlock(model: model, store: store)
GitSectionsList(model: model, store: store)
.frame(maxHeight: .infinity)
GitBottomStrip(model: model, store: store)
}
} else {
Color.clear
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Palette.editor)
.contentShape(Rectangle())
}
}
/// The console left, the branches right, 230pt tall; a wide window adds the commit list after them.
private struct GitBottomStrip: View {
let model: WorkspaceModel
let store: SourceControlStore
var body: some View {
GeometryReader { proxy in
let layout = GitStripLayout(width: proxy.size.width)
HStack(spacing: 0) {
GitConsolePanel(model: model, store: store)
.frame(width: layout.console)
Hairline(.vertical)
GitBranchesPanel(model: model, store: store)
.frame(width: layout.branches)
if let commits = layout.commits {
Hairline(.vertical)
GitCommitsPanel(store: store)
.frame(width: commits)
}
Spacer(minLength: 0)
}
}
.frame(height: GitMetrics.bottomStrip)
.background(Palette.panel)
.hairline(.top)
}
}
/// The widths of the bottom strip's panels for one strip width.
struct GitStripLayout: Equatable {
var console: CGFloat
var branches: CGFloat
/// Nil while the room left after the two capped panels is under `GitMetrics.commitsMinWidth`.
var commits: CGFloat?
init(width: CGFloat) {
let hairline = Metrics.hairline
let share = max(0, (width - hairline) / 2).rounded(.down)
console = min(GitMetrics.consoleMaxWidth, share)
branches = min(GitMetrics.branchesMaxWidth, share)
let left = width - console - branches - 2 * hairline
commits = left >= GitMetrics.commitsMinWidth ? left : nil
}
}
/// The Git view's fixed sizes, from the design handoff.
enum GitMetrics {
static let topBar: CGFloat = 44
static let topButton: CGFloat = 28
static let messageMin: CGFloat = 56
static let messageMax: CGFloat = 180
static let messageInset = CGSize(width: 16, height: 14)
static let commitFooter: CGFloat = 52
static let commitButton: CGFloat = 32
static let commitButtonMinWidth: CGFloat = 160
static let sectionHeader: CGFloat = 46
static let sectionGap: CGFloat = 28
static let fileRow: CGFloat = 36
static let accentBar: CGFloat = 3
static let actionWidth: CGFloat = 100
static let headerAction: CGFloat = 28
static let rowAction: CGFloat = 26
static let actionGap: CGFloat = 6
static let statusBadge: CGFloat = 18
static let statWidth: CGFloat = 52
static let diffLine: CGFloat = 22
static let diffGutter: CGFloat = 52
static let diffGap: CGFloat = 28
static let bottomStrip: CGFloat = 230
static let consoleMaxWidth: CGFloat = 820
static let branchesMaxWidth: CGFloat = 820
static let commitsMinWidth: CGFloat = 260
static let stripHeader: CGFloat = 32
static let branchRow: CGFloat = 28
}
/// A colour transition on hover, the only motion the view has.
struct HoverState: ViewModifier {
@Binding var isHovered: Bool
func body(content: Content) -> some View {
content
.onHover { isHovered = $0 }
.animation(Metrics.colorTransition, value: isHovered)
}
}
extension View {
func tracksHover(_ isHovered: Binding<Bool>) -> some View {
modifier(HoverState(isHovered: isHovered))
}
}