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
+24 -8
View File
@@ -195,19 +195,33 @@ impl RenderOnce for Sidebar {
.clone()
.unwrap_or_else(|| SharedString::from(self.id.to_string()));
let id_text = self.id.to_string();
let scroll_area_id = (self.id.clone(), "entries");
// Entry paint reads the theme through this borrow.
let row_count = entries
.iter()
.filter(|entry| matches!(entry, SidebarEntry::Row { .. }))
.count();
let mut row_position = 0usize;
let children: Vec<AnyElement> = entries
.iter()
.enumerate()
.map(|(index, entry)| {
let is_row = matches!(entry, SidebarEntry::Row { .. });
if is_row {
row_position += 1;
}
let (position_in_set, size_of_set) = if is_row {
(row_position, row_count)
} else {
(0, 0)
};
render_entry(
cx,
entry,
index,
entries.len(),
position_in_set,
size_of_set,
self.selected == Some(index),
material,
&self.on_change,
@@ -216,9 +230,10 @@ impl RenderOnce for Sidebar {
})
.collect();
let id = self.id;
div()
.id(self.id)
.debug_selector(move || format!("sidebar-{id_text}"))
.id(id.clone())
.debug_selector(move || format!("sidebar-{id}"))
.size_full()
.flex()
.flex_col()
@@ -258,7 +273,8 @@ fn render_entry(
cx: &App,
entry: &SidebarEntry,
index: usize,
count: usize,
position_in_set: usize,
size_of_set: usize,
selected: bool,
material: bool,
on_change: &Option<ChangeHandler>,
@@ -294,8 +310,8 @@ fn render_entry(
.rounded(theme.radius.sm)
.role(Role::ListItem)
.aria_selected(selected)
.aria_position_in_set(index + 1)
.aria_size_of_set(count)
.aria_position_in_set(position_in_set)
.aria_size_of_set(size_of_set)
.map(|row| {
if material && !*row_disabled {
if selected {