summaryrefslogtreecommitdiffstats
path: root/native/src
diff options
context:
space:
mode:
authorLibravatar Poly <marynczakbartlomiej@gmail.com>2022-07-04 01:17:29 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-07-09 17:07:38 +0200
commit15f794b7a89efb3299cb85b392ec13af145fb0fd (patch)
tree39d8c740168e4c09e15538451ba7f3899051ad43 /native/src
parente053e25d2ccb17f7a162685a106a8bbd915a873f (diff)
downloadiced-15f794b7a89efb3299cb85b392ec13af145fb0fd.tar.gz
iced-15f794b7a89efb3299cb85b392ec13af145fb0fd.tar.bz2
iced-15f794b7a89efb3299cb85b392ec13af145fb0fd.zip
Address Clippy lints
Diffstat (limited to 'native/src')
-rw-r--r--native/src/hasher.rs8
-rw-r--r--native/src/overlay/menu.rs22
-rw-r--r--native/src/program/state.rs2
-rw-r--r--native/src/user_interface.rs2
-rw-r--r--native/src/widget/checkbox.rs5
-rw-r--r--native/src/widget/pane_grid.rs3
-rw-r--r--native/src/widget/pane_grid/node.rs20
-rw-r--r--native/src/widget/pane_grid/state.rs5
-rw-r--r--native/src/widget/pick_list.rs13
-rw-r--r--native/src/widget/radio.rs8
-rw-r--r--native/src/widget/rule.rs2
-rw-r--r--native/src/widget/slider.rs4
-rw-r--r--native/src/widget/text.rs4
-rw-r--r--native/src/widget/text_input.rs22
-rw-r--r--native/src/widget/text_input/editor.rs19
-rw-r--r--native/src/widget/text_input/value.rs7
-rw-r--r--native/src/widget/toggler.rs7
17 files changed, 72 insertions, 81 deletions
diff --git a/native/src/hasher.rs b/native/src/hasher.rs
index 9f6aacce..fa52f16d 100644
--- a/native/src/hasher.rs
+++ b/native/src/hasher.rs
@@ -1,13 +1,7 @@
/// The hasher used to compare layouts.
-#[derive(Debug)]
+#[derive(Debug, Default)]
pub struct Hasher(twox_hash::XxHash64);
-impl Default for Hasher {
- fn default() -> Self {
- Hasher(twox_hash::XxHash64::default())
- }
-}
-
impl core::hash::Hasher for Hasher {
fn write(&mut self, bytes: &[u8]) {
self.0.write(bytes)
diff --git a/native/src/overlay/menu.rs b/native/src/overlay/menu.rs
index 979a13c3..0c25200c 100644
--- a/native/src/overlay/menu.rs
+++ b/native/src/overlay/menu.rs
@@ -174,9 +174,9 @@ where
Self {
container,
- width: width,
+ width,
target_height,
- style: style,
+ style,
}
}
}
@@ -230,7 +230,7 @@ where
shell: &mut Shell<'_, Message>,
) -> event::Status {
self.container.on_event(
- event.clone(),
+ event,
layout,
cursor_position,
renderer,
@@ -326,7 +326,8 @@ where
use std::f32;
let limits = limits.width(Length::Fill).height(Length::Shrink);
- let text_size = self.text_size.unwrap_or(renderer.default_size());
+ let text_size =
+ self.text_size.unwrap_or_else(|| renderer.default_size());
let size = {
let intrinsic = Size::new(
@@ -366,8 +367,9 @@ where
let bounds = layout.bounds();
if bounds.contains(cursor_position) {
- let text_size =
- self.text_size.unwrap_or(renderer.default_size());
+ let text_size = self
+ .text_size
+ .unwrap_or_else(|| renderer.default_size());
*self.hovered_option = Some(
((cursor_position.y - bounds.y)
@@ -380,8 +382,9 @@ where
let bounds = layout.bounds();
if bounds.contains(cursor_position) {
- let text_size =
- self.text_size.unwrap_or(renderer.default_size());
+ let text_size = self
+ .text_size
+ .unwrap_or_else(|| renderer.default_size());
*self.hovered_option = Some(
((cursor_position.y - bounds.y)
@@ -430,7 +433,8 @@ where
let appearance = theme.appearance(self.style);
let bounds = layout.bounds();
- let text_size = self.text_size.unwrap_or(renderer.default_size());
+ let text_size =
+ self.text_size.unwrap_or_else(|| renderer.default_size());
let option_height = (text_size + self.padding.vertical()) as usize;
let offset = viewport.y - bounds.y;
diff --git a/native/src/program/state.rs b/native/src/program/state.rs
index 7ec2a04f..2ddde2c2 100644
--- a/native/src/program/state.rs
+++ b/native/src/program/state.rs
@@ -113,7 +113,7 @@ where
&mut messages,
);
- messages.extend(self.queued_messages.drain(..));
+ messages.append(&mut self.queued_messages);
self.queued_events.clear();
debug.event_processing_finished();
diff --git a/native/src/user_interface.rs b/native/src/user_interface.rs
index 97a004e7..ef6f437e 100644
--- a/native/src/user_interface.rs
+++ b/native/src/user_interface.rs
@@ -430,7 +430,7 @@ where
overlay
.as_ref()
.and_then(|layout| {
- root.overlay(Layout::new(&base), renderer).map(|overlay| {
+ root.overlay(Layout::new(base), renderer).map(|overlay| {
let overlay_interaction = overlay.mouse_interaction(
Layout::new(layout),
cursor_position,
diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs
index 9e7f183a..a49d2fa2 100644
--- a/native/src/widget/checkbox.rs
+++ b/native/src/widget/checkbox.rs
@@ -158,7 +158,10 @@ where
Text::new(&self.label)
.font(self.font.clone())
.width(self.width)
- .size(self.text_size.unwrap_or(renderer.default_size())),
+ .size(
+ self.text_size
+ .unwrap_or_else(|| renderer.default_size()),
+ ),
)
.layout(renderer, limits)
}
diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs
index eb969dbf..70ca772c 100644
--- a/native/src/widget/pane_grid.rs
+++ b/native/src/widget/pane_grid.rs
@@ -835,8 +835,7 @@ fn hovered_split<'a>(
) -> Option<(Split, Axis, Rectangle)> {
splits
.filter_map(|(split, (axis, region, ratio))| {
- let bounds =
- axis.split_line_bounds(*region, *ratio, f32::from(spacing));
+ let bounds = axis.split_line_bounds(*region, *ratio, spacing);
if bounds.contains(cursor_position) {
Some((*split, *axis, bounds))
diff --git a/native/src/widget/pane_grid/node.rs b/native/src/widget/pane_grid/node.rs
index af6573a0..cc304b96 100644
--- a/native/src/widget/pane_grid/node.rs
+++ b/native/src/widget/pane_grid/node.rs
@@ -36,14 +36,11 @@ impl Node {
std::iter::from_fn(move || {
while let Some(node) = unvisited_nodes.pop() {
- match node {
- Node::Split { id, a, b, .. } => {
- unvisited_nodes.push(a);
- unvisited_nodes.push(b);
+ if let Node::Split { id, a, b, .. } = node {
+ unvisited_nodes.push(a);
+ unvisited_nodes.push(b);
- return Some(id);
- }
- _ => {}
+ return Some(id);
}
}
@@ -124,12 +121,9 @@ impl Node {
}
pub(crate) fn update(&mut self, f: &impl Fn(&mut Node)) {
- match self {
- Node::Split { a, b, .. } => {
- a.update(f);
- b.update(f);
- }
- _ => {}
+ if let Node::Split { a, b, .. } = self {
+ a.update(f);
+ b.update(f);
}
f(self);
diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs
index 6a282d24..4e90f645 100644
--- a/native/src/widget/pane_grid/state.rs
+++ b/native/src/widget/pane_grid/state.rs
@@ -66,6 +66,11 @@ impl<T> State<T> {
self.panes.len()
}
+ /// Returns `true` if the amount of panes in the [`State`] is 0.
+ pub fn is_empty(&self) -> bool {
+ self.len() == 0
+ }
+
/// Returns the internal state of the given [`Pane`], if it exists.
pub fn get(&self, pane: &Pane) -> Option<&T> {
self.panes.get(pane)
diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs
index c6cfcc01..e735151e 100644
--- a/native/src/widget/pick_list.rs
+++ b/native/src/widget/pick_list.rs
@@ -160,7 +160,7 @@ where
let limits = limits.width(width).height(Length::Shrink).pad(padding);
- let text_size = text_size.unwrap_or(renderer.default_size());
+ let text_size = text_size.unwrap_or_else(|| renderer.default_size());
let max_width = match width {
Length::Shrink => {
@@ -407,10 +407,9 @@ pub fn draw<T, Renderer>(
let label = selected.map(ToString::to_string);
- if let Some(label) =
- label.as_ref().map(String::as_str).or_else(|| placeholder)
- {
- let text_size = f32::from(text_size.unwrap_or(renderer.default_size()));
+ if let Some(label) = label.as_deref().or(placeholder) {
+ let text_size =
+ f32::from(text_size.unwrap_or_else(|| renderer.default_size()));
renderer.fill_text(Text {
content: label,
@@ -460,7 +459,7 @@ where
self.padding,
self.text_size,
&self.font,
- self.placeholder.as_ref().map(String::as_str),
+ self.placeholder.as_deref(),
&self.options,
)
}
@@ -513,7 +512,7 @@ where
self.padding,
self.text_size,
&self.font,
- self.placeholder.as_ref().map(String::as_str),
+ self.placeholder.as_deref(),
self.selected.as_ref(),
self.style,
)
diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs
index ba45a0f4..647e3c5a 100644
--- a/native/src/widget/radio.rs
+++ b/native/src/widget/radio.rs
@@ -168,11 +168,9 @@ where
.width(Length::Units(self.size))
.height(Length::Units(self.size)),
)
- .push(
- Text::new(&self.label)
- .width(self.width)
- .size(self.text_size.unwrap_or(renderer.default_size())),
- )
+ .push(Text::new(&self.label).width(self.width).size(
+ self.text_size.unwrap_or_else(|| renderer.default_size()),
+ ))
.layout(renderer, limits)
}
diff --git a/native/src/widget/rule.rs b/native/src/widget/rule.rs
index 26285df4..f0fda8a9 100644
--- a/native/src/widget/rule.rs
+++ b/native/src/widget/rule.rs
@@ -36,7 +36,7 @@ where
/// Creates a vertical [`Rule`] with the given width.
pub fn vertical(width: u16) -> Self {
Rule {
- width: Length::from(Length::Units(width)),
+ width: Length::Units(width),
height: Length::Fill,
is_horizontal: false,
style: Default::default(),
diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs
index bda31327..c75c1e99 100644
--- a/native/src/widget/slider.rs
+++ b/native/src/widget/slider.rs
@@ -303,7 +303,7 @@ pub fn draw<T, R>(
HandleShape::Rectangle {
width,
border_radius,
- } => (f32::from(width), f32::from(bounds.height), border_radius),
+ } => (f32::from(width), bounds.height, border_radius),
};
let value = value.into() as f32;
@@ -447,7 +447,7 @@ where
_viewport: &Rectangle,
_renderer: &Renderer,
) -> mouse::Interaction {
- mouse_interaction(layout, cursor_position, &self.state)
+ mouse_interaction(layout, cursor_position, self.state)
}
}
diff --git a/native/src/widget/text.rs b/native/src/widget/text.rs
index 242247b0..8d173b8a 100644
--- a/native/src/widget/text.rs
+++ b/native/src/widget/text.rs
@@ -131,7 +131,7 @@ where
) -> layout::Node {
let limits = limits.width(self.width).height(self.height);
- let size = self.size.unwrap_or(renderer.default_size());
+ let size = self.size.unwrap_or_else(|| renderer.default_size());
let bounds = limits.max();
@@ -205,7 +205,7 @@ pub fn draw<Renderer>(
renderer.fill_text(crate::text::Text {
content,
- size: f32::from(size.unwrap_or(renderer.default_size())),
+ size: f32::from(size.unwrap_or_else(|| renderer.default_size())),
bounds: Rectangle { x, y, ..bounds },
color: appearance.color.unwrap_or(style.text_color),
font,
diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs
index d345cec3..835b2b4d 100644
--- a/native/src/widget/text_input.rs
+++ b/native/src/widget/text_input.rs
@@ -198,7 +198,7 @@ pub fn layout<Renderer>(
where
Renderer: text::Renderer,
{
- let text_size = size.unwrap_or(renderer.default_size());
+ let text_size = size.unwrap_or_else(|| renderer.default_size());
let limits = limits
.pad(padding)
@@ -498,7 +498,7 @@ where
None => {
let content: String = clipboard
.read()
- .unwrap_or(String::new())
+ .unwrap_or_default()
.chars()
.filter(|c| !c.is_control())
.collect();
@@ -597,7 +597,7 @@ pub fn draw<Renderer>(
Renderer::Theme: StyleSheet,
{
let secure_value = is_secure.then(|| value.secure());
- let value = secure_value.as_ref().unwrap_or(&value);
+ let value = secure_value.as_ref().unwrap_or(value);
let bounds = layout.bounds();
let text_bounds = layout.children().next().unwrap().bounds();
@@ -623,16 +623,16 @@ pub fn draw<Renderer>(
);
let text = value.to_string();
- let size = size.unwrap_or(renderer.default_size());
+ let size = size.unwrap_or_else(|| renderer.default_size());
let (cursor, offset) = if state.is_focused() {
- match state.cursor.state(&value) {
+ match state.cursor.state(value) {
cursor::State::Index(position) => {
let (text_value_width, offset) =
measure_cursor_and_scroll_offset(
renderer,
text_bounds,
- &value,
+ value,
size,
position,
font.clone(),
@@ -664,7 +664,7 @@ pub fn draw<Renderer>(
measure_cursor_and_scroll_offset(
renderer,
text_bounds,
- &value,
+ value,
size,
left,
font.clone(),
@@ -674,7 +674,7 @@ pub fn draw<Renderer>(
measure_cursor_and_scroll_offset(
renderer,
text_bounds,
- &value,
+ value,
size,
right,
font.clone(),
@@ -998,16 +998,16 @@ fn find_cursor_position<Renderer>(
where
Renderer: text::Renderer,
{
- let size = size.unwrap_or(renderer.default_size());
+ let size = size.unwrap_or_else(|| renderer.default_size());
let offset =
- offset(renderer, text_bounds, font.clone(), size, &value, &state);
+ offset(renderer, text_bounds, font.clone(), size, value, state);
renderer
.hit_test(
&value.to_string(),
size.into(),
- font.clone(),
+ font,
Size::INFINITY,
Point::new(x + offset, text_bounds.height / 2.0),
true,
diff --git a/native/src/widget/text_input/editor.rs b/native/src/widget/text_input/editor.rs
index bac530e1..d53fa8d9 100644
--- a/native/src/widget/text_input/editor.rs
+++ b/native/src/widget/text_input/editor.rs
@@ -15,12 +15,9 @@ impl<'a> Editor<'a> {
}
pub fn insert(&mut self, character: char) {
- match self.cursor.selection(self.value) {
- Some((left, right)) => {
- self.cursor.move_left(self.value);
- self.value.remove_many(left, right);
- }
- _ => {}
+ if let Some((left, right)) = self.cursor.selection(self.value) {
+ self.cursor.move_left(self.value);
+ self.value.remove_many(left, right);
}
self.value.insert(self.cursor.end(self.value), character);
@@ -29,13 +26,9 @@ impl<'a> Editor<'a> {
pub fn paste(&mut self, content: Value) {
let length = content.len();
-
- match self.cursor.selection(self.value) {
- Some((left, right)) => {
- self.cursor.move_left(self.value);
- self.value.remove_many(left, right);
- }
- _ => {}
+ if let Some((left, right)) = self.cursor.selection(self.value) {
+ self.cursor.move_left(self.value);
+ self.value.remove_many(left, right);
}
self.value.insert_many(self.cursor.end(self.value), content);
diff --git a/native/src/widget/text_input/value.rs b/native/src/widget/text_input/value.rs
index 2034cca4..cf4da562 100644
--- a/native/src/widget/text_input/value.rs
+++ b/native/src/widget/text_input/value.rs
@@ -37,7 +37,7 @@ impl Value {
let previous_string =
&self.graphemes[..index.min(self.graphemes.len())].concat();
- UnicodeSegmentation::split_word_bound_indices(&previous_string as &str)
+ UnicodeSegmentation::split_word_bound_indices(previous_string as &str)
.filter(|(_, word)| !word.trim_start().is_empty())
.next_back()
.map(|(i, previous_word)| {
@@ -58,9 +58,8 @@ impl Value {
pub fn next_end_of_word(&self, index: usize) -> usize {
let next_string = &self.graphemes[index..].concat();
- UnicodeSegmentation::split_word_bound_indices(&next_string as &str)
- .filter(|(_, word)| !word.trim_start().is_empty())
- .next()
+ UnicodeSegmentation::split_word_bound_indices(next_string as &str)
+ .find(|(_, word)| !word.trim_start().is_empty())
.map(|(i, next_word)| {
index
+ UnicodeSegmentation::graphemes(next_word, true).count()
diff --git a/native/src/widget/toggler.rs b/native/src/widget/toggler.rs
index 0936c271..3deaf287 100644
--- a/native/src/widget/toggler.rs
+++ b/native/src/widget/toggler.rs
@@ -162,7 +162,10 @@ where
.horizontal_alignment(self.text_alignment)
.font(self.font.clone())
.width(self.width)
- .size(self.text_size.unwrap_or(renderer.default_size())),
+ .size(
+ self.text_size
+ .unwrap_or_else(|| renderer.default_size()),
+ ),
);
}
@@ -239,7 +242,7 @@ where
renderer,
style,
label_layout,
- &label,
+ label,
self.text_size,
self.font.clone(),
Default::default(),