Skip to content

Commit

Permalink
Merge pull request #1611 from iced-rs/fix/clippy-lints
Browse files Browse the repository at this point in the history
Fix `clippy` lints for Rust 1.66
  • Loading branch information
hecrj authored Dec 20, 2022
2 parents d2d1847 + 6bb01b7 commit 678de11
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 40 deletions.
4 changes: 2 additions & 2 deletions core/src/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ impl std::ops::Mul<f32> for Rectangle<f32> {

fn mul(self, scale: f32) -> Self {
Self {
x: self.x as f32 * scale,
y: self.y as f32 * scale,
x: self.x * scale,
y: self.y * scale,
width: self.width * scale,
height: self.height * scale,
}
Expand Down
6 changes: 4 additions & 2 deletions examples/game_of_life/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,10 @@ mod grid {
let old_scaling = self.scaling;

let scaling = (self.scaling * (1.0 + y / 30.0))
.max(Self::MIN_SCALING)
.min(Self::MAX_SCALING);
.clamp(
Self::MIN_SCALING,
Self::MAX_SCALING,
);

let translation =
if let Some(cursor_to_center) =
Expand Down
22 changes: 8 additions & 14 deletions native/src/layout/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Limits {
}
Length::Units(units) => {
let new_width =
(units as f32).min(self.max.width).max(self.min.width);
(units as f32).clamp(self.min.width, self.max.width);

self.min.width = new_width;
self.max.width = new_width;
Expand All @@ -73,7 +73,7 @@ impl Limits {
}
Length::Units(units) => {
let new_height =
(units as f32).min(self.max.height).max(self.min.height);
(units as f32).clamp(self.min.height, self.max.height);

self.min.height = new_height;
self.max.height = new_height;
Expand All @@ -86,32 +86,30 @@ impl Limits {

/// Applies a minimum width constraint to the current [`Limits`].
pub fn min_width(mut self, min_width: u32) -> Limits {
self.min.width =
self.min.width.max(min_width as f32).min(self.max.width);
self.min.width = self.min.width.clamp(min_width as f32, self.max.width);

self
}

/// Applies a maximum width constraint to the current [`Limits`].
pub fn max_width(mut self, max_width: u32) -> Limits {
self.max.width =
self.max.width.min(max_width as f32).max(self.min.width);
self.max.width = self.max.width.clamp(self.min.width, max_width as f32);

self
}

/// Applies a minimum height constraint to the current [`Limits`].
pub fn min_height(mut self, min_height: u32) -> Limits {
self.min.height =
self.min.height.max(min_height as f32).min(self.max.height);
self.min.height.clamp(min_height as f32, self.max.height);

self
}

/// Applies a maximum height constraint to the current [`Limits`].
pub fn max_height(mut self, max_height: u32) -> Limits {
self.max.height =
self.max.height.min(max_height as f32).max(self.min.height);
self.max.height.clamp(self.min.height, max_height as f32);

self
}
Expand Down Expand Up @@ -157,14 +155,10 @@ impl Limits {
/// intrinsic size of some content.
pub fn resolve(&self, intrinsic_size: Size) -> Size {
Size::new(
intrinsic_size
.width
.min(self.max.width)
.max(self.fill.width),
intrinsic_size.width.clamp(self.fill.width, self.max.width),
intrinsic_size
.height
.min(self.max.height)
.max(self.fill.height),
.clamp(self.fill.height, self.max.height),
)
}
}
13 changes: 5 additions & 8 deletions native/src/widget/image/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ where
} else {
state.scale / (1.0 + self.scale_step)
})
.max(self.min_scale)
.min(self.max_scale);
.clamp(self.min_scale, self.max_scale);

let image_size = image_size(
renderer,
Expand Down Expand Up @@ -251,16 +250,14 @@ where

let x = if bounds.width < image_size.width {
(state.starting_offset.x - delta.x)
.min(hidden_width)
.max(-hidden_width)
.clamp(-hidden_width, hidden_width)
} else {
0.0
};

let y = if bounds.height < image_size.height {
(state.starting_offset.y - delta.y)
.min(hidden_height)
.max(-hidden_height)
.clamp(-hidden_height, hidden_height)
} else {
0.0
};
Expand Down Expand Up @@ -374,8 +371,8 @@ impl State {
(image_size.height - bounds.height / 2.0).max(0.0).round();

Vector::new(
self.current_offset.x.min(hidden_width).max(-hidden_width),
self.current_offset.y.min(hidden_height).max(-hidden_height),
self.current_offset.x.clamp(-hidden_width, hidden_width),
self.current_offset.y.clamp(-hidden_height, hidden_height),
)
}

Expand Down
4 changes: 2 additions & 2 deletions native/src/widget/pane_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,13 +630,13 @@ pub fn update<'a, Message, T: Draggable>(
let position =
cursor_position.y - bounds.y - rectangle.y;

(position / rectangle.height).max(0.1).min(0.9)
(position / rectangle.height).clamp(0.1, 0.9)
}
Axis::Vertical => {
let position =
cursor_position.x - bounds.x - rectangle.x;

(position / rectangle.width).max(0.1).min(0.9)
(position / rectangle.width).clamp(0.1, 0.9)
}
};

Expand Down
2 changes: 1 addition & 1 deletion native/src/widget/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ where
/// * the current value of the [`ProgressBar`]
pub fn new(range: RangeInclusive<f32>, value: f32) -> Self {
ProgressBar {
value: value.max(*range.start()).min(*range.end()),
value: value.clamp(*range.start(), *range.end()),
range,
width: Length::Fill,
height: None,
Expand Down
5 changes: 2 additions & 3 deletions native/src/widget/scrollable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,7 @@ impl State {

self.offset = Offset::Absolute(
(self.offset.absolute(bounds, content_bounds) - delta_y)
.max(0.0)
.min((content_bounds.height - bounds.height) as f32),
.clamp(0.0, content_bounds.height - bounds.height),
);
}

Expand All @@ -905,7 +904,7 @@ impl State {
/// `0` represents scrollbar at the top, while `1` represents scrollbar at
/// the bottom.
pub fn snap_to(&mut self, percentage: f32) {
self.offset = Offset::Relative(percentage.max(0.0).min(1.0));
self.offset = Offset::Relative(percentage.clamp(0.0, 1.0));
}

/// Unsnaps the current scroll position, if snapped, given the bounds of the
Expand Down
4 changes: 2 additions & 2 deletions native/src/widget/toggler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ where
theme.active(&self.style, self.is_active)
};

let border_radius = bounds.height as f32 / BORDER_RADIUS_RATIO;
let space = SPACE_RATIO * bounds.height as f32;
let border_radius = bounds.height / BORDER_RADIUS_RATIO;
let space = SPACE_RATIO * bounds.height;

let toggler_background_bounds = Rectangle {
x: bounds.x + space,
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/buffer/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<T: ShaderType + WriteInto> Buffer<T> {
pub fn push(&mut self, value: &T) {
//this write operation on the cpu buffer will adjust for uniform alignment requirements
let offset = self.cpu.write(value);
self.offsets.push(offset as u32);
self.offsets.push(offset);
}

/// Resize buffer contents if necessary. This will re-create the GPU buffer if current size is
Expand Down
6 changes: 1 addition & 5 deletions wgpu/src/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,7 @@ impl Pipeline {
wgpu::IndexFormat::Uint32,
);

render_pass.draw_indexed(
0..(self.index_strides[index] as u32),
0,
0..1,
);
render_pass.draw_indexed(0..self.index_strides[index], 0, 0..1);
}
}

Expand Down

0 comments on commit 678de11

Please sign in to comment.