restores Helder in all its glory
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
import HelderCore
|
||||
import SwiftUI
|
||||
|
||||
/// The bare window: no title bar, the launcher card top-centred on the editor ground.
|
||||
struct LauncherScreen: View {
|
||||
let model: WorkspaceModel
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .top) {
|
||||
Palette.editor
|
||||
LauncherCard(model: model)
|
||||
.padding(.top, Metrics.launcherTopPadding)
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.bottom, 20)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Head, "Open new project…", the RECENT list and the key hints. Hover and the arrows move the same cursor.
|
||||
/// The card hugs a short list and scrolls a long one inside the window.
|
||||
struct LauncherCard: View {
|
||||
let model: WorkspaceModel
|
||||
|
||||
var body: some View {
|
||||
OverlayCard {
|
||||
ViewThatFits(in: .vertical) {
|
||||
VStack(spacing: 0) {
|
||||
head
|
||||
rows
|
||||
footer
|
||||
}
|
||||
VStack(spacing: 0) {
|
||||
head
|
||||
ScrollViewReader { proxy in
|
||||
ScrollView { rows }
|
||||
.onChange(of: model.launcher.selection) { _, selection in proxy.scrollTo(selection) }
|
||||
}
|
||||
footer
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(width: Metrics.launcherWidth)
|
||||
.frame(maxHeight: .infinity, alignment: .top)
|
||||
}
|
||||
|
||||
private var rows: some View {
|
||||
let launcher = model.launcher
|
||||
return LazyVStack(alignment: .leading, spacing: 0) {
|
||||
LauncherRow(index: 0, model: model) {
|
||||
Image(systemName: "plus")
|
||||
} text: {
|
||||
Text("Open new project…").typeRole(Typography.rowSelected).foregroundStyle(Palette.text1)
|
||||
} trailing: {
|
||||
EscChip("↵")
|
||||
}
|
||||
.frame(height: Metrics.launcherNewRow)
|
||||
.hairline(.bottom)
|
||||
if !launcher.recents.isEmpty {
|
||||
Text("Recent")
|
||||
.typeRole(Typography.panelLabel)
|
||||
.foregroundStyle(Palette.text4)
|
||||
.padding(EdgeInsets(top: 14, leading: 20, bottom: 6, trailing: 20))
|
||||
}
|
||||
ForEach(Array(launcher.recents.enumerated()), id: \.element.id) { offset, project in
|
||||
recentRow(project, index: offset + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var head: some View {
|
||||
HStack(spacing: 14) {
|
||||
Image(systemName: "sparkle").font(.system(size: 16, weight: .light)).foregroundStyle(Palette.amber)
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
Wordmark(role: Typography.launcherWordmark)
|
||||
Text("Open a project to begin").typeRole(Typography.tooltip).foregroundStyle(Palette.text4)
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.padding(20)
|
||||
.hairline(.bottom)
|
||||
}
|
||||
|
||||
private func recentRow(_ project: RecentProject, index: Int) -> some View {
|
||||
let selected = model.launcher.selection == index
|
||||
return LauncherRow(index: index, model: model) {
|
||||
Image(systemName: "folder")
|
||||
} text: {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 10) {
|
||||
Text(project.name).typeRole(Typography.rowSelected).foregroundStyle(selected ? Palette.text1 : Palette.text3)
|
||||
.lineLimit(1)
|
||||
Text(project.path).typeRole(Typography.meta).foregroundStyle(selected ? Palette.text3 : Palette.text4)
|
||||
.lineLimit(1).truncationMode(.head)
|
||||
}
|
||||
} trailing: {
|
||||
EmptyView()
|
||||
}
|
||||
.frame(height: Metrics.launcherRow)
|
||||
.help(project.path)
|
||||
}
|
||||
|
||||
private var footer: some View {
|
||||
OverlayFooter.hint([("⌘↑↓", "navigate"), ("↵", "open")])
|
||||
.typeRole(Typography.chip)
|
||||
.padding(.horizontal, 20)
|
||||
.frame(maxWidth: .infinity, minHeight: Metrics.launcherFooter, alignment: .leading)
|
||||
.hairline(.top)
|
||||
}
|
||||
}
|
||||
|
||||
private struct LauncherRow<Icon: View, Label: View, Trailing: View>: View {
|
||||
let index: Int
|
||||
let model: WorkspaceModel
|
||||
let icon: Icon
|
||||
let text: Label
|
||||
let trailing: Trailing
|
||||
@State private var isHovered = false
|
||||
|
||||
init(index: Int, model: WorkspaceModel, @ViewBuilder icon: () -> Icon, @ViewBuilder text: () -> Label,
|
||||
@ViewBuilder trailing: () -> Trailing) {
|
||||
self.index = index
|
||||
self.model = model
|
||||
self.icon = icon()
|
||||
self.text = text()
|
||||
self.trailing = trailing()
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
let selected = model.launcher.selection == index
|
||||
HStack(spacing: 12) {
|
||||
icon
|
||||
.font(.system(size: 13, weight: .light))
|
||||
.foregroundStyle(selected || index == 0 ? Palette.amber : Palette.text4)
|
||||
.frame(width: 16, height: 16)
|
||||
text
|
||||
Spacer(minLength: 8)
|
||||
trailing
|
||||
}
|
||||
.padding(.horizontal, 20)
|
||||
.frame(maxHeight: .infinity)
|
||||
.selectableRow(isSelected: selected, isHovered: isHovered)
|
||||
.contentShape(Rectangle())
|
||||
.id(index)
|
||||
.onHover { inside in
|
||||
isHovered = inside
|
||||
if inside { model.perform(.launcherSelect(index)) }
|
||||
}
|
||||
.onTapGesture {
|
||||
model.perform(.launcherSelect(index))
|
||||
model.perform(.launcherActivate)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user