From a6ce905e972cc7eaf76c652b2b008db8634a3dd3 Mon Sep 17 00:00:00 2001 From: david-swift Date: Sun, 13 Oct 2024 21:30:10 +0200 Subject: [PATCH] Fix style violations --- .swiftlint.yml | 2 +- Sources/Demo/Demo.swift | 10 ++--- Sources/winui-swift/Menu/MenuCollection.swift | 2 +- Sources/winui-swift/Menu/Separator.swift | 1 + .../winui-swift/Model/Enumerations/Edge.swift | 2 +- .../Enumerations/HorizontalAlignment.swift | 2 +- .../winui-swift/Model/Enumerations/Icon.swift | 7 ++- .../Model/Enumerations/KeyboardShortcut.swift | 2 +- .../Enumerations/VerticalAlignment.swift | 2 +- Sources/winui-swift/Model/WinUIApp.swift | 4 +- Sources/winui-swift/View/Button.swift | 7 ++- Sources/winui-swift/View/EitherView.swift | 43 +++++++++++-------- Sources/winui-swift/View/Grid.swift | 2 + .../winui-swift/View/ModifierWrapper.swift | 13 ++++-- Sources/winui-swift/View/NavigationView.swift | 14 +++--- Sources/winui-swift/View/Text.swift | 2 +- Sources/winui-swift/Window/Window.swift | 14 ++++-- 17 files changed, 79 insertions(+), 50 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 382b456..b492aed 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -133,7 +133,7 @@ file_header: missing_docs: warning: [internal, private] error: [open, public] - excludes_extensions: false + excludes_extensions: true excludes_inherited_types: false type_contents_order: order: diff --git a/Sources/Demo/Demo.swift b/Sources/Demo/Demo.swift index 468c291..4b85a6d 100644 --- a/Sources/Demo/Demo.swift +++ b/Sources/Demo/Demo.swift @@ -5,10 +5,10 @@ // Created by david-swift on 11.10.24. // -// swiftlint:disable missing_docs implicitly_unwrapped_optional no_magic_numbers +// swiftlint:disable missing_docs no_magic_numbers -import winui_swift import Foundation +import winui_swift Demo.main() @@ -73,7 +73,7 @@ struct ContentView: View { app.quit() } .keyboardShortcut(.init(key: .q)) - .icon(.systemIcon("\u{E7E8}")) + .icon(.systemIcon(unicode: "\u{E7E8}")) } } @@ -97,9 +97,9 @@ enum NavigationItem: String, CaseIterable, NavigationViewItem { case .search: "\u{E71E}" } - return .systemIcon(character) + return .systemIcon(unicode: character) } } -// swiftlint:enable missing_docs implicitly_unwrapped_optional no_magic_numbers +// swiftlint:enable missing_docs no_magic_numbers diff --git a/Sources/winui-swift/Menu/MenuCollection.swift b/Sources/winui-swift/Menu/MenuCollection.swift index d827369..0d4fb19 100644 --- a/Sources/winui-swift/Menu/MenuCollection.swift +++ b/Sources/winui-swift/Menu/MenuCollection.swift @@ -6,8 +6,8 @@ // import Foundation -import WinUI import WindowsFoundation +import WinUI /// A collection of menus. public struct MenuCollection: MenuWidget, Wrapper { diff --git a/Sources/winui-swift/Menu/Separator.swift b/Sources/winui-swift/Menu/Separator.swift index 0e31d3d..006316e 100644 --- a/Sources/winui-swift/Menu/Separator.swift +++ b/Sources/winui-swift/Menu/Separator.swift @@ -10,6 +10,7 @@ import WinUI /// A button widget for menus. public struct Separator: MenuWidget { + /// Initialize a separator menu item. public init() { } /// Initialize the widget. diff --git a/Sources/winui-swift/Model/Enumerations/Edge.swift b/Sources/winui-swift/Model/Enumerations/Edge.swift index b68d386..106f3c8 100644 --- a/Sources/winui-swift/Model/Enumerations/Edge.swift +++ b/Sources/winui-swift/Model/Enumerations/Edge.swift @@ -67,4 +67,4 @@ extension [Edge] { return (margin[0], margin[1], margin[2], margin[3]) } -} \ No newline at end of file +} diff --git a/Sources/winui-swift/Model/Enumerations/HorizontalAlignment.swift b/Sources/winui-swift/Model/Enumerations/HorizontalAlignment.swift index 9f61350..0f9f89e 100644 --- a/Sources/winui-swift/Model/Enumerations/HorizontalAlignment.swift +++ b/Sources/winui-swift/Model/Enumerations/HorizontalAlignment.swift @@ -33,4 +33,4 @@ public enum HorizontalAlignment { } } -} \ No newline at end of file +} diff --git a/Sources/winui-swift/Model/Enumerations/Icon.swift b/Sources/winui-swift/Model/Enumerations/Icon.swift index 40c540f..730fa15 100644 --- a/Sources/winui-swift/Model/Enumerations/Icon.swift +++ b/Sources/winui-swift/Model/Enumerations/Icon.swift @@ -12,9 +12,9 @@ import WinUI public enum Icon: Equatable { /// An SVG icon. - case svg(URL) + case svg(url: URL) /// A system icon. - case systemIcon(Character) + case systemIcon(unicode: Character) /// The WinUI icon. var winIcon: IconElement { @@ -30,5 +30,4 @@ public enum Icon: Equatable { return icon } } - -} \ No newline at end of file +} diff --git a/Sources/winui-swift/Model/Enumerations/KeyboardShortcut.swift b/Sources/winui-swift/Model/Enumerations/KeyboardShortcut.swift index 2a95664..bb5009b 100644 --- a/Sources/winui-swift/Model/Enumerations/KeyboardShortcut.swift +++ b/Sources/winui-swift/Model/Enumerations/KeyboardShortcut.swift @@ -46,4 +46,4 @@ public struct KeyboardShortcut: Equatable { self.menu = menu } -} \ No newline at end of file +} diff --git a/Sources/winui-swift/Model/Enumerations/VerticalAlignment.swift b/Sources/winui-swift/Model/Enumerations/VerticalAlignment.swift index 4882131..1a64d3e 100644 --- a/Sources/winui-swift/Model/Enumerations/VerticalAlignment.swift +++ b/Sources/winui-swift/Model/Enumerations/VerticalAlignment.swift @@ -33,4 +33,4 @@ public enum VerticalAlignment { } } -} \ No newline at end of file +} diff --git a/Sources/winui-swift/Model/WinUIApp.swift b/Sources/winui-swift/Model/WinUIApp.swift index 5329c4b..1375473 100644 --- a/Sources/winui-swift/Model/WinUIApp.swift +++ b/Sources/winui-swift/Model/WinUIApp.swift @@ -5,8 +5,8 @@ // Created by david-swift on 31.07.2024. // -import WinUI @_exported import Meta +import WinUI /// The app storage for the WinUI backend. public class WinUIApp: AppStorage { @@ -53,4 +53,4 @@ class BackendApp: SwiftApplication { Self.run() } -} \ No newline at end of file +} diff --git a/Sources/winui-swift/View/Button.swift b/Sources/winui-swift/View/Button.swift index 2479e1c..cc50c40 100644 --- a/Sources/winui-swift/View/Button.swift +++ b/Sources/winui-swift/View/Button.swift @@ -103,7 +103,12 @@ public struct Button: WinUIWidget { label.updateStorage(content, data: data, updateProperties: updateProperties, type: type) } if let menu, let content = storage.content["menu"]?.first { - MenuCollection { menu }.updateStorage(content, data: data.noModifiers, updateProperties: updateProperties, type: MenuContext.self) + MenuCollection { menu }.updateStorage( + content, + data: data.noModifiers, + updateProperties: updateProperties, + type: MenuContext.self + ) } } diff --git a/Sources/winui-swift/View/EitherView.swift b/Sources/winui-swift/View/EitherView.swift index bc7f449..f505a42 100644 --- a/Sources/winui-swift/View/EitherView.swift +++ b/Sources/winui-swift/View/EitherView.swift @@ -17,12 +17,27 @@ public struct EitherView: WinUIWidget, Meta.EitherView { /// The second view. var view2: Body + /// Initialize the either view. + /// - Parameters: + /// - condition: Whether the first view is visible- + /// - view1: The first view, visible if true. + /// - view2: The second view, visible if false. + public init( + _ condition: Bool, + @ViewBuilder view1: () -> Body, + @ViewBuilder else view2: () -> Body + ) { + self.condition = condition + self.view1 = view1() + self.view2 = view2() + } + /// The view storage. /// - Parameters: /// - data: The widget data. /// - type: The view render data type. /// - Returns: The view storage. - public func container(data: WidgetData, type: Data.Type) -> ViewStorage where Data : ViewRenderData { + public func container(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData { let view = WinUI.Grid() let storage = ViewStorage(view) update(storage, data: data, updateProperties: true, type: type) @@ -35,14 +50,21 @@ public struct EitherView: WinUIWidget, Meta.EitherView { /// - data: The widget data. /// - updateProperties: Whether to update the view's properties. /// - type: The view render data type. - public func update(_ storage: ViewStorage, data: WidgetData, updateProperties: Bool, type: Data.Type) where Data : ViewRenderData { + public func update( + _ storage: ViewStorage, + data: WidgetData, + updateProperties: Bool, + type: Data.Type + ) where Data: ViewRenderData { if let content1 = storage.content["view1"]?.first { view1.updateStorage(content1, data: data, updateProperties: updateProperties, type: type) } if let content2 = storage.content["view2"]?.first { view2.updateStorage(content2, data: data, updateProperties: updateProperties, type: type) } - guard updateProperties, (storage.previousState as? Self)?.condition != condition, let grid = storage.pointer as? WinUI.Grid else { + guard updateProperties, + (storage.previousState as? Self)?.condition != condition, + let grid = storage.pointer as? WinUI.Grid else { return } if condition, let content = storage.content["view1"]?.first { @@ -66,19 +88,4 @@ public struct EitherView: WinUIWidget, Meta.EitherView { storage.previousState = self } - /// Initialize the either view. - /// - Parameters: - /// - condition: Whether the first view is visible- - /// - view1: The first view, visible if true. - /// - view2: The second view, visible if false. - public init( - _ condition: Bool, - @ViewBuilder view1: () -> Body, - @ViewBuilder else view2: () -> Body - ) { - self.condition = condition - self.view1 = view1() - self.view2 = view2() - } - } diff --git a/Sources/winui-swift/View/Grid.swift b/Sources/winui-swift/View/Grid.swift index 58e53dd..04856c3 100644 --- a/Sources/winui-swift/View/Grid.swift +++ b/Sources/winui-swift/View/Grid.swift @@ -15,8 +15,10 @@ public struct Grid: WinUIWidget { var content: Body /// The grid's columns. var columns: [Column]? + // swiftlint:disable large_tuple /// The padding. var padding: (Double, Double, Double, Double)? + // swiftlint:enable large_tuple /// Whether to set the grid as the title bar (only for internal use). var title = false diff --git a/Sources/winui-swift/View/ModifierWrapper.swift b/Sources/winui-swift/View/ModifierWrapper.swift index 0aef195..1f47c6d 100644 --- a/Sources/winui-swift/View/ModifierWrapper.swift +++ b/Sources/winui-swift/View/ModifierWrapper.swift @@ -16,8 +16,10 @@ struct ModifierWrapper: WinUIWidget { var width: Double? /// The view's height. var height: Double? + // swiftlint:disable large_tuple /// The view's margin. var margin: (Double, Double, Double, Double)? + // swiftlint:enable large_tuple /// The horizontal alignment. var horizontalAlignment: HorizontalAlignment? /// The vertical alignment. @@ -30,7 +32,7 @@ struct ModifierWrapper: WinUIWidget { /// - data: The widget data. /// - type: The view render data type. /// - Returns: The view storage. - func container(data: WidgetData, type: Data.Type) -> ViewStorage where Data : ViewRenderData { + func container(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData { let storage = view.storage(data: data, type: type) update(storage, data: data, updateProperties: true, type: type) return storage @@ -42,7 +44,12 @@ struct ModifierWrapper: WinUIWidget { /// - data: The widget data. /// - updateProperties: Whether to update the view's properties. /// - type: The view render data type. - func update(_ storage: ViewStorage, data: WidgetData, updateProperties: Bool, type: Data.Type) where Data : ViewRenderData { + func update( + _ storage: ViewStorage, + data: WidgetData, + updateProperties: Bool, + type: Data.Type + ) where Data: ViewRenderData { view.updateStorage(storage, data: data, updateProperties: updateProperties, type: type) guard updateProperties, let view = storage.pointer as? WinUI.FrameworkElement else { return @@ -117,4 +124,4 @@ extension AnyView { ModifierWrapper(view: self, gridColumn: column) } -} \ No newline at end of file +} diff --git a/Sources/winui-swift/View/NavigationView.swift b/Sources/winui-swift/View/NavigationView.swift index f75d0c3..251cce0 100644 --- a/Sources/winui-swift/View/NavigationView.swift +++ b/Sources/winui-swift/View/NavigationView.swift @@ -30,7 +30,7 @@ public struct NavigationView: WinUIWidget where Item: NavigationViewItem { self.items = items self.content = content() self._selectedItem = .init { - .custom(selection.wrappedValue) + .custom(item: selection.wrappedValue) } set: { newValue in if case let .custom(value) = newValue { selection.wrappedValue = value @@ -56,7 +56,7 @@ public struct NavigationView: WinUIWidget where Item: NavigationViewItem { /// The settings item. case settings /// A custom item. - case custom(Item) + case custom(item: Item) } @@ -107,8 +107,8 @@ public struct NavigationView: WinUIWidget where Item: NavigationViewItem { navigationView.selectionChanged.addHandler { _, args in let name = (args?.selectedItem as? WinUI.NavigationViewItem)?.name ?? items.first?.description ?? "" if let item = items.first(where: { $0.description == name }) { - if selectedItem != .custom(item) { - selectedItem = .custom(item) + if selectedItem != .custom(item: item) { + selectedItem = .custom(item: item) } } else { selectedItem = .settings @@ -128,7 +128,8 @@ public struct NavigationView: WinUIWidget where Item: NavigationViewItem { if case .settings = selectedItem { navigationView.isSettingsVisible = true } else if case let .custom(name) = selectedItem { - navigationView.selectedItem = navigationView.menuItems.first { ($0 as? WinUI.NavigationViewItem)?.name as? String == name.description } ?? nil + navigationView.selectedItem = navigationView.menuItems + .first { ($0 as? WinUI.NavigationViewItem)?.name as? String == name.description } } storage.previousState = self } @@ -141,6 +142,7 @@ public typealias NavigationSelection = NavigationView.Selection wher /// A navigation view item. public protocol NavigationViewItem: CustomStringConvertible, Equatable { + /// The navigation view item's icon. var icon: Icon { get } } @@ -157,4 +159,4 @@ extension NavigationViewItem { return item } -} \ No newline at end of file +} diff --git a/Sources/winui-swift/View/Text.swift b/Sources/winui-swift/View/Text.swift index 4382ef4..7c268b2 100644 --- a/Sources/winui-swift/View/Text.swift +++ b/Sources/winui-swift/View/Text.swift @@ -95,4 +95,4 @@ public struct Text: WinUIWidget { modify { $0.textStyle = style } } -} \ No newline at end of file +} diff --git a/Sources/winui-swift/Window/Window.swift b/Sources/winui-swift/Window/Window.swift index 6e6c1e4..5acdd6c 100644 --- a/Sources/winui-swift/Window/Window.swift +++ b/Sources/winui-swift/Window/Window.swift @@ -74,9 +74,10 @@ public struct Window: WinUISceneElement { let scene = SceneStorage(id: id, pointer: window) { try? window.activate() } - let storage = fullContent(window: window).storage(data: .init(sceneStorage: scene, appStorage: app), type: WinUIMainView.self) - if let ui = storage.pointer as? UIElement { - window.content = ui + let storage = fullContent(window: window) + .storage(data: .init(sceneStorage: scene, appStorage: app), type: WinUIMainView.self) + if let content = storage.pointer as? UIElement { + window.content = content } scene.content[.mainContent] = [storage] window.systemBackdrop = MicaBackdrop() @@ -98,7 +99,12 @@ public struct Window: WinUISceneElement { let contentStorage = storage.content[.mainContent]?.first else { return } - fullContent(window: window).updateStorage(contentStorage, data: .init(sceneStorage: storage, appStorage: app), updateProperties: updateProperties, type: WinUIMainView.self) + fullContent(window: window).updateStorage( + contentStorage, + data: .init(sceneStorage: storage, appStorage: app), + updateProperties: updateProperties, + type: WinUIMainView.self + ) guard updateProperties else { return }