1use crate::prelude::*;
2use gpui::{img, Img, RenderOnce};
3
4#[derive(RenderOnce)]
5pub struct Avatar {
6 src: SharedString,
7 shape: Shape,
8}
9
10impl Component for Avatar {
11 type Rendered = Img;
12
13 fn render(self, _: &mut WindowContext) -> Self::Rendered {
14 let mut img = img();
15
16 if self.shape == Shape::Circle {
17 img = img.rounded_full();
18 } else {
19 img = img.rounded_md();
20 }
21
22 img.uri(self.src.clone())
23 .size_4()
24 // todo!(Pull the avatar fallback background from the theme.)
25 .bg(gpui::red())
26 }
27}
28
29impl Avatar {
30 pub fn new(src: impl Into<SharedString>) -> Self {
31 Self {
32 src: src.into(),
33 shape: Shape::Circle,
34 }
35 }
36
37 pub fn shape(mut self, shape: Shape) -> Self {
38 self.shape = shape;
39 self
40 }
41}