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 d55a145
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 27 deletions.
32 changes: 11 additions & 21 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: striped,
header_row,
min_col_width,
min_row_height,
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
8 changes: 4 additions & 4 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 @@ -215,14 +213,16 @@ 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"),
);
ui.add(
egui::Slider::new(&mut self.max_col_width, 0.0..=400.0).text("Maximum column width"),
);
ui.add(egui::Slider::new(&mut self.num_cols, 0..=8).text("Columns"));
ui.add(egui::Slider::new(&mut self.num_rows, 0..=20).text("Rows"));
ui.add(egui::Slider::new(&mut self.num_cols, 0..=8).text("Column stripes"));
ui.add(egui::Slider::new(&mut self.num_rows, 0..=20).text("Row stripes"));

ui.horizontal(|ui| {
ui.add(egui::Checkbox::new(&mut self.striped, "Striped"));
Expand Down

0 comments on commit d55a145

Please sign in to comment.