From 445e44cd1e77ba1719cdb7e20433262a6b273d19 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 11 Apr 2022 14:14:42 -0700 Subject: [PATCH] EventView: example pow coloring Definitely not final design, but neat demo Signed-off-by: William Casarin --- damus/Views/EventView.swift | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift index 844d403b..532a9339 100644 --- a/damus/Views/EventView.swift +++ b/damus/Views/EventView.swift @@ -34,12 +34,18 @@ struct EventView: View { } VStack { - Text(String(profile?.name ?? String(event.pubkey.prefix(16)))) - .bold() - .onTapGesture { - UIPasteboard.general.string = event.pubkey - } - .frame(maxWidth: .infinity, alignment: .leading) + HStack { + Text(String(profile?.name ?? String(event.pubkey.prefix(16)))) + .bold() + .onTapGesture { + UIPasteboard.general.string = event.pubkey + } + .frame(maxWidth: .infinity, alignment: .leading) + Spacer() + Text("\(event.pow ?? 0)") + .font(.callout) + .foregroundColor(calculate_pow_color(event.pow ?? 0)) + } Text(event.content) .textSelection(.enabled) .frame(maxWidth: .infinity, alignment: .leading) @@ -53,3 +59,9 @@ struct EventView: View { } } + +func calculate_pow_color(_ pow: Int) -> Color +{ + let x = Double(pow) / 30.0; + return Color(.sRGB, red: 2.0 * (1.0 - x), green: 2.0 * x, blue: 0, opacity: 1.0) +}