Fix style violations
Some checks failed
SwiftLint / SwiftLint (push) Failing after 5s

This commit is contained in:
david-swift 2024-10-13 21:30:10 +02:00
parent 7afe735433
commit a6ce905e97
17 changed files with 79 additions and 50 deletions

View File

@ -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:

View File

@ -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

View File

@ -6,8 +6,8 @@
//
import Foundation
import WinUI
import WindowsFoundation
import WinUI
/// A collection of menus.
public struct MenuCollection: MenuWidget, Wrapper {

View File

@ -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.

View File

@ -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
}
}
}

View File

@ -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 {

View File

@ -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
)
}
}

View File

@ -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>(data: WidgetData, type: Data.Type) -> ViewStorage where Data : ViewRenderData {
public func container<Data>(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<Data>(_ storage: ViewStorage, data: WidgetData, updateProperties: Bool, type: Data.Type) where Data : ViewRenderData {
public func update<Data>(
_ 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()
}
}

View File

@ -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

View File

@ -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>(data: WidgetData, type: Data.Type) -> ViewStorage where Data : ViewRenderData {
func container<Data>(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<Data>(_ storage: ViewStorage, data: WidgetData, updateProperties: Bool, type: Data.Type) where Data : ViewRenderData {
func update<Data>(
_ 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

View File

@ -30,7 +30,7 @@ public struct NavigationView<Item>: 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<Item>: 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<Item>: 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<Item>: 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<Item> = NavigationView<Item>.Selection wher
/// A navigation view item.
public protocol NavigationViewItem: CustomStringConvertible, Equatable {
/// The navigation view item's icon.
var icon: Icon { get }
}

View File

@ -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
}