Fix clippy warnings

This commit is contained in:
eraden 2022-02-28 18:59:19 +01:00
parent 06aca5e3ce
commit 879544adeb
11 changed files with 55 additions and 112 deletions

View File

@ -24,30 +24,6 @@ impl Arrows {
highlight: false, highlight: false,
} }
} }
/// Highlight these arrows in the plot.
pub fn highlight(mut self) -> Self {
self.highlight = true;
self
}
/// Set the arrows' color.
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.color = color.into();
self
}
/// Name of this set of arrows.
///
/// This name will show up in the plot legend, if legends are turned on.
///
/// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend.
#[allow(clippy::needless_pass_by_value)]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
}
} }
impl PlotItem for Arrows { impl PlotItem for Arrows {

View File

@ -28,47 +28,12 @@ impl HLine {
} }
} }
/// Highlight this line in the plot by scaling up the line.
pub fn highlight(mut self) -> Self {
self.highlight = true;
self
}
/// Add a stroke.
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
self.stroke = stroke.into();
self
}
/// Stroke width. A high value means the plot thickens.
pub fn width(mut self, width: impl Into<f32>) -> Self {
self.stroke.width = width.into();
self
}
/// Stroke color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned. /// Stroke color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
#[must_use]
pub fn color(mut self, color: impl Into<Color32>) -> Self { pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.stroke.color = color.into(); self.stroke.color = color.into();
self self
} }
/// Set the line's style. Default is `LineStyle::Solid`.
pub fn style(mut self, style: LineStyle) -> Self {
self.style = style;
self
}
/// Name of this horizontal line.
///
/// This name will show up in the plot legend, if legends are turned on.
///
/// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend.
#[allow(clippy::needless_pass_by_value)]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
}
} }
impl PlotItem for HLine { impl PlotItem for HLine {

View File

@ -120,51 +120,10 @@ impl Line {
} }
} }
/// Highlight this line in the plot by scaling up the line.
pub fn highlight(mut self) -> Self {
self.highlight = true;
self
}
/// Add a stroke.
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
self.stroke = stroke.into();
self
}
/// Stroke width. A high value means the plot thickens.
pub fn width(mut self, width: impl Into<f32>) -> Self {
self.stroke.width = width.into();
self
}
/// Stroke color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned. /// Stroke color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
#[must_use]
pub fn color(mut self, color: impl Into<Color32>) -> Self { pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.stroke.color = color.into(); self.stroke.color = color.into();
self self
} }
/// Fill the area between this line and a given horizontal reference line.
pub fn fill(mut self, y_reference: impl Into<f32>) -> Self {
self.fill = Some(y_reference.into());
self
}
/// Set the line's style. Default is `LineStyle::Solid`.
pub fn style(mut self, style: LineStyle) -> Self {
self.style = style;
self
}
/// Name of this line.
///
/// This name will show up in the plot legend, if legends are turned on.
///
/// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend.
#[allow(clippy::needless_pass_by_value)]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
}
} }

View File

