@@ -6,11 +6,70 @@ import SwiftCrossUI
6
6
import SwiftBundlerRuntime
7
7
#endif
8
8
9
+ struct FileDialogDemo : View {
10
+ @State var selectedFile : URL ? = nil
11
+ @State var saveDestination : URL ? = nil
12
+
13
+ @Environment ( \. chooseFile) var chooseFile
14
+ @Environment ( \. chooseFileSaveDestination) var chooseFileSaveDestination
15
+
16
+ var body : some View {
17
+ Text ( " File dialog demo " )
18
+ . font ( . system( size: 18 ) )
19
+
20
+ if let selectedFile {
21
+ Text ( " Selected file: \( selectedFile. path) " )
22
+ } else {
23
+ Text ( " No file selected " )
24
+ }
25
+
26
+ if let saveDestination {
27
+ Text ( " Save destination: \( saveDestination. path) " )
28
+ }
29
+
30
+ HStack {
31
+ Button ( " Open " ) {
32
+ Task {
33
+ guard let file = await chooseFile ( ) else {
34
+ return
35
+ }
36
+ selectedFile = file
37
+ }
38
+ }
39
+
40
+ Button ( " Save " ) {
41
+ Task {
42
+ guard let file = await chooseFileSaveDestination ( ) else {
43
+ return
44
+ }
45
+ saveDestination = file
46
+ }
47
+ }
48
+ }
49
+ }
50
+ }
51
+
52
+ struct AlertDemo : View {
53
+ @Environment ( \. presentAlert) var presentAlert
54
+
55
+ var body : some View {
56
+ Text ( " Alert demo " )
57
+ . font ( . system( size: 18 ) )
58
+
59
+ Button ( " Present error " ) {
60
+ Task {
61
+ await presentAlert ( " Failed to succeed " )
62
+ }
63
+ }
64
+ }
65
+ }
66
+
9
67
@main
10
68
@HotReloadable
11
69
struct WindowingApp : App {
12
70
@State var title = " My window "
13
71
@State var resizable = false
72
+ @State var errorMessage : String ? = nil
14
73
15
74
var body : some Scene {
16
75
WindowGroup ( title) {
@@ -20,16 +79,36 @@ struct WindowingApp: App {
20
79
Text ( " Window title: " )
21
80
TextField ( " My window " , $title)
22
81
}
82
+
23
83
Button ( resizable ? " Disable resizing " : " Enable resizing " ) {
24
84
resizable = !resizable
25
85
}
86
+
26
87
Image ( Bundle . module. bundleURL. appendingPathComponent ( " Banner.png " ) )
88
+
89
+ Divider ( )
90
+
91
+ FileDialogDemo ( )
92
+
93
+ Divider ( )
94
+
95
+ AlertDemo ( )
27
96
}
28
- . padding ( 10 )
97
+ . padding ( 20 )
29
98
}
30
99
}
31
100
. defaultSize ( width: 500 , height: 500 )
32
101
. windowResizability ( resizable ? . contentMinSize : . contentSize)
102
+ . commands {
103
+ CommandMenu ( " Demo menu " ) {
104
+ Button ( " Menu item " ) { }
105
+
106
+ Menu ( " Submenu " ) {
107
+ Button ( " Item 1 " ) { }
108
+ Button ( " Item 2 " ) { }
109
+ }
110
+ }
111
+ }
33
112
34
113
WindowGroup ( " Secondary window " ) {
35
114
#hotReloadable {
0 commit comments