Files
TerminalUI-mirror/Sources/sample/main.swift
Chris Eidhof 86092f63cd VStack sample
2021-05-10 07:56:30 +02:00

44 lines
1.2 KiB
Swift

import TerminalUI
var horizontal: some BuiltinView {
HStack(children: [
Text("Hello")
.padding()
.foregroundColor(.blue)
.border()
.padding()
.backgroundColor(.red),
Text("Testing A Longer Text")
.frame(maxWidth: .max)
.border()
.padding(),
ZStack(alignment: .center, children: [
Text("Test").padding().border(),
Text("+").backgroundColor(.green)
]),
Text(["This", "is", "a", "truncation", "test"].joined(separator: "\n")) // todo: fix this crash
], alignment: .bottom)
.overlay(Text("[x]", color: .red), alignment: .topTrailing)
.overlay(GeometryReader(alignment: .bottom) { size in
Text("\(size.width)\(size.height)")
})
.border()
}
func rootView(_ char: Int32?) -> some BuiltinView {
var alignment: HorizontalAlignment = .center
if char == 108 { alignment = .leading }
if char == 114 { alignment = .trailing }
return VStack(alignment: alignment, children: [
Text("Hello"),
Text("\(char ?? 0)"),
Text("Sunny World")
.border(style: .ascii)
]).padding()
.border()
}
run(rootView)