pub struct Grid {
id_salt: Id,
num_columns: Option<usize>,
min_col_width: Option<f32>,
min_row_height: Option<f32>,
max_cell_size: Vec2,
spacing: Option<Vec2>,
start_row: usize,
color_picker: Option<Box<dyn Send + Sync + Fn(usize, &Style) -> Option<Color32>>>,
}
Expand description
A simple grid layout.
The cells are always laid out left to right, top-down. The contents of each cell will be aligned to the left and center.
If you want to add multiple widgets to a cell you need to group them with
Ui::horizontal
, Ui::vertical
etc.
egui::Grid::new("some_unique_id").show(ui, |ui| {
ui.label("First row, first column");
ui.label("First row, second column");
ui.end_row();
ui.label("Second row, first column");
ui.label("Second row, second column");
ui.label("Second row, third column");
ui.end_row();
ui.horizontal(|ui| { ui.label("Same"); ui.label("cell"); });
ui.label("Third row, second column");
ui.end_row();
});
Fields§
§id_salt: Id
§num_columns: Option<usize>
§min_col_width: Option<f32>
§min_row_height: Option<f32>
§max_cell_size: Vec2
§spacing: Option<Vec2>
§start_row: usize
§color_picker: Option<Box<dyn Send + Sync + Fn(usize, &Style) -> Option<Color32>>>
Implementations§
source§impl Grid
impl Grid
sourcepub fn with_row_color<F>(self, color_picker: F) -> Self
pub fn with_row_color<F>(self, color_picker: F) -> Self
Setting this will allow for dynamic coloring of rows of the grid object
sourcepub fn num_columns(self, num_columns: usize) -> Self
pub fn num_columns(self, num_columns: usize) -> Self
Setting this will allow the last column to expand to take up the rest of the space of the parent Ui
.
sourcepub fn striped(self, striped: bool) -> Self
pub fn striped(self, striped: bool) -> Self
If true
, add a subtle background color to every other row.
This can make a table easier to read.
Default is whatever is in crate::Visuals::striped
.
sourcepub fn min_col_width(self, min_col_width: f32) -> Self
pub fn min_col_width(self, min_col_width: f32) -> Self
Set minimum width of each column.
Default: crate::style::Spacing::interact_size
.x
.
sourcepub fn min_row_height(self, min_row_height: f32) -> Self
pub fn min_row_height(self, min_row_height: f32) -> Self
Set minimum height of each row.
Default: crate::style::Spacing::interact_size
.y
.
sourcepub fn max_col_width(self, max_col_width: f32) -> Self
pub fn max_col_width(self, max_col_width: f32) -> Self
Set soft maximum width (wrapping width) of each column.
sourcepub fn spacing(self, spacing: impl Into<Vec2>) -> Self
pub fn spacing(self, spacing: impl Into<Vec2>) -> Self
Set spacing between columns/rows.
Default: crate::style::Spacing::item_spacing
.
sourcepub fn start_row(self, start_row: usize) -> Self
pub fn start_row(self, start_row: usize) -> Self
Change which row number the grid starts on.
This can be useful when you have a large crate::Grid
inside of crate::ScrollArea::show_rows
.