chore: Apply clippy lints

This commit is contained in:
Michael Aaron Murphy 2022-12-23 15:10:13 +01:00
parent 03dfc009fd
commit dcbde3b1f2
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
12 changed files with 100 additions and 58 deletions

View file

@ -67,60 +67,70 @@ where
}
/// Sets the [`Padding`] of the [`Container`].
#[must_use]
pub fn padding<P: Into<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<<Renderer::Theme as StyleSheet>::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<Message>) {
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>(

View file

@ -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<Message> {
let icon = match &element.name {
iced_lazy::lazy(hasher.finish(), move || -> Element<Message> {
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::<Renderer>::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()

View file

@ -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<Element<'a, Message>>) -> Self {
if !self.children.is_empty() {
self.children.push(horizontal_rule(10).into());
@ -53,6 +55,8 @@ impl<'a, Message: 'static> From<ListColumn<'a, Message>> 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 {

View file

@ -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<Message, Renderer> 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<Message, Renderer> 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<NavBar<'a, Message>>
}
}
#[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(),
}
}

View file

@ -71,60 +71,70 @@ where
}
/// Sets the [`Padding`] of the [`Container`].
#[must_use]
pub fn padding<P: Into<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<<Renderer::Theme as StyleSheet>::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<Message>) {
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>(

View file

@ -32,13 +32,13 @@ async fn start_listening<I: Copy, R: 'static + Hash + Copy + Send + Sync + Debug
State::Ready => {
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<I: Copy, R: 'static + Hash + Copy + Send + Sync + Debug
State::Waiting(rx, map),
);
}
return (None, State::Waiting(rx, map))
(None, State::Waiting(rx, map))
},
None => (None, State::Finished),
},

View file

@ -14,6 +14,7 @@ pub fn vertical_rule(size: u16) -> widget::Rule<Renderer> {
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 {

View file

@ -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<Element<'a, Message>>) -> Self {
self.children = self.children.add(item.into());
self

View file

@ -105,6 +105,7 @@ impl<'a, T: 'static + Copy + Hash + ToString, Message: 'static> From<SpinButton<
}
}
#[allow(clippy::trivially_copy_pass_by_ref)]
fn container_style(theme: &crate::Theme) -> iced_style::container::Appearance {
let secondary = &theme.cosmic().secondary;
let accent = &theme.cosmic().accent;