diff --git a/.arena-sample.swift b/.arena-sample.swift deleted file mode 100644 index 0ab716f..0000000 --- a/.arena-sample.swift +++ /dev/null @@ -1,80 +0,0 @@ -// Playground generated with 🏟 Arena (https://github.com/finestructure/arena) -// ℹ️ If running the playground fails with an error "no such module ..." -// go to Product -> Build to re-trigger building the SPM package. -// ℹ️ Please restart Xcode if autocomplete is not working. - -import SwiftUI -import TextBuilder -import PlaygroundSupport - -struct DemoView: View { - @State var name: String? - - var body: some View { - VStack(spacing: 20) { - welcomeText.font(.title) - descriptionText - someClickableText - footnote - } - .multilineTextAlignment(.center) - .padding() - .background(Color(.windowBackgroundColor)) - } - - @SpacedTextBuilder - var welcomeText: Text { - if let name = name, !name.isEmpty { - "Welcome," - name.text.bold() - } else { - "Welcome" - } - } - - @BasicTextBuilder - var descriptionText: Text { - "This is a demo of " - "TextBuilder".text.italic() - "." - } - - var someClickableText: Text { - Text(separator: " ") { - "This paragraph is implemented" - "without".text.underline() - "a builder to showcase the" - "Text.init(separator:content:)".text.font(.system(.body, design: .monospaced)).foregroundColor(.gray) - "initializer provided by this library." - } - } - - var footnote: some View { - Text { - "Made by " - "@davdroman".text.bold() - } - .underline() - .font(.system(.caption)) - .foregroundColor(.blue) - .pointable() - .onTapGesture { NSWorkspace.shared.open(URL(string: "https://github.com/davdroman/TextBuilder")!) } - } -} - -extension View { - func pointable() -> some View { - onHover { inside in - if inside { - NSCursor.pointingHand.push() - } else { - NSCursor.pop() - } - } - } -} - -let view = NSHostingController(rootView: DemoView(name: NSFullUserName())) -view.view.frame.size.width = 340 -PlaygroundPage.current.needsIndefiniteExecution = true -PlaygroundPage.current.liveView = view \ No newline at end of file diff --git a/.arena-sample.swift b/.arena-sample.swift new file mode 120000 index 0000000..4f47da6 --- /dev/null +++ b/.arena-sample.swift @@ -0,0 +1 @@ +TextBuilder.playground/Contents.swift \ No newline at end of file diff --git a/README.md b/README.md index 3e43bf0..c6862ff 100644 --- a/README.md +++ b/README.md @@ -110,3 +110,5 @@ var loremIpsum: Text { 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. Simply [install Arena](https://github.com/finestructure/Arena#how-to-install-arena) and run `arena davdroman/TextBuilder@branch:main --platform macos` in your terminal. + +Alternatively, a standalone demo Xcode Playground is also provided in this package. diff --git a/TextBuilder.playground/Contents.swift b/TextBuilder.playground/Contents.swift new file mode 100644 index 0000000..2b90b23 --- /dev/null +++ b/TextBuilder.playground/Contents.swift @@ -0,0 +1,75 @@ +import SwiftUI +import TextBuilder +import PlaygroundSupport + +struct DemoView: View { + @State var name: String? + + var body: some View { + VStack(spacing: 20) { + welcomeText.font(.title) + descriptionText + someClickableText + footnote + } + .multilineTextAlignment(.center) + .padding() + .background(Color(.windowBackgroundColor)) + } + + @SpacedTextBuilder + var welcomeText: Text { + if let name = name, !name.isEmpty { + "Welcome," + name.text.bold() + } else { + "Welcome" + } + } + + @BasicTextBuilder + var descriptionText: Text { + "This is a demo of " + "TextBuilder".text.italic() + "." + } + + var someClickableText: Text { + Text(separator: " ") { + "This paragraph is implemented" + "without".text.underline() + "a builder to showcase the" + "Text.init(separator:content:)".text.font(.system(.body, design: .monospaced)).foregroundColor(.gray) + "initializer provided by this library." + } + } + + var footnote: some View { + Text { + "Made by " + "@davdroman".text.bold() + } + .underline() + .font(.system(.caption)) + .foregroundColor(.blue) + .pointable() + .onTapGesture { NSWorkspace.shared.open(URL(string: "https://github.com/davdroman/TextBuilder")!) } + } +} + +extension View { + func pointable() -> some View { + onHover { inside in + if inside { + NSCursor.pointingHand.push() + } else { + NSCursor.pop() + } + } + } +} + +let view = NSHostingController(rootView: DemoView(name: NSFullUserName())) +view.view.frame.size.width = 340 +PlaygroundPage.current.needsIndefiniteExecution = true +PlaygroundPage.current.liveView = view diff --git a/TextBuilder.playground/contents.xcplayground b/TextBuilder.playground/contents.xcplayground new file mode 100644 index 0000000..1c968e7 --- /dev/null +++ b/TextBuilder.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/TextBuilder.playground/playground.xcworkspace/contents.xcworkspacedata b/TextBuilder.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/TextBuilder.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + +