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
84 changes: 81 additions & 3 deletions Sources/WeiBei/Support/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,63 @@ private struct WeiBeiRevealModifier: ViewModifier {
}
}

/// The single texture primitive behind hover pills, selected rows, and small
/// control chrome: base fill + top inner sheen + bottom inner shade + hairline
/// frame, over any insettable shape. Render nothing when invisible so idle
/// ghosts stay perfectly clean.
struct WeiBeiEtchedBackdrop<Shape: InsettableShape>: View {
@Environment(\.colorScheme) private var colorScheme

let shape: Shape
var fill: Color
var stroke: Color = .clear
/// Tight contact shadow so a hover pill sits on the surface (controls only;
/// lists skip it to stay light).
var showsContactShadow = false

init(
shape: Shape,
fill: Color,
stroke: Color = .clear,
showsContactShadow: Bool = false
) {
self.shape = shape
self.fill = fill
self.stroke = stroke
self.showsContactShadow = showsContactShadow
}

var body: some View {
let dark = colorScheme == .dark
return ZStack {
shape.fill(fill)
LinearGradient(
colors: [
WeiBeiTheme.glassHighlight.opacity(dark ? 0.20 : 0.34),
.clear,
],
startPoint: .top,
endPoint: UnitPoint(x: 0.5, y: 0.6)
)
.clipShape(shape)
}
.clipShape(shape)
.overlay(alignment: .bottom) {
shape
.stroke(WeiBeiTheme.paperInset.opacity(dark ? 0.50 : 0.52), lineWidth: 1)
.padding(0.5)
}
.overlay {
shape.stroke(stroke, lineWidth: 1)
}
.shadow(
color: WeiBeiTheme.ink.opacity(showsContactShadow ? (dark ? 0.24 : 0.10) : 0),
radius: 1.5,
y: 1
)
}
}

