From 9994072485a2c25eaba29c7c82ffe6550c652dae Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Sat, 31 Dec 2022 13:51:05 +1300 Subject: [PATCH] ui: render person 'followed', name line more uniform --- src/ui/feed.rs | 16 +-------------- src/ui/mod.rs | 26 +++++++++++++++++++++++- src/ui/people.rs | 51 ++---------------------------------------------- 3 files changed, 28 insertions(+), 65 deletions(-) diff --git a/src/ui/feed.rs b/src/ui/feed.rs index 82f59fdf..144c149d 100644 --- a/src/ui/feed.rs +++ b/src/ui/feed.rs @@ -258,21 +258,7 @@ fn render_post( ui.vertical(|ui| { // First row ui.horizontal(|ui| { - if let Some(person) = maybe_person { - if let Some(name) = &person.name { - ui.label(RichText::new(name).strong()); - } else { - ui.label(RichText::new(GossipUi::pubkey_short(&event.pubkey)).weak()); - } - - if let Some(dns_id) = &person.dns_id { - if person.dns_id_valid > 0 { - ui.label(RichText::new(dns_id).monospace().small()); - } else { - ui.label(RichText::new(dns_id).monospace().small().strikethrough()); - } - } - } + GossipUi::render_person_name_line(ui, maybe_person.as_ref()); ui.add_space(8.0); diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 75746369..c7ae0538 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -14,7 +14,7 @@ use crate::error::Error; use crate::globals::GLOBALS; use crate::settings::Settings; use eframe::{egui, IconData, Theme}; -use egui::{ColorImage, Context, ImageData, TextureHandle, TextureOptions}; +use egui::{ColorImage, Context, ImageData, RichText, TextureHandle, TextureOptions, Ui}; use nostr_types::{Id, PublicKey, PublicKeyHex}; use std::time::{Duration, Instant}; use zeroize::Zeroize; @@ -230,4 +230,28 @@ impl GossipUi { let hex: PublicKeyHex = (*pubkey).into(); hex.0 } + + pub fn render_person_name_line(ui: &mut Ui, maybe_person: Option<&DbPerson>) { + ui.horizontal(|ui| { + if let Some(person) = maybe_person { + if let Some(name) = &person.name { + ui.label(RichText::new(name).strong()); + } else { + ui.label(RichText::new(GossipUi::hex_pubkey_short(&person.pubkey)).weak()); + } + + if person.followed > 0 { + ui.label("🚶"); + } + + if let Some(dns_id) = &person.dns_id { + if person.dns_id_valid > 0 { + ui.label(RichText::new(dns_id).monospace().small()); + } else { + ui.label(RichText::new(dns_id).monospace().small().strikethrough()); + } + } + } + }); + } } diff --git a/src/ui/people.rs b/src/ui/people.rs index 38a94da7..766311a1 100644 --- a/src/ui/people.rs +++ b/src/ui/people.rs @@ -142,29 +142,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra ui.vertical(|ui| { ui.label(RichText::new(GossipUi::hex_pubkey_short(&person.pubkey)).weak()); - - ui.horizontal(|ui| { - if let Some(name) = &person.name { - ui.label(RichText::new(name).strong()); - } else { - ui.label( - RichText::new(GossipUi::hex_pubkey_short(&person.pubkey)) - .weak(), - ); - } - - ui.add_space(24.0); - - if let Some(dns_id) = &person.dns_id { - if person.dns_id_valid > 0 { - ui.label(RichText::new(dns_id).monospace().small()); - } else { - ui.label( - RichText::new(dns_id).monospace().small().strikethrough(), - ); - } - } - }); + GossipUi::render_person_name_line(ui, Some(person)); }); }); @@ -194,32 +172,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra ui.vertical(|ui| { ui.label(RichText::new(GossipUi::hex_pubkey_short(&person.pubkey)).weak()); - - ui.horizontal(|ui| { - if let Some(name) = &person.name { - ui.label(RichText::new(name).strong()); - } else { - ui.label( - RichText::new(GossipUi::hex_pubkey_short(&person.pubkey)).weak(), - ); - } - - ui.add_space(24.0); - - if let Some(dns_id) = &person.dns_id { - if person.dns_id_valid > 0 { - ui.label(RichText::new(dns_id).monospace().small()); - } else { - ui.label(RichText::new(dns_id).monospace().small().strikethrough()); - } - } - - if person.followed > 0 { - ui.label("FOLLOWED"); - } else { - ui.label("not followed"); - } - }); + GossipUi::render_person_name_line(ui, Some(person)); }); });