Skip to content

Commit ce05306

Browse files
committed
Add a full example
...
1 parent 64cb7cc commit ce05306

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,62 @@ The editor is similar to (but not exactly the same) the one used by
130130
[SVG Shaper for SwiftUI](https://zeezide.de/en/products/svgshaper/),
131131
for its SVG and Swift editor parts.
132132

133+
134+
### Complete Example
135+
136+
```swift
137+
import SwiftUI
138+
import CodeEditor
139+
140+
struct ContentView: View {
141+
142+
#if os(macOS)
143+
@AppStorage("fontsize") var fontSize = Int(NSFont.systemFontSize)
144+
#endif
145+
@State private var source = "let a = 42"
146+
@State private var language = CodeEditor.Language.swift
147+
@State private var theme = CodeEditor.ThemeName.pojoaque
148+
149+
var body: some View {
150+
VStack(spacing: 0) {
151+
HStack {
152+
Picker("Language", selection: $language) {
153+
ForEach(CodeEditor.availableLanguages) { language in
154+
Text("\(language.rawValue.capitalized)")
155+
.tag(language)
156+
}
157+
}
158+
Picker("Theme", selection: $theme) {
159+
ForEach(CodeEditor.availableThemes) {
160+
Text("\($0.rawValue.capitalized)")
161+
.tag($0)
162+
}
163+
}
164+
}
165+
.padding()
166+
167+
Divider()
168+
169+
#if os(macOS)
170+
CodeEditor(source: $source, language: language, theme: theme,
171+
fontSize: .init(get: { CGFloat(fontSize) },
172+
set: { fontSize = Int($0) }))
173+
.frame(minWidth: 640, minHeight: 480)
174+
#else
175+
CodeEditor(source: $source, language: language, theme: theme)
176+
#endif
177+
}
178+
}
179+
}
180+
181+
struct ContentView_Previews: PreviewProvider {
182+
static var previews: some View {
183+
ContentView()
184+
}
185+
}
186+
```
187+
188+
133189
### Who
134190

135191
SVGWebView is brought to you by [ZeeZide](https://zeezide.de).

0 commit comments

Comments
 (0)