Skip to content

Commit d3ce199

Browse files
authored
Add Path and Shape; no Gtk support (#123)
* initial implementation of path * My math is wrong... * that took way too long * A bunch more shape stuff * Code formatting, comments, and rounded rectangle * AppKitBackend * Fix subpaths * Add `Path = Never` to Gtk3Backend to get CI off my back * Implement Path in WinUIBackend * format code * Fix edge case with transforms * Fix arc on WinUIBackend * final cleanup and documentation * Address some PR comments * Make Path.if rethrows * Various fixes
1 parent a82eb0f commit d3ce199

24 files changed

+1907
-14
lines changed

.github/workflows/swift-macos.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
swift build --target StressTestExample && \
3636
swift build --target SpreadsheetExample && \
3737
swift build --target NotesExample && \
38-
swift build --target GtkExample
38+
swift build --target GtkExample && \
39+
swift build --target PathsExample
3940
- name: Test
4041
run: swift test --test-product swift-cross-uiPackageTests

.github/workflows/swift-uikit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
buildtarget NavigationExample
4747
buildtarget StressTestExample
4848
buildtarget NotesExample
49+
buildtarget PathsExample
4950
5051
if [ $devicetype != TV ]; then
5152
# Slider is not implemented for tvOS

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ DerivedData/
99
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
1010
/.vscode
1111
*.pyc
12-
/.swiftpm
12+
.swiftpm
1313
vcpkg_installed/
1414
*.trace

Examples/Bundler.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ version = '0.1.0'
4949
identifier = 'dev.swiftcrossui.NotesExample'
5050
product = 'NotesExample'
5151
version = '0.1.0'
52+
53+
[apps.PathsExample]
54+
identifier = 'dev.swiftcrossui.PathsExample'
55+
product = 'PathsExample'
56+
version = '0.1.0'

Examples/Package.resolved

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/Package.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,9 @@ let package = Package(
6565
name: "NotesExample",
6666
dependencies: exampleDependencies
6767
),
68+
.executableTarget(
69+
name: "PathsExample",
70+
dependencies: exampleDependencies
71+
)
6872
]
6973
)
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import DefaultBackend
2+
import Foundation // for sin, cos
3+
import SwiftCrossUI
4+
5+
struct ArcShape: StyledShape {
6+
var startAngle: Double
7+
var endAngle: Double
8+
var clockwise: Bool
9+
10+
var strokeColor: Color? = Color.green
11+
let fillColor: Color? = nil
12+
let strokeStyle: StrokeStyle? = StrokeStyle(width: 5.0)
13+
14+
func path(in bounds: Path.Rect) -> Path {
15+
Path()
16+
.addArc(
17+
center: bounds.center,
18+
radius: min(bounds.width, bounds.height) / 2.0 - 2.5,
19+
startAngle: startAngle,
20+
endAngle: endAngle,
21+
clockwise: clockwise
22+
)
23+
}
24+
25+
func size(fitting proposal: SIMD2<Int>) -> ViewSize {
26+
let diameter = max(11, min(proposal.x, proposal.y))
27+
return ViewSize(
28+
size: SIMD2(x: diameter, y: diameter),
29+
idealSize: SIMD2(x: 100, y: 100),
30+
idealWidthForProposedHeight: proposal.y,
31+
idealHeightForProposedWidth: proposal.x,
32+
minimumWidth: 11,
33+
minimumHeight: 11,
34+
maximumWidth: nil,
35+
maximumHeight: nil
36+
)
37+
}
38+
}
39+
40+
@main
41+
struct PathsApp: App {
42+
var body: some Scene {
43+
WindowGroup("PathsApp") {
44+
HStack {
45+
ZStack {
46+
RoundedRectangle(cornerRadius: 12)
47+
.fill(.gray)
48+
49+
HStack {
50+
VStack {
51+
Text("Clockwise")
52+
53+
HStack {
54+
ArcShape(
55+
startAngle: .pi * 2.0 / 3.0,
56+
endAngle: .pi * 1.5,
57+
clockwise: true
58+
)
59+
60+
ArcShape(
61+
startAngle: .pi * 1.5,
62+
endAngle: .pi * 1.0 / 3.0,
63+
clockwise: true
64+
)
65+
}
66+
67+
HStack {
68+
ArcShape(
69+
startAngle: .pi * 1.5,
70+
endAngle: .pi * 2.0 / 3.0,
71+
clockwise: true
72+
)
73+
74+
ArcShape(
75+
startAngle: .pi * 1.0 / 3.0,
76+
endAngle: .pi * 1.5,
77+
clockwise: true
78+
)
79+
}
80+
}
81+
82+
VStack {
83+
Text("Counter-clockwise")
84+
85+
HStack {
86+
ArcShape(
87+
startAngle: .pi * 1.5,
88+
endAngle: .pi * 2.0 / 3.0,
89+
clockwise: false
90+
)
91+
92+
ArcShape(
93+
startAngle: .pi * 1.0 / 3.0,
94+
endAngle: .pi * 1.5,
95+
clockwise: false
96+
)
97+
}
98+
99+
HStack {
100+
ArcShape(
101+
startAngle: .pi * 2.0 / 3.0,
102+
endAngle: .pi * 1.5,
103+
clockwise: false
104+
)
105+
106+
ArcShape(
107+
startAngle: .pi * 1.5,
108+
endAngle: .pi * 1.0 / 3.0,
109+
clockwise: false
110+
)
111+
}
112+
}
113+
}.padding()
114+
}
115+
.padding()
116+
117+
Ellipse()
118+
.fill(.blue)
119+
.padding()
120+
}
121+
}
122+
}
123+
}

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ let package = Package(
108108
),
109109
.package(
110110
url: "https://github.com/stackotter/swift-winui",
111-
branch: "42fe0034b7162f2de71ceea95725915d1147455a"
111+
branch: "a81bc36e3ac056fbc740e9df30ff0d80af5ecd21"
112112
),
113113
// .package(
114114
// url: "https://github.com/stackotter/TermKit",

0 commit comments

Comments
 (0)