@ -34,24 +34,28 @@ impl PlotImage {
} }
/// Highlight this image in the plot. /// Highlight this image in the plot.
#[must_use]
pub fn highlight(mut self) -> Self { pub fn highlight(mut self) -> Self {
self.highlight = true; self.highlight = true;
self self
} }
/// Select UV range. Default is (0,0) in top-left, (1,1) bottom right. /// Select UV range. Default is (0,0) in top-left, (1,1) bottom right.
#[must_use]
pub fn uv(mut self, uv: impl Into<Rect>) -> Self { pub fn uv(mut self, uv: impl Into<Rect>) -> Self {
self.uv = uv.into(); self.uv = uv.into();
self self
} }
/// A solid color to put behind the image. Useful for transparent images. /// A solid color to put behind the image. Useful for transparent images.
#[must_use]
pub fn bg_fill(mut self, bg_fill: impl Into<Color32>) -> Self { pub fn bg_fill(mut self, bg_fill: impl Into<Color32>) -> Self {
self.bg_fill = bg_fill.into(); self.bg_fill = bg_fill.into();
self self
} }
/// Multiply image color with this. Default is WHITE (no tint). /// Multiply image color with this. Default is WHITE (no tint).
#[must_use]
pub fn tint(mut self, tint: impl Into<Color32>) -> Self { pub fn tint(mut self, tint: impl Into<Color32>) -> Self {
self.tint = tint.into(); self.tint = tint.into();
self self
@ -64,6 +68,7 @@ impl PlotImage {
/// Multiple plot items may share the same name, in which case they will also share an entry in /// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend. /// the legend.
#[allow(clippy::needless_pass_by_value)] #[allow(clippy::needless_pass_by_value)]
#[must_use]
pub fn name(mut self, name: impl ToString) -> Self { pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string(); self.name = name.to_string();
self self

View File

@ -37,36 +37,42 @@ impl Points {
} }
/// Set the shape of the markers. /// Set the shape of the markers.
#[must_use]
pub fn shape(mut self, shape: MarkerShape) -> Self { pub fn shape(mut self, shape: MarkerShape) -> Self {
self.shape = shape; self.shape = shape;
self self
} }
/// Highlight these points in the plot by scaling up their markers. /// Highlight these points in the plot by scaling up their markers.
#[must_use]
pub fn highlight(mut self) -> Self { pub fn highlight(mut self) -> Self {
self.highlight = true; self.highlight = true;
self self
} }
/// Set the marker's color. /// Set the marker's color.
#[must_use]
pub fn color(mut self, color: impl Into<Color32>) -> Self { pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.color = color.into(); self.color = color.into();
self self
} }
/// Whether to fill the marker. /// Whether to fill the marker.
#[must_use]
pub fn filled(mut self, filled: bool) -> Self { pub fn filled(mut self, filled: bool) -> Self {
self.filled = filled; self.filled = filled;
self self
} }
/// Whether to add stems between the markers and a horizontal reference line. /// Whether to add stems between the markers and a horizontal reference line.
#[must_use]
pub fn stems(mut self, y_reference: impl Into<f32>) -> Self { pub fn stems(mut self, y_reference: impl Into<f32>) -> Self {
self.stems = Some(y_reference.into()); self.stems = Some(y_reference.into());
self self
} }
/// Set the maximum extent of the marker around its position. /// Set the maximum extent of the marker around its position.
#[must_use]
pub fn radius(mut self, radius: impl Into<f32>) -> Self { pub fn radius(mut self, radius: impl Into<f32>) -> Self {
self.radius = radius.into(); self.radius = radius.into();
self self
@ -79,6 +85,7 @@ impl Points {
/// Multiple plot items may share the same name, in which case they will also share an entry in /// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend. /// the legend.
#[allow(clippy::needless_pass_by_value)] #[allow(clippy::needless_pass_by_value)]
#[must_use]
pub fn name(mut self, name: impl ToString) -> Self { pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string(); self.name = name.to_string();
self self

View File

@ -30,36 +30,42 @@ impl Polygon {
/// Highlight this polygon in the plot by scaling up the stroke and reducing the fill /// Highlight this polygon in the plot by scaling up the stroke and reducing the fill
/// transparency. /// transparency.
#[must_use]
pub fn highlight(mut self) -> Self { pub fn highlight(mut self) -> Self {
self.highlight = true; self.highlight = true;
self self
} }
/// Add a custom stroke. /// Add a custom stroke.
#[must_use]
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self { pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
self.stroke = stroke.into(); self.stroke = stroke.into();
self self
} }
/// Set the stroke width. /// Set the stroke width.
#[must_use]
pub fn width(mut self, width: impl Into<f32>) -> Self { pub fn width(mut self, width: impl Into<f32>) -> Self {
self.stroke.width = width.into(); self.stroke.width = width.into();
self self
} }
/// Stroke color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned. /// Stroke color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
#[must_use]
pub fn color(mut self, color: impl Into<Color32>) -> Self { pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.stroke.color = color.into(); self.stroke.color = color.into();
self self
} }
/// Alpha of the filled area. /// Alpha of the filled area.
#[must_use]
pub fn fill_alpha(mut self, alpha: impl Into<f32>) -> Self { pub fn fill_alpha(mut self, alpha: impl Into<f32>) -> Self {
self.fill_alpha = alpha.into(); self.fill_alpha = alpha.into();
self self
} }
/// Set the outline's style. Default is `LineStyle::Solid`. /// Set the outline's style. Default is `LineStyle::Solid`.
#[must_use]
pub fn style(mut self, style: LineStyle) -> Self { pub fn style(mut self, style: LineStyle) -> Self {
self.style = style; self.style = style;
self self
@ -72,6 +78,7 @@ impl Polygon {
/// Multiple plot items may share the same name, in which case they will also share an entry in /// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend. /// the legend.
#[allow(clippy::needless_pass_by_value)] #[allow(clippy::needless_pass_by_value)]
#[must_use]
pub fn name(mut self, name: impl ToString) -> Self { pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string(); self.name = name.to_string();
self self

View File

@ -32,24 +32,28 @@ impl Text {
} }
/// Highlight this text in the plot by drawing a rectangle around it. /// Highlight this text in the plot by drawing a rectangle around it.
#[must_use]
pub fn highlight(mut self) -> Self { pub fn highlight(mut self) -> Self {
self.highlight = true; self.highlight = true;
self self
} }
/// Text style. Default is `TextStyle::Small`. /// Text style. Default is `TextStyle::Small`.
#[must_use]
pub fn style(mut self, style: TextStyle) -> Self { pub fn style(mut self, style: TextStyle) -> Self {
self.style = style; self.style = style;
self self
} }
/// Text color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned. /// Text color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
#[must_use]
pub fn color(mut self, color: impl Into<Color32>) -> Self { pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.color = color.into(); self.color = color.into();
self self
} }
/// Anchor position of the text. Default is `Align2::CENTER_CENTER`. /// Anchor position of the text. Default is `Align2::CENTER_CENTER`.
#[must_use]
pub fn anchor(mut self, anchor: Align2) -> Self { pub fn anchor(mut self, anchor: Align2) -> Self {
self.anchor = anchor; self.anchor = anchor;
self self
@ -62,6 +66,7 @@ impl Text {
/// Multiple plot items may share the same name, in which case they will also share an entry in /// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend. /// the legend.
#[allow(clippy::needless_pass_by_value)] #[allow(clippy::needless_pass_by_value)]
#[must_use]
pub fn name(mut self, name: impl ToString) -> Self { pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string(); self.name = name.to_string();
self self

View File

@ -75,30 +75,35 @@ impl VLine {
} }
/// Highlight this line in the plot by scaling up the line. /// Highlight this line in the plot by scaling up the line.
#[must_use]
pub fn highlight(mut self) -> Self { pub fn highlight(mut self) -> Self {
self.highlight = true; self.highlight = true;
self self
} }
/// Add a stroke. /// Add a stroke.
#[must_use]
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self { pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
self.stroke = stroke.into(); self.stroke = stroke.into();
self self
} }
/// Stroke width. A high value means the plot thickens. /// Stroke width. A high value means the plot thickens.
#[must_use]
pub fn width(mut self, width: impl Into<f32>) -> Self { pub fn width(mut self, width: impl Into<f32>) -> Self {
self.stroke.width = width.into(); self.stroke.width = width.into();
self self
} }
/// Stroke color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned. /// Stroke color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
#[must_use]
pub fn color(mut self, color: impl Into<Color32>) -> Self { pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.stroke.color = color.into(); self.stroke.color = color.into();
self self
} }
/// Set the line's style. Default is `LineStyle::Solid`. /// Set the line's style. Default is `LineStyle::Solid`.
#[must_use]
pub fn style(mut self, style: LineStyle) -> Self { pub fn style(mut self, style: LineStyle) -> Self {
self.style = style; self.style = style;
self self
@ -111,6 +116,7 @@ impl VLine {
/// Multiple plot items may share the same name, in which case they will also share an entry in /// Multiple plot items may share the same name, in which case they will also share an entry in
/// the legend. /// the legend.
#[allow(clippy::needless_pass_by_value)] #[allow(clippy::needless_pass_by_value)]
#[must_use]
pub fn name(mut self, name: impl ToString) -> Self { pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string(); self.name = name.to_string();
self self

View File

@ -17,16 +17,10 @@ impl ConfigFile {
impl Widget for ConfigFile { impl Widget for ConfigFile {
fn ui(self, ui: &mut Ui) -> Response { fn ui(self, ui: &mut Ui) -> Response {
ui.vertical(|ui| { ui.vertical(|ui| {
let mut matrix = { let mut matrix = { self.config.lock().speed_matrix().to_vec() }
#[allow(clippy::unnecessary_to_owned)] .into_iter()
self.config .enumerate()
.lock() .peekable();
.speed_matrix()
.to_vec()
.into_iter()
.enumerate()
.peekable()
};
let mut prev = None; let mut prev = None;

View File

@ -79,23 +79,27 @@ where
} }
} }
#[must_use]
pub fn x_axis_name(mut self, name: String) -> Self { pub fn x_axis_name(mut self, name: String) -> Self {
self.axis_names[0] = name; self.axis_names[0] = name;
self self
} }
#[must_use]
pub fn y_axis_name(mut self, name: String) -> Self { pub fn y_axis_name(mut self, name: String) -> Self {
self.axis_names[1] = name; self.axis_names[1] = name;
self self
} }
/// Show a legend including all named items. /// Show a legend including all named items.
#[must_use]
pub fn legend(mut self, legend: Legend) -> Self { pub fn legend(mut self, legend: Legend) -> Self {
self.legend_config = Some(legend); self.legend_config = Some(legend);
self self
} }
/// Add a data lines. /// Add a data lines.
#[must_use]
pub fn line(mut self, mut line: Line) -> Self { pub fn line(mut self, mut line: Line) -> Self {
if line.series.is_empty() { if line.series.is_empty() {
return self; return self;
@ -109,11 +113,13 @@ where
self self
} }
#[must_use]
pub fn selected(mut self, selected: Option<usize>) -> Self { pub fn selected(mut self, selected: Option<usize>) -> Self {
self.selected = selected; self.selected = selected;
self self
} }
#[must_use]
fn auto_color(&mut self) -> Color32 { fn auto_color(&mut self) -> Color32 {
let i = self.next_auto_color_idx; let i = self.next_auto_color_idx;
self.next_auto_color_idx += 1; self.next_auto_color_idx += 1;
@ -126,6 +132,7 @@ where
/// For instance, it can be useful to set this to `1.0` for when the two axes show the same /// For instance, it can be useful to set this to `1.0` for when the two axes show the same
/// unit. /// unit.
/// By default the plot window's aspect ratio is used. /// By default the plot window's aspect ratio is used.
#[must_use]
pub fn data_aspect(mut self, data_aspect: f32) -> Self { pub fn data_aspect(mut self, data_aspect: f32) -> Self {
self.data_aspect = Some(data_aspect); self.data_aspect = Some(data_aspect);
self self
@ -133,6 +140,7 @@ where
/// width / height ratio of the plot region. /// width / height ratio of the plot region.
/// By default no fixed aspect ratio is set (and width/height will fill the ui it is in). /// By default no fixed aspect ratio is set (and width/height will fill the ui it is in).
#[must_use]
pub fn view_aspect(mut self, view_aspect: f32) -> Self { pub fn view_aspect(mut self, view_aspect: f32) -> Self {
self.view_aspect = Some(view_aspect); self.view_aspect = Some(view_aspect);
self self
@ -140,6 +148,7 @@ where
/// Width of plot. By default a plot will fill the ui it is in. /// Width of plot. By default a plot will fill the ui it is in.
/// If you set [`Self::view_aspect`], the width can be calculated from the height. /// If you set [`Self::view_aspect`], the width can be calculated from the height.
#[must_use]
pub fn width(mut self, width: f32) -> Self { pub fn width(mut self, width: f32) -> Self {
self.min_size.x = width; self.min_size.x = width;
self.width = Some(width); self.width = Some(width);
@ -148,6 +157,7 @@ where
/// Height of plot. By default a plot will fill the ui it is in. /// Height of plot. By default a plot will fill the ui it is in.
/// If you set [`Self::view_aspect`], the height can be calculated from the width. /// If you set [`Self::view_aspect`], the height can be calculated from the width.
#[must_use]
pub fn height(mut self, height: f32) -> Self { pub fn height(mut self, height: f32) -> Self {
self.min_size.y = height; self.min_size.y = height;
self.height = Some(height); self.height = Some(height);
@ -155,16 +165,19 @@ where
} }
/// Minimum size of the plot view. /// Minimum size of the plot view.
#[must_use]
pub fn min_size(mut self, min_size: Vec2) -> Self { pub fn min_size(mut self, min_size: Vec2) -> Self {
self.min_size = min_size; self.min_size = min_size;
self self
} }
#[must_use]
pub fn allow_drag(mut self, allow_drag: bool) -> Self { pub fn allow_drag(mut self, allow_drag: bool) -> Self {
self.allow_drag = allow_drag; self.allow_drag = allow_drag;
self self
} }
#[must_use]
pub fn allow_zoom(mut self, allow_zoom: bool) -> Self { pub fn allow_zoom(mut self, allow_zoom: bool) -> Self {
self.allow_zoom = allow_zoom; self.allow_zoom = allow_zoom;
self self
@ -173,6 +186,7 @@ where
/// Add a horizontal line. /// Add a horizontal line.
/// Can be useful e.g. to show min/max bounds or similar. /// Can be useful e.g. to show min/max bounds or similar.
/// Always fills the full width of the plot. /// Always fills the full width of the plot.
#[must_use]
pub fn hline(mut self, mut hline: HLine) -> Self { pub fn hline(mut self, mut hline: HLine) -> Self {
if hline.stroke.color == Color32::TRANSPARENT { if hline.stroke.color == Color32::TRANSPARENT {
hline.stroke.color = self.auto_color(); hline.stroke.color = self.auto_color();
@ -184,6 +198,7 @@ where
/// Add a vertical line. /// Add a vertical line.
/// Can be useful e.g. to show min/max bounds or similar. /// Can be useful e.g. to show min/max bounds or similar.
/// Always fills the full height of the plot. /// Always fills the full height of the plot.
#[must_use]
pub fn vline(mut self, mut vline: VLine) -> Self { pub fn vline(mut self, mut vline: VLine) -> Self {
if vline.stroke.color == Color32::TRANSPARENT { if vline.stroke.color == Color32::TRANSPARENT {
vline.stroke.color = self.auto_color(); vline.stroke.color = self.auto_color();
@ -192,6 +207,7 @@ where
self self
} }
#[must_use]
pub fn on_event(mut self, f: OnEvent) -> Self { pub fn on_event(mut self, f: OnEvent) -> Self {
self.on_event = Some(f); self.on_event = Some(f);
self self

View File

@ -45,18 +45,21 @@ impl Default for Legend {
impl Legend { impl Legend {
/// Which text style to use for the legend. Default: `TextStyle::Body`. /// Which text style to use for the legend. Default: `TextStyle::Body`.
#[must_use]
pub fn text_style(mut self, style: TextStyle) -> Self { pub fn text_style(mut self, style: TextStyle) -> Self {
self.text_style = style; self.text_style = style;
self self
} }
/// The alpha of the legend background. Default: `0.75`. /// The alpha of the legend background. Default: `0.75`.
#[must_use]
pub fn background_alpha(mut self, alpha: f32) -> Self { pub fn background_alpha(mut self, alpha: f32) -> Self {
self.background_alpha = alpha; self.background_alpha = alpha;
self self
} }
/// In which corner to place the legend. Default: `Corner::RightTop`. /// In which corner to place the legend. Default: `Corner::RightTop`.
#[must_use]
pub fn position(mut self, corner: Corner) -> Self { pub fn position(mut self, corner: Corner) -> Self {
self.position = corner; self.position = corner;
self self