From 9a6d66c6781aff1e180a80a6651cbb801fd050be Mon Sep 17 00:00:00 2001 From: KrLite Date: Thu, 19 Dec 2024 20:00:11 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20SwiftFormat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scroll Views/AutoScrollView.swift | 2 +- .../Main Window/Sidebar/LuminareSidebar.swift | 6 +++--- .../Utilities/EnvironmentValues.swift | 18 ++++++++-------- .../Extensions/EdgeInsets+Extensions.swift | 3 +-- .../Extensions/View+Extensions.swift | 14 ++++++------- .../Utilities/LuminareManagerProtocol.swift | 21 +++++++++---------- 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Sources/Luminare/Components/Auxiliary/Scroll Views/AutoScrollView.swift b/Sources/Luminare/Components/Auxiliary/Scroll Views/AutoScrollView.swift index 02d6e26..1c393c1 100644 --- a/Sources/Luminare/Components/Auxiliary/Scroll Views/AutoScrollView.swift +++ b/Sources/Luminare/Components/Auxiliary/Scroll Views/AutoScrollView.swift @@ -69,7 +69,7 @@ public struct AutoScrollView: View where Content: View { } private var allowedAxes: Axis.Set { - if isHorizontalScrollingDisabled && isVerticalScrollingDisabled { + if isHorizontalScrollingDisabled, isVerticalScrollingDisabled { axes } else if isHorizontalScrollingDisabled { axes.intersection(.vertical) diff --git a/Sources/Luminare/Main Window/Sidebar/LuminareSidebar.swift b/Sources/Luminare/Main Window/Sidebar/LuminareSidebar.swift index 2ecc31b..d8e04d2 100644 --- a/Sources/Luminare/Main Window/Sidebar/LuminareSidebar.swift +++ b/Sources/Luminare/Main Window/Sidebar/LuminareSidebar.swift @@ -12,7 +12,7 @@ public struct LuminareSidebar: View where Content: View { @Environment(\.luminareContentMarginsTop) private var contentMarginsTop @Environment(\.luminareContentMarginsBottom) private var contentMarginsBottom @Environment(\.luminareSidebarOverflow) private var overflow - + @ViewBuilder private var content: () -> Content /// Initializes a ``LuminareSidebar``. @@ -46,9 +46,9 @@ public struct LuminareSidebar: View where Content: View { endPoint: .bottom ) .frame(height: overflow) - + Color.white - + LinearGradient( colors: [.clear, .white], startPoint: .top, diff --git a/Sources/Luminare/Utilities/EnvironmentValues.swift b/Sources/Luminare/Utilities/EnvironmentValues.swift index 7f66540..bf14a43 100644 --- a/Sources/Luminare/Utilities/EnvironmentValues.swift +++ b/Sources/Luminare/Utilities/EnvironmentValues.swift @@ -29,7 +29,7 @@ public extension EnvironmentValues { @Entry var luminareWindow: NSWindow? @Entry var luminareSidebarOverflow: CGFloat = 50 @Entry var luminareClickedOutside: Bool = false - + @Entry var luminareWindowMinWidth: CGFloat = 100 @Entry var luminareWindowMaxWidth: CGFloat = .infinity @Entry var luminareWindowMinHeight: CGFloat = 100 @@ -47,7 +47,7 @@ public extension EnvironmentValues { // MARK: Sheet @Entry var luminareSheetCornerRadii: RectangleCornerRadii = .init(12) - + @Entry var luminareSheetPresentation: LuminareSheetPresentation = .windowCenter @Entry var luminareSheetIsMovableByWindowBackground: Bool = false @Entry var luminareSheetClosesOnDefocus: Bool = false @@ -55,7 +55,7 @@ public extension EnvironmentValues { // MARK: Popup @Entry var luminarePopupCornerRadii: RectangleCornerRadii = .init(12) - + @Entry var luminarePopupPadding: CGFloat = 12 // MARK: Color Picker @@ -70,17 +70,17 @@ public extension EnvironmentValues { // MARK: General @Entry var luminareCornerRadii: RectangleCornerRadii = .init(12) - + @Entry var luminareMinHeight: CGFloat = 34 @Entry var luminareHorizontalPadding: CGFloat = 8 @Entry var luminareIsBordered: Bool = true @Entry var luminareHasBackground: Bool = true @Entry var luminareHasDividers: Bool = true - + @Entry var luminareAspectRatio: CGFloat? @Entry var luminareAspectRatioContentMode: ContentMode? = .fit @Entry var luminareAspectRatioHasFixedHeight: Bool = true - + @Entry var luminareContentMarginsTop: CGFloat = 0 @Entry var luminareContentMarginsLeading: CGFloat = 0 @Entry var luminareContentMarginsBottom: CGFloat = 0 @@ -90,7 +90,7 @@ public extension EnvironmentValues { @Entry var luminareButtonCornerRadii: RectangleCornerRadii = .init(2) @Entry var luminareCompactButtonCornerRadii: RectangleCornerRadii = .init(8) - + @Entry var luminareButtonMaterial: Material? = nil @Entry var luminareButtonHighlightOnHover: Bool = true @@ -136,11 +136,11 @@ public extension EnvironmentValues { // MARK: List @Entry var luminareListItemCornerRadii: RectangleCornerRadii = .init(2) - + @Entry var luminareListItemHeight: CGFloat = 50 @Entry var luminareListItemHighlightOnHover: Bool = true @Entry var luminareListFixedHeightUntil: CGFloat? = nil - + @Entry var luminareListRoundedTopCornerBehavior: LuminareListRoundedCornerBehavior = .never @Entry var luminareListRoundedBottomCornerBehavior: LuminareListRoundedCornerBehavior = .never diff --git a/Sources/Luminare/Utilities/Extensions/EdgeInsets+Extensions.swift b/Sources/Luminare/Utilities/Extensions/EdgeInsets+Extensions.swift index 0576e74..cbe3698 100644 --- a/Sources/Luminare/Utilities/Extensions/EdgeInsets+Extensions.swift +++ b/Sources/Luminare/Utilities/Extensions/EdgeInsets+Extensions.swift @@ -5,7 +5,6 @@ // Created by KrLite on 2024/12/19. // - import SwiftUI public extension EdgeInsets { @@ -19,7 +18,7 @@ public extension EdgeInsets { trailing: length ) } - + init(_ edges: Edge.Set, _ length: CGFloat) { self.init( top: edges.contains(.top) ? length : 0, diff --git a/Sources/Luminare/Utilities/Extensions/View+Extensions.swift b/Sources/Luminare/Utilities/Extensions/View+Extensions.swift index 51195cf..f934474 100644 --- a/Sources/Luminare/Utilities/Extensions/View+Extensions.swift +++ b/Sources/Luminare/Utilities/Extensions/View+Extensions.swift @@ -147,7 +147,7 @@ public extension View { if let maxHeight { view.environment(\.luminareWindowMaxHeight, maxHeight) } view } - + @ViewBuilder func luminareSizebarOverflow(_ overflow: CGFloat) -> some View { environment(\.luminareSidebarOverflow, overflow) } @@ -238,7 +238,7 @@ public extension View { @ViewBuilder func luminareHasDividers(_ hasDividers: Bool) -> some View { environment(\.luminareHasDividers, hasDividers) } - + @ViewBuilder func luminareAspectRatio(unapplying: Bool) -> some View { if unapplying { environment(\.luminareAspectRatioContentMode, nil) @@ -246,7 +246,7 @@ public extension View { self } } - + @ViewBuilder func luminareAspectRatio( _ aspectRatio: CGFloat? = nil, contentMode: ContentMode, hasFixedHeight: Bool? = nil ) -> some View { @@ -256,7 +256,7 @@ public extension View { if let hasFixedHeight { view.environment(\.luminareAspectRatioHasFixedHeight, hasFixedHeight) } view } - + @ViewBuilder func luminareAspectRatio( _ aspectRatio: CGSize, contentMode: ContentMode, hasFixedHeight: Bool? = nil ) -> some View { @@ -266,14 +266,14 @@ public extension View { hasFixedHeight: hasFixedHeight ) } - + @ViewBuilder func luminareContentMargins(_ insets: EdgeInsets) -> some View { environment(\.luminareContentMarginsTop, insets.top) .environment(\.luminareContentMarginsLeading, insets.leading) .environment(\.luminareContentMarginsBottom, insets.bottom) .environment(\.luminareContentMarginsTrailing, insets.trailing) } - + @ViewBuilder func luminareContentMargins(_ edges: Edge.Set, _ length: CGFloat) -> some View { let view = self if edges.contains(.top) { view.environment(\.luminareContentMarginsTop, length) } @@ -282,7 +282,7 @@ public extension View { if edges.contains(.trailing) { view.environment(\.luminareContentMarginsTrailing, length) } view } - + @ViewBuilder func luminareContentMargins(_ length: CGFloat) -> some View { luminareContentMargins(.all, length) } diff --git a/Sources/Luminare/Utilities/LuminareManagerProtocol.swift b/Sources/Luminare/Utilities/LuminareManagerProtocol.swift index 31268a6..4319e9d 100644 --- a/Sources/Luminare/Utilities/LuminareManagerProtocol.swift +++ b/Sources/Luminare/Utilities/LuminareManagerProtocol.swift @@ -5,17 +5,16 @@ // Created by KrLite on 2024/12/19. // - import SwiftUI public protocol LuminareManagerProtocol: View { var luminare: LuminareWindow? { get set } var isVisible: Bool { get } - + var blurRadius: CGFloat? { get } var minFrame: CGSize { get } var maxFrame: CGSize { get } - + mutating func show() mutating func close() mutating func toggle() @@ -29,24 +28,24 @@ public extension LuminareManagerProtocol { false } } - + var blurRadius: CGFloat? { nil } - + var minFrame: CGSize { .init(width: 100, height: 100) } - + var maxFrame: CGSize { .init(width: CGFloat.infinity, height: CGFloat.infinity) } } - + public extension LuminareManagerProtocol { mutating func show() { if luminare == nil { - let body = self.body + let body = body luminare = LuminareWindow( blurRadius: blurRadius, minFrame: minFrame, @@ -54,15 +53,15 @@ public extension LuminareManagerProtocol { ) { body } luminare?.center() } - + luminare?.show() } - + mutating func close() { luminare?.close() luminare = nil } - + mutating func toggle() { if isVisible { close()