Skip to content

Commit

Permalink
Cargo clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
genusistimelord committed Dec 18, 2023
1 parent c918396 commit 1ae540e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/native/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum InnerBounds {
}
impl InnerBounds {
/// Gets the inner bounds of the Set type.
#[must_use]
pub fn get_bounds(&self, outer_bounds: Rectangle) -> Rectangle {
use InnerBounds::{Custom, Padding, Ratio, Square};
match self {
Expand Down
4 changes: 2 additions & 2 deletions src/native/selection_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ where
.options
.iter()
.map(|_| graphics::text::Paragraph::new())
.collect()
.collect();
}

fn width(&self) -> Length {
Expand Down Expand Up @@ -322,7 +322,7 @@ pub struct State {

impl State {
/// Creates a new [`State`], representing an unfocused [`TextInput`].
pub fn new<'a, T>(options: &'a [T]) -> Self
pub fn new<T>(options: &[T]) -> Self
where
T: Clone + Display + Eq + Hash,
[T]: ToOwned<Owned = Vec<T>>,
Expand Down
27 changes: 16 additions & 11 deletions src/native/slide_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use iced_widget::core::{

use std::ops::RangeInclusive;

/// Constant Default height of SliderBar.
/// Constant Default height of `SliderBar`.
pub const DEFAULT_HEIGHT: f32 = 30.0;

/// A widget that draws a SlideBar
/// A widget that draws a `SlideBar`
#[allow(missing_debug_implementations)]
pub struct SlideBar<'a, T, Message>
where
Expand Down Expand Up @@ -98,25 +98,29 @@ where
///
/// Typically, the user's interaction with the slider is finished when this message is produced.
/// This is useful if you need to spawn a long-running task from the slider's result, where
/// the default on_change message could create too many events.
/// the default `on_change` message could create too many events.
#[must_use]
pub fn on_release(mut self, on_release: Message) -> Self {
self.on_release = Some(on_release);
self
}

/// Sets the width of the [`Slider`].
#[must_use]
pub fn width(mut self, width: impl Into<Length>) -> Self {
self.width = width.into();
self
}

/// Sets the height of the [`Slider`].
#[must_use]
pub fn height(mut self, height: Option<Length>) -> Self {
self.height = height;
self
}

/// Sets the step size of the [`Slider`].
#[must_use]
pub fn step(mut self, step: impl Into<T>) -> Self {
self.step = step.into();
self
Expand Down Expand Up @@ -167,7 +171,7 @@ where
_viewport: &Rectangle,
) -> event::Status {
update(
event,
&event,
layout,
cursor,
shell,
Expand All @@ -190,14 +194,15 @@ where
_cursor: Cursor,
_viewport: &Rectangle,
) {
draw(renderer, layout, &self);
draw(renderer, layout, self);
}
}

/// Processes an [`Event`] and updates the [`State`] of a [`SliderBar`]
/// accordingly.
#[allow(clippy::too_many_arguments)]
pub fn update<Message, T>(
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
shell: &mut Shell<'_, Message>,
Expand Down Expand Up @@ -255,8 +260,7 @@ where
}
}
Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left))
| Event::Touch(touch::Event::FingerLifted { .. })
| Event::Touch(touch::Event::FingerLost { .. }) => {
| Event::Touch(touch::Event::FingerLifted { .. } | touch::Event::FingerLost { .. }) => {
if is_dragging {
if let Some(on_release) = on_release.clone() {
shell.publish(on_release);
Expand Down Expand Up @@ -307,7 +311,7 @@ where
}
};

let background = slider.background.unwrap_or(Color::from([1.0; 3]));
let background = slider.background.unwrap_or_else(|| Color::from([1.0; 3]));

renderer.fill_quad(
renderer::Quad {
Expand Down Expand Up @@ -351,7 +355,8 @@ pub struct State {

impl State {
/// Creates a new [`State`].
pub fn new() -> State {
State::default()
#[must_use]
pub fn new() -> Self {
Self::default()
}
}

0 comments on commit 1ae540e

Please sign in to comment.