egui_extras: fix row indexing

This commit is contained in:
Wayne Warren 2022-04-03 20:03:11 -06:00
parent 91d78fa2e9
commit 51a98d586b

View file

@ -421,7 +421,7 @@ impl<'a> TableBody<'a> {
// iterator with the boolean built in based on the enumerated index of the iterator element // iterator with the boolean built in based on the enumerated index of the iterator element
let mut striped_heights = heights let mut striped_heights = heights
.enumerate() .enumerate()
.map(|(index, height)| (index % 2 == 0, height)); .map(|(index, height)| (index, index % 2 == 0, height));
let max_height = self.end_y - self.start_y + VIRTUAL_EXTENSION; let max_height = self.end_y - self.start_y + VIRTUAL_EXTENSION;
let delta = self.delta() - VIRTUAL_EXTENSION; let delta = self.delta() - VIRTUAL_EXTENSION;
@ -431,16 +431,13 @@ impl<'a> TableBody<'a> {
// cumulative height of all rows below those being displayed // cumulative height of all rows below those being displayed
let mut height_below_visible: f64 = 0.0; let mut height_below_visible: f64 = 0.0;
let mut row_index = 0;
// calculate height above visible table range // calculate height above visible table range
while let Some((_, height)) = striped_heights.next() { while let Some((_, _, height)) = striped_heights.next() {
// when delta is greater than height above 0, we need to increment the row index and // when delta is greater than height above 0, we need to increment the row index and
// update the height above visble with the current height then continue // update the height above visble with the current height then continue
if height_above_visible >= delta as f64 { if height_above_visible >= delta as f64 {
break; break;
} }
row_index += 1;
height_above_visible += height as f64; height_above_visible += height as f64;
} }
@ -452,7 +449,7 @@ impl<'a> TableBody<'a> {
// populate visible rows // populate visible rows
let mut current_height: f64 = 0.0; // used to track height of visible rows let mut current_height: f64 = 0.0; // used to track height of visible rows
while let Some((striped, height)) = striped_heights.next() { while let Some((row_index, striped, height)) = striped_heights.next() {
if current_height > max_height as f64 { if current_height > max_height as f64 {
break; break;
} }
@ -464,12 +461,11 @@ impl<'a> TableBody<'a> {
}; };
self.row_nr += 1; self.row_nr += 1;
populate_row(row_index, tr); populate_row(row_index, tr);
row_index += 1;
current_height += height as f64; current_height += height as f64;
} }
// calculate height below the visible table range // calculate height below the visible table range
while let Some((_, height)) = striped_heights.next() { while let Some((_, _, height)) = striped_heights.next() {
height_below_visible += height as f64 height_below_visible += height as f64
} }