ui: render person 'followed', name line more uniform

This commit is contained in:
Mike Dilger 2022-12-31 13:51:05 +13:00
parent 63d1b3d8ab
commit 9994072485
3 changed files with 28 additions and 65 deletions

View File

@ -258,21 +258,7 @@ fn render_post(
ui.vertical(|ui| { ui.vertical(|ui| {
// First row // First row
ui.horizontal(|ui| { ui.horizontal(|ui| {
if let Some(person) = maybe_person { GossipUi::render_person_name_line(ui, maybe_person.as_ref());
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());
}
}
}
ui.add_space(8.0); ui.add_space(8.0);

View File

@ -14,7 +14,7 @@ use crate::error::Error;
use crate::globals::GLOBALS; use crate::globals::GLOBALS;
use crate::settings::Settings; use crate::settings::Settings;
use eframe::{egui, IconData, Theme}; 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 nostr_types::{Id, PublicKey, PublicKeyHex};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use zeroize::Zeroize; use zeroize::Zeroize;
@ -230,4 +230,28 @@ impl GossipUi {
let hex: PublicKeyHex = (*pubkey).into(); let hex: PublicKeyHex = (*pubkey).into();
hex.0 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());
}
}
}
});
}
} }

View File

@ -142,29 +142,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.vertical(|ui| { ui.vertical(|ui| {
ui.label(RichText::new(GossipUi::hex_pubkey_short(&person.pubkey)).weak()); ui.label(RichText::new(GossipUi::hex_pubkey_short(&person.pubkey)).weak());
GossipUi::render_person_name_line(ui, Some(person));
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(),
);
}
}
});
}); });
}); });
@ -194,32 +172,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.vertical(|ui| { ui.vertical(|ui| {
ui.label(RichText::new(GossipUi::hex_pubkey_short(&person.pubkey)).weak()); ui.label(RichText::new(GossipUi::hex_pubkey_short(&person.pubkey)).weak());
GossipUi::render_person_name_line(ui, Some(person));
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");
}
});
}); });
}); });