pub struct TableBody<'a> { /* private fields */ }
Expand description
The body of a table.
Is created by calling body
on a Table
(after adding a header row) or TableBuilder
(without a header row).
Implementations§
Source§impl<'a> TableBody<'a>
impl<'a> TableBody<'a>
Sourcepub fn ui_mut(&mut self) -> &mut Ui
pub fn ui_mut(&mut self) -> &mut Ui
Access the contained egui::Ui
.
You can use this to e.g. modify the egui::Style
with egui::Ui::style_mut
.
Sourcepub fn widths(&self) -> &[f32]
pub fn widths(&self) -> &[f32]
Return a vector containing all column widths for this table body.
This is primarily meant for use with TableBody::heterogeneous_rows
in cases where row
heights are expected to according to the width of one or more cells – for example, if text
is wrapped rather than clipped within the cell.
Sourcepub fn row(
&mut self,
height: f32,
add_row_content: impl FnOnce(TableRow<'a, '_>),
)
pub fn row( &mut self, height: f32, add_row_content: impl FnOnce(TableRow<'a, '_>), )
Add a single row with the given height.
⚠️ It is much more performant to use Self::rows
or Self::heterogeneous_rows
,
as those functions will only render the visible rows.
Sourcepub fn rows(
self,
row_height_sans_spacing: f32,
total_rows: usize,
add_row_content: impl FnMut(TableRow<'_, '_>),
)
pub fn rows( self, row_height_sans_spacing: f32, total_rows: usize, add_row_content: impl FnMut(TableRow<'_, '_>), )
Add many rows with same height.
Is a lot more performant than adding each individual row as non visible rows must not be rendered.
If you need many rows with different heights, use Self::heterogeneous_rows
instead.
§Example
use egui_extras::{TableBuilder, Column};
TableBuilder::new(ui)
.column(Column::remainder().at_least(100.0))
.body(|mut body| {
let row_height = 18.0;
let num_rows = 10_000;
body.rows(row_height, num_rows, |mut row| {
let row_index = row.index();
row.col(|ui| {
ui.label(format!("First column of row {row_index}"));
});
});
});
Sourcepub fn heterogeneous_rows(
self,
heights: impl Iterator<Item = f32>,
add_row_content: impl FnMut(TableRow<'_, '_>),
)
pub fn heterogeneous_rows( self, heights: impl Iterator<Item = f32>, add_row_content: impl FnMut(TableRow<'_, '_>), )
Add rows with varying heights.
This takes a very slight performance hit compared to TableBody::rows
due to the need to
iterate over all row heights in order to calculate the virtual table height above and below the
visible region, but it is many orders of magnitude more performant than adding individual
heterogeneously-sized rows using TableBody::row
at the cost of the additional complexity
that comes with pre-calculating row heights and representing them as an iterator.
§Example
use egui_extras::{TableBuilder, Column};
TableBuilder::new(ui)
.column(Column::remainder().at_least(100.0))
.body(|mut body| {
let row_heights: Vec<f32> = vec![60.0, 18.0, 31.0, 240.0];
body.heterogeneous_rows(row_heights.into_iter(), |mut row| {
let row_index = row.index();
let thick = row_index % 6 == 0;
row.col(|ui| {
ui.centered_and_justified(|ui| {
ui.label(row_index.to_string());
});
});
});
});