From 06f39d40f20cf059b6b9b264ad2ab31015918834 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 2 Sep 2023 18:02:51 -0700 Subject: [PATCH] Remove another circletext parameter --- Meshtastic/Views/Bluetooth/Connect.swift | 2 +- Meshtastic/Views/Helpers/CircleText.swift | 29 +++++++++++++------ .../Views/Helpers/Node/NodeInfoView.swift | 4 +-- .../Views/Messages/ChannelMessageList.swift | 2 +- Meshtastic/Views/Messages/UserList.swift | 2 +- .../Views/Messages/UserMessageList.swift | 2 +- Meshtastic/Views/Nodes/NodeList.swift | 2 +- 7 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Meshtastic/Views/Bluetooth/Connect.swift b/Meshtastic/Views/Bluetooth/Connect.swift index 25be7d12..545ba52d 100644 --- a/Meshtastic/Views/Bluetooth/Connect.swift +++ b/Meshtastic/Views/Bluetooth/Connect.swift @@ -49,7 +49,7 @@ struct Connect: View { if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.state == .connected { HStack { VStack(alignment: .center) { - CircleText(text: node?.user?.shortName ?? "?", color: Color(UIColor(hex: UInt32(node?.num ?? 0))), circleSize: 90, textColor: UIColor(hex: UInt32(node?.num ?? 0)).isLight() ? .black : .white ) + CircleText(text: node?.user?.shortName ?? "?", color: Color(UIColor(hex: UInt32(node?.num ?? 0))), circleSize: 90) } .padding(.trailing) VStack(alignment: .leading) { diff --git a/Meshtastic/Views/Helpers/CircleText.swift b/Meshtastic/Views/Helpers/CircleText.swift index 66cbb746..3b84b0d8 100644 --- a/Meshtastic/Views/Helpers/CircleText.swift +++ b/Meshtastic/Views/Helpers/CircleText.swift @@ -9,7 +9,6 @@ struct CircleText: View { var text: String var color: Color var circleSize: CGFloat = 45 - var textColor: Color? = .white var body: some View { @@ -19,21 +18,33 @@ struct CircleText: View { .frame(width: circleSize, height: circleSize) Text(text) .textCase(.uppercase) - .foregroundColor(textColor) + .foregroundColor(color.isLight() ? .black : .white) .font(.system(size: 500)) .minimumScaleFactor(0.001) - .frame(width: circleSize * 0.90, - height: circleSize * 0.90, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) + .frame(width: circleSize * 0.94, height: circleSize * 0.94, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) } } } struct CircleText_Previews: PreviewProvider { static var previews: some View { - CircleText(text: "MOMO", color: Color.accentColor, circleSize: 80) - CircleText(text: "WWWW", color: Color.accentColor, circleSize: 80) - CircleText(text: "LCP", color: Color.accentColor, circleSize: 80) - CircleText(text: "8", color: Color.accentColor, circleSize: 80) - .previewLayout(.fixed(width: 300, height: 100)) + VStack { + CircleText(text: "MOMO", color: Color.secondary, circleSize: 80) + .previewLayout(.fixed(width: 300, height: 100)) + CircleText(text: "WWWW", color: Color.accentColor, circleSize: 80) + .previewLayout(.fixed(width: 300, height: 100)) + CircleText(text: "LCP", color: Color.primary, circleSize: 80) + .previewLayout(.fixed(width: 300, height: 100)) + CircleText(text: "69", color: Color.green, circleSize: 80) + .previewLayout(.fixed(width: 300, height: 100)) + 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)) + } } } diff --git a/Meshtastic/Views/Helpers/Node/NodeInfoView.swift b/Meshtastic/Views/Helpers/Node/NodeInfoView.swift index da95af44..8e30b7ea 100644 --- a/Meshtastic/Views/Helpers/Node/NodeInfoView.swift +++ b/Meshtastic/Views/Helpers/Node/NodeInfoView.swift @@ -27,7 +27,7 @@ struct NodeInfoView: View { if UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac { HStack { VStack(alignment: .center) { - CircleText(text: node.user?.shortName ?? "?", color: Color(UIColor(hex: UInt32(node.num))), circleSize: 150, textColor: UIColor(hex: UInt32(node.num)).isLight() ? .black : .white) + CircleText(text: node.user?.shortName ?? "?", color: Color(UIColor(hex: UInt32(node.num))), circleSize: 150) } Divider() VStack { @@ -123,7 +123,7 @@ struct NodeInfoView: View { HStack { VStack(alignment: .center) { - CircleText(text: node.user?.shortName ?? "?", color: Color(UIColor(hex: UInt32(node.num))), circleSize: 65, textColor: UIColor(hex: UInt32(node.num)).isLight() ? .black : .white ) + CircleText(text: node.user?.shortName ?? "?", color: Color(UIColor(hex: UInt32(node.num))), circleSize: 65) } if node.user != nil { Divider() diff --git a/Meshtastic/Views/Messages/ChannelMessageList.swift b/Meshtastic/Views/Messages/ChannelMessageList.swift index 45a0e16b..15336573 100644 --- a/Meshtastic/Views/Messages/ChannelMessageList.swift +++ b/Meshtastic/Views/Messages/ChannelMessageList.swift @@ -56,7 +56,7 @@ struct ChannelMessageList: View { HStack(alignment: .top) { if currentUser { Spacer(minLength: 50) } if !currentUser { - CircleText(text: message.fromUser?.shortName ?? "?", color: Color(UIColor(hex: UInt32(message.fromUser?.num ?? 0))), circleSize: 44, textColor: UIColor(hex: UInt32(message.fromUser?.num ?? 0)).isLight() ? .black : .white) + CircleText(text: message.fromUser?.shortName ?? "?", color: Color(UIColor(hex: UInt32(message.fromUser?.num ?? 0))), circleSize: 44) .padding(.all, 5) .offset(y: -5) } diff --git a/Meshtastic/Views/Messages/UserList.swift b/Meshtastic/Views/Messages/UserList.swift index 7a7e8a3d..1e88d615 100644 --- a/Meshtastic/Views/Messages/UserList.swift +++ b/Meshtastic/Views/Messages/UserList.swift @@ -56,7 +56,7 @@ struct UserList: View { .brightness(0.2) } - CircleText(text: user.shortName ?? "?", color: Color(UIColor(hex: UInt32(user.num))), textColor: UIColor(hex: UInt32(user.num)).isLight() ? .black : .white) + CircleText(text: user.shortName ?? "?", color: Color(UIColor(hex: UInt32(user.num)))) VStack(alignment: .leading){ HStack{ diff --git a/Meshtastic/Views/Messages/UserMessageList.swift b/Meshtastic/Views/Messages/UserMessageList.swift index bfe09a1e..68dfbbd8 100644 --- a/Meshtastic/Views/Messages/UserMessageList.swift +++ b/Meshtastic/Views/Messages/UserMessageList.swift @@ -363,7 +363,7 @@ struct UserMessageList: View { .toolbar { ToolbarItem(placement: .principal) { HStack { - CircleText(text: user.shortName ?? "?", color: Color(UIColor(hex: UInt32(user.num))), circleSize: 44, textColor: UIColor(hex: UInt32(user.num)).isLight() ? .black : .white) + CircleText(text: user.shortName ?? "?", color: Color(UIColor(hex: UInt32(user.num))), circleSize: 44) } } ToolbarItem(placement: .navigationBarTrailing) { diff --git a/Meshtastic/Views/Nodes/NodeList.swift b/Meshtastic/Views/Nodes/NodeList.swift index 5bde18ca..8cd324e5 100644 --- a/Meshtastic/Views/Nodes/NodeList.swift +++ b/Meshtastic/Views/Nodes/NodeList.swift @@ -47,7 +47,7 @@ struct NodeList: View { LazyVStack(alignment: .leading) { HStack { VStack(alignment: .leading) { - CircleText(text: node.user?.shortName ?? "?", color: Color(UIColor(hex: UInt32(node.num))), circleSize: 65, textColor: UIColor(hex: UInt32(node.num)).isLight() ? .black : .white) + CircleText(text: node.user?.shortName ?? "?", color: Color(UIColor(hex: UInt32(node.num))), circleSize: 65) .padding(.trailing, 5) let deviceMetrics = node.telemetries?.filtered(using: NSPredicate(format: "metricsType == 0")) if deviceMetrics?.count ?? 0 >= 1 {