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