perf: get item.height() less often on render

This commit is contained in:
EdJoPaTo
2024-02-24 00:36:32 +01:00
parent 2781a2d146
commit 4130a800b8
+11 -7
View File
@@ -228,17 +228,20 @@ where
let mut end = start; let mut end = start;
let mut height = 0; let mut height = 0;
for Flattened { item, .. } in visible.iter().skip(start) { for item_height in visible
if height + item.height() > available_height { .iter()
.skip(start)
.map(|flattened| flattened.item.height())
{
if height + item_height > available_height {
break; break;
} }
height += item_height;
height += item.height();
end += 1; end += 1;
} }
while state.ensure_selected_in_view_on_next_render && selected_index >= end { while state.ensure_selected_in_view_on_next_render && selected_index >= end {
height = height.saturating_add(visible[end].item.height()); height += visible[end].item.height();
end += 1; end += 1;
while height > available_height { while height > available_height {
height = height.saturating_sub(visible[start].item.height()); height = height.saturating_sub(visible[start].item.height());
@@ -271,13 +274,14 @@ where
let x = area.x; let x = area.x;
let y = area.y + current_height; let y = area.y + current_height;
current_height += item.height() as u16; let height = item.height() as u16;
current_height += height;
let area = Rect { let area = Rect {
x, x,
y, y,
width: area.width, width: area.width,
height: item.height() as u16, height,
}; };
let item_style = self.style.patch(item.style); let item_style = self.style.patch(item.style);