diff --git a/Meshtastic/Extensions/UIColor.swift b/Meshtastic/Extensions/UIColor.swift index 482ddc1b..83623967 100644 --- a/Meshtastic/Extensions/UIColor.swift +++ b/Meshtastic/Extensions/UIColor.swift @@ -31,7 +31,7 @@ extension UIColor { } func darker(componentDelta: CGFloat = 0.1) -> UIColor { - return makeColor(componentDelta: -3*componentDelta) + return makeColor(componentDelta: -2*componentDelta) } private func add(_ value: CGFloat, toComponent: CGFloat) -> CGFloat { diff --git a/Meshtastic/Views/Bluetooth/Connect.swift b/Meshtastic/Views/Bluetooth/Connect.swift index c5633eb7..e0be4345 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, fontSize: (node?.user?.shortName ?? "???").isEmoji() ? 52 : (node?.user?.shortName?.count ?? 0 == 4 ? 26 : 36), 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, textColor: UIColor(hex: UInt32(node?.num ?? 0)).isLight() ? .black : .white ) } .padding(.trailing) VStack(alignment: .leading) { diff --git a/Meshtastic/Views/Helpers/CircleText.swift b/Meshtastic/Views/Helpers/CircleText.swift index 2f8ebb05..dcfd7118 100644 --- a/Meshtastic/Views/Helpers/CircleText.swift +++ b/Meshtastic/Views/Helpers/CircleText.swift @@ -8,29 +8,30 @@ import SwiftUI struct CircleText: View { var text: String var color: Color - var circleSize: CGFloat? = 60 - var fontSize: CGFloat? = 20 - var brightness: Double? = 0 + var circleSize: CGFloat? = 45 var textColor: Color? = .white - + var body: some View { - let font = Font.system(size: fontSize!) + let font = Font.system(size: (text.count == 1) ? ((circleSize ?? 45) * 0.75) : (text.count == 2 ? ((circleSize ?? 45) * 0.52) : (text.count == 3 ? ((circleSize ?? 45) * 0.42) : ((circleSize ?? 45) * 0.32)))) ZStack { Circle() .fill(color) - .brightness(brightness ?? 0) .frame(width: circleSize, height: circleSize) - Text(text).textCase(.uppercase).font(font).foregroundColor(textColor).fixedSize() - .frame(width: circleSize, height: circleSize, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/).offset(x: 0, y: 0) + Text(text) + .textCase(.uppercase) + .font(font) + .foregroundColor(textColor) + .fixedSize() + .frame(width: circleSize, height: circleSize, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) } } } struct CircleText_Previews: PreviewProvider { static var previews: some View { - CircleText(text: "MOMO", color: Color.accentColor) + CircleText(text: "MOMO", color: Color.accentColor, 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 f6de23a6..5e73a481 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, fontSize: (node.user?.shortName ?? "???").isEmoji() ? 105 : 55, textColor: UIColor(hex: UInt32(node.num)).isLight() ? .black : .white ) + CircleText(text: node.user?.shortName ?? "???", color: Color(UIColor(hex: UInt32(node.num))), circleSize: 150, textColor: UIColor(hex: UInt32(node.num)).isLight() ? .black : .white) } 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, fontSize: (node.user?.shortName ?? "???").isEmoji() ? 42 : 20, textColor: UIColor(hex: UInt32(node.num)).isLight() ? .black : .white ) + CircleText(text: node.user?.shortName ?? "???", color: Color(UIColor(hex: UInt32(node.num))), circleSize: 65, textColor: UIColor(hex: UInt32(node.num)).isLight() ? .black : .white ) } if node.user != nil { Divider() diff --git a/Meshtastic/Views/Messages/ChannelList.swift b/Meshtastic/Views/Messages/ChannelList.swift index 39c0cff3..dfbf5e9f 100644 --- a/Meshtastic/Views/Messages/ChannelList.swift +++ b/Meshtastic/Views/Messages/ChannelList.swift @@ -47,7 +47,7 @@ struct ChannelList: View { .foregroundColor(.accentColor) .brightness(0.2) } - CircleText(text: String(channel.index), color: .accentColor, circleSize: 45, fontSize: 40) + CircleText(text: String(channel.index), color: .accentColor) .brightness(0.2) VStack(alignment: .leading){ diff --git a/Meshtastic/Views/Messages/ChannelMessageList.swift b/Meshtastic/Views/Messages/ChannelMessageList.swift index 2b91f2dc..a1f83d11 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, fontSize: 14, 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, textColor: UIColor(hex: UInt32(message.fromUser?.num ?? 0)).isLight() ? .black : .white) .padding(.all, 5) .offset(y: -5) } @@ -400,7 +400,7 @@ struct ChannelMessageList: View { .toolbar { ToolbarItem(placement: .principal) { HStack { - CircleText(text: String(channel.index), color: .accentColor, circleSize: 44, fontSize: 30).fixedSize() + CircleText(text: String(channel.index), color: .accentColor, circleSize: 44).fixedSize() Text(String(channel.name ?? "unknown".localized).camelCaseToWords()).font(.headline) } } diff --git a/Meshtastic/Views/Messages/UserList.swift b/Meshtastic/Views/Messages/UserList.swift index 9b0c2c49..7d8f29dd 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))), circleSize: 45, fontSize: (user.shortName ?? "???").isEmoji() ? 32 : (user.shortName?.count ?? 0 == 4 ? 14 : (user.shortName?.count ?? 0 == 3 ? 18 : 22)), brightness: 0.0, textColor: UIColor(hex: UInt32(user.num)).isLight() ? .black : .white) + CircleText(text: user.shortName ?? "???", color: Color(UIColor(hex: UInt32(user.num))), textColor: UIColor(hex: UInt32(user.num)).isLight() ? .black : .white) VStack(alignment: .leading){ HStack{ diff --git a/Meshtastic/Views/Messages/UserMessageList.swift b/Meshtastic/Views/Messages/UserMessageList.swift index da1d899e..5f25bda7 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, fontSize: (user.shortName ?? "???").isEmoji() ? 32 : (user.shortName?.count ?? 0 == 4 ? 14 : (user.shortName?.count ?? 0 == 3 ? 18 : 22)), brightness: 0.0, textColor: UIColor(hex: UInt32(user.num)).isLight() ? .black : .white) + CircleText(text: user.shortName ?? "???", color: Color(UIColor(hex: UInt32(user.num))), circleSize: 44, textColor: UIColor(hex: UInt32(user.num)).isLight() ? .black : .white) } } ToolbarItem(placement: .navigationBarTrailing) { diff --git a/Meshtastic/Views/Nodes/NodeList.swift b/Meshtastic/Views/Nodes/NodeList.swift index 033e7d62..af72c01d 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, fontSize: (node.user?.shortName ?? "???").isEmoji() ? 44 : (node.user?.shortName?.count ?? 0 == 4 ? 19 : 26), brightness: 0.0, textColor: UIColor(hex: UInt32(node.num)).isLight() ? .black : .white) + CircleText(text: node.user?.shortName ?? "???", color: Color(UIColor(hex: UInt32(node.num))), circleSize: 65, textColor: UIColor(hex: UInt32(node.num)).isLight() ? .black : .white) .padding(.trailing, 5) let deviceMetrics = node.telemetries?.filtered(using: NSPredicate(format: "metricsType == 0")) if deviceMetrics?.count ?? 0 >= 1 { diff --git a/Meshtastic/Views/Settings/Channels.swift b/Meshtastic/Views/Settings/Channels.swift index c28b580c..04373b6e 100644 --- a/Meshtastic/Views/Settings/Channels.swift +++ b/Meshtastic/Views/Settings/Channels.swift @@ -64,8 +64,9 @@ struct Channels: View { }) { VStack(alignment: .leading) { HStack { - CircleText(text: String(channel.index), color: .accentColor, circleSize: 45, fontSize: 36, brightness: 0.1) + CircleText(text: String(channel.index), color: .accentColor, circleSize: 45) .padding(.trailing, 5) + .brightness(0.1) VStack { HStack { if channel.name?.isEmpty ?? false {