zed/crates/ui/src/elements/avatar.rs
Marshall Bowers baa07e935e
Extract UI elements from storybook into new ui crate (#3008)
This PR extracts the various UI elements from the `storybook` crate into
a new `ui` library crate.

Release Notes:

- N/A
2023-09-21 19:25:35 -04:00

43 lines
935 B
Rust

use gpui2::elements::img;
use gpui2::style::StyleHelpers;
use gpui2::{ArcCow, Element, IntoElement, ViewContext};
use crate::prelude::*;
use crate::theme;
#[derive(Element, Clone)]
pub struct Avatar {
src: ArcCow<'static, str>,
shape: Shape,
}
pub fn avatar(src: impl Into<ArcCow<'static, str>>) -> Avatar {
Avatar {
src: src.into(),
shape: Shape::Circle,
}
}
impl Avatar {
pub fn shape(mut self, shape: Shape) -> Self {
self.shape = shape;
self
}
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
let theme = theme(cx);
let mut img = img();
if self.shape == Shape::Circle {
img = img.rounded_full();
} else {
img = img.rounded_md();
}
img.uri(self.src.clone())
.size_4()
.fill(theme.middle.warning.default.foreground)
}
}