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