Meshtastic-Apple/Meshtastic/Views/Helpers/CircleText.swift

84 lines
2.7 KiB
Swift
Raw Normal View History

/*
Abstract:
A view draws a circle in the background of the shortName text
*/
import SwiftUI
2025-04-01 23:57:37 -07:00
import CoreData
struct CircleText: View {
2025-04-01 23:57:37 -07:00
var text: String
var color: Color
var circleSize: CGFloat = 45
2025-04-27 14:04:47 -07:00
2025-04-01 23:57:37 -07:00
var body: some View {
circleContent
2025-04-01 23:57:37 -07:00
}
2025-04-01 23:57:37 -07:00
var circleContent: some View {
ZStack {
Circle()
.fill(color)
.frame(width: circleSize, height: circleSize)
Text(text)
.frame(width: circleSize * 0.9, height: circleSize * 0.9, alignment: .center)
2023-09-02 18:02:51 -07:00
.foregroundColor(color.isLight() ? .black : .white)
2024-05-28 13:27:25 -07:00
.minimumScaleFactor(0.001)
2024-05-31 20:39:45 -07:00
.font(.system(size: 1300))
2025-04-01 23:57:37 -07:00
}
}
}
struct CircleText_Previews: PreviewProvider {
2025-04-01 23:57:37 -07:00
static var previews: some View {
2024-04-26 08:18:49 -07:00
VStack {
HStack {
2023-10-21 15:33:00 -07:00
CircleText(text: "N1", color: Color.yellow, circleSize: 80)
.previewLayout(.fixed(width: 300, height: 100))
CircleText(text: "8", color: Color.purple, circleSize: 80)
.previewLayout(.fixed(width: 300, height: 100))
CircleText(text: "😝", color: Color.red, circleSize: 80)
.previewLayout(.fixed(width: 300, height: 100))
CircleText(text: "🍔", color: Color.brown, circleSize: 80)
.previewLayout(.fixed(width: 300, height: 100))
2024-04-26 08:18:49 -07:00
}
HStack {
2023-10-21 15:33:00 -07:00
CircleText(text: "👻", color: Color.orange, circleSize: 80)
.previewLayout(.fixed(width: 300, height: 100))
CircleText(text: "🤙", color: Color.orange, circleSize: 80)
.previewLayout(.fixed(width: 300, height: 100))
CircleText(text: "69", color: Color.green, circleSize: 80)
.previewLayout(.fixed(width: 300, height: 100))
CircleText(text: "WWWW", color: Color.cyan, circleSize: 80)
.previewLayout(.fixed(width: 300, height: 100))
2024-04-26 08:18:49 -07:00
}
HStack {
2023-10-21 15:33:00 -07:00
CircleText(text: "CW-A", color: Color.secondary)
.previewLayout(.fixed(width: 300, height: 100))
CircleText(text: "CW-A", color: Color.secondary, circleSize: 80)
.previewLayout(.fixed(width: 300, height: 100))
CircleText(text: "MOMO", color: Color.mint, circleSize: 80)
.previewLayout(.fixed(width: 300, height: 100))
CircleText(text: "IIII", color: Color.accentColor, circleSize: 80)
.previewLayout(.fixed(width: 300, height: 100))
2024-04-26 08:18:49 -07:00
}
HStack {
2024-04-26 08:18:49 -07:00
CircleText(text: "🚗", color: Color.orange)
.previewLayout(.fixed(width: 300, height: 100))
CircleText(text: "🔋", color: Color.indigo, circleSize: 80)
.previewLayout(.fixed(width: 300, height: 100))
CircleText(text: "🛢️", color: Color.orange, circleSize: 80)
.previewLayout(.fixed(width: 300, height: 100))
CircleText(text: "LCP", color: Color.indigo, circleSize: 80)
.previewLayout(.fixed(width: 300, height: 100))
}
HStack {
CircleText(text: "🤡", color: Color.red, circleSize: 80)
2023-10-21 15:33:00 -07:00
.previewLayout(.fixed(width: 300, height: 100))
}
2023-09-02 18:02:51 -07:00
}
2025-04-01 23:57:37 -07:00
}
}