1use gpui2::elements::img;
2use gpui2::ArcCow;
3
4use crate::prelude::*;
5use crate::theme;
6
7#[derive(Element, Clone)]
8pub struct Avatar {
9 src: ArcCow<'static, str>,
10 shape: Shape,
11}
12
13impl Avatar {
14 pub fn new(src: impl Into<ArcCow<'static, str>>) -> Self {
15 Self {
16 src: src.into(),
17 shape: Shape::Circle,
18 }
19 }
20
21 pub fn shape(mut self, shape: Shape) -> Self {
22 self.shape = shape;
23 self
24 }
25
26 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
27 let theme = theme(cx);
28
29 let mut img = img();
30
31 if self.shape == Shape::Circle {
32 img = img.rounded_full();
33 } else {
34 img = img.rounded_md();
35 }
36
37 img.uri(self.src.clone())
38 .size_4()
39 .fill(theme.middle.warning.default.foreground)
40 }
41}