chore: reduce component overhead (#3)

Reviewed-on: reya/gpui-native-kit#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
+16 -11
View File
@@ -32,6 +32,8 @@ pub enum TabsVariant {
/// One tab of a [`Tabs`] strip.
pub struct Tab {
/// The stable identity for element state; must survive reordering.
key: ElementId,
label: SharedString,
icon: Option<IconRole>,
lead: Option<AnyElement>,
@@ -42,12 +44,14 @@ pub struct Tab {
}
impl Tab {
/// Creates a tab with this label.
pub fn new<L>(label: L) -> Self
/// Creates a tab shown as `label`, identified by `key`.
pub fn new<K, L>(key: K, label: L) -> Self
where
K: Into<ElementId>,
L: Into<SharedString>,
{
Self {
key: key.into(),
label: label.into(),
icon: None,
lead: None,
@@ -210,7 +214,6 @@ impl RenderOnce for Tabs {
cx,
tab,
index,
self.selected == index,
self.selected,
self.variant,
&self.on_change,
@@ -268,7 +271,6 @@ fn render_tab(
cx: &App,
tab: Tab,
index: usize,
selected: bool,
selected_index: usize,
variant: TabsVariant,
on_change: &Option<ChangeHandler>,
@@ -276,6 +278,7 @@ fn render_tab(
focus: &gpui::FocusHandle,
) -> AnyElement {
let mut tab = tab;
let selected = index == selected_index;
let theme = cx.theme();
let metrics = theme.sizes.resolve(Size::default());
@@ -301,10 +304,11 @@ fn render_tab(
};
let mut strip_tab = div()
.id(("tab", index))
.id((tab.key.clone(), "tab"))
.debug_selector({
let id = format!("{tabs_id}-tab-{}", tab.label);
move || id
let tabs_id = tabs_id.clone();
let label = tab.label.clone();
move || format!("{tabs_id}-tab-{}", label)
})
.flex()
.items_center()
@@ -364,7 +368,7 @@ fn render_tab(
if tab.busy && !tab.disabled {
strip_tab = strip_tab.child(
Spinner::new(("tab-busy", index))
Spinner::new((tab.key.clone(), "tab-busy"))
.small()
.accessibility_label("Loading"),
);
@@ -401,14 +405,15 @@ fn render_tab_close(
index: usize,
on_close: &Option<CloseHandler>,
) -> AnyElement {
Button::new(("tab-close", index))
Button::new((tab.key.clone(), "tab-close"))
.icon(IconRole::Close)
.variant(ButtonVariant::Ghost)
.small()
.tab_stop(false)
.debug_selector({
let id = format!("{tabs_id}-close-{}", tab.label);
move || id.clone()
let tabs_id = tabs_id.clone();
let label = tab.label.clone();
move || format!("{tabs_id}-close-{}", label)
})
.tooltip(Tooltip::text("Close"))
.accessibility_label(SharedString::from(format!("Close {}", tab.label)))