Skip to content

Commit

Permalink
Fix clippy warnings (#143)
Browse files Browse the repository at this point in the history
* cupertino: Remove a useless else branch

* cupertino: Use to_owned instead of to_string

* cupertino: Remove useless returns

* cupertino: Remove unnecessary not boolean operation

* cupertino: Allow the use of todo! macro in production code

* cupertino: Use expect instead of unwrap with more suitable messages

* cupertino: Allow type repetition

* cupertino: Add #[must_use] to a self function

* cupertino: Fix consistent format

* cupertino: Remove useless lifetime
  • Loading branch information
Luni-4 authored Jul 12, 2023
1 parent 84f77a4 commit e5a671b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 34 deletions.
67 changes: 43 additions & 24 deletions src/native/cupertino/cupertino_alert.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::todo)]

use iced_native::{
alignment,
event::Status,
Expand Down Expand Up @@ -158,8 +160,8 @@ where
width: Length::Fixed(400.0),
height: Length::Fixed(200.0),
is_hidden: true,
title: "Title".to_string(),
content: "Content".to_string(),
title: "Title".to_owned(),
content: "Content".to_owned(),
actions: vec![],
backdrop: None,
on_escape: None,
Expand Down Expand Up @@ -244,7 +246,7 @@ where
{
let as_text_element = element.into().font(SF_UI_ROUNDED);

return Element::from(as_text_element);
Element::from(as_text_element)
}
}

Expand All @@ -257,36 +259,36 @@ where
<Renderer as iced_native::text::Renderer>::Font: From<Font>,
{
fn width(&self) -> Length {
if !self.is_hidden {
self.width
} else {
if self.is_hidden {
Length::Fixed(0.0)
} else {
self.width
}
}

fn height(&self) -> Length {
if !self.is_hidden {
self.height
} else {
if self.is_hidden {
Length::Fixed(0.0)
} else {
self.height
}
}

fn layout(&self, _renderer: &Renderer, limits: &Limits) -> Node {
return Node::new(
Node::new(
limits
.width(if !self.is_hidden {
self.width
} else {
.width(if self.is_hidden {
Length::Fixed(0.0)
})
.height(if !self.is_hidden {
self.height
} else {
self.width
})
.height(if self.is_hidden {
Length::Fixed(0.0)
} else {
self.height
})
.resolve(Size::new(f32::INFINITY, f32::INFINITY)),
);
)
}

fn draw(
Expand Down Expand Up @@ -544,7 +546,12 @@ where

if hit_x.contains(&cursor_position.x) && hit_y.contains(&cursor_position.y)
{
shell.publish(self.actions[0].on_pressed.clone().unwrap());
shell.publish(
self.actions[0]
.on_pressed
.clone()
.expect("Unable to retrieve the left button click message"),
);
}
}

Expand All @@ -557,7 +564,12 @@ where

if hit_x.contains(&cursor_position.x) && hit_y.contains(&cursor_position.y)
{
shell.publish(self.actions[1].on_pressed.clone().unwrap());
shell.publish(
self.actions[1]
.on_pressed
.clone()
.expect("Unable to retrieve the right button click message"),
);
}
}
}
Expand All @@ -569,7 +581,11 @@ where

if !hit_x.contains(&cursor_position.x) || !hit_y.contains(&cursor_position.y) {
if self.backdrop.is_some() {
shell.publish(self.backdrop.clone().unwrap());
shell.publish(
self.backdrop
.clone()
.expect("Unable to retrieve the backdrop message"),
);
}

// Default behaviour: hide the modal after clicking on the backdrop //
Expand All @@ -581,20 +597,23 @@ where
if key_code == keyboard::KeyCode::Escape && self.on_escape.is_some() {
self.is_hidden = true;

shell.publish(self.on_escape.clone().unwrap());
shell.publish(
self.on_escape
.clone()
.expect("Unable to retrieve the escape message"),
);
return Status::Captured;
} else {
return Status::Ignored;
}
}

_ => return Status::Ignored,
}

return Status::Ignored;
Status::Ignored
}
}

#[allow(clippy::type_repetition_in_bounds)]
impl<'a, Message, Renderer: 'a> From<CupertinoAlert<'a, Message, Renderer>>
for Element<'a, Message, Renderer>
where
Expand Down
13 changes: 9 additions & 4 deletions src/native/cupertino/cupertino_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ where
}

/// Sets the `colour` of the [`CupertinoButton`](CupertinoButton).
#[must_use]
pub fn colour(mut self, colour: Option<Color>) -> Self {
self.colour = colour;
self
Expand Down Expand Up @@ -180,7 +181,7 @@ where
new_style.clone_from(style);

if self.colour.is_some() {
new_style.text_color = self.colour.unwrap();
new_style.text_color = self.colour.expect("Unable to retrieve the text colour");
} else if self.is_filled && self.on_pressed.is_some() {
new_style.text_color = Color::WHITE;
} else if !self.is_filled && self.on_pressed.is_some() {
Expand All @@ -199,7 +200,7 @@ where
layout,
cursor_position,
viewport,
)
);
}

fn on_event(
Expand All @@ -225,7 +226,11 @@ where
.contains(&cursor_position.y);

if hit_x && hit_y {
shell.publish(self.on_pressed.clone().unwrap());
shell.publish(
self.on_pressed
.clone()
.expect("Unable to retrieve the pressed message"),
);
return Status::Captured;
}
}
Expand All @@ -234,7 +239,7 @@ where
_ => {}
}

return Status::Ignored;
Status::Ignored
}
}

Expand Down
17 changes: 11 additions & 6 deletions src/native/cupertino/cupertino_switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ where
}
}

impl<'a, Message, B, T> Widget<Message, Renderer<B, T>> for CupertinoSwitch<Message>
impl<Message, B, T> Widget<Message, Renderer<B, T>> for CupertinoSwitch<Message>
where
B: Backend,
Message: Clone,
Expand All @@ -180,12 +180,12 @@ where
}

fn layout(&self, _renderer: &Renderer<B, T>, limits: &Limits) -> Node {
return Node::new(
Node::new(
limits
.width(self.width)
.height(self.height)
.resolve(Size::new(f32::INFINITY, f32::INFINITY)),
);
)
}

fn draw(
Expand Down Expand Up @@ -386,7 +386,12 @@ where
state.animation_frame = 0;

if self.on_changed.as_ref().is_some() {
shell.publish((self.on_changed.as_ref().unwrap())(!self.value));
shell.publish((self
.on_changed
.as_ref()
.expect("Unable to retrieve the changed message"))(
!self.value
));

state.prev_value = self.value;
state.published = true;
Expand All @@ -399,7 +404,7 @@ where
_ => {}
}

return Status::Ignored;
Status::Ignored
}

fn overlay<'b>(
Expand All @@ -412,7 +417,7 @@ where

state.bounds = layout.bounds();

return None;
None
}
}

Expand Down

0 comments on commit e5a671b

Please sign in to comment.