chore: fixing linter warnings

This commit is contained in:
danieleades 2023-11-28 19:02:08 +00:00 committed by GitHub
parent ebcfa5f2d0
commit 8e99406a8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 79 additions and 75 deletions

View file

@ -215,7 +215,7 @@ impl Config {
//TODO: handle errors //TODO: handle errors
} }
}, },
Err(err) => { Err(_err) => {
//TODO: handle errors //TODO: handle errors
} }
} }
@ -224,7 +224,7 @@ impl Config {
f(&watch_config, &keys); f(&watch_config, &keys);
} }
} }
Err(err) => { Err(_err) => {
//TODO: handle errors //TODO: handle errors
} }
} }

View file

@ -5,7 +5,6 @@ use cosmic::{
cosmic_theme, cosmic_theme,
iced::widget::{checkbox, column, progress_bar, radio, slider, text, text_input}, iced::widget::{checkbox, column, progress_bar, radio, slider, text, text_input},
iced::{id, Alignment, Length}, iced::{id, Alignment, Length},
iced_core::Color,
theme::ThemeType, theme::ThemeType,
widget::{ widget::{
button, color_picker::ColorPickerUpdate, cosmic_container::container, dropdown, icon, button, color_picker::ColorPickerUpdate, cosmic_container::container, dropdown, icon,

View file

@ -1,7 +1,7 @@
use cosmic::iced::widget::{horizontal_space, row}; use cosmic::iced::widget::{horizontal_space, row};
use cosmic::iced::{Alignment, Length}; use cosmic::iced::{Alignment, Length};
use cosmic::widget::{button, icon, segmented_button, view_switcher}; use cosmic::widget::{button, icon, segmented_button, view_switcher};
use cosmic::{theme, Apply, Element}; use cosmic::{Apply, Element};
use slotmap::Key; use slotmap::Key;
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]

View file

@ -78,7 +78,7 @@ where
fn new((core, flags): Self::Flags) -> (Self, iced::Command<Self::Message>) { fn new((core, flags): Self::Flags) -> (Self, iced::Command<Self::Message>) {
let (model, command) = T::init(core, flags); let (model, command) = T::init(core, flags);
(Cosmic::new(model), command) (Self::new(model), command)
} }
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]

View file

@ -92,11 +92,11 @@ pub trait ColorExt {
impl ColorExt for iced::Color { impl ColorExt for iced::Color {
fn blend_alpha(self, background: Self, alpha: f32) -> Self { fn blend_alpha(self, background: Self, alpha: f32) -> Self {
Color { Self {
a: 1.0, a: 1.0,
r: background.r + (self.r - background.r) * alpha, r: (self.r - background.r).mul_add(alpha, background.r),
g: background.g + (self.g - background.g) * alpha, g: (self.g - background.g).mul_add(alpha, background.g),
b: background.b + (self.b - background.b) * alpha, b: (self.b - background.b).mul_add(alpha, background.b),
} }
} }
} }

View file

@ -68,7 +68,7 @@ pub fn appearance(
} }
Button::Icon | Button::IconVertical => { Button::Icon | Button::IconVertical => {
if let Button::IconVertical = style { if matches!(style, Button::IconVertical) {
corner_radii = &cosmic.corner_radii.radius_m; corner_radii = &cosmic.corner_radii.radius_m;
} }

View file

@ -84,17 +84,17 @@ impl Button {
fn cosmic<'a>(&'a self, theme: &'a Theme) -> &CosmicComponent { fn cosmic<'a>(&'a self, theme: &'a Theme) -> &CosmicComponent {
let cosmic = theme.cosmic(); let cosmic = theme.cosmic();
match self { match self {
Button::Primary => &cosmic.accent_button, Self::Primary => &cosmic.accent_button,
Button::Secondary => &theme.current_container().component, Self::Secondary => &theme.current_container().component,
Button::Positive => &cosmic.success_button, Self::Positive => &cosmic.success_button,
Button::Destructive => &cosmic.destructive_button, Self::Destructive => &cosmic.destructive_button,
Button::Text => &cosmic.text_button, Self::Text => &cosmic.text_button,
Button::Link => &cosmic.accent_button, Self::Link => &cosmic.accent_button,
Button::LinkActive => &cosmic.accent_button, Self::LinkActive => &cosmic.accent_button,
Button::Transparent => &TRANSPARENT_COMPONENT, Self::Transparent => &TRANSPARENT_COMPONENT,
Button::Deactivated => &theme.current_container().component, Self::Deactivated => &theme.current_container().component,
Button::Card => &theme.current_container().component, Self::Card => &theme.current_container().component,
Button::Custom { .. } => &TRANSPARENT_COMPONENT, Self::Custom { .. } => &TRANSPARENT_COMPONENT,
} }
} }
} }
@ -950,7 +950,7 @@ pub enum Text {
impl From<Color> for Text { impl From<Color> for Text {
fn from(color: Color) -> Self { fn from(color: Color) -> Self {
Text::Color(color) Self::Color(color)
} }
} }

View file

@ -306,7 +306,7 @@ where
} }
} }
if let event::Status::Captured = self.content.as_widget_mut().on_event( if self.content.as_widget_mut().on_event(
&mut tree.children[0], &mut tree.children[0],
event.clone(), event.clone(),
layout.children().next().unwrap(), layout.children().next().unwrap(),
@ -315,7 +315,8 @@ where
clipboard, clipboard,
shell, shell,
viewport, viewport,
) { ) == event::Status::Captured
{
return event::Status::Captured; return event::Status::Captured;
} }
@ -549,6 +550,7 @@ where
/// The local state of a [`Button`]. /// The local state of a [`Button`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[allow(clippy::struct_field_names)]
pub struct State { pub struct State {
is_hovered: bool, is_hovered: bool,
is_pressed: bool, is_pressed: bool,
@ -557,8 +559,8 @@ pub struct State {
impl State { impl State {
/// Creates a new [`State`]. /// Creates a new [`State`].
pub fn new() -> State { pub fn new() -> Self {
State::default() Self::default()
} }
/// Returns whether the [`Button`] is currently focused or not. /// Returns whether the [`Button`] is currently focused or not.
@ -806,15 +808,15 @@ pub fn focus<Message: 'static>(id: Id) -> Command<Message> {
impl operation::Focusable for State { impl operation::Focusable for State {
fn is_focused(&self) -> bool { fn is_focused(&self) -> bool {
State::is_focused(*self) Self::is_focused(*self)
} }
fn focus(&mut self) { fn focus(&mut self) {
State::focus(self); Self::focus(self);
} }
fn unfocus(&mut self) { fn unfocus(&mut self) {
State::unfocus(self); Self::unfocus(self);
} }
} }

View file

@ -589,16 +589,20 @@ where
let t = t.cosmic(); let t = t.cosmic();
let handle_radius = f32::from(t.space_xs()) / 2.0; let handle_radius = f32::from(t.space_xs()) / 2.0;
let (x, y) = ( let (x, y) = (
(self.active_color.saturation * bounds.width) + bounds.position().x - handle_radius, self.active_color
((1.0 - self.active_color.value) * bounds.height) + bounds.position().y - handle_radius, .saturation
.mul_add(bounds.width, bounds.position().x)
- handle_radius,
(1.0 - self.active_color.value).mul_add(bounds.height, bounds.position().y)
- handle_radius,
); );
renderer.fill_quad( renderer.fill_quad(
Quad { Quad {
bounds: Rectangle { bounds: Rectangle {
x, x,
y, y,
width: 1.0 + handle_radius * 2.0, width: handle_radius.mul_add(2.0, 1.0),
height: 1.0 + handle_radius * 2.0, height: handle_radius.mul_add(2.0, 1.0),
}, },
border_radius: (1.0 + handle_radius).into(), border_radius: (1.0 + handle_radius).into(),
border_width: 1.0, border_width: 1.0,
@ -654,8 +658,8 @@ where
match event { match event {
Event::Mouse(mouse::Event::CursorMoved { .. } | mouse::Event::CursorEntered) => { Event::Mouse(mouse::Event::CursorMoved { .. } | mouse::Event::CursorEntered) => {
if let Some(mut clamped) = cursor.position() { if let Some(mut clamped) = cursor.position() {
clamped.x = clamped.x.min(bounds.x + bounds.width).max(bounds.x); clamped.x = clamped.x.clamp(bounds.x, bounds.x + bounds.width);
clamped.y = clamped.y.min(bounds.y + bounds.height).max(bounds.y); clamped.y = clamped.y.clamp(bounds.y, bounds.y + bounds.height);
let relative_pos = clamped - bounds.position(); let relative_pos = clamped - bounds.position();
let (s, v) = ( let (s, v) = (
relative_pos.x / bounds.width, relative_pos.x / bounds.width,
@ -678,7 +682,7 @@ where
} }
let column_tree = &mut tree.children[0]; let column_tree = &mut tree.children[0];
if let event::Status::Captured = self.inner.as_widget_mut().on_event( if self.inner.as_widget_mut().on_event(
column_tree, column_tree,
event.clone(), event.clone(),
column_layout, column_layout,
@ -687,7 +691,8 @@ where
clipboard, clipboard,
shell, shell,
viewport, viewport,
) { ) == event::Status::Captured
{
return event::Status::Captured; return event::Status::Captured;
} }

View file

@ -17,7 +17,6 @@ use iced_core::{
}; };
use iced_renderer::core::widget::OperationOutputWrapper; use iced_renderer::core::widget::OperationOutputWrapper;
pub use iced_style::container::{Appearance, StyleSheet};
#[must_use] #[must_use]
pub struct ContextDrawer<'a, Message> { pub struct ContextDrawer<'a, Message> {

View file

@ -423,14 +423,14 @@ impl<'a, S: AsRef<str>, Message> Widget<Message, crate::Renderer> for List<'a, S
let bounds = Rectangle { let bounds = Rectangle {
x: bounds.x, x: bounds.x,
y: bounds.y + (option_height * i as f32), y: option_height.mul_add(i as f32, bounds.y),
width: bounds.width, width: bounds.width,
height: option_height, height: option_height,
}; };
let (color, font) = if self.selected_option == Some(i) { let (color, font) = if self.selected_option == Some(i) {
let item_x = bounds.x + appearance.border_width; let item_x = bounds.x + appearance.border_width;
let item_width = bounds.width - appearance.border_width * 2.0; let item_width = appearance.border_width.mul_add(-2.0, bounds.width);
renderer.fill_quad( renderer.fill_quad(
renderer::Quad { renderer::Quad {
@ -463,7 +463,7 @@ impl<'a, S: AsRef<str>, Message> Widget<Message, crate::Renderer> for List<'a, S
(appearance.selected_text_color, crate::font::FONT_SEMIBOLD) (appearance.selected_text_color, crate::font::FONT_SEMIBOLD)
} else if *self.hovered_option == Some(i) { } else if *self.hovered_option == Some(i) {
let item_x = bounds.x + appearance.border_width; let item_x = bounds.x + appearance.border_width;
let item_width = bounds.width - appearance.border_width * 2.0; let item_width = appearance.border_width.mul_add(-2.0, bounds.width);
renderer.fill_quad( renderer.fill_quad(
renderer::Quad { renderer::Quad {

View file

@ -173,7 +173,6 @@ impl<'a, S: AsRef<str>, Message: 'a> Widget<Message, crate::Renderer> for Dropdo
self.gap, self.gap,
self.padding, self.padding,
self.text_size.unwrap_or(14.0), self.text_size.unwrap_or(14.0),
self.font,
self.selections, self.selections,
self.selected, self.selected,
&self.on_selected, &self.on_selected,
@ -359,7 +358,6 @@ pub fn overlay<'a, S: AsRef<str>, Message: 'a>(
gap: f32, gap: f32,
padding: Padding, padding: Padding,
text_size: f32, text_size: f32,
font: Option<crate::font::Font>,
selections: &'a [S], selections: &'a [S],
selected_option: Option<usize>, selected_option: Option<usize>,
on_selected: &'a dyn Fn(usize) -> Message, on_selected: &'a dyn Fn(usize) -> Message,

View file

@ -72,8 +72,14 @@ impl Icon {
fn into_element<Message: 'static>(self) -> Element<'static, Message> { fn into_element<Message: 'static>(self) -> Element<'static, Message> {
let from_image = |handle| { let from_image = |handle| {
Image::new(handle) Image::new(handle)
.width(self.width.unwrap_or(Length::Fixed(f32::from(self.size)))) .width(
.height(self.height.unwrap_or(Length::Fixed(f32::from(self.size)))) self.width
.unwrap_or_else(|| Length::Fixed(f32::from(self.size))),
)
.height(
self.height
.unwrap_or_else(|| Length::Fixed(f32::from(self.size))),
)
.content_fit(self.content_fit) .content_fit(self.content_fit)
.into() .into()
}; };
@ -81,8 +87,14 @@ impl Icon {
let from_svg = |handle| { let from_svg = |handle| {
Svg::<Renderer>::new(handle) Svg::<Renderer>::new(handle)
.style(self.style.clone()) .style(self.style.clone())
.width(self.width.unwrap_or(Length::Fixed(f32::from(self.size)))) .width(
.height(self.height.unwrap_or(Length::Fixed(f32::from(self.size)))) self.width
.unwrap_or_else(|| Length::Fixed(f32::from(self.size))),
)
.height(
self.height
.unwrap_or_else(|| Length::Fixed(f32::from(self.size))),
)
.content_fit(self.content_fit) .content_fit(self.content_fit)
.symbolic(self.handle.symbolic) .symbolic(self.handle.symbolic)
.into() .into()

View file

@ -48,10 +48,10 @@ where
let num = self.model.items.len(); let num = self.model.items.len();
if num != 0 { if num != 0 {
let spacing = f32::from(self.spacing); let spacing = f32::from(self.spacing);
bounds.width = (bounds.width - (num as f32 * spacing) + spacing) / num as f32; bounds.width = ((num as f32).mul_add(-spacing, bounds.width) + spacing) / num as f32;
if nth != 0 { if nth != 0 {
bounds.x += (nth as f32 * bounds.width) + (nth as f32 * spacing); bounds.x += (nth as f32).mul_add(bounds.width, nth as f32 * spacing);
} }
} }
@ -69,7 +69,7 @@ where
let spacing = f32::from(self.spacing); let spacing = f32::from(self.spacing);
if num != 0 { if num != 0 {
width = (num as f32 * width) + (num as f32 * spacing) - spacing; width = (num as f32).mul_add(width, num as f32 * spacing) - spacing;
} }
let size = limits let size = limits

View file

@ -183,7 +183,7 @@ where
self.storage self.storage
.0 .0
.entry(TypeId::of::<Data>()) .entry(TypeId::of::<Data>())
.or_insert_with(SecondaryMap::new) .or_default()
.insert(id, Box::new(data)); .insert(id, Box::new(data));
} }
} }
@ -297,7 +297,7 @@ where
} }
pub fn indent(&self, id: Entity) -> Option<u16> { pub fn indent(&self, id: Entity) -> Option<u16> {
self.indents.get(id).map(|indent| *indent) self.indents.get(id).copied()
} }
pub fn indent_set(&mut self, id: Entity, indent: u16) -> Option<u16> { pub fn indent_set(&mut self, id: Entity, indent: u16) -> Option<u16> {

View file

@ -28,7 +28,7 @@ pub enum State {
impl Default for Cursor { impl Default for Cursor {
fn default() -> Self { fn default() -> Self {
Cursor { Self {
state: State::Index(0), state: State::Index(0),
} }
} }

View file

@ -915,7 +915,7 @@ pub fn layout<Message>(
text_node.move_to(Point::new( text_node.move_to(Point::new(
padding.left + leading_icon_width, padding.left + leading_icon_width,
padding.top + ((text_input_height - text_size * 1.2) / 2.0).max(0.0), padding.top + (text_size.mul_add(-1.2, text_input_height) / 2.0).max(0.0),
)); ));
let mut node_list: Vec<_> = Vec::with_capacity(3); let mut node_list: Vec<_> = Vec::with_capacity(3);
@ -1515,18 +1515,6 @@ where
} }
} }
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
Event::PlatformSpecific(PlatformSpecific::Wayland(wayland::Event::DataSource(
wayland::DataSourceEvent::Cancelled
| wayland::DataSourceEvent::DndFinished
| wayland::DataSourceEvent::Cancelled,
))) => {
let state = state();
if matches!(state.dragging_state, Some(DraggingState::Dnd(..))) {
state.dragging_state = None;
return event::Status::Captured;
}
}
#[cfg(feature = "wayland")]
Event::PlatformSpecific(PlatformSpecific::Wayland(wayland::Event::DataSource( Event::PlatformSpecific(PlatformSpecific::Wayland(wayland::Event::DataSource(
wayland::DataSourceEvent::DndActionAccepted(action), wayland::DataSourceEvent::DndActionAccepted(action),
))) => { ))) => {
@ -1872,8 +1860,8 @@ pub fn draw<'a, Message>(
let offset_bounds = Rectangle { let offset_bounds = Rectangle {
x: bounds.x - border_offset, x: bounds.x - border_offset,
y: bounds.y - border_offset, y: bounds.y - border_offset,
width: bounds.width + border_offset * 2.0, width: border_offset.mul_add(2.0, bounds.width),
height: bounds.height + border_offset * 2.0, height: border_offset.mul_add(2.0, bounds.height),
}; };
renderer.fill_quad( renderer.fill_quad(
renderer::Quad { renderer::Quad {
@ -2228,6 +2216,7 @@ impl State {
Self { Self {
is_focused: None, is_focused: None,
dragging_state: None, dragging_state: None,
#[allow(clippy::default_constructed_unit_structs)]
dnd_offer: DndOfferState::default(), dnd_offer: DndOfferState::default(),
is_pasting: None, is_pasting: None,
last_click: None, last_click: None,
@ -2288,33 +2277,33 @@ impl State {
impl operation::Focusable for State { impl operation::Focusable for State {
fn is_focused(&self) -> bool { fn is_focused(&self) -> bool {
State::is_focused(self) Self::is_focused(self)
} }
fn focus(&mut self) { fn focus(&mut self) {
State::focus(self); Self::focus(self);
} }
fn unfocus(&mut self) { fn unfocus(&mut self) {
State::unfocus(self); Self::unfocus(self);
} }
} }
impl operation::TextInput for State { impl operation::TextInput for State {
fn move_cursor_to_front(&mut self) { fn move_cursor_to_front(&mut self) {
State::move_cursor_to_front(self); Self::move_cursor_to_front(self);
} }
fn move_cursor_to_end(&mut self) { fn move_cursor_to_end(&mut self) {
State::move_cursor_to_end(self); Self::move_cursor_to_end(self);
} }
fn move_cursor_to(&mut self, position: usize) { fn move_cursor_to(&mut self, position: usize) {
State::move_cursor_to(self, position); Self::move_cursor_to(self, position);
} }
fn select_all(&mut self) { fn select_all(&mut self) {
State::select_all(self); Self::select_all(self);
} }
} }