core: round avatar and pixel avatar corners

This commit is contained in:
2026-11-12 20:26:58 +07:00
parent e2ec1fa7c2
commit 306644e581
+16 -3
View File
@@ -92,12 +92,13 @@ impl gpui::Styled for Avatar {
impl RenderOnce for Avatar { impl RenderOnce for Avatar {
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.theme(); let theme = cx.theme();
let side = theme.sizes.resolve(self.size).avatar_size;
let radius = if self.fully_rounded { let radius = if self.fully_rounded {
theme.radius.full theme.radius.full
} else { } else {
theme.radius.control theme.radius.sm
}; };
let side = theme.sizes.resolve(self.size).avatar_size;
let base = h_flex() let base = h_flex()
.id(ElementId::from(self.id.clone())) .id(ElementId::from(self.id.clone()))
@@ -112,10 +113,12 @@ impl RenderOnce for Avatar {
.refine_style(&self.style); .refine_style(&self.style);
match self.picture { match self.picture {
Some(url) => base.child(gpui::img(url).size_full()), Some(url) => base.child(gpui::img(url).size_full().rounded(radius)),
None => base.child(PixelAvatar { None => base.child(PixelAvatar {
seed: fnv1a(self.id.as_bytes()), seed: fnv1a(self.id.as_bytes()),
side, side,
radius,
fully_rounded: self.fully_rounded,
}), }),
} }
.into_any_element() .into_any_element()
@@ -127,6 +130,8 @@ impl RenderOnce for Avatar {
struct PixelAvatar { struct PixelAvatar {
seed: u64, seed: u64,
side: gpui::Pixels, side: gpui::Pixels,
radius: gpui::Pixels,
fully_rounded: bool,
} }
impl RenderOnce for PixelAvatar { impl RenderOnce for PixelAvatar {
@@ -153,6 +158,12 @@ impl RenderOnce for PixelAvatar {
.to_hsla() .to_hsla()
}; };
let inset = if self.fully_rounded {
self.side / GRID_SIZE as f32
} else {
gpui::Pixels::ZERO
};
for row in 0..GRID_SIZE { for row in 0..GRID_SIZE {
for col in 0..GRID_SIZE { for col in 0..GRID_SIZE {
let value = pattern[row * GRID_SIZE + col]; let value = pattern[row * GRID_SIZE + col];
@@ -176,6 +187,8 @@ impl RenderOnce for PixelAvatar {
.grid_rows(GRID_SIZE as u16) .grid_rows(GRID_SIZE as u16)
.size(self.side) .size(self.side)
.flex_none() .flex_none()
.p(inset)
.rounded(self.radius)
.bg(gpui::Hsla { .bg(gpui::Hsla {
a: PIXEL_AVATAR_TINT_ALPHA, a: PIXEL_AVATAR_TINT_ALPHA,
..main ..main