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 {
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.theme();
let side = theme.sizes.resolve(self.size).avatar_size;
let radius = if self.fully_rounded {
theme.radius.full
} else {
theme.radius.control
theme.radius.sm
};
let side = theme.sizes.resolve(self.size).avatar_size;
let base = h_flex()
.id(ElementId::from(self.id.clone()))
@@ -112,10 +113,12 @@ impl RenderOnce for Avatar {
.refine_style(&self.style);
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 {
seed: fnv1a(self.id.as_bytes()),
side,
radius,
fully_rounded: self.fully_rounded,
}),
}
.into_any_element()
@@ -127,6 +130,8 @@ impl RenderOnce for Avatar {
struct PixelAvatar {
seed: u64,
side: gpui::Pixels,
radius: gpui::Pixels,
fully_rounded: bool,
}
impl RenderOnce for PixelAvatar {
@@ -153,6 +158,12 @@ impl RenderOnce for PixelAvatar {
.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 col in 0..GRID_SIZE {
let value = pattern[row * GRID_SIZE + col];
@@ -176,6 +187,8 @@ impl RenderOnce for PixelAvatar {
.grid_rows(GRID_SIZE as u16)
.size(self.side)
.flex_none()
.p(inset)
.rounded(self.radius)
.bg(gpui::Hsla {
a: PIXEL_AVATAR_TINT_ALPHA,
..main