enum WeiBeiIconButtonProminence {
case neutral
/// Solid cinnabar fill with an on-cinnabar (米白) icon in every state —
Expand Down Expand Up @@ -1497,11 +1554,13 @@ private struct WeiBeiIconButtonBody: View {
.weiBeiText(13, weight: .semibold)
.frame(width: size * textScale, height: size * textScale)
.foregroundStyle(foreground(isPressed: configuration.isPressed))
.background(background(isPressed: configuration.isPressed))
.background { chromeBackground }
.clipShape(RoundedRectangle(cornerRadius: cornerRadius))
.overlay {
RoundedRectangle(cornerRadius: cornerRadius)
.stroke(border, lineWidth: 1)
if prominence == .primary {
RoundedRectangle(cornerRadius: cornerRadius)
.stroke(border, lineWidth: 1)
}
}
.scaleEffect(configuration.isPressed ? 0.94 : hovering ? 1.015 : 1)
.animation(WeiBeiMotion.press, value: configuration.isPressed)
Expand All @@ -1516,6 +1575,25 @@ private struct WeiBeiIconButtonBody: View {
}
}

/// Neutral hover/active states go through the etched backdrop (top sheen +
/// bottom shade + hairline + contact shadow); the filled `.primary` keeps
/// its solid cinnabar fill untouched.
@ViewBuilder
private var chromeBackground: some View {
let chromeShape = RoundedRectangle(cornerRadius: cornerRadius, style: .continuous)
if prominence == .primary {
chromeShape
.fill(background(isPressed: configuration.isPressed))
} else if active || hovering || configuration.isPressed {
WeiBeiEtchedBackdrop(
shape: chromeShape,
fill: background(isPressed: configuration.isPressed),
stroke: border,
showsContactShadow: !configuration.isPressed
)
}
}

private func foreground(isPressed: Bool) -> Color {
guard isEnabled else { return WeiBeiTheme.tertiaryInk.opacity(0.58) }
if prominence == .primary {
Expand Down
98 changes: 62 additions & 36 deletions Sources/WeiBei/Views/SidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,12 @@ struct SidebarView: View {
.foregroundColor(WeiBeiTheme.ink)
.weiBeiText(12.5)
}
.padding(.horizontal, 8)
.frame(height: 28)
.frame(maxWidth: .infinity, alignment: .leading)
.background {
RoundedRectangle(cornerRadius: 8, style: .continuous)
.fill(WeiBeiTheme.paperInset.opacity(librarySearchFocused ? 0.20 : 0.34))
}
.overlay {
RoundedRectangle(cornerRadius: 8, style: .continuous)
.strokeBorder(
librarySearchFocused
? WeiBeiTheme.link.opacity(0.36)
: WeiBeiTheme.hairline.opacity(0.46),
lineWidth: 1
)
}
.animation(WeiBeiMotion.reveal, value: librarySearchFocused)
.weibeiInputSurface(
active: librarySearchFocused,
height: 28,
horizontalPadding: 8
)
}

private func importMaterialsFromSidebar() {
Expand Down Expand Up @@ -496,6 +485,8 @@ private struct SidebarCourseGroupHeader: View {
var add: (() -> Void)? = nil
var onDropItem: ((String) -> Void)? = nil

@State private var hoveringAdd = false

var body: some View {
HStack(spacing: 5) {
Image(systemName: systemImage)
Expand All @@ -512,8 +503,19 @@ private struct SidebarCourseGroupHeader: View {
Button(action: add) {
Image(systemName: "plus")
.weiBeiText(9.5, weight: .semibold)
.frame(width: 18, height: 18)
.background {
if hoveringAdd {
WeiBeiEtchedBackdrop(
shape: Circle(),
fill: WeiBeiTheme.paperInset.opacity(0.34),
stroke: WeiBeiTheme.hairline.opacity(0.30)
)
}
}
}
.buttonStyle(.plain)
.onHover { hoveringAdd = $0 }
.foregroundStyle(accent.opacity(0.82))
.accessibilityLabel(Text("添加\(title)"))
.help("添加\(title)")
Expand Down Expand Up @@ -580,7 +582,13 @@ private struct SidebarCourseRow: View {
.foregroundStyle(enterTint)
.frame(width: 22, height: 22)
.background {
Circle().fill(WeiBeiTheme.paperInset.opacity(enterBackdropOpacity))
if enterBackdropOpacity > 0 {
WeiBeiEtchedBackdrop(
shape: Circle(),
fill: WeiBeiTheme.paperInset.opacity(enterBackdropOpacity),
stroke: WeiBeiTheme.hairline.opacity(0.30)
)
}
}
}
.buttonStyle(.plain)
Expand All @@ -591,7 +599,7 @@ private struct SidebarCourseRow: View {
.padding(.horizontal, 9)
.frame(height: 48)
.frame(maxWidth: .infinity, alignment: .leading)
.background(rowBackground)
.background { rowBackdrop }
.offset(x: expanded || hovering ? 2 : 0)
.clipShape(RoundedRectangle(cornerRadius: 8, style: .continuous))
.onHover { hovering = $0 }
Expand All @@ -600,10 +608,21 @@ private struct SidebarCourseRow: View {
.animation(WeiBeiMotion.hover, value: hoveringEnter)
}

private var rowBackground: Color {
if expanded { return WeiBeiTheme.paperInset.opacity(0.70) }
if hovering { return WeiBeiTheme.paperInset.opacity(0.30) }
return .clear
@ViewBuilder
private var rowBackdrop: some View {
if expanded {
WeiBeiEtchedBackdrop(
shape: RoundedRectangle(cornerRadius: 8, style: .continuous),
fill: WeiBeiTheme.paperInset.opacity(0.70),
stroke: WeiBeiTheme.hairline.opacity(0.40)
)
} else if hovering {
WeiBeiEtchedBackdrop(
shape: RoundedRectangle(cornerRadius: 8, style: .continuous),
fill: WeiBeiTheme.paperInset.opacity(0.30),
stroke: WeiBeiTheme.hairline.opacity(0.30)
)
}
}

private var accent: Color {
Expand Down Expand Up @@ -640,15 +659,11 @@ private struct SidebarAddMenuButtonBody: View {
.foregroundStyle(hovering ? WeiBeiTheme.ink : WeiBeiTheme.secondaryInk)
.frame(width: 28, height: 28)
.background {
RoundedRectangle(cornerRadius: 8, style: .continuous)
.fill(WeiBeiTheme.paperInset.opacity(highlighted ? 0.42 : 0.18))
}
.overlay {
RoundedRectangle(cornerRadius: 8, style: .continuous)
.strokeBorder(
WeiBeiTheme.hairline.opacity(highlighted ? 0.62 : 0.42),
lineWidth: 1
)
WeiBeiEtchedBackdrop(
shape: RoundedRectangle(cornerRadius: 7, style: .continuous),
fill: WeiBeiTheme.paperInset.opacity(highlighted ? 0.42 : 0.18),
stroke: WeiBeiTheme.hairline.opacity(highlighted ? 0.62 : 0.42)
)
}
.scaleEffect(configuration.isPressed ? 0.95 : 1)
.animation(WeiBeiMotion.press, value: configuration.isPressed)
Expand Down Expand Up @@ -796,7 +811,7 @@ private struct LibraryRow: View {
.padding(.horizontal, compact ? 7 : 9)
.frame(height: compact ? 38 : (tags.isEmpty ? 48 : 58))
.frame(maxWidth: .infinity, alignment: .leading)
.background(rowBackground)
.background { rowBackdrop }
.offset(x: selected || hovering ? (compact ? 1 : 2) : 0)
.clipShape(RoundedRectangle(cornerRadius: compact ? 6 : 8, style: .continuous))
.overlay(alignment: .leading) {
Expand All @@ -812,10 +827,21 @@ private struct LibraryRow: View {
.animation(WeiBeiMotion.hover, value: hovering)
}

private var rowBackground: Color {
if selected { return WeiBeiTheme.paperInset.opacity(compact ? 0.54 : 0.70) }
if hovering { return WeiBeiTheme.paperInset.opacity(compact ? 0.22 : 0.30) }
return .clear
@ViewBuilder
private var rowBackdrop: some View {
if selected {
WeiBeiEtchedBackdrop(
shape: RoundedRectangle(cornerRadius: compact ? 6 : 8, style: .continuous),
fill: WeiBeiTheme.paperInset.opacity(compact ? 0.54 : 0.70),
stroke: WeiBeiTheme.hairline.opacity(0.40)
)
} else if hovering {
WeiBeiEtchedBackdrop(
shape: RoundedRectangle(cornerRadius: compact ? 6 : 8, style: .continuous),
fill: WeiBeiTheme.paperInset.opacity(compact ? 0.22 : 0.30),
stroke: WeiBeiTheme.hairline.opacity(0.30)
)
}
}

private var iconColor: Color {
Expand Down