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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto",
"state" : {
"revision" : "a6ce32a18b81b04ce7e897d1d98df6eb2da04786",
"version" : "3.12.2"
"revision" : "e8d6eba1fef23ae5b359c46b03f7d94be2f41fed",
"version" : "3.12.3"
}
},
{
Expand Down Expand Up @@ -308,7 +308,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/stackotter/swift-winui",
"state" : {
"revision" : "42fe0034b7162f2de71ceea95725915d1147455a"
"revision" : "a81bc36e3ac056fbc740e9df30ff0d80af5ecd21"
}
},
{
Expand Down Expand Up @@ -343,17 +343,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/yonaskolb/XcodeGen",
"state" : {
"revision" : "82c6ab9bbd5b6075fc0887d897733fc0c4ffc9ab",
"version" : "2.42.0"
"revision" : "7193eb447a6f60061f069e07bc1efd32d73c0e19",
"version" : "2.43.0"
}
},
{
"identity" : "xcodeproj",
"kind" : "remoteSourceControl",
"location" : "https://github.com/tuist/XcodeProj",
"state" : {
"revision" : "447c159b0c5fb047a024fd8d942d4a76cf47dde0",
"version" : "8.16.0"
"revision" : "dc3b87a4e69f9cd06c6cb16199f5d0472e57ef6b",
"version" : "8.24.3"
}
},
{
Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "b91f917bbebb41572e4a589a5f5f3fa23970b5412aa202d7d5a9ffd85f7382b3",
"originHash" : "b27fd5296427d0b831ec73c4d0cea714e68fa1e046809b1001bb42cf87171755",
"pins" : [
{
"identity" : "jpeg",
Expand Down Expand Up @@ -112,7 +112,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/stackotter/swift-winui",
"state" : {
"revision" : "42fe0034b7162f2de71ceea95725915d1147455a"
"revision" : "a81bc36e3ac056fbc740e9df30ff0d80af5ecd21"
}
},
{
Expand Down
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