feat: add basic profile panel
This commit is contained in:
@@ -113,10 +113,9 @@ impl Styled for Avatar {
|
||||
}
|
||||
|
||||
impl RenderOnce for Avatar {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let size = self.size;
|
||||
let side = size.avatar_rems() * window.rem_size();
|
||||
|
||||
let radius = if self.fully_rounded {
|
||||
theme.radius.full
|
||||
@@ -143,7 +142,6 @@ impl RenderOnce for Avatar {
|
||||
.when(!has_picture, |avatar| {
|
||||
avatar.child(PixelAvatar {
|
||||
seed,
|
||||
side,
|
||||
radius,
|
||||
fully_rounded: self.fully_rounded,
|
||||
})
|
||||
@@ -155,7 +153,6 @@ impl RenderOnce for Avatar {
|
||||
#[derive(IntoElement)]
|
||||
struct PixelAvatar {
|
||||
seed: u64,
|
||||
side: Pixels,
|
||||
radius: Pixels,
|
||||
fully_rounded: bool,
|
||||
}
|
||||
@@ -207,16 +204,11 @@ impl RenderOnce for PixelAvatar {
|
||||
.to_hsla()
|
||||
};
|
||||
|
||||
let inset = if self.fully_rounded {
|
||||
self.side / GRID_SIZE as f32
|
||||
} else {
|
||||
Pixels::ZERO
|
||||
};
|
||||
let fully_rounded = self.fully_rounded;
|
||||
|
||||
div()
|
||||
.flex_none()
|
||||
.size(self.side)
|
||||
.p(inset)
|
||||
.size_full()
|
||||
.rounded(self.radius)
|
||||
.bg(Hsla {
|
||||
a: PIXEL_AVATAR_TINT_ALPHA,
|
||||
@@ -224,18 +216,33 @@ impl RenderOnce for PixelAvatar {
|
||||
})
|
||||
.child(
|
||||
canvas(
|
||||
|bounds, _, _| bounds.size,
|
||||
move |bounds, area, window, _| {
|
||||
let cell = area.width / GRID_SIZE as f32;
|
||||
move |bounds, _, _| {
|
||||
// Rounded avatars keep one empty cell between art and edge.
|
||||
let inset = if fully_rounded {
|
||||
bounds.size.width / GRID_SIZE as f32
|
||||
} else {
|
||||
Pixels::ZERO
|
||||
};
|
||||
|
||||
Bounds {
|
||||
origin: bounds.origin + point(inset, inset),
|
||||
size: size(
|
||||
bounds.size.width - inset * 2.0,
|
||||
bounds.size.height - inset * 2.0,
|
||||
),
|
||||
}
|
||||
},
|
||||
move |_bounds, area, window, _| {
|
||||
let cell = area.size.width / GRID_SIZE as f32;
|
||||
for (index, value) in pattern.iter().enumerate() {
|
||||
if *value == 0 {
|
||||
continue;
|
||||
}
|
||||
let color = if *value == 2 { shade } else { main };
|
||||
let top_left = bounds.origin
|
||||
let top_left = area.origin
|
||||
+ point(
|
||||
(index % GRID_SIZE) as f32 * cell,
|
||||
(index / GRID_SIZE) as f32 * cell,
|
||||
cell * (index % GRID_SIZE) as f32,
|
||||
cell * (index / GRID_SIZE) as f32,
|
||||
);
|
||||
window.paint_quad(fill(
|
||||
Bounds {
|
||||
|
||||
@@ -236,8 +236,13 @@ impl RenderOnce for DropdownMenu {
|
||||
})
|
||||
};
|
||||
|
||||
let trigger_bounds: TriggerBoundsCell = Rc::new(RefCell::new(None));
|
||||
let chevron_bounds: TriggerBoundsCell = Rc::new(RefCell::new(None));
|
||||
// Keyed so the panel can anchor to bounds captured by the last paint.
|
||||
let trigger_bounds: TriggerBoundsCell = window
|
||||
.use_keyed_state((self.id.clone(), "trigger-bounds"), cx, |_, _| {
|
||||
Rc::new(RefCell::new(None)) as TriggerBoundsCell
|
||||
})
|
||||
.read(cx)
|
||||
.clone();
|
||||
|
||||
let items = if self.open {
|
||||
self.items
|
||||
@@ -247,6 +252,7 @@ impl RenderOnce for DropdownMenu {
|
||||
Rc::from([])
|
||||
};
|
||||
|
||||
let chevron_bounds: TriggerBoundsCell = Rc::new(RefCell::new(None));
|
||||
let on_close = Some(on_open.clone());
|
||||
|
||||
let spec = MenuPanelSpec {
|
||||
|
||||
@@ -295,6 +295,7 @@ impl Theme {
|
||||
let window_variant = ThemeVariant::from_appearance(window.appearance());
|
||||
let theme = cx.global::<Theme>();
|
||||
let engine = cx.global::<ThemeEngine>();
|
||||
|
||||
if engine.mode_override.is_none()
|
||||
&& engine
|
||||
.preset
|
||||
@@ -538,9 +539,11 @@ impl ThemeEngine {
|
||||
let preset = engine.preset.as_ref().map(|(_, def)| def.clone());
|
||||
let mode_override = engine.mode_override;
|
||||
let custom = engine.custom.clone();
|
||||
|
||||
let variant = mode_override
|
||||
.or(preset.as_ref().and_then(|def| def.mode()))
|
||||
.unwrap_or(system_appearance);
|
||||
|
||||
(
|
||||
preset,
|
||||
mode_override,
|
||||
@@ -552,8 +555,10 @@ impl ThemeEngine {
|
||||
let resolved = ResolvedTheme::resolve(&system, preset.as_ref(), mode_override, custom);
|
||||
|
||||
cx.set_reduce_motion(resolved.accessibility.reduce_motion);
|
||||
|
||||
let theme = Theme::from_resolved(resolved);
|
||||
let theme_changed = cx.try_global::<Theme>() != Some(&theme);
|
||||
|
||||
if theme_changed {
|
||||
cx.set_global(theme);
|
||||
cx.refresh_windows();
|
||||
|
||||
Reference in New Issue
Block a user