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 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 {

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.
#[must_use]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.stroke.color = color.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 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 {

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.
#[must_use]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.stroke.color = color.into();
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.
#[must_use]
pub fn highlight(mut self) -> Self {
self.highlight = true;
self
}
/// 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 {
self.uv = uv.into();
self
}
/// 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 {
self.bg_fill = bg_fill.into();
self
}
/// Multiply image color with this. Default is WHITE (no tint).
#[must_use]
pub fn tint(mut self, tint: impl Into<Color32>) -> Self {
self.tint = tint.into();
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
/// the legend.
#[allow(clippy::needless_pass_by_value)]
#[must_use]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self

View File

@ -37,36 +37,42 @@ impl Points {
}
/// Set the shape of the markers.
#[must_use]
pub fn shape(mut self, shape: MarkerShape) -> Self {
self.shape = shape;
self
}
/// Highlight these points in the plot by scaling up their markers.
#[must_use]
pub fn highlight(mut self) -> Self {
self.highlight = true;
self
}
/// Set the marker's color.
#[must_use]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.color = color.into();
self
}
/// Whether to fill the marker.
#[must_use]
pub fn filled(mut self, filled: bool) -> Self {
self.filled = filled;
self
}
/// 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 {
self.stems = Some(y_reference.into());
self
}
/// Set the maximum extent of the marker around its position.
#[must_use]
pub fn radius(mut self, radius: impl Into<f32>) -> Self {
self.radius = radius.into();
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
/// the legend.
#[allow(clippy::needless_pass_by_value)]
#[must_use]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self

View File

@ -30,36 +30,42 @@ impl Polygon {
/// Highlight this polygon in the plot by scaling up the stroke and reducing the fill
/// transparency.
#[must_use]
pub fn highlight(mut self) -> Self {
self.highlight = true;
self
}
/// Add a custom stroke.
#[must_use]
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
self.stroke = stroke.into();
self
}
/// Set the stroke width.
#[must_use]
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.
#[must_use]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.stroke.color = color.into();
self
}
/// Alpha of the filled area.
#[must_use]
pub fn fill_alpha(mut self, alpha: impl Into<f32>) -> Self {
self.fill_alpha = alpha.into();
self
}
/// Set the outline's style. Default is `LineStyle::Solid`.
#[must_use]
pub fn style(mut self, style: LineStyle) -> Self {
self.style = style;
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
/// the legend.
#[allow(clippy::needless_pass_by_value)]
#[must_use]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self

View File

@ -32,24 +32,28 @@ impl Text {
}
/// Highlight this text in the plot by drawing a rectangle around it.
#[must_use]
pub fn highlight(mut self) -> Self {
self.highlight = true;
self
}
/// Text style. Default is `TextStyle::Small`.
#[must_use]
pub fn style(mut self, style: TextStyle) -> Self {
self.style = style;
self
}
/// 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 {
self.color = color.into();
self
}
/// Anchor position of the text. Default is `Align2::CENTER_CENTER`.
#[must_use]
pub fn anchor(mut self, anchor: Align2) -> Self {
self.anchor = anchor;
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
/// the legend.
#[allow(clippy::needless_pass_by_value)]
#[must_use]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self

View File

@ -75,30 +75,35 @@ impl VLine {
}
/// Highlight this line in the plot by scaling up the line.
#[must_use]
pub fn highlight(mut self) -> Self {
self.highlight = true;
self
}
/// Add a stroke.
#[must_use]
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
self.stroke = stroke.into();
self
}
/// Stroke width. A high value means the plot thickens.
#[must_use]
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.
#[must_use]
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.stroke.color = color.into();
self
}
/// Set the line's style. Default is `LineStyle::Solid`.
#[must_use]
pub fn style(mut self, style: LineStyle) -> Self {
self.style = style;
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
/// the legend.
#[allow(clippy::needless_pass_by_value)]
#[must_use]
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self

View File

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

View File

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

View File

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