Skip to content

Commit 51426f5

Browse files
committed
Update examples to just unconditionally use the GtkBackend
1 parent 355d8b2 commit 51426f5

File tree

9 files changed

+18
-63
lines changed

9 files changed

+18
-63
lines changed

Examples/Counter/CounterApp.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1+
import GtkBackend
12
import SwiftCrossUI
23

3-
#if canImport(GtkBackend)
4-
import GtkBackend
5-
typealias SelectedBackend = GtkBackend
6-
#else
7-
#error("No valid backends found")
8-
#endif
9-
104
class CounterState: Observable {
115
@Observed
126
var count = 0
137
}
148

159
@main
1610
struct CounterApp: App {
17-
typealias Backend = SelectedBackend
11+
typealias Backend = GtkBackend
1812

1913
let identifier = "dev.stackotter.CounterApp"
2014

Examples/FileViewer/FileViewerApp.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import Foundation
2+
import GtkBackend
23
import SwiftCrossUI
34

4-
#if canImport(GtkBackend)
5-
import GtkBackend
6-
typealias SelectedBackend = GtkBackend
7-
#else
8-
#error("No valid backends found")
9-
#endif
10-
115
#if canImport(FileDialog)
126
import FileDialog
137
#endif
@@ -18,7 +12,7 @@ class FileViewerAppState: Observable {
1812

1913
@main
2014
struct FileViewerApp: App {
21-
typealias Backend = SelectedBackend
15+
typealias Backend = GtkBackend
2216

2317
let identifier = "dev.stackotter.FileViewerApp"
2418

Examples/GreetingGenerator/GreetingGenerator.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1+
import GtkBackend
12
import SwiftCrossUI
23

3-
#if canImport(GtkBackend)
4-
import GtkBackend
5-
typealias SelectedBackend = GtkBackend
6-
#else
7-
#error("No valid backends found")
8-
#endif
9-
104
class GreetingGeneratorState: Observable {
115
@Observed var name = ""
126
@Observed var greetings: [String] = []
137
}
148

159
@main
1610
struct GreetingGeneratorApp: App {
17-
typealias Backend = SelectedBackend
11+
typealias Backend = GtkBackend
1812

1913
let identifier = "dev.stackotter.GreetingGenerator"
2014

Examples/Navigation/NavigationApp.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import Foundation
2+
import GtkBackend
23
import SwiftCrossUI
34

4-
#if canImport(GtkBackend)
5-
import GtkBackend
6-
typealias SelectedBackend = GtkBackend
7-
#else
8-
#error("No valid backends found")
9-
#endif
10-
115
enum SubjectArea: Codable {
126
case science
137
case humanities

Examples/RandomNumberGenerator/RandomNumberGeneratorApp.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1+
import GtkBackend
12
import SwiftCrossUI
23

3-
#if canImport(GtkBackend)
4-
import GtkBackend
5-
typealias SelectedBackend = GtkBackend
6-
#else
7-
#error("No valid backends found")
8-
#endif
9-
104
class RandomNumberGeneratorState: Observable {
115
@Observed var minNum = 0
126
@Observed var maxNum = 100
@@ -33,7 +27,7 @@ enum ColorOption: String, CaseIterable {
3327

3428
@main
3529
struct RandomNumberGeneratorApp: App {
36-
typealias Backend = SelectedBackend
30+
typealias Backend = GtkBackend
3731

3832
let identifier = "dev.stackotter.RandomNumberGeneratorApp"
3933

Examples/Split/SplitApp.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import Foundation
2+
import GtkBackend
23
import SwiftCrossUI
34

4-
#if canImport(GtkBackend)
5-
import GtkBackend
6-
typealias SelectedBackend = GtkBackend
7-
#else
8-
#error("No valid backends found")
9-
#endif
10-
115
enum SubjectArea {
126
case science
137
case humanities
@@ -36,7 +30,7 @@ class SplitAppState: Observable {
3630

3731
@main
3832
struct SplitApp: App {
39-
typealias Backend = SelectedBackend
33+
typealias Backend = GtkBackend
4034

4135
let identifier = "dev.stackotter.SplitApp"
4236

Examples/WindowProperties/WindowPropertiesApp.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
import Foundation
2+
import GtkBackend
23
import SwiftCrossUI
34

4-
#if canImport(GtkBackend)
5-
import GtkBackend
6-
typealias SelectedBackend = GtkBackend
7-
#else
8-
#error("No valid backends found")
9-
#endif
10-
115
class WindowPropertiesAppState: Observable {
126
@Observed var count = 0
137
}
148

159
@main
1610
struct WindowPropertiesApp: App {
17-
typealias Backend = SelectedBackend
11+
typealias Backend = GtkBackend
1812

1913
let identifier = "dev.stackotter.WindowPropertiesApp"
2014

Package.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ var dependencies: [Package.Dependency] = [
3939

4040
var conditionalProducts: [Product] = []
4141
var conditionalTargets: [Target] = []
42-
var exampleDependencies: [Target.Dependency] = ["SwiftCrossUI"]
43-
var fileViewerExampleDependencies: [Target.Dependency] = ["SwiftCrossUI"]
42+
var exampleDependencies: [Target.Dependency] = ["SwiftCrossUI", "GtkBackend"]
43+
var fileViewerExampleDependencies: [Target.Dependency] = ["SwiftCrossUI", "GtkBackend", "CGtk"]
4444
var backendTargets: [String] = []
4545

4646
// If Gtk is detected, add Gtk-related products and targets
4747
if let version = getGtk4MinorVersion() {
4848
var gtkSwiftSettings: [SwiftSetting] = []
4949
var gtkExampleDependencies: [Target.Dependency] = ["Gtk"]
50-
exampleDependencies.append("GtkBackend")
5150
backendTargets.append("GtkBackend")
5251
fileViewerExampleDependencies.append("GtkBackend")
5352

@@ -59,7 +58,6 @@ if let version = getGtk4MinorVersion() {
5958

6059
gtkExampleDependencies.append("FileDialog")
6160
fileViewerExampleDependencies.append("FileDialog")
62-
fileViewerExampleDependencies.append("CGtk")
6361
gtkSwiftSettings.append(.define("GTK_4_10_PLUS"))
6462
}
6563

@@ -102,7 +100,6 @@ if let version = getGtk4MinorVersion() {
102100
#if canImport(AppKit)
103101
conditionalTargets.append(.target(name: "AppKitBackend", dependencies: ["SwiftCrossUI"]))
104102
backendTargets.append("AppKitBackend")
105-
exampleDependencies.append("AppKitBackend")
106103
#endif
107104

108105
if checkQtInstalled() {
@@ -113,7 +110,6 @@ if checkQtInstalled() {
113110
)
114111
)
115112
backendTargets.append("QtBackend")
116-
exampleDependencies.append("QtBackend")
117113
dependencies.append(
118114
.package(
119115
url: "https://github.com/Longhanks/qlift",
@@ -134,7 +130,6 @@ if checkSDL2Installed() {
134130
)
135131
)
136132
backendTargets.append("LVGLBackend")
137-
exampleDependencies.append("LVGLBackend")
138133
dependencies.append(
139134
.package(
140135
url: "https://github.com/PADL/LVGLSwift",
@@ -152,7 +147,6 @@ if checkSDL2Installed() {
152147
)
153148
)
154149
backendTargets.append("CursesBackend")
155-
exampleDependencies.append("CursesBackend")
156150
dependencies.append(
157151
.package(
158152
url: "https://github.com/migueldeicaza/TermKit",

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Here's a simple example app demonstrate how easy it is to get started with Swift
4141

4242
```swift
4343
import SwiftCrossUI
44+
import GtkBackend
4445

4546
class CounterState: Observable {
4647
@Observed var count = 0
@@ -87,6 +88,8 @@ swift run FileViewerExample
8788
swift run NavigationExample
8889
```
8990

91+
All examples use the `GtkBackend` but can easily be updated to test out other backends.
92+
9093
## Documentation
9194

9295
Here's the [documentation site](https://stackotter.github.io/swift-cross-ui/documentation/swiftcrossui). Keep in mind that the project is still very much a work-in-progress, proper documentation and tutorials will be created once the project has matured a bit, because otherwise I have to spend too much time keeping the documentation up-to-date.

0 commit comments

Comments
 (0)