forked from AparokshaUI/adwaita-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo.swift
182 lines (164 loc) · 6.03 KB
/
Demo.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//
// Demo.swift
// Adwaita
//
// Created by david-swift on 25.09.23.
//
// swiftlint:disable missing_docs implicitly_unwrapped_optional no_magic_numbers
import Adwaita
import Foundation
@main
struct Demo: App {
let id = "io.github.AparokshaUI.Demo"
var app: GTUIApp!
@State private var pictureURL: URL?
var scene: Scene {
Window(id: "main") { window in
DemoContent(window: window, app: app, pictureURL: pictureURL)
}
.devel()
HelperWindows()
FileDialog(importer: "picture", extensions: ["jpg", "jpeg", "png", "svg"]) { pictureURL = $0 } onClose: { }
}
struct HelperWindows: WindowSceneGroup {
var scene: Scene {
Window(id: "content", open: 0) { _ in
WindowsDemo.WindowContent()
}
.resizable(false)
.closeShortcut()
.defaultSize(width: 400, height: 250)
Window(id: "toolbar-demo", open: 0) { _ in
ToolbarDemo.WindowContent().stopModifiers()
}
.closeShortcut()
.defaultSize(width: 400, height: 250)
.title("Toolbar Demo")
Window(id: "switcher-demo", open: 0) { _ in
ViewSwitcherDemo.WindowContent()
}
.closeShortcut()
.defaultSize(width: 600, height: 400)
.resizable(false)
.title("View Switcher Demo")
Window(id: "form-demo", open: 0) { _ in
FormDemo.WindowContent()
}
.closeShortcut()
.defaultSize(width: 400, height: 250)
.title("Form Demo")
Window(id: "password-checker-demo", open: 0) { _ in
PasswordCheckerDemo.WindowContent()
}
.closeShortcut()
.defaultSize(width: 400, height: 250)
.title("Password Checker Demo")
Window(id: "navigation", open: 0) { _ in
NavigationViewDemo.WindowContent()
}
.closeShortcut()
.title("Navigation View Demo")
}
}
struct DemoContent: WindowView {
@State("selection")
private var selection: Page = .welcome
@State private var toast: Signal = .init()
@State("sidebar-visible")
private var sidebarVisible = true
@State("width")
private var width = 650
@State("height")
private var height = 450
@State("maximized")
private var maximized = false
@State private var about = false
var window: GTUIApplicationWindow
var app: GTUIApp!
var pictureURL: URL?
var view: Body {
OverlaySplitView(visible: $sidebarVisible) {
ScrollView {
List(Page.allCases, selection: $selection) { element in
Text(element.label)
.halign(.start)
.padding()
}
.sidebarStyle()
}
.topToolbar {
HeaderBar.end {
menu
}
.headerBarTitle {
WindowTitle(subtitle: "", title: "Demo")
}
}
} content: {
ViewStack(element: selection) { selection in
StatusPage(
selection.label,
icon: selection.icon,
description: selection.description
) { selection.view(app: app, window: window, toast: toast, pictureURL: pictureURL) }
.topToolbar {
HeaderBar {
Toggle(icon: .default(icon: .sidebarShow), isOn: $sidebarVisible)
.tooltip("Toggle Sidebar")
} end: {
if sidebarVisible {
Text("").transition(.crossfade)
} else {
menu.transition(.crossfade)
}
}
.headerBarTitle {
if sidebarVisible {
Text("")
.transition(.crossfade)
} else {
WindowTitle(subtitle: "Demo", title: selection.label)
.transition(.crossfade)
}
}
}
.toast("This is a toast!", signal: toast)
}
}
.aboutDialog(
visible: $about,
app: "Demo",
developer: "david-swift",
version: "Test",
icon: .default(icon: .applicationXExecutable),
website: .init(string: "https://aparokshaui.github.io/adwaita-swift/"),
issues: .init(string: "https://github.com/AparokshaUI/adwaita-swift/issues")
)
}
var menu: View {
Menu(icon: .default(icon: .openMenu), app: app, window: window) {
MenuButton("New Window", window: false) {
app.addWindow("main")
}
.keyboardShortcut("n".ctrl())
MenuButton("Close Window") {
window.close()
}
.keyboardShortcut("w".ctrl())
MenuSection {
MenuButton("About") { about = true }
MenuButton("Quit", window: false) { app.quit() }
.keyboardShortcut("q".ctrl())
}
}
.primary()
.tooltip("Main Menu")
}
func window(_ window: Window) -> Window {
window
.size(width: $width, height: $height)
.maximized($maximized)
}
}
}
// swiftlint:enable missing_docs implicitly_unwrapped_optional no_magic_numbers