Skip to content

Commit 420a8f8

Browse files
authored
Merge pull request #5 from davdroman/demo-playground [skip ci]
Demo playground
2 parents 2cf65ea + 4b4a9fb commit 420a8f8

File tree

5 files changed

+89
-80
lines changed

5 files changed

+89
-80
lines changed

.arena-sample.swift

Lines changed: 0 additions & 80 deletions
This file was deleted.

.arena-sample.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TextBuilder.playground/Contents.swift

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,5 @@ var loremIpsum: Text {
110110
TextBuilder supports [Arena](https://github.com/finestructure/Arena) to effortlessly take it for a spin in a playground before you decide to add it to your codebase.
111111

112112
Simply [install Arena](https://github.com/finestructure/Arena#how-to-install-arena) and run `arena davdroman/TextBuilder@branch:main --platform macos` in your terminal.
113+
114+
Alternatively, a standalone demo Xcode Playground is also provided in this package.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import SwiftUI
2+
import TextBuilder
3+
import PlaygroundSupport
4+
5+
struct DemoView: View {
6+
@State var name: String?
7+
8+
var body: some View {
9+
VStack(spacing: 20) {
10+
welcomeText.font(.title)
11+
descriptionText
12+
someClickableText
13+
footnote
14+
}
15+
.multilineTextAlignment(.center)
16+
.padding()
17+
.background(Color(.windowBackgroundColor))
18+
}
19+
20+
@SpacedTextBuilder
21+
var welcomeText: Text {
22+
if let name = name, !name.isEmpty {
23+
"Welcome,"
24+
name.text.bold()
25+
} else {
26+
"Welcome"
27+
}
28+
}
29+
30+
@BasicTextBuilder
31+
var descriptionText: Text {
32+
"This is a demo of "
33+
"TextBuilder".text.italic()
34+
"."
35+
}
36+
37+
var someClickableText: Text {
38+
Text(separator: " ") {
39+
"This paragraph is implemented"
40+
"without".text.underline()
41+
"a builder to showcase the"
42+
"Text.init(separator:content:)".text.font(.system(.body, design: .monospaced)).foregroundColor(.gray)
43+
"initializer provided by this library."
44+
}
45+
}
46+
47+
var footnote: some View {
48+
Text {
49+
"Made by "
50+
"@davdroman".text.bold()
51+
}
52+
.underline()
53+
.font(.system(.caption))
54+
.foregroundColor(.blue)
55+
.pointable()
56+
.onTapGesture { NSWorkspace.shared.open(URL(string: "https://github.com/davdroman/TextBuilder")!) }
57+
}
58+
}
59+
60+
extension View {
61+
func pointable() -> some View {
62+
onHover { inside in
63+
if inside {
64+
NSCursor.pointingHand.push()
65+
} else {
66+
NSCursor.pop()
67+
}
68+
}
69+
}
70+
}
71+
72+
let view = NSHostingController(rootView: DemoView(name: NSFullUserName()))
73+
view.view.frame.size.width = 340
74+
PlaygroundPage.current.needsIndefiniteExecution = true
75+
PlaygroundPage.current.liveView = view
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<playground version='5.0' target-platform='macos' buildActiveScheme='true' importAppTypes='true'>
3+
<timeline fileName='timeline.xctimeline'/>
4+
</playground>

TextBuilder.playground/playground.xcworkspace/contents.xcworkspacedata

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

0 commit comments

Comments
 (0)