94 lines
3.2 KiB
Swift
94 lines
3.2 KiB
Swift
import SwiftUI
|
|
|
|
/// The launcher without a project; with one, the title bar, four columns and status bar, overlays above.
|
|
struct WorkspaceView: View {
|
|
let model: WorkspaceModel
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
if model.root == nil {
|
|
if model.isReady { LauncherScreen(model: model) } else { Palette.editor }
|
|
} else {
|
|
workspace
|
|
}
|
|
ToastStack(toasts: model.toasts)
|
|
if model.isFocusFlashVisible { FocusFlash(model: model) }
|
|
}
|
|
.ignoresSafeArea()
|
|
}
|
|
|
|
private var workspace: some View {
|
|
GeometryReader { proxy in
|
|
VStack(spacing: 0) {
|
|
TitleBarView(model: model)
|
|
.zIndex(2)
|
|
Columns(model: model)
|
|
.frame(maxHeight: .infinity)
|
|
.zIndex(1)
|
|
StatusBarView(model: model)
|
|
}
|
|
.overlay { OverlayHost(model: model) }
|
|
.overlay {
|
|
if model.overlay.current == .launcher { RecentProjectsOverlay(model: model) }
|
|
}
|
|
.onAppear { model.layout.windowResized(width: proxy.size.width) }
|
|
.onChange(of: proxy.size.width) { _, width in model.layout.windowResized(width: width) }
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The four columns and their splitters. The agent column is keyed by the project so its terminals respawn on a switch.
|
|
private struct Columns: View {
|
|
let model: WorkspaceModel
|
|
|
|
var body: some View {
|
|
let layout = model.layout
|
|
HStack(spacing: 0) {
|
|
if layout.gitVisible {
|
|
SourceControlColumn(model: model)
|
|
.frame(width: layout.widths.sourceControl)
|
|
.refreshFlash(model.refreshTick)
|
|
Splitter(onDrag: { layout.dragSourceControl(by: $0) }, onEnd: layout.endDrag)
|
|
}
|
|
ExplorerColumn(model: model)
|
|
.frame(width: layout.widths.explorer)
|
|
.refreshFlash(model.refreshTick)
|
|
Splitter(onDrag: { layout.dragExplorer(by: $0) }, onEnd: layout.endDrag)
|
|
EditorColumn(model: model)
|
|
.frame(minWidth: Metrics.minEditorWidth, maxWidth: .infinity)
|
|
.refreshFlash(model.refreshTick)
|
|
Splitter(onDrag: { layout.dragAgent(by: $0) }, onEnd: layout.endDrag)
|
|
AgentColumn(model: model)
|
|
.frame(width: layout.widths.agent)
|
|
.id(model.root)
|
|
}
|
|
.clipped()
|
|
}
|
|
}
|
|
|
|
/// ⌘R lightens a column for a moment and lets it settle back; each new tick replays it.
|
|
private struct RefreshFlash: ViewModifier {
|
|
let tick: Int
|
|
@State private var strength = 0.0
|
|
|
|
func body(content: Content) -> some View {
|
|
content
|
|
.overlay {
|
|
Palette.refreshFlash
|
|
.blendMode(.plusLighter)
|
|
.opacity(strength)
|
|
.allowsHitTesting(false)
|
|
}
|
|
.onChange(of: tick) {
|
|
strength = 1
|
|
withAnimation(.easeOut(duration: Metrics.refreshFlashDuration)) { strength = 0 }
|
|
}
|
|
}
|
|
}
|
|
|
|
extension View {
|
|
fileprivate func refreshFlash(_ tick: Int) -> some View {
|
|
modifier(RefreshFlash(tick: tick))
|
|
}
|
|
}
|