Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Grid now follows style.visuals.striped setting if not explicitly overwritten #3723

Merged
merged 1 commit into from
Dec 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions crates/egui/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,12 @@ impl Grid {
/// Default is whatever is in [`crate::Visuals::striped`].
pub fn striped(self, striped: bool) -> Self {
if striped {
self.with_row_color(move |row, style| {
if row % 2 == 1 {
return Some(style.visuals.faint_bg_color);
}
None
})
self.with_row_color(striped_row_color)
} else {
self
// Explicitly set the row color to nothing.
// Needed so that when the style.visuals.striped value is checked later on,
// it is clear that the user does not want stripes on this specific Grid.
self.with_row_color(|_row: usize, _style: &Style| None)
}
}

Expand Down Expand Up @@ -410,11 +408,14 @@ impl Grid {
max_cell_size,
spacing,
start_row,
color_picker,
mut color_picker,
} = self;
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);
if color_picker.is_none() && ui.visuals().striped {
color_picker = Some(Box::new(striped_row_color));
}

let id = ui.make_persistent_id(id_source);
let prev_state = State::load(ui.ctx(), id);
Expand Down Expand Up @@ -454,3 +455,10 @@ impl Grid {
})
}
}

fn striped_row_color(row: usize, style: &Style) -> Option<Color32> {
if row % 2 == 1 {
return Some(style.visuals.faint_bg_color);
}
None
}
Loading