184 lines
6.3 KiB
Swift
184 lines
6.3 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)
|
|
GeometryReader { proxy in
|
|
switch GitBodyMode(width: proxy.size.width) {
|
|
case .sideColumns:
|
|
GitSideColumns(model: model, store: store, height: proxy.size.height)
|
|
case .bottomStrip:
|
|
VStack(spacing: 0) {
|
|
GitChanges(model: model, store: store)
|
|
GitBottomStrip(model: model, store: store)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
Color.clear
|
|
}
|
|
}
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.background(Palette.editor)
|
|
.contentShape(Rectangle())
|
|
}
|
|
}
|
|
|
|
/// The commit block over the sections, filling the height it gets.
|
|
private struct GitChanges: View {
|
|
let model: WorkspaceModel
|
|
let store: SourceControlStore
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
GitCommitBlock(model: model, store: store)
|
|
GitSectionsList(model: model, store: store)
|
|
.frame(maxHeight: .infinity)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Branches over commits on the left, the changes in the middle, the console on the right, all full height.
|
|
private struct GitSideColumns: View {
|
|
let model: WorkspaceModel
|
|
let store: SourceControlStore
|
|
let height: CGFloat
|
|
|
|
var body: some View {
|
|
let half = max(0, (height - Metrics.hairline) / 2).rounded(.down)
|
|
HStack(spacing: 0) {
|
|
VStack(spacing: 0) {
|
|
GitBranchesPanel(model: model, store: store)
|
|
.frame(height: half)
|
|
Hairline()
|
|
GitCommitsPanel(store: store)
|
|
.frame(maxHeight: .infinity)
|
|
}
|
|
.frame(width: GitMetrics.sideColumnWidth)
|
|
.background(Palette.panel)
|
|
.hairline(.trailing)
|
|
GitChanges(model: model, store: store)
|
|
.frame(maxWidth: .infinity)
|
|
GitConsolePanel(model: model, store: store)
|
|
.frame(width: GitMetrics.consoleColumnWidth)
|
|
.frame(maxHeight: .infinity)
|
|
.background(Palette.panel)
|
|
.hairline(.leading)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// 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)
|
|
}
|
|
}
|
|
|
|
/// How the body under the top bar is laid out for one window width.
|
|
enum GitBodyMode: Equatable {
|
|
case sideColumns
|
|
case bottomStrip
|
|
|
|
init(width: CGFloat) {
|
|
self = width >= GitMetrics.sideColumnsMinWidth ? .sideColumns : .bottomStrip
|
|
}
|
|
}
|
|
|
|
/// 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 sideColumnsMinWidth: CGFloat = 1600
|
|
static let sideColumnWidth: CGFloat = 480
|
|
static let consoleColumnWidth: CGFloat = 560
|
|
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))
|
|
}
|
|
}
|