Struct egui_extras::TableBody

source ·
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>

source

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.

source

pub fn max_rect(&self) -> Rect

Where in screen-space is the table body?

source

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.

source

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.

source

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}"));
            });
        });
    });
source

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 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());
                });
            });
        });
    });

Trait Implementations§

source§

impl<'a> Drop for TableBody<'a>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for TableBody<'a>

§

impl<'a> !RefUnwindSafe for TableBody<'a>

§

impl<'a> Send for TableBody<'a>

§

impl<'a> Sync for TableBody<'a>

§

impl<'a> Unpin for TableBody<'a>

§

impl<'a> !UnwindSafe for TableBody<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.