chore: reduce component overhead (#3)

Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
2026-11-09 10:09:56 +00:00
parent 6815585528
commit 1c091db699
44 changed files with 1376 additions and 1241 deletions
+11 -30
View File
@@ -1,12 +1,10 @@
use std::cell::RefCell;
use gpui::prelude::FluentBuilder as _;
use std::rc::Rc;
use gpui::prelude::FluentBuilder as _;
use gpui::{
Animation, AnimationExt as _, AnyElement, App, Bounds, ElementId, FontWeight,
InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent,
ParentElement as _, Pixels, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
Styled as _, Window, canvas, div, ease_out_quint, relative,
Animation, AnimationExt as _, AnyElement, App, ElementId, FontWeight, InteractiveElement as _,
IntoElement, KeyDownEvent, MouseButton, ParentElement as _, RenderOnce, Role, SharedString,
StatefulInteractiveElement as _, Styled as _, Window, canvas, div, ease_out_quint, relative,
};
use gpui_native_theme::ActiveTheme as _;
@@ -16,9 +14,6 @@ use crate::common::v_flex;
pub type ChangeHandler = Rc<dyn Fn(bool, &mut Window, &mut App)>;
type ContentFn = Box<dyn Fn(&mut Window, &mut App) -> AnyElement>;
type ActionsFn = Box<dyn Fn(&mut Window, &mut App) -> Vec<AnyElement>>;
/// Bounds captured during the last paint, shared with the scrim listener.
type BoundsCell = Rc<RefCell<Option<Bounds<Pixels>>>>;
/// A centred panel over a dim scrim: the platform's modal.
#[derive(IntoElement)]
pub struct Dialog {
@@ -165,7 +160,6 @@ impl RenderOnce for Dialog {
let content = self.content.map(|build| build(window, cx));
let actions = self.actions.map(|build| build(window, cx));
let panel_bounds: BoundsCell = Rc::new(RefCell::new(None));
let panel = v_flex()
.id("dialog-panel")
@@ -211,19 +205,13 @@ impl RenderOnce for Dialog {
panel.child(div().flex().justify_end().gap_2().children(actions))
})
.child(
canvas(
{
let cell = panel_bounds.clone();
move |bounds, _window, _cx| *cell.borrow_mut() = Some(bounds)
},
{
move |_, _, window, cx| {
if !focus.contains_focused(window, cx) {
window.focus(&focus, cx);
}
canvas(|_, _, _| {}, {
move |_, _, window, cx| {
if !focus.contains_focused(window, cx) {
window.focus(&focus, cx);
}
},
)
}
})
.absolute()
.inset_0(),
);
@@ -235,15 +223,8 @@ impl RenderOnce for Dialog {
.occlude()
.when(!alert, |scrim| {
scrim.on_mouse_down(MouseButton::Left, {
let panel_bounds = panel_bounds.clone();
let on_change = on_change.clone();
move |event: &MouseDownEvent, _window, cx| {
let on_panel = panel_bounds
.borrow()
.is_some_and(|bounds| bounds.contains(&event.position));
if on_panel {
return;
}
move |_, _window, cx| {
if let Some(on_change) = &on_change {
on_change(false, _window, cx);
}