mirror of
https://github.com/insidegui/VirtualBuddy.git
synced 2026-12-02 00:29:56 +08:00
* Raise deployment target to macOS 14, bump version * Integrate Liquid Glass compatibility components * Fix onChange(of:) deprecation warnings * Update project settings * Improve styling of setup and configuration UI components * Fix fatal error in VMSavedStatesController.preview * Tweak session UI * Do not use prominent button style in VM configuration sheet so it matches overall setup wizard style * Fix incorrectly sized buttons in grouped lists
114 lines
3.0 KiB
Swift
114 lines
3.0 KiB
Swift
import SwiftUI
|
|
|
|
public enum ControlGroupLevel: Int {
|
|
case primary
|
|
case secondary
|
|
}
|
|
|
|
public struct ControlGroupMetrics {
|
|
static let primaryGroupRadius: Double = 14
|
|
static let secondaryGroupRadius: Double = 8
|
|
}
|
|
|
|
public extension ControlGroupLevel {
|
|
var cornerRadius: Double {
|
|
switch self {
|
|
case .primary: ControlGroupMetrics.primaryGroupRadius
|
|
case .secondary: ControlGroupMetrics.secondaryGroupRadius
|
|
}
|
|
}
|
|
}
|
|
|
|
public extension View {
|
|
func controlGroup(level: ControlGroupLevel = .primary) -> some View {
|
|
modifier(ControlGroupChrome(level: level, shapeBuilder: {
|
|
RoundedRectangle(cornerRadius: level.cornerRadius, style: .continuous)
|
|
}))
|
|
}
|
|
|
|
func controlGroup<S>(_ shape: S, level: ControlGroupLevel = .primary) -> some View where S: InsettableShape {
|
|
modifier(ControlGroupChrome<S>(level: level, shapeBuilder: { shape }))
|
|
}
|
|
}
|
|
|
|
private struct ControlGroupChrome<Shape: InsettableShape>: ViewModifier {
|
|
@Environment(\.colorScheme)
|
|
private var colorScheme
|
|
|
|
var level: ControlGroupLevel
|
|
var shapeBuilder: () -> Shape
|
|
|
|
var dark: Bool { colorScheme == .dark }
|
|
|
|
private var innerRimOpacity: Double {
|
|
switch level {
|
|
case .primary:
|
|
return dark ? 0.15 : 0
|
|
case .secondary:
|
|
return dark ? 0.1 : 0
|
|
}
|
|
}
|
|
|
|
private var outerRimOpacity: Double {
|
|
switch level {
|
|
case .primary:
|
|
return dark ? 0.5 : 0.8
|
|
case .secondary:
|
|
return dark ? 0.4 : 0.7
|
|
}
|
|
}
|
|
|
|
private var shadowOpacity: Double {
|
|
switch level {
|
|
case .primary:
|
|
return dark ? 0.2 : 0.1
|
|
case .secondary:
|
|
return dark ? 0.1 : 0.05
|
|
}
|
|
}
|
|
|
|
private var material: Material {
|
|
switch level {
|
|
case .primary:
|
|
return .thin
|
|
case .secondary:
|
|
return .regular
|
|
}
|
|
}
|
|
|
|
func body(content: Content) -> some View {
|
|
content
|
|
.background(material, in: shape)
|
|
.clipShape(shape)
|
|
.shadow(color: Color.black.opacity(outerRimOpacity), radius: 1, x: 0, y: 0)
|
|
.shadow(color: Color.black.opacity(shadowOpacity), radius: dark ? 8 : 10, x: 0, y: 0)
|
|
.chromeBorder(shape: shape, highlightEnabled: true, rimEnabled: false, shadowEnabled: false, highlightIntensity: innerRimOpacity)
|
|
.unfocusOnTap()
|
|
.containerShape(shape)
|
|
}
|
|
|
|
private var shape: Shape {
|
|
shapeBuilder()
|
|
}
|
|
}
|
|
|
|
#if DEBUG
|
|
struct ControlGroupChrome_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
VStack {
|
|
Text("Primary Group")
|
|
|
|
VStack {
|
|
Text("Secondary Group")
|
|
}
|
|
.padding()
|
|
.controlGroup(level: .secondary)
|
|
}
|
|
.padding(30)
|
|
.controlGroup()
|
|
.padding(50)
|
|
.background(BlurHashFullBleedBackground(blurHash: .virtualBuddyBackground))
|
|
}
|
|
}
|
|
#endif
|