Improves helder

This commit is contained in:
2026-10-05 09:24:25 +02:00
parent 8fafea4fc3
commit 336987d821
44 changed files with 3454 additions and 542 deletions
+79 -33
View File
@@ -1,12 +1,13 @@
import HelderCore
import SwiftUI
/// 44pt bar: traffic-light inset, wordmark, project · branch, the open file's breadcrumb, and the toolbar.
/// 44pt bar: traffic-light inset, wordmark, project · branch, the open file's breadcrumb, the pane toggles
/// centred on the window, and the toolbar.
struct TitleBarView: View {
let model: WorkspaceModel
var body: some View {
HStack(spacing: Metrics.titleBarGap) {
TitleBarLayout(leading: model.layout.isFullScreen ? 14 : Metrics.trafficLightInset, trailing: 14, gap: Metrics.titleBarGap) {
HStack(alignment: .firstTextBaseline, spacing: Metrics.titleClusterGap) {
Wordmark()
ProjectName(name: model.name) { model.perform(.openFolder) }
@@ -19,16 +20,45 @@ struct TitleBarView: View {
.fixedSize()
Breadcrumb(path: model.editor?.activePath, isDirty: model.editor.map { e in e.activePath.map(e.isDirty) ?? false } ?? false)
.frame(maxWidth: .infinity, alignment: .leading)
PaneToggles(model: model)
TitleToolbar(model: model)
}
.padding(.leading, model.layout.isFullScreen ? 14 : Metrics.trafficLightInset)
.padding(.trailing, 14)
.frame(height: Metrics.titleBar)
.background(Palette.panel)
.hairline(.bottom)
}
}
/// Lays out the four title-bar parts: the pane toggles sit on the window's centre, and the breadcrumb
/// gets only the room left of them. The toggles move left only when the toolbar would run into them.
private struct TitleBarLayout: Layout {
var leading: CGFloat
var trailing: CGFloat
var gap: CGFloat
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
CGSize(width: proposal.width ?? 0, height: proposal.height ?? Metrics.titleBar)
}
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
guard subviews.count == 4 else { return }
let (cluster, crumb, toggles, toolbar) = (subviews[0], subviews[1], subviews[2], subviews[3])
let y = bounds.midY
let clusterSize = cluster.sizeThatFits(.unspecified)
let togglesSize = toggles.sizeThatFits(.unspecified)
let toolbarSize = toolbar.sizeThatFits(.unspecified)
let clusterX = bounds.minX + leading
let toolbarX = bounds.maxX - trailing - toolbarSize.width
let togglesX = min(bounds.midX - togglesSize.width / 2, toolbarX - gap - togglesSize.width)
let crumbX = clusterX + clusterSize.width + gap
cluster.place(at: CGPoint(x: clusterX, y: y), anchor: .leading, proposal: ProposedViewSize(clusterSize))
toggles.place(at: CGPoint(x: togglesX, y: y), anchor: .leading, proposal: ProposedViewSize(togglesSize))
toolbar.place(at: CGPoint(x: toolbarX, y: y), anchor: .leading, proposal: ProposedViewSize(toolbarSize))
crumb.place(at: CGPoint(x: crumbX, y: y), anchor: .leading,
proposal: ProposedViewSize(width: max(0, togglesX - gap - crumbX), height: bounds.height))
}
}
private struct ProjectName: View {
let name: String
let action: () -> Void
@@ -58,7 +88,7 @@ private struct Breadcrumb: View {
ForEach(Array(segments.enumerated()), id: \.offset) { index, segment in
if index > 0 { Text("›").foregroundStyle(Palette.text4) }
if index == segments.count - 1 {
Text(segment).typeRole(Typography.crumbLeaf).foregroundStyle(Palette.text1)
Text(segment).typeRole(Typography.crumbLeaf).foregroundStyle(Palette.text1).layoutPriority(1)
} else {
Text(segment).foregroundStyle(Palette.text4)
}
@@ -76,42 +106,58 @@ private struct Breadcrumb: View {
}
}
/// Search ⌘F · Fluid ⌘L · Hidden ⌘. · Note ⌘N · Git ⌘G · `?`, each with a tooltip that names its state.
/// Git · Explorer · File · Claude: one toggle per column. Hiding a column keeps everything inside it.
private struct PaneToggles: View {
let model: WorkspaceModel
var body: some View {
ButtonGroup([
toggle("Git", .sourceControl, column: "Source Control"),
toggle("Explorer", .explorer, column: "Explorer"),
toggle("File", .editor, column: "File"),
toggle("Claude", .terminal, column: "Claude"),
])
}
private func toggle(_ label: String, _ panel: Panel, column: String) -> GroupItem {
let shown = model.layout.isVisible(panel)
let tip = shown
? Tooltip.stated(column + " column: ", "shown", ". Click to hide it.")
: Tooltip.stated(column + " column: ", "hidden", ". Click to show it.")
return GroupItem(label, kind: .toggle(isOn: shown), tip: tip) {
model.perform(.togglePane(panel))
}
}
}
/// Search ⌘F · Fluid ⌘L · Hidden ⌘. · Note ⌘N, then `?`. Search and Note are actions; Fluid and Hidden toggle.
private struct TitleToolbar: View {
let model: WorkspaceModel
var body: some View {
let layout = model.layout
let overlay = model.overlay.current
HStack(spacing: Metrics.toolbarGap) {
ToolbarToggle("Search", keys: "⌘F", isOn: isSearch(overlay)) { model.perform(.showSearch(seed: "")) }
.tip("Search the open file, the project and the file names.", edge: .trailing)
ToolbarToggle("Fluid", keys: "⌘L", isOn: layout.fluid) { model.perform(.toggleAutoFit) }
.tip(layout.fluid
? Tooltip.stated("Column widths: ", "fluid", " — the columns re-fit on resize and focus. Click to lock them.")
: Tooltip.stated("Column widths: ", "locked", " — the columns keep their size. Click to make them fluid."),
edge: .trailing)
ToolbarToggle("Hidden", keys: "⌘.", isOn: layout.showHidden, muted: !layout.showHidden) { model.perform(.toggleHidden) }
.tip(layout.showHidden
? Tooltip.stated("Hidden files: ", "shown", " — dotfiles appear in the tree and the search. Click to hide them.")
: Tooltip.stated("Hidden files: ", "hidden", " — dotfiles are excluded from the tree and the search. Click to show them."),
edge: .trailing)
ToolbarToggle("Note", keys: "⌘N", isOn: overlay == .note) { model.perform(.showNote) }
.tip("Project note (.notes.txt) — kept next to this project.", edge: .trailing)
ToolbarToggle("Git", keys: "⌘G", isOn: layout.gitVisible) { model.perform(.toggleGit) }
.tip(layout.gitVisible
? Tooltip.stated("Source Control column: ", "shown", ". Click to hide it.")
: Tooltip.stated("Source Control column: ", "hidden", ". Click to show it."),
edge: .trailing)
HStack(spacing: Metrics.toolbarIconGap) {
ButtonGroup([
GroupItem("Search", keys: "⌘F", kind: .action,
tip: Text("Search the open file, the project and the file names.")) { model.perform(.showSearch(seed: "")) },
GroupItem("Fluid", keys: "⌘L", kind: .toggle(isOn: layout.fluid),
tip: layout.fluid
? Tooltip.stated("Column widths: ", "fluid", " — the columns re-fit on resize and focus. Click to lock them.")
: Tooltip.stated("Column widths: ", "locked", " — the columns keep their size. Click to make them fluid.")) {
model.perform(.toggleAutoFit)
},
GroupItem("Hidden", keys: "⌘.", kind: .toggle(isOn: layout.showHidden),
tip: layout.showHidden
? Tooltip.stated("Hidden files: ", "shown", " — dotfiles appear in the tree and the search. Click to hide them.")
: Tooltip.stated("Hidden files: ", "hidden", " — dotfiles are excluded from the tree and the search. Click to show them.")) {
model.perform(.toggleHidden)
},
GroupItem("Note", keys: "⌘N", kind: .action,
tip: Text("Project note (.notes.txt) — kept next to this project.")) { model.perform(.showNote) },
], tipEdge: .trailing)
ToolbarIconButton("?") { model.perform(.showShortcuts) }
.padding(.leading, 6)
.tip("Keyboard shortcuts.", edge: .trailing)
}
.fixedSize()
}
private func isSearch(_ overlay: Overlay) -> Bool {
if case .search = overlay { return true }
return false
}
}