Skip to content

Commit

Permalink
Box ColorPickerFn
Browse files Browse the repository at this point in the history
  • Loading branch information
skairunner committed Jun 12, 2021
1 parent 64664c3 commit 9756d07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions egui/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl GuiColor {

/// Provided either a row or column number, return a color to paint for the background.
/// Returning None means painting is skipped.
pub type ColorPickerFn = fn(usize) -> Option<GuiColor>;
pub type ColorPickerFn = Box<dyn Fn(usize) -> Option<GuiColor>>;

/// Describe conditional colors for a grid.
/// All predicates are evaluated for each row/col, and colors will be painted on top of each other.
Expand Down Expand Up @@ -486,7 +486,7 @@ impl Grid {

// Set convenience color specs
if row_stripes {
grid.color_spec.row_pickers.push(|row| {
grid.color_spec.row_pickers.push(Box::new(move |row| {
if row % 2 == 0 {
Some(GuiColor::light_dark(
Rgba::from_black_alpha(0.075),
Expand All @@ -495,11 +495,11 @@ impl Grid {
} else {
None
}
});
}));
}

if header_row {
grid.color_spec.row_pickers.push(|row| {
grid.color_spec.row_pickers.push(Box::new(|row| {
if row == 0 {
Some(GuiColor::light_dark(
Rgba::from_black_alpha(0.75),
Expand All @@ -508,7 +508,7 @@ impl Grid {
} else {
None
}
});
}));
}

// ---
Expand Down
4 changes: 2 additions & 2 deletions egui_demo_lib/src/apps/demo/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ impl super::View for GridTest {
.min_col_width(self.min_col_width)
.max_col_width(self.max_col_width);
if self.with_column_stripes {
grid = grid.add_column_color(|col| {
grid = grid.add_column_color(Box::new(|col| {
if col % 2 == 0 {
Some(Rgba::from_rgba_premultiplied(0.01, 0.01, 0.01, 0.01).into())
} else {
None
}
});
}));
}
grid.show(ui, |ui| {
for row in 0..self.num_rows {
Expand Down

0 comments on commit 9756d07

Please sign in to comment.