chore: reduce component overhead (#3)
Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
+11
-18
@@ -4,7 +4,10 @@ use gpui::{
|
||||
App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role,
|
||||
SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, div,
|
||||
};
|
||||
use gpui_native_theme::{ActiveTheme as _, Oklch, Size, ThemeVariant};
|
||||
use gpui_native_theme::{
|
||||
ActiveTheme as _, Oklch, PIXEL_AVATAR_DARK_FACTOR, PIXEL_AVATAR_DARK_FLOOR,
|
||||
PIXEL_AVATAR_LIGHT_CAP, PIXEL_AVATAR_LIGHT_LIFT, PIXEL_AVATAR_TINT_ALPHA, Size, ThemeVariant,
|
||||
};
|
||||
|
||||
use crate::common::{Sizable, StyledExt, h_flex};
|
||||
|
||||
@@ -108,12 +111,10 @@ impl RenderOnce for Avatar {
|
||||
.refine_style(&self.style);
|
||||
|
||||
match self.picture {
|
||||
Some(url) => base.child(gpui::img(url).size_full().rounded(radius)),
|
||||
Some(url) => base.child(gpui::img(url).size_full()),
|
||||
None => base.child(PixelAvatar {
|
||||
seed: fnv1a(self.id.as_bytes()),
|
||||
side,
|
||||
radius,
|
||||
style: self.style,
|
||||
}),
|
||||
}
|
||||
.into_any_element()
|
||||
@@ -125,14 +126,6 @@ impl RenderOnce for Avatar {
|
||||
struct PixelAvatar {
|
||||
seed: u64,
|
||||
side: gpui::Pixels,
|
||||
radius: gpui::Pixels,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl gpui::Styled for PixelAvatar {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for PixelAvatar {
|
||||
@@ -147,13 +140,13 @@ impl RenderOnce for PixelAvatar {
|
||||
|
||||
let shade = if theme.variant == ThemeVariant::Dark {
|
||||
Oklch {
|
||||
l: (accent.l * 1.6).min(0.95),
|
||||
l: (accent.l * PIXEL_AVATAR_LIGHT_LIFT).min(PIXEL_AVATAR_LIGHT_CAP),
|
||||
..Oklch::from_hsla(main)
|
||||
}
|
||||
.to_hsla()
|
||||
} else {
|
||||
Oklch {
|
||||
l: (accent.l * 0.45).max(0.18),
|
||||
l: (accent.l * PIXEL_AVATAR_DARK_FACTOR).max(PIXEL_AVATAR_DARK_FLOOR),
|
||||
..Oklch::from_hsla(main)
|
||||
}
|
||||
.to_hsla()
|
||||
@@ -182,11 +175,11 @@ impl RenderOnce for PixelAvatar {
|
||||
.grid_rows(GRID_SIZE as u16)
|
||||
.size(self.side)
|
||||
.flex_none()
|
||||
.rounded(self.radius)
|
||||
.overflow_hidden()
|
||||
.bg(gpui::Hsla { a: 0.16, ..main })
|
||||
.bg(gpui::Hsla {
|
||||
a: PIXEL_AVATAR_TINT_ALPHA,
|
||||
..main
|
||||
})
|
||||
.children(cells)
|
||||
.refine_style(&self.style)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user