Add Visuals::striped as global default for Grids and Tables
This commit is contained in:
parent
51081d69fc
commit
126be51ac3
3 changed files with 25 additions and 8 deletions
|
@ -278,7 +278,7 @@ impl GridLayout {
|
||||||
pub struct Grid {
|
pub struct Grid {
|
||||||
id_source: Id,
|
id_source: Id,
|
||||||
num_columns: Option<usize>,
|
num_columns: Option<usize>,
|
||||||
striped: bool,
|
striped: Option<bool>,
|
||||||
min_col_width: Option<f32>,
|
min_col_width: Option<f32>,
|
||||||
min_row_height: Option<f32>,
|
min_row_height: Option<f32>,
|
||||||
max_cell_size: Vec2,
|
max_cell_size: Vec2,
|
||||||
|
@ -292,7 +292,7 @@ impl Grid {
|
||||||
Self {
|
Self {
|
||||||
id_source: Id::new(id_source),
|
id_source: Id::new(id_source),
|
||||||
num_columns: None,
|
num_columns: None,
|
||||||
striped: false,
|
striped: None,
|
||||||
min_col_width: None,
|
min_col_width: None,
|
||||||
min_row_height: None,
|
min_row_height: None,
|
||||||
max_cell_size: Vec2::INFINITY,
|
max_cell_size: Vec2::INFINITY,
|
||||||
|
@ -310,9 +310,9 @@ impl Grid {
|
||||||
/// If `true`, add a subtle background color to every other row.
|
/// If `true`, add a subtle background color to every other row.
|
||||||
///
|
///
|
||||||
/// This can make a table easier to read.
|
/// This can make a table easier to read.
|
||||||
/// Default: `false`.
|
/// Default is whatever is in [`crate::Visuals::striped`].
|
||||||
pub fn striped(mut self, striped: bool) -> Self {
|
pub fn striped(mut self, striped: bool) -> Self {
|
||||||
self.striped = striped;
|
self.striped = Some(striped);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,6 +371,7 @@ impl Grid {
|
||||||
spacing,
|
spacing,
|
||||||
start_row,
|
start_row,
|
||||||
} = self;
|
} = self;
|
||||||
|
let striped = striped.unwrap_or(ui.visuals().striped);
|
||||||
let min_col_width = min_col_width.unwrap_or_else(|| ui.spacing().interact_size.x);
|
let min_col_width = min_col_width.unwrap_or_else(|| ui.spacing().interact_size.x);
|
||||||
let min_row_height = min_row_height.unwrap_or_else(|| ui.spacing().interact_size.y);
|
let min_row_height = min_row_height.unwrap_or_else(|| ui.spacing().interact_size.y);
|
||||||
let spacing = spacing.unwrap_or_else(|| ui.spacing().item_spacing);
|
let spacing = spacing.unwrap_or_else(|| ui.spacing().item_spacing);
|
||||||
|
|
|
@ -492,6 +492,10 @@ pub struct Visuals {
|
||||||
|
|
||||||
/// Show a background behind collapsing headers.
|
/// Show a background behind collapsing headers.
|
||||||
pub collapsing_header_frame: bool,
|
pub collapsing_header_frame: bool,
|
||||||
|
|
||||||
|
/// Wether or not Grids and Tables should be striped by default
|
||||||
|
/// (have alternating rows differently colored).
|
||||||
|
pub striped: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Visuals {
|
impl Visuals {
|
||||||
|
@ -735,6 +739,8 @@ impl Visuals {
|
||||||
clip_rect_margin: 3.0, // should be at least half the size of the widest frame stroke + max WidgetVisuals::expansion
|
clip_rect_margin: 3.0, // should be at least half the size of the widest frame stroke + max WidgetVisuals::expansion
|
||||||
button_frame: true,
|
button_frame: true,
|
||||||
collapsing_header_frame: false,
|
collapsing_header_frame: false,
|
||||||
|
|
||||||
|
striped: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1259,6 +1265,8 @@ impl Visuals {
|
||||||
clip_rect_margin,
|
clip_rect_margin,
|
||||||
button_frame,
|
button_frame,
|
||||||
collapsing_header_frame,
|
collapsing_header_frame,
|
||||||
|
|
||||||
|
striped,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
ui.collapsing("Background Colors", |ui| {
|
ui.collapsing("Background Colors", |ui| {
|
||||||
|
@ -1315,6 +1323,8 @@ impl Visuals {
|
||||||
ui.checkbox(button_frame, "Button has a frame");
|
ui.checkbox(button_frame, "Button has a frame");
|
||||||
ui.checkbox(collapsing_header_frame, "Collapsing header has a frame");
|
ui.checkbox(collapsing_header_frame, "Collapsing header has a frame");
|
||||||
|
|
||||||
|
ui.checkbox(striped, "By default, add stripes to grids and tables?");
|
||||||
|
|
||||||
ui.vertical_centered(|ui| reset_button(ui, self));
|
ui.vertical_centered(|ui| reset_button(ui, self));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,7 +218,7 @@ impl Default for TableScrollOptions {
|
||||||
pub struct TableBuilder<'a> {
|
pub struct TableBuilder<'a> {
|
||||||
ui: &'a mut Ui,
|
ui: &'a mut Ui,
|
||||||
columns: Vec<Column>,
|
columns: Vec<Column>,
|
||||||
striped: bool,
|
striped: Option<bool>,
|
||||||
resizable: bool,
|
resizable: bool,
|
||||||
cell_layout: egui::Layout,
|
cell_layout: egui::Layout,
|
||||||
scroll_options: TableScrollOptions,
|
scroll_options: TableScrollOptions,
|
||||||
|
@ -230,16 +230,18 @@ impl<'a> TableBuilder<'a> {
|
||||||
Self {
|
Self {
|
||||||
ui,
|
ui,
|
||||||
columns: Default::default(),
|
columns: Default::default(),
|
||||||
striped: false,
|
striped: None,
|
||||||
resizable: false,
|
resizable: false,
|
||||||
cell_layout,
|
cell_layout,
|
||||||
scroll_options: Default::default(),
|
scroll_options: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enable striped row background for improved readability (default: `false`)
|
/// Enable striped row background for improved readability.
|
||||||
|
///
|
||||||
|
/// Default is whatever is in [`egui::Visuals::striped`].
|
||||||
pub fn striped(mut self, striped: bool) -> Self {
|
pub fn striped(mut self, striped: bool) -> Self {
|
||||||
self.striped = striped;
|
self.striped = Some(striped);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,6 +375,8 @@ impl<'a> TableBuilder<'a> {
|
||||||
scroll_options,
|
scroll_options,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
|
let striped = striped.unwrap_or(ui.visuals().striped);
|
||||||
|
|
||||||
let state_id = ui.id().with("__table_state");
|
let state_id = ui.id().with("__table_state");
|
||||||
|
|
||||||
let initial_widths =
|
let initial_widths =
|
||||||
|
@ -431,6 +435,8 @@ impl<'a> TableBuilder<'a> {
|
||||||
scroll_options,
|
scroll_options,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
|
let striped = striped.unwrap_or(ui.visuals().striped);
|
||||||
|
|
||||||
let state_id = ui.id().with("__table_state");
|
let state_id = ui.id().with("__table_state");
|
||||||
|
|
||||||
let initial_widths =
|
let initial_widths =
|
||||||
|
|
Loading…
Reference in a new issue