correctly add egui lints and fix all warnings

This commit is contained in:
René Rössler 2022-02-09 12:56:01 +01:00
parent 8a78302bd0
commit eeb79c0f88
7 changed files with 37 additions and 36 deletions

View file

@ -114,7 +114,7 @@ impl<'a> Widget for DatePickerButton<'a> {
calendar: self.calendar, calendar: self.calendar,
calendar_week: self.calendar_week, calendar_week: self.calendar_week,
} }
.draw(ui) .draw(ui);
}) })
}) })
.response; .response;

View file

@ -130,7 +130,7 @@ impl<'a> DatePickerPopup<'a> {
} }
}); });
}); });
}) });
}); });
} }
@ -225,7 +225,7 @@ impl<'a> DatePickerPopup<'a> {
} }
}); });
}); });
}) });
}); });
} }
@ -343,7 +343,7 @@ impl<'a> DatePickerPopup<'a> {
} }
}); });
}); });
}) });
}); });
}); });

View file

@ -18,7 +18,7 @@ pub struct GridBuilder<'a> {
impl<'a> GridBuilder<'a> { impl<'a> GridBuilder<'a> {
/// Create new grid builder /// Create new grid builder
/// After adding size hints with [Self::column]/[Self::columns] the grid can be build with [Self::horizontal]/[Self::vertical] /// After adding size hints with `[Self::column]`/`[Self::columns]` the grid can be build with `[Self::horizontal]`/`[Self::vertical]`
pub fn new(ui: &'a mut Ui, padding: Padding) -> Self { pub fn new(ui: &'a mut Ui, padding: Padding) -> Self {
let sizing = Sizing::new(); let sizing = Sizing::new();
@ -38,7 +38,7 @@ impl<'a> GridBuilder<'a> {
/// Add size hint for columns/rows [count] times /// Add size hint for columns/rows [count] times
pub fn sizes(mut self, size: Size, count: usize) -> Self { pub fn sizes(mut self, size: Size, count: usize) -> Self {
for _ in 0..count { for _ in 0..count {
self.sizing.add_size(size.clone()); self.sizing.add_size(size);
} }
self self
} }
@ -134,20 +134,20 @@ impl<'a, 'b> Grid<'a, 'b> {
self._cell(false, add_contents); self._cell(false, add_contents);
} }
pub fn _grid(&mut self, clip: bool, grid_builder: impl FnOnce(GridBuilder)) { pub fn _grid(&mut self, clip: bool, grid_builder: impl FnOnce(GridBuilder<'_>)) {
let padding = self.padding.clone(); let padding = self.padding.clone();
self._cell(clip, |ui| { self._cell(clip, |ui| {
grid_builder(GridBuilder::new(ui, padding)); grid_builder(GridBuilder::new(ui, padding));
}); });
} }
/// Add grid as cell, content is clipped /// Add grid as cell, content is clipped
pub fn grid(&mut self, grid_builder: impl FnOnce(GridBuilder)) { pub fn grid(&mut self, grid_builder: impl FnOnce(GridBuilder<'_>)) {
self._grid(true, grid_builder) self._grid(true, grid_builder);
} }
/// Add grid as cell, content is not clipped /// Add grid as cell, content is not clipped
pub fn grid_noclip(&mut self, grid_builder: impl FnOnce(GridBuilder)) { pub fn grid_noclip(&mut self, grid_builder: impl FnOnce(GridBuilder<'_>)) {
self._grid(false, grid_builder) self._grid(false, grid_builder);
} }
} }

View file

@ -1,6 +1,7 @@
use crate::Padding; use crate::Padding;
use egui::{Pos2, Rect, Response, Rgba, Sense, Ui, Vec2}; use egui::{Pos2, Rect, Response, Rgba, Sense, Ui, Vec2};
#[derive(Clone, Copy)]
pub(crate) enum CellSize { pub(crate) enum CellSize {
/// Absolute size in points /// Absolute size in points
Absolute(f32), Absolute(f32),
@ -15,7 +16,7 @@ pub(crate) enum LineDirection {
TopToBottom, TopToBottom,
} }
/// Positions cells in [LineDirection] and starts a new line on [Layout::end_line] /// Positions cells in `[LineDirection]` and starts a new line on `[Layout::end_line]`
pub struct Layout<'l> { pub struct Layout<'l> {
ui: &'l mut Ui, ui: &'l mut Ui,
padding: Padding, padding: Padding,
@ -153,12 +154,12 @@ impl<'l> Layout<'l> {
child_ui.set_clip_rect(clip_rect); child_ui.set_clip_rect(clip_rect);
} }
add_contents(&mut child_ui) add_contents(&mut child_ui);
} }
} }
impl<'a> Drop for Layout<'a> { impl<'a> Drop for Layout<'a> {
fn drop(&mut self) { fn drop(&mut self) {
self.set_rect() self.set_rect();
} }
} }

View file

@ -1,21 +1,3 @@
#[cfg(feature = "chrono")]
mod datepicker;
mod grid;
mod layout;
mod padding;
mod sizing;
mod table;
#[cfg(feature = "chrono")]
pub use datepicker::DatePickerButton;
pub use grid::*;
pub(crate) use layout::Layout;
pub use padding::Padding;
pub use sizing::Size;
pub use table::*;
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
#![warn( #![warn(
clippy::all, clippy::all,
@ -95,3 +77,21 @@ pub use table::*;
)] )]
#![allow(clippy::float_cmp)] #![allow(clippy::float_cmp)]
#![allow(clippy::manual_range_contains)] #![allow(clippy::manual_range_contains)]
#[cfg(feature = "chrono")]
mod datepicker;
mod grid;
mod layout;
mod padding;
mod sizing;
mod table;
#[cfg(feature = "chrono")]
pub use datepicker::DatePickerButton;
pub use grid::*;
pub(crate) use layout::Layout;
pub use padding::Padding;
pub use sizing::Size;
pub use table::*;

View file

@ -1,5 +1,5 @@
/// Size hint for table column/grid cell /// Size hint for table column/grid cell
#[derive(Clone, Debug)] #[derive(Clone, Debug, Copy)]
pub enum Size { pub enum Size {
/// Absolute size in points /// Absolute size in points
Absolute(f32), Absolute(f32),

View file

@ -53,7 +53,7 @@ impl<'a> TableBuilder<'a> {
/// Add size hint for column [count] times /// Add size hint for column [count] times
pub fn columns(mut self, size: Size, count: usize) -> Self { pub fn columns(mut self, size: Size, count: usize) -> Self {
for _ in 0..count { for _ in 0..count {
self.sizing.add_size(size.clone()); self.sizing.add_size(size);
} }
self self
} }
@ -105,7 +105,7 @@ impl<'a> TableBuilder<'a> {
scroll: self.scroll, scroll: self.scroll,
striped: self.striped, striped: self.striped,
} }
.body(body) .body(body);
} }
} }
@ -157,7 +157,7 @@ pub struct TableBody<'a> {
impl<'a> TableBody<'a> { impl<'a> TableBody<'a> {
/// Add rows with same height /// Add rows with same height
/// Is a lot more performant than adding each individual row as non visible rows must not be rendered /// Is a lot more performant than adding each individual row as non visible rows must not be rendered
pub fn rows(mut self, height: f32, rows: usize, mut row: impl FnMut(usize, TableRow)) { pub fn rows(mut self, height: f32, rows: usize, mut row: impl FnMut(usize, TableRow<'_, '_>)) {
let delta = self.layout.current_y() - self.start_y; let delta = self.layout.current_y() - self.start_y;
let mut start = 0; let mut start = 0;