From 1d9f642e5d7600d54ba27fb1dbb23582b314db31 Mon Sep 17 00:00:00 2001 From: taekchef Date: Sat, 22 Aug 2026 13:30:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=BB=E8=9A=80=E7=BA=B8=E9=9D=A2?= =?UTF-8?q?=E8=B4=A8=E6=84=9F=E6=8E=A8=E5=B9=BF=E5=88=B0=E5=85=A8=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=9B=BE=E6=A0=87=E6=8C=89=E9=92=AE=E4=B8=8E=E4=BE=A7?= =?UTF-8?q?=E8=BE=B9=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Theme 新增 WeiBeiEtchedBackdrop 纹理原语:任意形状上的 底色+顶部内反光+底部内阴影+发丝框(+可选贴地投影), 不可见时零渲染 - WeiBeiIconButtonStyle 中性态(悬停/激活/按压)全应用 21 处 调用统一走该原语;.primary 实心朱砂填充不受影响 - 侧边栏:搜索框换 weibeiInputSurface 同款刻蚀;加号按钮、 课程行悬停/展开、行尾进入小圆、分组头小加号、资料/笔记行 悬停/选中全部接入同一纹理语言 --- Sources/WeiBei/Support/Theme.swift | 84 +++++++++++++++++++++- Sources/WeiBei/Views/SidebarView.swift | 98 ++++++++++++++++---------- 2 files changed, 143 insertions(+), 39 deletions(-) diff --git a/Sources/WeiBei/Support/Theme.swift b/Sources/WeiBei/Support/Theme.swift index 1b7eab106..b44cfb98c 100644 --- a/Sources/WeiBei/Support/Theme.swift +++ b/Sources/WeiBei/Support/Theme.swift @@ -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: 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 — @@ -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) @@ -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 { diff --git a/Sources/WeiBei/Views/SidebarView.swift b/Sources/WeiBei/Views/SidebarView.swift index 2db766bda..7b5a13be9 100644 --- a/Sources/WeiBei/Views/SidebarView.swift +++ b/Sources/WeiBei/Views/SidebarView.swift @@ -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() { @@ -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) @@ -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)") @@ -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) @@ -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 } @@ -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 { @@ -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) @@ -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) { @@ -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 {