mirror of
https://github.com/zed-industries/zed.git
synced 2024-10-26 08:31:04 +00:00
baa07e935e
This PR extracts the various UI elements from the `storybook` crate into a new `ui` library crate. Release Notes: - N/A
43 lines
935 B
Rust
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)
|
|
}
|
|
}
|