Skip to content
This repository was archived by the owner on Dec 27, 2020. It is now read-only.

Commit 4c2859e

Browse files
authored
shapes (#42)
1 parent f7d1547 commit 4c2859e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+793
-4
lines changed

Demo/SwiftUIExtensionsDemo iOS/ContentView.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,29 @@ struct ContentView: View {
2020
}
2121
}
2222
}
23+
24+
Section(header: Text("Shapes")) {
25+
NavigationLink(destination: RegularPolygonsView()) {
26+
HStack {
27+
Image(systemName: "square.fill")
28+
Text("Regular Polygons")
29+
}
30+
}
31+
32+
NavigationLink(destination: LinesView()) {
33+
HStack {
34+
Image(systemName: "pencil.and.outline")
35+
Text("Lines")
36+
}
37+
}
38+
39+
NavigationLink(destination: PatternsView()) {
40+
HStack {
41+
Image(systemName: "rectangle.split.3x3.fill")
42+
Text("Patterns")
43+
}
44+
}
45+
}
2346
}
2447
.listStyle(
2548
GroupedListStyle()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import SwiftUI
2+
import SwiftUIExtensions
3+
4+
struct LinesView: View {
5+
var body: some View {
6+
ScrollView {
7+
Line(unitPoints: [
8+
UnitPoint(x: 0.0, y: 0.1),
9+
UnitPoint(x: 0.5, y: 0.9),
10+
UnitPoint(x: 1.0, y: 0.1)
11+
])
12+
.stroke(Color.red, style: .init(lineWidth: 4, lineCap: .round))
13+
.frame(height: 200)
14+
.padding()
15+
16+
QuadCurve(unitData: [
17+
0.1, 0.9, 0.1
18+
])
19+
.stroke(Color.blue, style: .init(lineWidth: 2, lineCap: .round))
20+
.frame(height: 200)
21+
.padding()
22+
}
23+
.navigationBarTitle("Lines")
24+
}
25+
}
26+
27+
struct LinesView_Previews: PreviewProvider {
28+
static var previews: some View {
29+
LinesView()
30+
}
31+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import SwiftUI
2+
import SwiftUIExtensions
3+
4+
struct PatternsView: View {
5+
var body: some View {
6+
ScrollView {
7+
GridPattern(horizontalLines: 20, verticalLines: 40)
8+
.stroke(Color.white.opacity(0.3), style: .init(lineWidth: 1, lineCap: .round))
9+
.frame(height: 200)
10+
.background(Color.blue)
11+
.padding()
12+
13+
14+
LinearGradient(gradient: Gradient(colors: [.orange, .red, .blue, .purple]), startPoint: .topLeading, endPoint: .bottomTrailing)
15+
.frame(height: 200)
16+
.clipShape(
17+
GridPattern(horizontalLines: 25, verticalLines: 25).inset(by: 1).stroke(lineWidth: 1)
18+
)
19+
.padding()
20+
21+
LinearGradient(gradient: Gradient(colors: [.purple, .red, .orange]), startPoint: .topLeading, endPoint: .bottomTrailing)
22+
.frame(height: 200)
23+
.clipShape(
24+
GridPattern(horizontalLines: 10)
25+
.inset(by: 2)
26+
.stroke(style: .init(lineWidth: 4, lineCap: .round, lineJoin: .round, miterLimit: 2, dash: [10], dashPhase: 0))
27+
)
28+
.padding()
29+
30+
}
31+
.navigationBarTitle("Patterns")
32+
}
33+
}
34+
35+
struct PatternsView_Previews: PreviewProvider {
36+
static var previews: some View {
37+
PatternsView()
38+
}
39+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import SwiftUI
2+
import SwiftUIExtensions
3+
4+
struct RegularPolygonsView: View {
5+
var body: some View {
6+
HStack(alignment: .center, spacing: 16) {
7+
RegularPolygon(sides: 4)
8+
.strokeBorder(lineWidth: 20)
9+
.foregroundColor(.blue)
10+
11+
Pentagon()
12+
.strokeBorder(lineWidth: 20)
13+
.foregroundColor(.yellow)
14+
15+
Hexagon()
16+
.foregroundColor(.orange)
17+
18+
Heptagon()
19+
.foregroundColor(.blue)
20+
21+
Octagon()
22+
.foregroundColor(.pink)
23+
24+
Nonagon()
25+
.foregroundColor(.red)
26+
27+
Decagon()
28+
.foregroundColor(.green)
29+
}
30+
.frame(height: 100)
31+
.padding()
32+
.navigationBarTitle("Regular Polygons")
33+
}
34+
}
35+
36+
struct ShapesView_Previews: PreviewProvider {
37+
static var previews: some View {
38+
RegularPolygonsView()
39+
}
40+
}

Demo/SwiftUIExtensionsDemo macOS/ContentView.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,24 @@ struct ContentView: View {
1313
Text("Staggered Grid")
1414
}
1515
}
16+
17+
Section(header: Text("Shapes")) {
18+
NavigationLink(destination: RegularPolygonsView()) {
19+
Text("Regular Polygons")
20+
}
21+
22+
NavigationLink(destination: LinesView()) {
23+
Text("Lines")
24+
}
25+
26+
NavigationLink(destination: PatternsView()) {
27+
Text("Patterns")
28+
}
29+
}
1630
}
17-
.listStyle(SidebarListStyle())
1831
.frame(minWidth: 200, maxWidth: 300)
32+
.listStyle(SidebarListStyle())
33+
1934
}
2035
.navigationViewStyle(
2136
DoubleColumnNavigationViewStyle()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import SwiftUI
2+
import SwiftUIExtensions
3+
4+
struct LinesView: View {
5+
var body: some View {
6+
ScrollView {
7+
Line(unitPoints: [
8+
UnitPoint(x: 0.0, y: 0.1),
9+
UnitPoint(x: 0.5, y: 0.9),
10+
UnitPoint(x: 1.0, y: 0.1)
11+
])
12+
.stroke(Color.red, style: .init(lineWidth: 4, lineCap: .round))
13+
.frame(height: 200)
14+
.padding()
15+
16+
QuadCurve(unitData: [
17+
0.1, 0.9, 0.1
18+
])
19+
.stroke(Color.blue, style: .init(lineWidth: 2, lineCap: .round))
20+
.frame(height: 200)
21+
.padding()
22+
}
23+
}
24+
}
25+
26+
struct LinesView_Previews: PreviewProvider {
27+
static var previews: some View {
28+
LinesView()
29+
}
30+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import SwiftUI
2+
import SwiftUIExtensions
3+
4+
struct PatternsView: View {
5+
var body: some View {
6+
ScrollView {
7+
GridPattern(horizontalLines: 20, verticalLines: 40)
8+
.stroke(Color.white.opacity(0.3), style: .init(lineWidth: 1, lineCap: .round))
9+
.frame(height: 200)
10+
.background(Color.blue)
11+
.padding()
12+
13+
14+
LinearGradient(gradient: Gradient(colors: [.orange, .red, .blue, .purple]), startPoint: .topLeading, endPoint: .bottomTrailing)
15+
.frame(height: 200)
16+
.clipShape(
17+
GridPattern(horizontalLines: 25, verticalLines: 25).inset(by: 1).stroke(lineWidth: 1)
18+
)
19+
.padding()
20+
21+
LinearGradient(gradient: Gradient(colors: [.purple, .red, .orange]), startPoint: .topLeading, endPoint: .bottomTrailing)
22+
.frame(height: 200)
23+
.clipShape(
24+
GridPattern(horizontalLines: 10)
25+
.inset(by: 2)
26+
.stroke(style: .init(lineWidth: 4, lineCap: .round, lineJoin: .round, miterLimit: 2, dash: [10], dashPhase: 0))
27+
)
28+
.padding()
29+
30+
}
31+
}
32+
}
33+
34+
struct PatternsView_Previews: PreviewProvider {
35+
static var previews: some View {
36+
PatternsView()
37+
}
38+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import SwiftUI
2+
import SwiftUIExtensions
3+
4+
struct RegularPolygonsView: View {
5+
var body: some View {
6+
ScrollView {
7+
HStack(alignment: .center, spacing: 16) {
8+
RegularPolygon(sides: 4)
9+
.strokeBorder(lineWidth: 20)
10+
.foregroundColor(.blue)
11+
12+
Pentagon()
13+
.strokeBorder(lineWidth: 20)
14+
.foregroundColor(.yellow)
15+
16+
Hexagon()
17+
.foregroundColor(.orange)
18+
19+
Heptagon()
20+
.foregroundColor(.blue)
21+
22+
Octagon()
23+
.foregroundColor(.pink)
24+
25+
Nonagon()
26+
.foregroundColor(.red)
27+
28+
Decagon()
29+
.foregroundColor(.green)
30+
}
31+
.frame(height: 100)
32+
.padding()
33+
}
34+
35+
}
36+
}
37+
38+
struct ShapesView_Previews: PreviewProvider {
39+
static var previews: some View {
40+
RegularPolygonsView()
41+
}
42+
}

Demo/SwiftUIExtensionsDemo.xcodeproj/project.pbxproj

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
FA2C328823A35FE6002DF6F7 /* Card.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA37C45B239DE7330037BFE3 /* Card.swift */; };
2121
FA2C328923A35FE6002DF6F7 /* SharedAssets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FA37C45A239DE7330037BFE3 /* SharedAssets.xcassets */; };
2222
FA2C328C23A36DB5002DF6F7 /* SwiftUIExtensions in Frameworks */ = {isa = PBXBuildFile; productRef = FA2C328B23A36DB5002DF6F7 /* SwiftUIExtensions */; };
23+
FA2C329123A3704B002DF6F7 /* PatternsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA2C328E23A3704B002DF6F7 /* PatternsView.swift */; };
24+
FA2C329223A3704B002DF6F7 /* RegularPolygonsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA2C328F23A3704B002DF6F7 /* RegularPolygonsView.swift */; };
25+
FA2C329323A3704B002DF6F7 /* LinesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA2C329023A3704B002DF6F7 /* LinesView.swift */; };
26+
FA2C329823A3725A002DF6F7 /* PatternsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA2C329523A37259002DF6F7 /* PatternsView.swift */; };
27+
FA2C329923A3725A002DF6F7 /* LinesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA2C329623A37259002DF6F7 /* LinesView.swift */; };
28+
FA2C329A23A3725A002DF6F7 /* RegularPolygonsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA2C329723A37259002DF6F7 /* RegularPolygonsView.swift */; };
2329
FA37C437239DE2560037BFE3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA37C436239DE2560037BFE3 /* AppDelegate.swift */; };
2430
FA37C439239DE2560037BFE3 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA37C438239DE2560037BFE3 /* SceneDelegate.swift */; };
2531
FA37C43B239DE2560037BFE3 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA37C43A239DE2560037BFE3 /* ContentView.swift */; };
@@ -121,6 +127,12 @@
121127
FA2C327923A35EA1002DF6F7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
122128
FA2C328023A35F58002DF6F7 /* StaggeredGridView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StaggeredGridView.swift; sourceTree = "<group>"; };
123129
FA2C328223A35F73002DF6F7 /* ModularGridView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModularGridView.swift; sourceTree = "<group>"; };
130+
FA2C328E23A3704B002DF6F7 /* PatternsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PatternsView.swift; sourceTree = "<group>"; };
131+
FA2C328F23A3704B002DF6F7 /* RegularPolygonsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegularPolygonsView.swift; sourceTree = "<group>"; };
132+
FA2C329023A3704B002DF6F7 /* LinesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinesView.swift; sourceTree = "<group>"; };
133+
FA2C329523A37259002DF6F7 /* PatternsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PatternsView.swift; sourceTree = "<group>"; };
134+
FA2C329623A37259002DF6F7 /* LinesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinesView.swift; sourceTree = "<group>"; };
135+
FA2C329723A37259002DF6F7 /* RegularPolygonsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegularPolygonsView.swift; sourceTree = "<group>"; };
124136
FA37C433239DE2560037BFE3 /* SwiftUIExtensionsDemo iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SwiftUIExtensionsDemo iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
125137
FA37C436239DE2560037BFE3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
126138
FA37C438239DE2560037BFE3 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
@@ -253,6 +265,26 @@
253265
path = StaggeredGrid;
254266
sourceTree = "<group>";
255267
};
268+
FA2C328D23A37034002DF6F7 /* Shapes */ = {
269+
isa = PBXGroup;
270+
children = (
271+
FA2C329023A3704B002DF6F7 /* LinesView.swift */,
272+
FA2C328E23A3704B002DF6F7 /* PatternsView.swift */,
273+
FA2C328F23A3704B002DF6F7 /* RegularPolygonsView.swift */,
274+
);
275+
path = Shapes;
276+
sourceTree = "<group>";
277+
};
278+
FA2C329423A37236002DF6F7 /* Shapes */ = {
279+
isa = PBXGroup;
280+
children = (
281+
FA2C329623A37259002DF6F7 /* LinesView.swift */,
282+
FA2C329523A37259002DF6F7 /* PatternsView.swift */,
283+
FA2C329723A37259002DF6F7 /* RegularPolygonsView.swift */,
284+
);
285+
path = Shapes;
286+
sourceTree = "<group>";
287+
};
256288
FA37C434239DE2560037BFE3 /* Products */ = {
257289
isa = PBXGroup;
258290
children = (
@@ -273,6 +305,7 @@
273305
FA37C438239DE2560037BFE3 /* SceneDelegate.swift */,
274306
FA37C43A239DE2560037BFE3 /* ContentView.swift */,
275307
FA37C448239DE6250037BFE3 /* Layouts */,
308+
FA2C328D23A37034002DF6F7 /* Shapes */,
276309
FA37C43C239DE2570037BFE3 /* Assets.xcassets */,
277310
FA37C441239DE2570037BFE3 /* LaunchScreen.storyboard */,
278311
FA37C444239DE2570037BFE3 /* Info.plist */,
@@ -348,6 +381,7 @@
348381
FA37C466239DE9960037BFE3 /* AppDelegate.swift */,
349382
FA37C468239DE9960037BFE3 /* ContentView.swift */,
350383
FA37C479239DEAF10037BFE3 /* Layouts */,
384+
FA2C329423A37236002DF6F7 /* Shapes */,
351385
FA37C46A239DE9990037BFE3 /* Assets.xcassets */,
352386
FA37C46F239DE9990037BFE3 /* Main.storyboard */,
353387
FA37C472239DE9990037BFE3 /* Info.plist */,
@@ -722,12 +756,15 @@
722756
buildActionMask = 2147483647;
723757
files = (
724758
FA37C45C239DE7330037BFE3 /* Color+Random.swift in Sources */,
759+
FA2C329323A3704B002DF6F7 /* LinesView.swift in Sources */,
760+
FA2C329123A3704B002DF6F7 /* PatternsView.swift in Sources */,
725761
FA37C45D239DE7330037BFE3 /* Item.swift in Sources */,
726762
FA37C437239DE2560037BFE3 /* AppDelegate.swift in Sources */,
727763
FA37C44F239DE6820037BFE3 /* ModularGridView.swift in Sources */,
728764
FA37C450239DE6820037BFE3 /* ModularGridSettingsView.swift in Sources */,
729765
FA37C439239DE2560037BFE3 /* SceneDelegate.swift in Sources */,
730766
FA37C452239DE6820037BFE3 /* StaggeredGridView.swift in Sources */,
767+
FA2C329223A3704B002DF6F7 /* RegularPolygonsView.swift in Sources */,
731768
FA37C45F239DE7330037BFE3 /* Card.swift in Sources */,
732769
FA37C451239DE6820037BFE3 /* StaggeredGridSettingsView.swift in Sources */,
733770
FA37C43B239DE2560037BFE3 /* ContentView.swift in Sources */,
@@ -741,12 +778,15 @@
741778
FA37C484239DEB2C0037BFE3 /* Color+Random.swift in Sources */,
742779
FA37C486239DEB2C0037BFE3 /* Card.swift in Sources */,
743780
FA37C480239DEB200037BFE3 /* ModularGridView.swift in Sources */,
781+
FA2C329823A3725A002DF6F7 /* PatternsView.swift in Sources */,
744782
FA37C482239DEB200037BFE3 /* StaggeredGridSettingsView.swift in Sources */,
745783
FA37C469239DE9960037BFE3 /* ContentView.swift in Sources */,
746784
FA37C485239DEB2C0037BFE3 /* Item.swift in Sources */,
747785
FA37C481239DEB200037BFE3 /* ModularGridSettingsView.swift in Sources */,
786+
FA2C329A23A3725A002DF6F7 /* RegularPolygonsView.swift in Sources */,
748787
FA37C467239DE9960037BFE3 /* AppDelegate.swift in Sources */,
749788
FA37C483239DEB200037BFE3 /* StaggeredGridView.swift in Sources */,
789+
FA2C329923A3725A002DF6F7 /* LinesView.swift in Sources */,
750790
);
751791
runOnlyForDeploymentPostprocessing = 0;
752792
};

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
.target(
1818
name: "SwiftUIExtensions",
1919
dependencies: [],
20-
exclude: ["Demo"]
20+
exclude: ["Demo", "Resources"]
2121
)
2222
]
2323
)

0 commit comments

Comments
 (0)