damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | LICENSE

commit 445e44cd1e77ba1719cdb7e20433262a6b273d19
parent c7e3664831944bf0e85bc38043a9777113b637d2
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 11 Apr 2022 14:14:42 -0700

EventView: example pow coloring

Definitely not final design, but neat demo

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/Views/EventView.swift | 24++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)

diff --git 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) +}