Skip to content

Commit

Permalink
Fix: Renamings and other superficial changes
Browse files Browse the repository at this point in the history
  • Loading branch information
skairunner committed Jun 9, 2021
1 parent b8b7c42 commit d6c6fbe
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
34 changes: 12 additions & 22 deletions egui/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ impl GridLayout {
}

/// Paint the background for the next row & columns.
pub(crate) fn do_paint(&mut self, min: Pos2, painter: &Painter) {
pub(crate) fn paint(&mut self, cursor_min: Pos2, painter: &Painter) {
for p in &self.color_spec.row_pickers {
if let Some(color) = p(self.row) {
self.paint_row(min, color, painter)
self.paint_row(cursor_min, color, painter)
}
}
// Only paint columns when we're on the first row.
Expand All @@ -310,7 +310,7 @@ impl GridLayout {
// Iterate over columns
for col in 0..self.prev_state.dimensions().y {
if let Some(color) = p(col) {
self.paint_column(col, min, color, painter);
self.paint_column(col, cursor_min, color, painter);
}
}
}
Expand All @@ -325,7 +325,7 @@ impl GridLayout {
self.col = 0;
self.row += 1;

self.do_paint(cursor.min, painter);
self.paint(cursor.min, painter);
}

pub(crate) fn save(&self) {
Expand Down Expand Up @@ -369,7 +369,7 @@ impl GridLayout {
#[must_use = "You should call .show()"]
pub struct Grid {
id_source: Id,
striped: bool,
row_stripes: bool,
header_row: bool,
min_col_width: Option<f32>,
min_row_height: Option<f32>,
Expand All @@ -384,7 +384,7 @@ impl Grid {
pub fn new(id_source: impl std::hash::Hash) -> Self {
Self {
id_source: Id::new(id_source),
striped: false,
row_stripes: false,
header_row: false,
min_col_width: None,
min_row_height: None,
Expand All @@ -395,24 +395,12 @@ impl Grid {
}
}

/// Replace the color picker for columns
pub fn with_column_color(mut self, predicate: ColorPickerFn) -> Self {
self.color_spec.col_pickers = vec![predicate];
self
}

/// Add a `ColorPickerFn` to the color spec without overwriting existing column colors.
pub fn add_column_color(mut self, predicate: ColorPickerFn) -> Self {
self.color_spec.col_pickers.push(predicate);
self
}

/// Replace the color picker for rows
pub fn with_row_color(mut self, predicate: ColorPickerFn) -> Self {
self.color_spec.row_pickers = vec![predicate];
self
}

/// Add a `ColorPickerFn` to the color spec without overwriting existing row colors.
pub fn add_row_color(mut self, predicate: ColorPickerFn) -> Self {
self.color_spec.row_pickers.push(predicate);
Expand All @@ -423,11 +411,13 @@ impl Grid {
///
/// This can make a table easier to read.
/// Default: `false`.
pub fn striped(mut self, striped: bool) -> Self {
self.striped = striped;
pub fn striped(mut self, row_stripes: bool) -> Self {
self.row_stripes = row_stripes;
self
}

/// If `true`, adds a contrasting color to the first row.
/// Default: `false`.
pub fn header_row(mut self, header_row: bool) -> Self {
self.header_row = header_row;
self
Expand Down Expand Up @@ -472,7 +462,7 @@ impl Grid {
pub fn show<R>(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
let Self {
id_source,
striped,
row_stripes,
header_row,
min_col_width,
min_row_height,
Expand Down Expand Up @@ -501,7 +491,7 @@ impl Grid {
};

// Set convenience color specs
if striped {
if row_stripes {
grid.color_spec.row_pickers.push(|row| {
if row % 2 == 0 {
Some(GuiColor::light_dark(
Expand Down
2 changes: 1 addition & 1 deletion egui/src/placer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl Placer {

pub(crate) fn start_row(&mut self, painter: &Painter) {
if let Some(grid) = &mut self.grid {
grid.do_paint(self.region.cursor.min, painter)
grid.paint(self.region.cursor.min, painter)
}
}

Expand Down
2 changes: 1 addition & 1 deletion egui_demo_lib/src/apps/demo/demo_app_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ impl Default for Tests {
fn default() -> Self {
Self::from_demos(vec![
Box::new(super::tests::CursorTest::default()),
Box::new(super::tests::GridTest::default()),
Box::new(super::tests::IdTest::default()),
Box::new(super::tests::InputTest::default()),
Box::new(super::layout_test::LayoutTest::default()),
Box::new(super::tests::ManualLayoutTest::default()),
Box::new(super::tests::GridTest::default()),
])
}
}
Expand Down
26 changes: 16 additions & 10 deletions egui_demo_lib/src/apps/demo/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use egui::Rgba;

#[derive(Default)]
pub struct CursorTest {}

Expand Down Expand Up @@ -182,8 +180,8 @@ pub struct GridTest {
min_col_width: f32,
max_col_width: f32,
with_header: bool,
with_columns: bool,
striped: bool,
with_column_stripes: bool,
with_row_stripes: bool,
}

impl Default for GridTest {
Expand All @@ -193,8 +191,8 @@ impl Default for GridTest {
num_rows: 4,
min_col_width: 10.0,
max_col_width: 200.0,
striped: true,
with_columns: false,
with_row_stripes: true,
with_column_stripes: false,
with_header: false,
}
}
Expand All @@ -215,6 +213,8 @@ impl super::Demo for GridTest {

impl super::View for GridTest {
fn ui(&mut self, ui: &mut egui::Ui) {
use egui::Rgba;

ui.add(
egui::Slider::new(&mut self.min_col_width, 0.0..=400.0).text("Minimum column width"),
);
Expand All @@ -225,9 +225,15 @@ impl super::View for GridTest {
ui.add(egui::Slider::new(&mut self.num_rows, 0..=20).text("Rows"));

ui.horizontal(|ui| {
ui.add(egui::Checkbox::new(&mut self.striped, "Striped"));
ui.add(egui::Checkbox::new(
&mut self.with_row_stripes,
"Row stripes",
));
ui.add(egui::Checkbox::new(&mut self.with_header, "Headers"));
ui.add(egui::Checkbox::new(&mut self.with_columns, "Columns"));
ui.add(egui::Checkbox::new(
&mut self.with_column_stripes,
"Column stripes",
));
});
ui.separator();

Expand All @@ -237,11 +243,11 @@ impl super::View for GridTest {
];

let mut grid = egui::Grid::new("my_grid")
.striped(self.striped)
.striped(self.with_row_stripes)
.header_row(self.with_header)
.min_col_width(self.min_col_width)
.max_col_width(self.max_col_width);
if self.with_columns {
if self.with_column_stripes {
grid = grid.add_column_color(|col| {
if col % 2 == 0 {
Some(Rgba::from_rgba_premultiplied(0.01, 0.01, 0.01, 0.01).into())
Expand Down

0 comments on commit d6c6fbe

Please sign in to comment.