1
0
forked from GRIN/grim

gui: remove avatar name ring

Names never affect the avatar anymore: claimed and anonymous identities
render identically (picture or pubkey-seeded gradient). Drops
gradient_avatar_ringed/name_ring/is_named and the ringed rows in the
avatar_ring example sheet.
This commit is contained in:
2ro
2026-07-02 22:31:06 -04:00
parent 54344bd1d3
commit c83771bbf8
2 changed files with 14 additions and 75 deletions
+6 -22
View File
@@ -1,6 +1,6 @@
//! G1 sizing-checkpoint harness: renders the REAL `avatar_tex` (custom-image
//! avatar + username conic ring) and `gradient_avatar` across every size the
//! app uses, so the ring thickness/inset can be dialed in by eye.
//! Avatar sizing-checkpoint harness: renders the REAL `avatar_tex` (custom
//! image, no ring) and `gradient_avatar` across every size the app uses.
//! Names never affect the avatar — this just checks sizing by eye.
//! Run: `cargo run --example avatar_ring` (screenshots taken externally).
use eframe::egui;
@@ -14,7 +14,7 @@ struct App {
}
/// A synthetic "profile photo": diagonal two-tone blend with a light disc, so
/// the ring is judged against something photo-like rather than a flat fill.
/// sizing is judged against something photo-like rather than a flat fill.
fn photo(ctx: &egui::Context, name: &str, a: [u8; 3], b: [u8; 3]) -> egui::TextureHandle {
const N: usize = 128;
let mut px = Vec::with_capacity(N * N);
@@ -60,9 +60,7 @@ impl eframe::App for App {
.frame(egui::Frame::default().fill(egui::Color32::from_rgb(0xFA, 0xFA, 0xF7)))
.show(ctx, |ui| {
ui.add_space(10.0);
ui.heading(
"G1 avatar ring — sizing sheet (thickness = max(1, size*0.06), gap = max(1, size*0.03))",
);
ui.heading("avatar sizing sheet (no ring — names never affect the avatar)");
ui.add_space(12.0);
for (i, name) in NAMES.iter().enumerate() {
ui.horizontal(|ui| {
@@ -76,7 +74,7 @@ impl eframe::App for App {
ui.add_space(14.0);
}
ui.separator();
ui.label("anonymous npub (grinmark gradient, ring-less):");
ui.label("anonymous npub (grinmark gradient):");
ui.add_space(8.0);
ui.horizontal(|ui| {
ui.add_space(12.0);
@@ -86,20 +84,6 @@ impl eframe::App for App {
w::gradient_avatar(ui, &format!("{i}deadbeef{i}"), *size);
}
});
ui.add_space(14.0);
ui.label("named account (SAME gradient, unchanged) + username ring:");
ui.add_space(8.0);
for name in NAMES {
ui.horizontal(|ui| {
ui.add_space(12.0);
ui.label(format!("{name:>7}"));
for size in SIZES {
ui.add_space(14.0);
w::gradient_avatar_ringed(ui, "deadbeefcafe", name, size);
}
});
ui.add_space(6.0);
}
ui.add_space(10.0);
ui.horizontal(|ui| {
ui.add_space(12.0);
+8 -53
View File
@@ -27,44 +27,18 @@ pub fn amount_str(atomic: u64) -> String {
grin_core::core::amount_to_hr_string(atomic, true)
}
/// A custom-picture avatar: the texture drawn to fill the circle, with a thin
/// light-yellow outline hugging its edge when the identity is a claimed name.
pub fn avatar_tex(ui: &mut Ui, tex: &egui::TextureHandle, name: &str, size: f32) -> Response {
/// A custom-picture avatar: the texture drawn to fill the circle. Names never
/// affect the avatar — claimed and anonymous identities render identically.
pub fn avatar_tex(ui: &mut Ui, tex: &egui::TextureHandle, _name: &str, size: f32) -> Response {
let (rect, resp) = ui.allocate_exact_size(Vec2::splat(size), Sense::click());
let rounding = eframe::epaint::CornerRadius::same((rect.width() / 2.0) as u8);
egui::Image::new(tex)
.corner_radius(rounding)
.fit_to_exact_size(rect.size())
.paint_at(ui, rect);
if is_named(name) {
name_ring(ui, rect.center(), size);
}
resp
}
/// A thin light-yellow outline on the avatar's edge — the marker of a claimed
/// name. Just an outline that touches the circle (no gap, no gradient); the
/// yellow reads as "this identity has a name" and nothing more.
fn name_ring(ui: &Ui, center: egui::Pos2, size: f32) {
let thickness = (size * 0.03).max(1.0);
// Goblin accent yellow, lightened toward white so the outline stays soft.
let c = super::theme::tokens().accent;
let light = Color32::from_rgb(
c.r().saturating_add((255 - c.r()) / 3),
c.g().saturating_add((255 - c.g()) / 3),
c.b().saturating_add((255 - c.b()) / 3),
);
// Sit the stroke just inside the perimeter so it stays fully on-canvas.
let radius = size / 2.0 - thickness / 2.0;
ui.painter()
.circle_stroke(center, radius, egui::Stroke::new(thickness, light));
}
/// Whether a display name is a real claimed name (not empty, not a bare npub).
fn is_named(name: &str) -> bool {
!name.is_empty() && !name.starts_with("npub")
}
/// Deterministic gradient avatar (a pubkey-seeded two-tone tile with the Grin
/// mark on top) — the fallback for anonymous nostr users. `id` is the npub or
/// hex pubkey; the image is a pure function of it, so the same key always draws
@@ -75,18 +49,6 @@ pub fn gradient_avatar(ui: &mut Ui, id: &str, size: f32) -> Response {
resp
}
/// The UNCHANGED npub-seeded grinmark gradient orb with a thin light-yellow
/// outline hugging its edge to mark a claimed name — the orb fills the circle
/// exactly as a ring-less avatar draws it; the outline is all the name adds.
pub fn gradient_avatar_ringed(ui: &mut Ui, id: &str, name: &str, size: f32) -> Response {
let (rect, resp) = ui.allocate_exact_size(Vec2::splat(size), Sense::click());
paint_gradient(ui, id, rect);
if is_named(name) {
name_ring(ui, rect.center(), size);
}
resp
}
/// Paint the pubkey-seeded grinmark gradient into `rect` (rasterized at 2x,
/// cached by egui via the `uri`).
fn paint_gradient(ui: &mut Ui, id: &str, rect: egui::Rect) {
@@ -103,11 +65,11 @@ fn paint_gradient(ui: &mut Ui, id: &str, rect: egui::Rect) {
.paint_at(ui, rect);
}
/// Picture avatar (with the username conic ring) when a texture exists;
/// otherwise the deterministic pubkey-seeded grinmark gradient for everyone,
/// named or anonymous. When no pubkey is known (last resort) the name seeds the
/// gradient instead, so the tile is still deterministic. `id` is the npub/hex
/// used to seed the gradient.
/// Picture avatar when a texture exists; otherwise the deterministic
/// pubkey-seeded grinmark gradient for everyone, named or anonymous — names
/// never affect the avatar. When no pubkey is known (last resort) the name
/// seeds the gradient instead, so the tile is still deterministic. `id` is
/// the npub/hex used to seed the gradient.
pub fn avatar_any(
ui: &mut Ui,
name: &str,
@@ -115,15 +77,8 @@ pub fn avatar_any(
size: f32,
tex: Option<&egui::TextureHandle>,
) -> Response {
// A conic ring (seeded by the username) marks a CLAIMED identity — on a
// custom picture or the grinmark gradient. Anonymous keys (the display name
// is still an `npub…`) stay ring-less.
let named = !name.is_empty() && !name.starts_with("npub");
match tex {
Some(t) => avatar_tex(ui, t, name, size),
None if named => {
gradient_avatar_ringed(ui, if id.is_empty() { name } else { id }, name, size)
}
None if !id.is_empty() => gradient_avatar(ui, id, size),
None => gradient_avatar(ui, name, size),
}