Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Sources/WeiBei/Support/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,79 @@ struct WeiBeiTextActionButtonStyle: ButtonStyle {
}
}

/// Dialog / sheet action buttons in the paper language: the solid-cinnabar
/// primary (same filled treatment as the send action) and the etched
/// secondary, so sheets stop mixing system `.bordered` chrome in.
struct WeiBeiDialogButtonStyle: ButtonStyle {
enum Prominence {
case primary
case secondary
}

@Environment(\.isEnabled) private var isEnabled
@Environment(\.colorScheme) private var colorScheme
var prominence: Prominence = .secondary
@State private var hovering = false

func makeBody(configuration: Configuration) -> some View {
let shape = RoundedRectangle(cornerRadius: WeiBeiMetric.controlRadius, style: .continuous)
return configuration.label
.weiBeiText(12, weight: prominence == .primary ? .semibold : .medium)
.foregroundStyle(foreground)
.padding(.horizontal, 14)
.frame(height: 28)
.background { background(isPressed: configuration.isPressed, shape: shape) }
.clipShape(shape)
.scaleEffect(configuration.isPressed ? 0.97 : 1)
.animation(WeiBeiMotion.press, value: configuration.isPressed)
.animation(WeiBeiMotion.hover, value: hovering)
.onHover { hovering = isEnabled && $0 }
.onChange(of: isEnabled) { _, enabled in
if !enabled { hovering = false }
}
}

private var foreground: Color {
guard isEnabled else {
return prominence == .primary
? WeiBeiTheme.onCinnabar.opacity(0.66)
: WeiBeiTheme.tertiaryInk.opacity(0.60)
}
if prominence == .primary { return WeiBeiTheme.onCinnabar }
return hovering ? WeiBeiTheme.ink : WeiBeiTheme.secondaryInk
}

@ViewBuilder
private func background(isPressed: Bool, shape: RoundedRectangle) -> some View {
if !isEnabled {
if prominence == .primary {
shape.fill(WeiBeiTheme.cinnabar.opacity(0.38))
} else {
WeiBeiEtchedBackdrop(
shape: shape,
fill: WeiBeiTheme.paperInset.opacity(0.16),
stroke: WeiBeiTheme.hairline.opacity(0.28)
)
}
} else if prominence == .primary {
if isPressed {
shape.fill(WeiBeiTheme.cinnabar.opacity(colorScheme == .dark ? 0.78 : 0.86))
} else if hovering {
shape.fill(WeiBeiTheme.cinnabar.opacity(colorScheme == .dark ? 0.86 : 0.92))
} else {
shape.fill(WeiBeiTheme.cinnabar)
}
} else {
WeiBeiEtchedBackdrop(
shape: shape,
fill: WeiBeiTheme.paperInset.opacity(isPressed ? 0.40 : hovering ? 0.34 : 0.22),
stroke: WeiBeiTheme.hairline.opacity(hovering || isPressed ? 0.55 : 0.40),
showsContactShadow: hovering && !isPressed
)
}
}
}

extension View {
func weibeiPanel() -> some View {
self
Expand Down
3 changes: 2 additions & 1 deletion Sources/WeiBei/Views/CourseRecordsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,13 @@ private struct LearningMemoryEditSheet: View {
Button(store.ui("取消", "Cancel")) {
dismiss()
}
.buttonStyle(WeiBeiDialogButtonStyle(prominence: .secondary))
Button(store.ui("保存修改", "Save")) {
if store.updateLearningMemory(memory.id, in: scope, kind: kind, text: text) {
dismiss()
}
}
.buttonStyle(.borderedProminent)
.buttonStyle(WeiBeiDialogButtonStyle(prominence: .primary))
.disabled(
text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|| text.trimmingCharacters(in: .whitespacesAndNewlines).count > 500
Expand Down
39 changes: 27 additions & 12 deletions Sources/WeiBei/Views/EmptyWorkspaceLauncherView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,17 @@ private struct LibraryPlacementNoticeCard: View {
.lineLimit(1)
.truncationMode(.middle)
}
.padding(.horizontal, 12)
.padding(.vertical, 7)
.frame(maxWidth: .infinity)
.background {
WeiBeiEtchedBackdrop(
shape: RoundedRectangle(cornerRadius: 7, style: .continuous),
fill: WeiBeiTheme.paperInset.opacity(0.32),
stroke: WeiBeiTheme.hairline.opacity(0.45)
)
}
.clipShape(RoundedRectangle(cornerRadius: 7, style: .continuous))

if let relocationErrorText {
Text(relocationErrorText)
Expand All @@ -657,28 +668,32 @@ private struct LibraryPlacementNoticeCard: View {
ProgressView()
.progressViewStyle(.linear)
} else {
HStack(spacing: 14) {
Button(store.ui("就用这里", "Use This Folder")) {
confirmed = true
}
.buttonStyle(WeiBeiTextActionButtonStyle(active: true))

HStack(spacing: 10) {
Button(store.ui("换个位置…", "Choose Another Location…")) {
relocateLibrary()
}
.buttonStyle(WeiBeiTextActionButtonStyle())
.buttonStyle(WeiBeiDialogButtonStyle(prominence: .secondary))

Button(store.ui("就用这里", "Use This Folder")) {
confirmed = true
}
.buttonStyle(WeiBeiDialogButtonStyle(prominence: .primary))
}
}
}
.padding(.horizontal, 16)
.padding(.vertical, 13)
.frame(maxWidth: 470)
.background(WeiBeiTheme.paperRaised.opacity(0.55))
.clipShape(RoundedRectangle(cornerRadius: 8, style: .continuous))
.overlay {
RoundedRectangle(cornerRadius: 8, style: .continuous)
.stroke(WeiBeiTheme.hairline.opacity(0.5), lineWidth: 1)
.background {
WeiBeiEtchedBackdrop(
shape: RoundedRectangle(cornerRadius: 8, style: .continuous),
fill: WeiBeiTheme.paperRaised.opacity(0.55),
stroke: WeiBeiTheme.hairline.opacity(0.5)
)
}
.clipShape(RoundedRectangle(cornerRadius: 8, style: .continuous))
.shadow(color: WeiBeiTheme.ink.opacity(0.06), radius: 2, y: 1)
.shadow(color: WeiBeiTheme.ink.opacity(0.05), radius: 10, y: 3)
.padding(.top, 10)
.accessibilityElement(children: .contain)
.accessibilityIdentifier("library-placement-notice")
Expand Down
3 changes: 2 additions & 1 deletion Sources/WeiBei/Views/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,11 @@ struct SettingsView: View {
Button(store.ui("开始迁移", "Start Migration")) {
confirmMigration(to: destination)
}
.buttonStyle(.borderedProminent)
.buttonStyle(WeiBeiDialogButtonStyle(prominence: .primary))
Button(store.ui("取消", "Cancel")) {
pendingMigrationDestination = nil
}
.buttonStyle(WeiBeiDialogButtonStyle(prominence: .secondary))
}
}
.padding(.horizontal, 14)
Expand Down