Skip to content

Add Path and Shape #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/swift-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
swift build --target StressTestExample && \
swift build --target SpreadsheetExample && \
swift build --target NotesExample && \
swift build --target GtkExample
swift build --target GtkExample && \
swift build --target PathsExample
- name: Test
run: swift test --test-product swift-cross-uiPackageTests
1 change: 1 addition & 0 deletions .github/workflows/swift-uikit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
buildtarget NavigationExample
buildtarget StressTestExample
buildtarget NotesExample
buildtarget PathsExample

if [ $devicetype != TV ]; then
# Slider is not implemented for tvOS
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ DerivedData/
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
/.vscode
*.pyc
/.swiftpm
.swiftpm
vcpkg_installed/
*.trace
5 changes: 5 additions & 0 deletions Examples/Bundler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ version = '0.1.0'
identifier = 'dev.swiftcrossui.NotesExample'
product = 'NotesExample'
version = '0.1.0'

[apps.PathsExample]
identifier = 'dev.swiftcrossui.PathsExample'
product = 'PathsExample'
version = '0.1.0'
14 changes: 7 additions & 7 deletions Examples/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Examples/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,9 @@ let package = Package(
name: "NotesExample",
dependencies: exampleDependencies
),
.executableTarget(
name: "PathsExample",
dependencies: exampleDependencies
)
]
)
123 changes: 123 additions & 0 deletions Examples/Sources/PathsExample/PathsApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import DefaultBackend
import Foundation // for sin, cos
import SwiftCrossUI

struct ArcShape: StyledShape {
var startAngle: Double
var endAngle: Double
var clockwise: Bool

var strokeColor: Color? = Color.green
let fillColor: Color? = nil
let strokeStyle: StrokeStyle? = StrokeStyle(width: 5.0)

func path(in bounds: Path.Rect) -> Path {
Path()
.addArc(
center: bounds.center,
radius: min(bounds.width, bounds.height) / 2.0 - 2.5,
startAngle: startAngle,
endAngle: endAngle,
clockwise: clockwise
)
}

func size(fitting proposal: SIMD2<Int>) -> ViewSize {
let diameter = max(11, min(proposal.x, proposal.y))
return ViewSize(
size: SIMD2(x: diameter, y: diameter),
idealSize: SIMD2(x: 100, y: 100),
idealWidthForProposedHeight: proposal.y,
idealHeightForProposedWidth: proposal.x,
minimumWidth: 11,
minimumHeight: 11,
maximumWidth: nil,
maximumHeight: nil
)
}
}

@main
struct PathsApp: App {
var body: some Scene {
WindowGroup("PathsApp") {
HStack {
ZStack {
RoundedRectangle(cornerRadius: 12)
.fill(.gray)

HStack {
VStack {
Text("Clockwise")

HStack {
ArcShape(
startAngle: .pi * 2.0 / 3.0,
endAngle: .pi * 1.5,
clockwise: true
)

ArcShape(
startAngle: .pi * 1.5,
endAngle: .pi * 1.0 / 3.0,
clockwise: true
)
}

HStack {
ArcShape(
startAngle: .pi * 1.5,
endAngle: .pi * 2.0 / 3.0,
clockwise: true
)

ArcShape(
startAngle: .pi * 1.0 / 3.0,
endAngle: .pi * 1.5,
clockwise: true
)
}
}

VStack {
Text("Counter-clockwise")

HStack {
ArcShape(
startAngle: .pi * 1.5,
endAngle: .pi * 2.0 / 3.0,
clockwise: false
)

ArcShape(
startAngle: .pi * 1.0 / 3.0,
endAngle: .pi * 1.5,
clockwise: false
)
}

HStack {
ArcShape(
startAngle: .pi * 2.0 / 3.0,
endAngle: .pi * 1.5,
clockwise: false
)

ArcShape(
startAngle: .pi * 1.5,
endAngle: .pi * 1.0 / 3.0,
clockwise: false
)
}
}
}.padding()
}
.padding()

Ellipse()
.fill(.blue)
.padding()
}
}
}
}
4 changes: 2 additions & 2 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ let package = Package(
),
.package(
url: "https://github.com/stackotter/swift-winui",
branch: "42fe0034b7162f2de71ceea95725915d1147455a"
branch: "a81bc36e3ac056fbc740e9df30ff0d80af5ecd21"
),
// .package(
// url: "https://github.com/stackotter/TermKit",
Expand Down
Loading
Loading