diff --git a/src/lib.rs b/src/lib.rs index 402ac775..8318e81f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ // Copyright 2022 System76 // SPDX-License-Identifier: MPL-2.0 +#![allow(clippy::module_name_repetitions)] + pub use iced; pub use iced_lazy; pub use iced_native; @@ -21,12 +23,14 @@ pub use theme::Theme; pub type Renderer = iced::Renderer; pub type Element<'a, Message> = iced::Element<'a, Message, Renderer>; +#[must_use] pub fn settings() -> iced::Settings { - let mut settings = iced::Settings::default(); - settings.default_font = match font::FONT { - iced::Font::Default => None, - iced::Font::External { bytes, .. } => Some(bytes), - }; - settings.default_text_size = 18; - settings + iced::Settings { + default_font: match font::FONT { + iced::Font::Default => None, + iced::Font::External { bytes, .. } => Some(bytes), + }, + default_text_size: 18, + .. iced::Settings::default() + } } diff --git a/src/theme/mod.rs b/src/theme/mod.rs index a5ccab08..99e7530a 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -144,6 +144,8 @@ impl Default for Button { } impl Button { + #[allow(clippy::trivially_copy_pass_by_ref)] + #[allow(clippy::match_same_arms)] fn cosmic(&self, theme: &Theme) -> &'static CosmicComponent { let cosmic = theme.cosmic(); match self { @@ -177,8 +179,7 @@ impl button::StyleSheet for Theme { _ => 24.0, }, background: match style { - Button::Text => None, - Button::Link => None, + Button::Link | Button::Text => None, Button::LinkActive => Some(Background::Color(cosmic.divider.into())), _ => Some(Background::Color(cosmic.base.into())), }, @@ -196,7 +197,7 @@ impl button::StyleSheet for Theme { return hover(self); } - let active = self.active(&style); + let active = self.active(style); let cosmic = style.cosmic(self); button::Appearance { @@ -416,7 +417,7 @@ impl slider::StyleSheet for Theme { } fn hovered(&self, style: &Self::Style) -> slider::Appearance { - let mut style = self.active(&style); + let mut style = self.active(style); style.handle.shape = slider::HandleShape::Circle { radius: 16.0 }; @@ -429,7 +430,7 @@ impl slider::StyleSheet for Theme { } fn dragging(&self, style: &Self::Style) -> slider::Appearance { - let mut style = self.hovered(&style); + let mut style = self.hovered(style); style.handle.border_color = match self { Theme::Dark => Color::from_rgba8(0xFF, 0xFF, 0xFF, 0.2), Theme::Light => Color::from_rgba8(0, 0, 0, 0.2), @@ -484,7 +485,7 @@ impl pick_list::StyleSheet for Theme { pick_list::Appearance { background: Background::Color(cosmic.hover.into()), - ..self.active(&style) + ..self.active(style) } } } @@ -508,7 +509,7 @@ impl radio::StyleSheet for Theme { } fn hovered(&self, style: &Self::Style, is_selected: bool) -> radio::Appearance { - let active = self.active(&style, is_selected); + let active = self.active(style, is_selected); let palette = self.extended_palette(); radio::Appearance { @@ -565,7 +566,7 @@ impl toggler::StyleSheet for Theme { } else { Color::from_rgb8(0xb6, 0xb6, 0xb6) }, - ..self.active(&style, is_active) + ..self.active(style, is_active) }, Theme::Light => toggler::Appearance { background: if is_active { @@ -573,7 +574,7 @@ impl toggler::StyleSheet for Theme { } else { Color::from_rgb8(0x54, 0x54, 0x54) }, - ..self.active(&style, is_active) + ..self.active(style, is_active) } } } @@ -752,6 +753,7 @@ impl svg::StyleSheet for Theme { type Style = Svg; fn appearance(&self, style: &Self::Style) -> svg::Appearance { + #[allow(clippy::match_same_arms)] match style { Svg::Default => svg::Appearance::default(), Svg::Custom(appearance) => appearance(self), diff --git a/src/theme/palette.rs b/src/theme/palette.rs index bd330836..6aca2263 100644 --- a/src/theme/palette.rs +++ b/src/theme/palette.rs @@ -17,6 +17,7 @@ pub struct Palette { } impl Palette { + #[allow(clippy::cast_precision_loss)] pub const LIGHT: Self = Self { background: Color::from_rgb( 0xee as f32 / 255.0, @@ -45,6 +46,7 @@ impl Palette { ), }; + #[allow(clippy::cast_precision_loss)] pub const DARK: Self = Self { background: Color::from_rgb( 0x1e as f32 / 255.0, @@ -107,6 +109,7 @@ pub struct Pair { } impl Pair { + #[must_use] pub fn new(color: Color, text: Color) -> Self { Self { color, diff --git a/src/widget/aspect_ratio.rs b/src/widget/aspect_ratio.rs index 8bcd6e8c..796b0e49 100644 --- a/src/widget/aspect_ratio.rs +++ b/src/widget/aspect_ratio.rs @@ -67,60 +67,70 @@ where } /// Sets the [`Padding`] of the [`Container`]. + #[must_use] pub fn padding>(mut self, padding: P) -> Self { self.container = self.container.padding(padding); self } /// Sets the width of the [`self.`]. + #[must_use] pub fn width(mut self, width: Length) -> Self { self.container = self.container.width(width); self } /// Sets the height of the [`Container`]. + #[must_use] pub fn height(mut self, height: Length) -> Self { self.container = self.container.height(height); self } /// Sets the maximum width of the [`Container`]. + #[must_use] pub fn max_width(mut self, max_width: u32) -> Self { self.container = self.container.max_width(max_width); self } /// Sets the maximum height of the [`Container`] in pixels. + #[must_use] pub fn max_height(mut self, max_height: u32) -> Self { self.container = self.container.max_height(max_height); self } /// Sets the content alignment for the horizontal axis of the [`Container`]. + #[must_use] pub fn align_x(mut self, alignment: alignment::Horizontal) -> Self { self.container = self.container.align_x(alignment); self } /// Sets the content alignment for the vertical axis of the [`Container`]. + #[must_use] pub fn align_y(mut self, alignment: alignment::Vertical) -> Self { self.container = self.container.align_y(alignment); self } /// Centers the contents in the horizontal axis of the [`Container`]. + #[must_use] pub fn center_x(mut self) -> Self { self.container = self.container.center_x(); self } /// Centers the contents in the vertical axis of the [`Container`]. + #[must_use] pub fn center_y(mut self) -> Self { self.container = self.container.center_y(); self } /// Sets the style of the [`Container`]. + #[must_use] pub fn style(mut self, style: impl Into<::Style>) -> Self { self.container = self.container.style(style); self @@ -155,7 +165,7 @@ where } fn operate(&self, tree: &mut Tree, layout: Layout<'_>, operation: &mut dyn Operation) { - self.container.operate(tree, layout, operation) + self.container.operate(tree, layout, operation); } fn on_event( @@ -209,7 +219,7 @@ where layout, cursor_position, viewport, - ) + ); } fn overlay<'b>( diff --git a/src/widget/icon.rs b/src/widget/icon.rs index 6ff4203b..e1564e00 100644 --- a/src/widget/icon.rs +++ b/src/widget/icon.rs @@ -7,9 +7,8 @@ use iced::{ widget::{svg, Image}, Length, ContentFit, }; -use std::{borrow::{Cow, Borrow}, ffi::OsStr, path::Path}; +use std::{borrow::Cow, collections::hash_map::DefaultHasher, ffi::OsStr, hash::Hasher, path::Path}; use std::hash::Hash; -use std::rc::Rc; use derive_setters::Setters; use crate::{Element, Renderer}; @@ -97,56 +96,56 @@ impl<'a> Icon<'a> { return image.into(); } - let element = Rc::new(self); - let element_clone = Rc::clone(&element); + let mut hasher = DefaultHasher::new(); + self.hash(&mut hasher); - iced_lazy::lazy(element_clone, move || -> Element { - let icon = match &element.name { + iced_lazy::lazy(hasher.finish(), move || -> Element { + let icon = match &self.name { IconSource::Path(path) => Some(Cow::from(*path)), IconSource::Name(name) => { - let icon = freedesktop_icons::lookup(&name) - .with_size(element.size) - .with_theme(&element.theme) + let icon = freedesktop_icons::lookup(name) + .with_size(self.size) + .with_theme(&self.theme) .with_cache() .find(); if icon.is_none() { - freedesktop_icons::lookup(&name) - .with_size(element.size) + freedesktop_icons::lookup(name) + .with_size(self.size) .with_cache() .find() } else { icon - }.map(|p| Cow::from(p)) + }.map(Cow::from) }, IconSource::Embedded(_) => unimplemented!(), }; - let is_svg = element.force_svg || icon.as_ref().map(|path| path.extension() == Some(&OsStr::new("svg"))).unwrap_or(true); + let is_svg = self.force_svg || icon.as_ref().map_or(true, |path| path.extension() == Some(OsStr::new("svg"))); if is_svg { let handle = if let Some(path) = icon { svg::Handle::from_path(path) } else { - eprintln!("icon '{:?}' size {} not found", &element.name, element.size); + eprintln!("icon '{:?}' size {} not found", &self.name, self.size); svg::Handle::from_memory(Vec::new()) }; - + let mut widget = svg::Svg::::new(handle) - .style(element.style) - .width(element.width.unwrap_or(Length::Units(element.size))) - .height(element.height.unwrap_or(Length::Units(element.size))); - - if let Some(content_fit) = element.content_fit { + .style(self.style) + .width(self.width.unwrap_or(Length::Units(self.size))) + .height(self.height.unwrap_or(Length::Units(self.size))); + + if let Some(content_fit) = self.content_fit { widget = widget.content_fit(content_fit); } - + widget.into() } else { let icon_path = icon.unwrap(); let mut image = Image::new(icon_path) - .width(element.width.unwrap_or(Length::Units(element.size))) - .height(element.height.unwrap_or(Length::Units(element.size))); - if let Some(content_fit) = element.content_fit { + .width(self.width.unwrap_or(Length::Units(self.size))) + .height(self.height.unwrap_or(Length::Units(self.size))); + if let Some(content_fit) = self.content_fit { image = image.content_fit(content_fit); } image.into() diff --git a/src/widget/list/column.rs b/src/widget/list/column.rs index 6222202a..5ae11c36 100644 --- a/src/widget/list/column.rs +++ b/src/widget/list/column.rs @@ -22,11 +22,13 @@ impl<'a, Message: 'static> Default for ListColumn<'a, Message> { } impl<'a, Message: 'static> ListColumn<'a, Message> { + #[must_use] pub fn new() -> Self { Self::default() } #[must_use] + #[allow(clippy::should_implement_trait)] pub fn add(mut self, item: impl Into>) -> Self { if !self.children.is_empty() { self.children.push(horizontal_rule(10).into()); @@ -53,6 +55,8 @@ impl<'a, Message: 'static> From> for Element<'a, Message } } +#[must_use] +#[allow(clippy::trivially_copy_pass_by_ref)] pub fn style(theme: &crate::Theme) -> iced::widget::container::Appearance { let cosmic = &theme.cosmic().primary; iced::widget::container::Appearance { diff --git a/src/widget/navigation/navbar.rs b/src/widget/navigation/navbar.rs index 0c4138f9..93d89286 100644 --- a/src/widget/navigation/navbar.rs +++ b/src/widget/navigation/navbar.rs @@ -21,9 +21,10 @@ pub struct NavBar<'a, Message> { } impl<'a, Message> NavBar<'a, Message> { + #[must_use] pub fn new() -> Self { Self { - source: Default::default(), + source: BTreeMap::default(), active: false, condensed: false, on_page_selected: None, @@ -31,6 +32,7 @@ impl<'a, Message> NavBar<'a, Message> { } } +#[must_use] pub fn nav_bar<'a, Message>() -> NavBar<'a, Message> { NavBar::new() } @@ -44,11 +46,13 @@ pub struct NavBarSection { } impl NavBarSection { + #[must_use] pub fn new() -> Self { Self::default() } } +#[must_use] pub fn nav_bar_section() -> NavBarSection { NavBarSection::new() } @@ -60,6 +64,7 @@ pub struct NavBarPage { } impl NavBarPage { + #[must_use] pub fn new() -> Self { Self { title: String::new(), @@ -67,6 +72,7 @@ impl NavBarPage { } } +#[must_use] pub fn nav_bar_page(title: &str) -> NavBarPage { let mut page = NavBarPage::new(); page.title = title.to_string(); @@ -136,9 +142,9 @@ impl<'a, Message> Component for NavBar<'a, Message> { ) .style( if *section == state.selected_section && state.section_active { - theme::Button::Primary.into() + theme::Button::Primary } else { - theme::Button::Text.into() + theme::Button::Text }, ) .on_press(NavBarEvent::SectionSelected(section.clone())) @@ -151,12 +157,12 @@ impl<'a, Message> Component for NavBar<'a, Message> { .padding(10) .style(if let Some(selected_page) = &state.selected_page { if state.page_active && page == selected_page { - theme::Button::Primary.into() + theme::Button::Primary } else { - theme::Button::Text.into() + theme::Button::Text } } else { - theme::Button::Text.into() + theme::Button::Text }) .on_press(NavBarEvent::PageSelected(section.clone(), page.clone())) .into(), @@ -218,14 +224,15 @@ impl<'a, Message: 'static> From> } } +#[must_use] pub fn section_button_style(theme: &Theme) -> Appearance { let primary = &theme.cosmic().primary; Appearance { - shadow_offset: Default::default(), + shadow_offset: iced::Vector::default(), background: Some(Background::Color(primary.base.into())), border_radius: 5.0, border_width: 0.0, - border_color: Default::default(), - text_color: Default::default(), + border_color: iced::Color::default(), + text_color: iced::Color::default(), } } diff --git a/src/widget/rectangle_tracker/mod.rs b/src/widget/rectangle_tracker/mod.rs index bc7f68ce..e30d4a85 100644 --- a/src/widget/rectangle_tracker/mod.rs +++ b/src/widget/rectangle_tracker/mod.rs @@ -71,60 +71,70 @@ where } /// Sets the [`Padding`] of the [`Container`]. + #[must_use] pub fn padding>(mut self, padding: P) -> Self { self.container = self.container.padding(padding); self } /// Sets the width of the [`self.`]. + #[must_use] pub fn width(mut self, width: Length) -> Self { self.container = self.container.width(width); self } /// Sets the height of the [`Container`]. + #[must_use] pub fn height(mut self, height: Length) -> Self { self.container = self.container.height(height); self } /// Sets the maximum width of the [`Container`]. + #[must_use] pub fn max_width(mut self, max_width: u32) -> Self { self.container = self.container.max_width(max_width); self } /// Sets the maximum height of the [`Container`] in pixels. + #[must_use] pub fn max_height(mut self, max_height: u32) -> Self { self.container = self.container.max_height(max_height); self } /// Sets the content alignment for the horizontal axis of the [`Container`]. + #[must_use] pub fn align_x(mut self, alignment: alignment::Horizontal) -> Self { self.container = self.container.align_x(alignment); self } /// Sets the content alignment for the vertical axis of the [`Container`]. + #[must_use] pub fn align_y(mut self, alignment: alignment::Vertical) -> Self { self.container = self.container.align_y(alignment); self } /// Centers the contents in the horizontal axis of the [`Container`]. + #[must_use] pub fn center_x(mut self) -> Self { self.container = self.container.center_x(); self } /// Centers the contents in the vertical axis of the [`Container`]. + #[must_use] pub fn center_y(mut self) -> Self { self.container = self.container.center_y(); self } /// Sets the style of the [`Container`]. + #[must_use] pub fn style(mut self, style: impl Into<::Style>) -> Self { self.container = self.container.style(style); self @@ -159,7 +169,7 @@ where } fn operate(&self, tree: &mut Tree, layout: Layout<'_>, operation: &mut dyn Operation) { - self.container.operate(tree, layout, operation) + self.container.operate(tree, layout, operation); } fn on_event( @@ -215,7 +225,7 @@ where layout, cursor_position, viewport, - ) + ); } fn overlay<'b>( diff --git a/src/widget/rectangle_tracker/subscription.rs b/src/widget/rectangle_tracker/subscription.rs index 468f8ab2..94c53ebb 100644 --- a/src/widget/rectangle_tracker/subscription.rs +++ b/src/widget/rectangle_tracker/subscription.rs @@ -32,13 +32,13 @@ async fn start_listening { let (tx, rx) = unbounded(); - return ( + ( Some((id, RectangleUpdate::Init(RectangleTracker { tx }))), State::Waiting(rx, HashMap::new()), - ); + ) } State::Waiting(mut rx, mut map) => match rx.next().await { - Some(u) => + Some(u) => { if let Some(prev) = map.get(&u.0) { let new = u.1; @@ -56,8 +56,8 @@ async fn start_listening (None, State::Finished), }, diff --git a/src/widget/separator.rs b/src/widget/separator.rs index f00bea74..9d1a6767 100644 --- a/src/widget/separator.rs +++ b/src/widget/separator.rs @@ -14,6 +14,7 @@ pub fn vertical_rule(size: u16) -> widget::Rule { widget::vertical_rule(size).style(theme::Rule::Custom(separator_style)) } +#[allow(clippy::trivially_copy_pass_by_ref)] fn separator_style(theme: &Theme) -> widget::rule::Appearance { let cosmic = &theme.cosmic().primary; widget::rule::Appearance { diff --git a/src/widget/settings/section.rs b/src/widget/settings/section.rs index 72712a9c..59fa7ce8 100644 --- a/src/widget/settings/section.rs +++ b/src/widget/settings/section.rs @@ -22,6 +22,7 @@ pub struct Section<'a, Message> { impl<'a, Message: 'static> Section<'a, Message> { #[must_use] + #[allow(clippy::should_implement_trait)] pub fn add(mut self, item: impl Into>) -> Self { self.children = self.children.add(item.into()); self diff --git a/src/widget/spin_button/mod.rs b/src/widget/spin_button/mod.rs index fb7774b5..a15196c1 100644 --- a/src/widget/spin_button/mod.rs +++ b/src/widget/spin_button/mod.rs @@ -105,6 +105,7 @@ impl<'a, T: 'static + Copy + Hash + ToString, Message: 'static> From iced_style::container::Appearance { let secondary = &theme.cosmic().secondary; let accent = &theme.cosmic().accent;