1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

egui_extras: follow closure-based conventions for TableBody.heterogeneous_rows

This commit is contained in:
Wayne Warren
2022-04-03 11:18:13 -06:00
parent ab4930fde7
commit 44bd8c1cc4
2 changed files with 33 additions and 38 deletions

View File

@@ -351,15 +351,16 @@ pub struct TableBody<'a> {
end_y: f32,
}
pub trait TableRowBuilder {
fn row_heights(&self, widths: &Vec<f32>) -> Box<dyn Iterator<Item = f32> + '_>;
fn populate_row(&self, index: usize, row: TableRow<'_, '_>);
}
impl<'a> TableBody<'a> {
pub fn heterogeneous_rows(mut self, builder: impl TableRowBuilder) {
let mut heights = builder.row_heights(&self.widths);
pub fn widths(&self) -> &Vec<f32> {
&self.widths
}
pub fn heterogeneous_rows(
&mut self,
mut heights: impl Iterator<Item = f32>,
mut populate_row: impl FnMut(usize, TableRow<'_, '_>),
) {
let max_height = self.end_y - self.start_y;
let delta = self.start_y - self.layout.current_y();
@@ -398,7 +399,7 @@ impl<'a> TableBody<'a> {
height: height,
};
self.row_nr += 1;
builder.populate_row(row_index, tr);
populate_row(row_index, tr);
row_index += 1;
current_height += height;
continue;