<img width="1384" alt="image" src="https://github.com/user-attachments/assets/1e66aa8c-0c87-4d8d-abb7-38e5f616fe3e" /> <img width="1384" alt="image" src="https://github.com/user-attachments/assets/bd32b6e0-aa0f-4d01-af9f-4bfaea1a3718" />
39 lines
1.1 KiB
Rust
39 lines
1.1 KiB
Rust
mod avatar;
|
|
mod avatar_group;
|
|
|
|
pub use avatar::*;
|
|
pub use avatar_group::*;
|
|
|
|
use crate::{Icon, Size, StyledExt as _};
|
|
use gpui::{px, rems, Div, Img, IntoElement, Pixels, Styled};
|
|
|
|
/// Returns the size of the avatar based on the given [`Size`].
|
|
pub(super) fn avatar_size(size: Size) -> Pixels {
|
|
match size {
|
|
Size::Large => px(80.),
|
|
Size::Medium => px(48.),
|
|
Size::Small => px(24.),
|
|
Size::XSmall => px(20.),
|
|
Size::Size(size) => size,
|
|
}
|
|
}
|
|
|
|
/// Extension for add `avatar_size` method to `IntoElement` to apply avatar size to element.
|
|
pub(super) trait AvatarSized: IntoElement + Styled {
|
|
fn avatar_size(self, size: Size) -> Self {
|
|
self.size(avatar_size(size))
|
|
}
|
|
|
|
fn avatar_text_size(self, size: Size) -> Self {
|
|
match size {
|
|
Size::Large => self.text_3xl().font_semibold(),
|
|
Size::Medium => self.text_sm(),
|
|
Size::Small => self.text_xs(),
|
|
Size::XSmall => self.text_size(rems(0.65)),
|
|
Size::Size(size) => self.size(size * 0.5),
|
|
}
|
|
}
|
|
}
|
|
impl AvatarSized for Div {}
|
|
impl AvatarSized for Icon {}
|
|
impl AvatarSized for Img {}
|