Skip to content

Commit 295c05f

Browse files
committed
Added WinUI Support
Additionally added wrapped ControlsExample in ScrollView to be fully visible on Windows
1 parent 3133026 commit 295c05f

File tree

2 files changed

+56
-53
lines changed

2 files changed

+56
-53
lines changed

Examples/Sources/ControlsExample/ControlsApp.swift

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,76 +21,78 @@ struct ControlsApp: App {
2121
var body: some Scene {
2222
WindowGroup("ControlsApp") {
2323
#hotReloadable {
24-
VStack(spacing: 30) {
25-
VStack {
26-
Text("Button")
27-
Button("Click me!") {
28-
count += 1
24+
ScrollView {
25+
VStack(spacing: 30) {
26+
VStack {
27+
Text("Button")
28+
Button("Click me!") {
29+
count += 1
30+
}
31+
Text("Count: \(count)")
2932
}
30-
Text("Count: \(count)")
31-
}
32-
.padding(.bottom, 20)
33-
34-
#if !canImport(UIKitBackend)
33+
.padding(.bottom, 20)
34+
35+
#if !canImport(UIKitBackend)
3536
VStack {
3637
Text("Toggle button")
3738
Toggle("Toggle me!", active: $exampleButtonState)
3839
.toggleStyle(.button)
3940
Text("Currently enabled: \(exampleButtonState)")
4041
}
4142
.padding(.bottom, 20)
42-
#endif
43-
44-
VStack {
45-
Text("Toggle switch")
46-
Toggle("Toggle me:", active: $exampleSwitchState)
47-
.toggleStyle(.switch)
48-
Text("Currently enabled: \(exampleSwitchState)")
49-
}
50-
51-
#if !canImport(UIKitBackend)
43+
#endif
44+
45+
VStack {
46+
Text("Toggle switch")
47+
Toggle("Toggle me:", active: $exampleSwitchState)
48+
.toggleStyle(.switch)
49+
Text("Currently enabled: \(exampleSwitchState)")
50+
}
51+
52+
#if !canImport(UIKitBackend)
5253
VStack {
5354
Text("Checkbox")
5455
Toggle("Toggle me:", active: $exampleCheckboxState)
5556
.toggleStyle(.checkbox)
5657
Text("Currently enabled: \(exampleCheckboxState)")
5758
}
58-
#endif
59-
60-
VStack {
61-
Text("Slider")
62-
Slider($sliderValue, minimum: 0, maximum: 10)
63-
.frame(maxWidth: 200)
64-
Text("Value: \(String(format: "%.02f", sliderValue))")
65-
}
66-
67-
VStack {
68-
Text("Text field")
69-
TextField("Text field", text: $text)
70-
Text("Value: \(text)")
71-
}
72-
73-
VStack {
74-
Text("Drop down")
75-
HStack {
76-
Text("Flavor: ")
77-
Picker(of: ["Vanilla", "Chocolate", "Strawberry"], selection: $flavor)
59+
#endif
60+
61+
VStack {
62+
Text("Slider")
63+
Slider($sliderValue, minimum: 0, maximum: 10)
64+
.frame(maxWidth: 200)
65+
Text("Value: \(String(format: "%.02f", sliderValue))")
7866
}
79-
Text("You chose: \(flavor ?? "Nothing yet!")")
80-
}
81-
}.padding().disabled(!enabled)
82-
.focusable(isFocusable)
83-
84-
Toggle(enabled ? "Disable all" : "Enable all", active: $enabled)
67+
68+
VStack {
69+
Text("Text field")
70+
TextField("Text field", text: $text)
71+
Text("Value: \(text)")
72+
}
73+
74+
VStack {
75+
Text("Drop down")
76+
HStack {
77+
Text("Flavor: ")
78+
Picker(of: ["Vanilla", "Chocolate", "Strawberry"], selection: $flavor)
79+
}
80+
Text("You chose: \(flavor ?? "Nothing yet!")")
81+
}
82+
}.padding().disabled(!enabled)
83+
.focusable(isFocusable)
84+
85+
Toggle(enabled ? "Disable all" : "Enable all", active: $enabled)
86+
.padding()
87+
.focusable(isFocusable)
88+
89+
Toggle(
90+
isFocusable ? "Disable focusability for all" : "Enable focusability for all",
91+
active: $isFocusable
92+
)
8593
.padding()
8694
.focusable(isFocusable)
87-
88-
Toggle(
89-
isFocusable ? "Disable focusability for all" : "Enable focusability for all",
90-
active: $isFocusable
91-
)
92-
.padding()
93-
.focusable(isFocusable)
95+
}
9496
}
9597

9698
}.defaultSize(width: 400, height: 600)

Sources/WinUIBackend/WinUIBackend.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,7 @@ extension EnvironmentValues {
17831783
control.fontWeight.weight = resolvedFont.winUIFontWeight
17841784
control.foreground = winUIForegroundBrush
17851785
control.isEnabled = isEnabled
1786+
control.isTabStop = isFocusable
17861787
if resolvedFont.isItalic {
17871788
control.fontStyle = .italic
17881789
}

0 commit comments

Comments
 (0)