This commit is contained in:
parent
7afe735433
commit
a6ce905e97
@ -133,7 +133,7 @@ file_header:
|
|||||||
missing_docs:
|
missing_docs:
|
||||||
warning: [internal, private]
|
warning: [internal, private]
|
||||||
error: [open, public]
|
error: [open, public]
|
||||||
excludes_extensions: false
|
excludes_extensions: true
|
||||||
excludes_inherited_types: false
|
excludes_inherited_types: false
|
||||||
type_contents_order:
|
type_contents_order:
|
||||||
order:
|
order:
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
// Created by david-swift on 11.10.24.
|
// 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 Foundation
|
||||||
|
import winui_swift
|
||||||
|
|
||||||
Demo.main()
|
Demo.main()
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ struct ContentView: View {
|
|||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
.keyboardShortcut(.init(key: .q))
|
.keyboardShortcut(.init(key: .q))
|
||||||
.icon(.systemIcon("\u{E7E8}"))
|
.icon(.systemIcon(unicode: "\u{E7E8}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -97,9 +97,9 @@ enum NavigationItem: String, CaseIterable, NavigationViewItem {
|
|||||||
case .search:
|
case .search:
|
||||||
"\u{E71E}"
|
"\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
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import WinUI
|
|
||||||
import WindowsFoundation
|
import WindowsFoundation
|
||||||
|
import WinUI
|
||||||
|
|
||||||
/// A collection of menus.
|
/// A collection of menus.
|
||||||
public struct MenuCollection: MenuWidget, Wrapper {
|
public struct MenuCollection: MenuWidget, Wrapper {
|
||||||
|
@ -10,6 +10,7 @@ import WinUI
|
|||||||
/// A button widget for menus.
|
/// A button widget for menus.
|
||||||
public struct Separator: MenuWidget {
|
public struct Separator: MenuWidget {
|
||||||
|
|
||||||
|
/// Initialize a separator menu item.
|
||||||
public init() { }
|
public init() { }
|
||||||
|
|
||||||
/// Initialize the widget.
|
/// Initialize the widget.
|
||||||
|
@ -67,4 +67,4 @@ extension [Edge] {
|
|||||||
return (margin[0], margin[1], margin[2], margin[3])
|
return (margin[0], margin[1], margin[2], margin[3])
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,4 +33,4 @@ public enum HorizontalAlignment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,9 @@ import WinUI
|
|||||||
public enum Icon: Equatable {
|
public enum Icon: Equatable {
|
||||||
|
|
||||||
/// An SVG icon.
|
/// An SVG icon.
|
||||||
case svg(URL)
|
case svg(url: URL)
|
||||||
/// A system icon.
|
/// A system icon.
|
||||||
case systemIcon(Character)
|
case systemIcon(unicode: Character)
|
||||||
|
|
||||||
/// The WinUI icon.
|
/// The WinUI icon.
|
||||||
var winIcon: IconElement {
|
var winIcon: IconElement {
|
||||||
@ -30,5 +30,4 @@ public enum Icon: Equatable {
|
|||||||
return icon
|
return icon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -46,4 +46,4 @@ public struct KeyboardShortcut: Equatable {
|
|||||||
self.menu = menu
|
self.menu = menu
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,4 +33,4 @@ public enum VerticalAlignment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
// Created by david-swift on 31.07.2024.
|
// Created by david-swift on 31.07.2024.
|
||||||
//
|
//
|
||||||
|
|
||||||
import WinUI
|
|
||||||
@_exported import Meta
|
@_exported import Meta
|
||||||
|
import WinUI
|
||||||
|
|
||||||
/// The app storage for the WinUI backend.
|
/// The app storage for the WinUI backend.
|
||||||
public class WinUIApp: AppStorage {
|
public class WinUIApp: AppStorage {
|
||||||
@ -53,4 +53,4 @@ class BackendApp: SwiftApplication {
|
|||||||
Self.run()
|
Self.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,12 @@ public struct Button: WinUIWidget {
|
|||||||
label.updateStorage(content, data: data, updateProperties: updateProperties, type: type)
|
label.updateStorage(content, data: data, updateProperties: updateProperties, type: type)
|
||||||
}
|
}
|
||||||
if let menu, let content = storage.content["menu"]?.first {
|
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
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,27 @@ public struct EitherView: WinUIWidget, Meta.EitherView {
|
|||||||
/// The second view.
|
/// The second view.
|
||||||
var view2: Body
|
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.
|
/// The view storage.
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - data: The widget data.
|
/// - data: The widget data.
|
||||||
/// - type: The view render data type.
|
/// - type: The view render data type.
|
||||||
/// - Returns: The view storage.
|
/// - 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 view = WinUI.Grid()
|
||||||
let storage = ViewStorage(view)
|
let storage = ViewStorage(view)
|
||||||
update(storage, data: data, updateProperties: true, type: type)
|
update(storage, data: data, updateProperties: true, type: type)
|
||||||
@ -35,14 +50,21 @@ public struct EitherView: WinUIWidget, Meta.EitherView {
|
|||||||
/// - data: The widget data.
|
/// - data: The widget data.
|
||||||
/// - updateProperties: Whether to update the view's properties.
|
/// - updateProperties: Whether to update the view's properties.
|
||||||
/// - type: The view render data type.
|
/// - 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 {
|
if let content1 = storage.content["view1"]?.first {
|
||||||
view1.updateStorage(content1, data: data, updateProperties: updateProperties, type: type)
|
view1.updateStorage(content1, data: data, updateProperties: updateProperties, type: type)
|
||||||
}
|
}
|
||||||
if let content2 = storage.content["view2"]?.first {
|
if let content2 = storage.content["view2"]?.first {
|
||||||
view2.updateStorage(content2, data: data, updateProperties: updateProperties, type: type)
|
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
|
return
|
||||||
}
|
}
|
||||||
if condition, let content = storage.content["view1"]?.first {
|
if condition, let content = storage.content["view1"]?.first {
|
||||||
@ -66,19 +88,4 @@ public struct EitherView: WinUIWidget, Meta.EitherView {
|
|||||||
storage.previousState = self
|
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()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,10 @@ public struct Grid: WinUIWidget {
|
|||||||
var content: Body
|
var content: Body
|
||||||
/// The grid's columns.
|
/// The grid's columns.
|
||||||
var columns: [Column]?
|
var columns: [Column]?
|
||||||
|
// swiftlint:disable large_tuple
|
||||||
/// The padding.
|
/// The padding.
|
||||||
var padding: (Double, Double, Double, Double)?
|
var padding: (Double, Double, Double, Double)?
|
||||||
|
// swiftlint:enable large_tuple
|
||||||
/// Whether to set the grid as the title bar (only for internal use).
|
/// Whether to set the grid as the title bar (only for internal use).
|
||||||
var title = false
|
var title = false
|
||||||
|
|
||||||
|
@ -16,8 +16,10 @@ struct ModifierWrapper: WinUIWidget {
|
|||||||
var width: Double?
|
var width: Double?
|
||||||
/// The view's height.
|
/// The view's height.
|
||||||
var height: Double?
|
var height: Double?
|
||||||
|
// swiftlint:disable large_tuple
|
||||||
/// The view's margin.
|
/// The view's margin.
|
||||||
var margin: (Double, Double, Double, Double)?
|
var margin: (Double, Double, Double, Double)?
|
||||||
|
// swiftlint:enable large_tuple
|
||||||
/// The horizontal alignment.
|
/// The horizontal alignment.
|
||||||
var horizontalAlignment: HorizontalAlignment?
|
var horizontalAlignment: HorizontalAlignment?
|
||||||
/// The vertical alignment.
|
/// The vertical alignment.
|
||||||
@ -30,7 +32,7 @@ struct ModifierWrapper: WinUIWidget {
|
|||||||
/// - data: The widget data.
|
/// - data: The widget data.
|
||||||
/// - type: The view render data type.
|
/// - type: The view render data type.
|
||||||
/// - Returns: The view storage.
|
/// - 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)
|
let storage = view.storage(data: data, type: type)
|
||||||
update(storage, data: data, updateProperties: true, type: type)
|
update(storage, data: data, updateProperties: true, type: type)
|
||||||
return storage
|
return storage
|
||||||
@ -42,7 +44,12 @@ struct ModifierWrapper: WinUIWidget {
|
|||||||
/// - data: The widget data.
|
/// - data: The widget data.
|
||||||
/// - updateProperties: Whether to update the view's properties.
|
/// - updateProperties: Whether to update the view's properties.
|
||||||
/// - type: The view render data type.
|
/// - 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)
|
view.updateStorage(storage, data: data, updateProperties: updateProperties, type: type)
|
||||||
guard updateProperties, let view = storage.pointer as? WinUI.FrameworkElement else {
|
guard updateProperties, let view = storage.pointer as? WinUI.FrameworkElement else {
|
||||||
return
|
return
|
||||||
@ -117,4 +124,4 @@ extension AnyView {
|
|||||||
ModifierWrapper(view: self, gridColumn: column)
|
ModifierWrapper(view: self, gridColumn: column)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public struct NavigationView<Item>: WinUIWidget where Item: NavigationViewItem {
|
|||||||
self.items = items
|
self.items = items
|
||||||
self.content = content()
|
self.content = content()
|
||||||
self._selectedItem = .init {
|
self._selectedItem = .init {
|
||||||
.custom(selection.wrappedValue)
|
.custom(item: selection.wrappedValue)
|
||||||
} set: { newValue in
|
} set: { newValue in
|
||||||
if case let .custom(value) = newValue {
|
if case let .custom(value) = newValue {
|
||||||
selection.wrappedValue = value
|
selection.wrappedValue = value
|
||||||
@ -56,7 +56,7 @@ public struct NavigationView<Item>: WinUIWidget where Item: NavigationViewItem {
|
|||||||
/// The settings item.
|
/// The settings item.
|
||||||
case settings
|
case settings
|
||||||
/// A custom item.
|
/// 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
|
navigationView.selectionChanged.addHandler { _, args in
|
||||||
let name = (args?.selectedItem as? WinUI.NavigationViewItem)?.name ?? items.first?.description ?? ""
|
let name = (args?.selectedItem as? WinUI.NavigationViewItem)?.name ?? items.first?.description ?? ""
|
||||||
if let item = items.first(where: { $0.description == name }) {
|
if let item = items.first(where: { $0.description == name }) {
|
||||||
if selectedItem != .custom(item) {
|
if selectedItem != .custom(item: item) {
|
||||||
selectedItem = .custom(item)
|
selectedItem = .custom(item: item)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
selectedItem = .settings
|
selectedItem = .settings
|
||||||
@ -128,7 +128,8 @@ public struct NavigationView<Item>: WinUIWidget where Item: NavigationViewItem {
|
|||||||
if case .settings = selectedItem {
|
if case .settings = selectedItem {
|
||||||
navigationView.isSettingsVisible = true
|
navigationView.isSettingsVisible = true
|
||||||
} else if case let .custom(name) = selectedItem {
|
} 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
|
storage.previousState = self
|
||||||
}
|
}
|
||||||
@ -141,6 +142,7 @@ public typealias NavigationSelection<Item> = NavigationView<Item>.Selection wher
|
|||||||
/// A navigation view item.
|
/// A navigation view item.
|
||||||
public protocol NavigationViewItem: CustomStringConvertible, Equatable {
|
public protocol NavigationViewItem: CustomStringConvertible, Equatable {
|
||||||
|
|
||||||
|
/// The navigation view item's icon.
|
||||||
var icon: Icon { get }
|
var icon: Icon { get }
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -157,4 +159,4 @@ extension NavigationViewItem {
|
|||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -95,4 +95,4 @@ public struct Text: WinUIWidget {
|
|||||||
modify { $0.textStyle = style }
|
modify { $0.textStyle = style }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -74,9 +74,10 @@ public struct Window: WinUISceneElement {
|
|||||||
let scene = SceneStorage(id: id, pointer: window) {
|
let scene = SceneStorage(id: id, pointer: window) {
|
||||||
try? window.activate()
|
try? window.activate()
|
||||||
}
|
}
|
||||||
let storage = fullContent(window: window).storage(data: .init(sceneStorage: scene, appStorage: app), type: WinUIMainView.self)
|
let storage = fullContent(window: window)
|
||||||
if let ui = storage.pointer as? UIElement {
|
.storage(data: .init(sceneStorage: scene, appStorage: app), type: WinUIMainView.self)
|
||||||
window.content = ui
|
if let content = storage.pointer as? UIElement {
|
||||||
|
window.content = content
|
||||||
}
|
}
|
||||||
scene.content[.mainContent] = [storage]
|
scene.content[.mainContent] = [storage]
|
||||||
window.systemBackdrop = MicaBackdrop()
|
window.systemBackdrop = MicaBackdrop()
|
||||||
@ -98,7 +99,12 @@ public struct Window: WinUISceneElement {
|
|||||||
let contentStorage = storage.content[.mainContent]?.first else {
|
let contentStorage = storage.content[.mainContent]?.first else {
|
||||||
return
|
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 {
|
guard updateProperties else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user