From e05dd78dd2b8794416779d91a5dee93151780cee Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 10 Dec 2024 12:12:32 +0100 Subject: [PATCH] list: compute tail height Instead of using a bad esitimation. Signed-off-by: Dietmar Maurer --- src/widget/list.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/widget/list.rs b/src/widget/list.rs index 86c6897..abbcd2f 100644 --- a/src/widget/list.rs +++ b/src/widget/list.rs @@ -176,6 +176,18 @@ impl SizeAccumulator { height + rest * min_row_height, ) } + + fn compute_tail_height(&mut self, row_count: usize, end: usize, min_row_height: u64) -> u64 { + if self.height_list.len() < row_count { + self.height_list.resize(row_count, min_row_height); + } + + let mut height = 0u64; + for i in ((end + 1)..row_count).rev() { + height += self.height_list[i]; + } + height + } } #[doc(hidden)] @@ -287,7 +299,13 @@ impl PwtList { let offset_end = offset as f64 + self.table_height; - let height = offset_end + item_count.saturating_sub(end) as f64 * self.row_height; + let tail_height = self.start_space.compute_tail_height( + props.item_count as usize, + end as usize, + props.min_row_height, + ); + + let height = offset_end + tail_height as f64; self.scroll_info = VirtualScrollInfo { start, -- 2.39.5