Skip to main content

gpui_component/avatar/
mod.rs

1mod avatar;
2mod avatar_group;
3
4pub use avatar::*;
5pub use avatar_group::*;
6
7use crate::{Icon, Size, StyledExt as _};
8use gpui::{Div, Img, IntoElement, Pixels, Styled, px, rems};
9
10/// Returns the size of the avatar based on the given [`Size`].
11pub(super) fn avatar_size(size: Size) -> Pixels {
12    match size {
13        Size::Large => px(80.),
14        Size::Medium => px(48.),
15        Size::Small => px(24.),
16        Size::XSmall => px(16.),
17        Size::Size(size) => size,
18    }
19}
20
21/// Extension for add `avatar_size` method to `IntoElement` to apply avatar size to element.
22pub(super) trait AvatarSized: IntoElement + Styled {
23    fn avatar_text_size(self, size: Size) -> Self {
24        match size {
25            Size::Large => self.text_3xl().font_semibold(),
26            Size::Medium => self.text_sm(),
27            Size::Small => self.text_xs(),
28            Size::XSmall => self.text_size(rems(0.65)),
29            Size::Size(size) => self.size(size * 0.5),
30        }
31    }
32}
33impl AvatarSized for Div {}
34impl AvatarSized for Icon {}
35impl AvatarSized for Img {}