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 {
|
||||
id_source: Id,
|
||||
num_columns: Option<usize>,
|
||||
striped: bool,
|
||||
striped: Option<bool>,
|
||||
min_col_width: Option<f32>,
|
||||
min_row_height: Option<f32>,
|
||||
max_cell_size: Vec2,
|
||||
|
@ -292,7 +292,7 @@ impl Grid {
|
|||
Self {
|
||||
id_source: Id::new(id_source),
|
||||
num_columns: None,
|
||||
striped: false,
|
||||
striped: None,
|
||||
min_col_width: None,
|
||||
min_row_height: None,
|
||||
max_cell_size: Vec2::INFINITY,
|
||||
|
@ -310,9 +310,9 @@ impl Grid {
|
|||
/// If `true`, add a subtle background color to every other row.
|
||||
///
|
||||
/// 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 {
|
||||
self.striped = striped;
|
||||
self.striped = Some(striped);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -371,6 +371,7 @@ impl Grid {
|
|||
spacing,
|
||||
start_row,
|
||||
} = 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_row_height = min_row_height.unwrap_or_else(|| ui.spacing().interact_size.y);
|
||||
let spacing = spacing.unwrap_or_else(|| ui.spacing().item_spacing);
|
||||
|
|
|
@ -492,6 +492,10 @@ pub struct Visuals {
|
|||
|
||||
/// Show a background behind collapsing headers.
|
||||
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 {
|
||||
|
@ -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
|
||||
button_frame: true,
|
||||
collapsing_header_frame: false,
|
||||
|
||||
striped: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1259,6 +1265,8 @@ impl Visuals {
|
|||
clip_rect_margin,
|
||||
button_frame,
|
||||
collapsing_header_frame,
|
||||
|
||||
striped,
|
||||
} = self;
|
||||
|
||||
ui.collapsing("Background Colors", |ui| {
|
||||
|
@ -1315,6 +1323,8 @@ impl Visuals {
|
|||
ui.checkbox(button_frame, "Button 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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -218,7 +218,7 @@ impl Default for TableScrollOptions {
|
|||
pub struct TableBuilder<'a> {
|
||||
ui: &'a mut Ui,
|
||||
columns: Vec<Column>,
|
||||
striped: bool,
|
||||
striped: Option<bool>,
|
||||
resizable: bool,
|
||||
cell_layout: egui::Layout,
|
||||
scroll_options: TableScrollOptions,
|
||||
|
@ -230,16 +230,18 @@ impl<'a> TableBuilder<'a> {
|
|||
Self {
|
||||
ui,
|
||||
columns: Default::default(),
|
||||
striped: false,
|
||||
striped: None,
|
||||
resizable: false,
|
||||
cell_layout,
|
||||
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 {
|
||||
self.striped = striped;
|
||||
self.striped = Some(striped);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -373,6 +375,8 @@ impl<'a> TableBuilder<'a> {
|
|||
scroll_options,
|
||||
} = self;
|
||||
|
||||
let striped = striped.unwrap_or(ui.visuals().striped);
|
||||
|
||||
let state_id = ui.id().with("__table_state");
|
||||
|
||||
let initial_widths =
|
||||
|
@ -431,6 +435,8 @@ impl<'a> TableBuilder<'a> {
|
|||
scroll_options,
|
||||
} = self;
|
||||
|
||||
let striped = striped.unwrap_or(ui.visuals().striped);
|
||||
|
||||
let state_id = ui.id().with("__table_state");
|
||||
|
||||
let initial_widths =
|
||||
|
|
Loading…
Reference in a new issue