Skip to content

Commit

Permalink
fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Sep 21, 2024
1 parent 99b0ded commit 7b3b235
Show file tree
Hide file tree
Showing 24 changed files with 56 additions and 45 deletions.
2 changes: 2 additions & 0 deletions src/configs/types/config_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub trait ScaleAndCheck {

impl ScaleAndCheck for SizeTuple {
fn scale_and_check(self, factor: f64) -> SizeTuple {
#[allow(clippy::cast_possible_truncation)]
let factor = factor as f32;
let mut x = self.0 * factor;
let mut y = self.1 * factor;
Expand All @@ -121,6 +122,7 @@ impl ScaleAndCheck for SizeTuple {

impl ScaleAndCheck for PositionTuple {
fn scale_and_check(self, factor: f64) -> PositionTuple {
#[allow(clippy::cast_possible_truncation)]
let factor = factor as f32;
let mut x = self.0 * factor;
let mut y = self.1 * factor;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/components/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn footer<'a>(
color_gradient: GradientType,
font: Font,
font_footer: Font,
newer_release_available: Arc<Mutex<Option<bool>>>,
newer_release_available: &Arc<Mutex<Option<bool>>>,
) -> Container<'a, Message, StyleType> {
if thumbnail {
return thumbnail_footer();
Expand Down Expand Up @@ -128,7 +128,7 @@ fn get_release_details<'a>(
language: Language,
font: Font,
font_footer: Font,
newer_release_available: Arc<Mutex<Option<bool>>>,
newer_release_available: &Arc<Mutex<Option<bool>>>,
) -> Row<'a, Message, StyleType> {
let mut ret_val = Row::new()
.align_y(Alignment::Center)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/components/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn confirm_button_row<'a>(
)
}

pub fn new_modal<'a>(
pub fn modal<'a>(
base: Element<'a, Message, StyleType>,
content: Element<'a, Message, StyleType>,
on_blur: Message,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/pages/initial_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use crate::utils::types::icon::Icon;
use crate::{ConfigSettings, IpVersion, Language, Protocol, StyleType};

/// Computes the body of gui initial page
pub fn initial_page<'a>(sniffer: &'a Sniffer) -> Container<'a, Message, StyleType> {
pub fn initial_page(sniffer: &Sniffer) -> Container<Message, StyleType> {
let ConfigSettings {
style,
language,
Expand Down
10 changes: 5 additions & 5 deletions src/gui/pages/inspect_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ fn report_header_row(
.align_y(Alignment::Center),
);
} else {
col_header = col_header.push(sort_arrows(sort_type, report_col));
col_header = col_header.push(sort_arrows(sort_type, &report_col));
}
ret_val = ret_val.push(col_header);
}
Expand Down Expand Up @@ -256,7 +256,7 @@ fn title_report_col_display(

fn sort_arrows<'a>(
active_sort_type: ReportSortType,
report_col: ReportCol,
report_col: &ReportCol,
) -> Container<'a, Message, StyleType> {
Container::new(
button(
Expand All @@ -265,9 +265,9 @@ fn sort_arrows<'a>(
.align_x(Alignment::Center)
.align_y(Alignment::Center),
)
.class(active_sort_type.button_type(&report_col))
.class(active_sort_type.button_type(report_col))
.on_press(Message::ReportSortSelection(
active_sort_type.next_sort(&report_col),
active_sort_type.next_sort(report_col),
)),
)
.align_y(Alignment::Center)
Expand Down Expand Up @@ -530,7 +530,7 @@ mod tests {
for report_col in ReportCol::ALL {
for language in Language::ALL {
let (title, title_small, tooltip_val) =
title_report_col_display(&report_col, language);
title_report_col_display(report_col, language);
let title_chars = title.chars().collect::<Vec<char>>();
let title_small_chars = title_small.chars().collect::<Vec<char>>();
let max_chars = report_col.get_max_chars(Some(language));
Expand Down
2 changes: 1 addition & 1 deletion src/gui/pages/notifications_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::utils::types::icon::Icon;
use crate::{ByteMultiple, ConfigSettings, Language, RunningPage, Sniffer, StyleType};

/// Computes the body of gui notifications page
pub fn notifications_page<'a>(sniffer: &'a Sniffer) -> Container<'a, Message, StyleType> {
pub fn notifications_page(sniffer: &Sniffer) -> Container<Message, StyleType> {
let ConfigSettings {
style,
language,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/pages/settings_general_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::utils::types::icon::Icon;
use crate::utils::types::web_page::WebPage;
use crate::{ConfigSettings, Language, RunningPage, Sniffer, StyleType};

pub fn settings_general_page<'a>(sniffer: &'a Sniffer) -> Container<'a, Message, StyleType> {
pub fn settings_general_page(sniffer: &Sniffer) -> Container<Message, StyleType> {
let ConfigSettings {
style,
language,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/pages/thumbnail_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const MAX_CHARS_HOST: usize = 26;
const MAX_CHARS_SERVICE: usize = 13;

/// Computes the body of the thumbnail view
pub fn thumbnail_page<'a>(sniffer: &'a Sniffer) -> Container<'a, Message, StyleType> {
pub fn thumbnail_page(sniffer: &Sniffer) -> Container<Message, StyleType> {
let ConfigSettings { style, .. } = sniffer.configs.lock().unwrap().settings;
let font = style.get_extension().font;

Expand Down
20 changes: 7 additions & 13 deletions src/gui/sniffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::configs::types::config_window::{
};
use crate::gui::components::footer::footer;
use crate::gui::components::header::header;
use crate::gui::components::modal::{get_clear_all_overlay, get_exit_overlay, new_modal};
use crate::gui::components::modal::{get_clear_all_overlay, get_exit_overlay, modal};
use crate::gui::components::types::my_modal::MyModal;
use crate::gui::pages::connection_details_page::connection_details_page;
use crate::gui::pages::initial_page::initial_page;
Expand Down Expand Up @@ -61,9 +61,7 @@ use crate::secondary_threads::parse_packets::parse_packets;
use crate::translations::types::language::Language;
use crate::utils::types::file_info::FileInfo;
use crate::utils::types::web_page::WebPage;
use crate::{
ConfigSettings, Configs, InfoTraffic, RunTimeData, StyleType, TrafficChart, SNIFFNET_TITLECASE,
};
use crate::{ConfigSettings, Configs, InfoTraffic, RunTimeData, StyleType, TrafficChart};

/// Update period (milliseconds)
pub const PERIOD_TICK: u64 = 1000;
Expand Down Expand Up @@ -130,10 +128,6 @@ pub struct Sniffer {
}

impl Sniffer {
pub fn title(&self) -> String {
String::from(SNIFFNET_TITLECASE)
}

pub fn new(
configs: &Arc<Mutex<Configs>>,
newer_release_available: Arc<Mutex<Option<bool>>>,
Expand Down Expand Up @@ -560,7 +554,7 @@ impl Sniffer {
color_gradient,
font,
font_headers,
self.newer_release_available.clone(),
&self.newer_release_available,
);

let content: Element<Message, StyleType> =
Expand All @@ -576,13 +570,13 @@ impl Sniffer {
}
.into();

new_modal(content, overlay, Message::CloseSettings)
modal(content, overlay, Message::CloseSettings)
} else {
content
}
}
Some(modal) => {
let overlay: Element<Message, StyleType> = match modal {
Some(m) => {
let overlay: Element<Message, StyleType> = match m {
MyModal::Quit => get_exit_overlay(color_gradient, font, font_headers, language),
MyModal::ClearAll => {
get_clear_all_overlay(color_gradient, font, font_headers, language)
Expand All @@ -591,7 +585,7 @@ impl Sniffer {
}
.into();

new_modal(content, overlay, Message::HideModal)
modal(content, overlay, Message::HideModal)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/styles/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::gui::styles::types::gradient_type::{
use crate::gui::styles::types::palette::mix_colors;
use crate::StyleType;

#[derive(Clone, Copy, Default)]
#[derive(Default)]
pub enum ButtonType {
#[default]
Standard,
Expand Down
4 changes: 3 additions & 1 deletion src/gui/styles/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use iced::{Background, Border};
use crate::gui::styles::style_constants::BORDER_WIDTH;
use crate::StyleType;

#[derive(Clone, Copy, Default)]
#[derive(Default)]
pub enum CheckboxType {
#[default]
Standard,
Expand All @@ -17,6 +17,7 @@ pub enum CheckboxType {
const CHECKBOX_BORDER_RADIUS: f32 = 5.0;

impl CheckboxType {
#[allow(clippy::unused_self)]
fn active(&self, style: &StyleType, is_checked: bool) -> Style {
let colors = style.get_palette();
let ext = style.get_extension();
Expand All @@ -32,6 +33,7 @@ impl CheckboxType {
}
}

#[allow(clippy::unused_self)]
fn hovered(&self, style: &StyleType, _is_checked: bool) -> Style {
let colors = style.get_palette();
let ext = style.get_extension();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/styles/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::gui::styles::style_constants::{BORDER_ROUNDED_RADIUS, BORDER_WIDTH};
use crate::gui::styles::types::gradient_type::{get_gradient_headers, GradientType};
use crate::StyleType;

#[derive(Clone, Copy, Default)]
#[derive(Default)]
pub enum ContainerType {
#[default]
Standard,
Expand Down
8 changes: 5 additions & 3 deletions src/gui/styles/picklist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::gui::styles::style_constants::BORDER_WIDTH;
use crate::gui::styles::types::palette::mix_colors;
use crate::StyleType;

#[derive(Clone, Copy, Default)]
#[derive(Default)]
pub enum PicklistType {
#[default]
Standard,
Expand All @@ -18,6 +18,7 @@ pub enum PicklistType {
const PICKLIST_BORDER_RADIUS: f32 = 8.0;

impl PicklistType {
#[allow(clippy::unused_self)]
fn appearance(&self, style: &StyleType) -> iced::overlay::menu::Style {
let colors = style.get_palette();
let ext = style.get_extension();
Expand All @@ -36,6 +37,7 @@ impl PicklistType {
}

impl PicklistType {
#[allow(clippy::unused_self)]
fn active(&self, style: &StyleType) -> Style {
let colors = style.get_palette();
let ext = style.get_extension();
Expand All @@ -52,6 +54,7 @@ impl PicklistType {
}
}

#[allow(clippy::unused_self)]
fn hovered(&self, style: &StyleType) -> Style {
let colors = style.get_palette();
let ext = style.get_extension();
Expand Down Expand Up @@ -93,9 +96,8 @@ impl Catalog for StyleType {

fn style(&self, class: &<Self as Catalog>::Class<'_>, status: Status) -> Style {
match status {
Status::Active => class.active(self),
Status::Active | Status::Opened => class.active(self),
Status::Hovered => class.hovered(self),
Status::Opened => class.active(self),
}
}
}
2 changes: 1 addition & 1 deletion src/gui/styles/radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// use crate::gui::styles::style_constants::BORDER_WIDTH;
// use crate::StyleType;
//
// #[derive(Clone, Copy, Default)]
// #[derive(Default)]
// pub enum RadioType {
// #[default]
// Standard,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/styles/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::StyleType;
use iced::widget::rule::{Catalog, FillMode, Style};
use iced::Color;

#[derive(Clone, Copy, Default)]
#[derive(Default)]
pub enum RuleType {
#[default]
Standard,
Expand Down
4 changes: 3 additions & 1 deletion src/gui/styles/scrollbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ use iced::widget::scrollable::{Catalog, Rail, Status, Style};
use iced::widget::scrollable::{Scrollbar, Scroller};
use iced::{Background, Border, Color};

#[derive(Clone, Copy, Default)]
#[derive(Default)]
pub enum ScrollbarType {
#[default]
Standard,
}

impl ScrollbarType {
#[allow(clippy::unused_self)]
fn active(&self, style: &StyleType) -> Style {
let ext = style.get_extension();

Expand Down Expand Up @@ -48,6 +49,7 @@ impl ScrollbarType {
}
}

#[allow(clippy::unused_self)]
fn hovered(&self, style: &StyleType, is_mouse_over_scrollbar: bool) -> Style {
let colors = style.get_palette();
let ext = style.get_extension();
Expand Down
5 changes: 4 additions & 1 deletion src/gui/styles/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ use crate::gui::styles::style_constants::{BORDER_ROUNDED_RADIUS, BORDER_WIDTH};
use crate::gui::styles::types::palette::mix_colors;
use crate::StyleType;

#[derive(Clone, Copy, Default)]
#[derive(Default)]
pub enum SliderType {
#[default]
Standard,
}

impl SliderType {
#[allow(clippy::unused_self)]
fn active(&self, style: &StyleType) -> Style {
let colors = style.get_palette();
let ext = style.get_extension();
Expand All @@ -41,6 +42,7 @@ impl SliderType {
}
}

#[allow(clippy::unused_self)]
fn hovered(&self, style: &StyleType) -> Style {
let colors = style.get_palette();
let ext = style.get_extension();
Expand All @@ -65,6 +67,7 @@ impl SliderType {
}
}

#[allow(clippy::unused_self)]
fn dragging(&self, style: &StyleType) -> Style {
let colors = style.get_palette();
let ext = style.get_extension();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/styles/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use iced::widget::svg::{Catalog, Status, Style};

use crate::StyleType;

#[derive(Clone, Copy, Default)]
#[derive(Default)]
pub enum SvgType {
AdaptColor,
#[default]
Expand Down
8 changes: 4 additions & 4 deletions src/gui/styles/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use iced::{Color, Font};
use crate::gui::types::message::Message;
use crate::StyleType;

#[derive(Clone, Copy, Default, PartialEq)]
#[derive(Copy, Clone, Default, PartialEq)]
pub enum TextType {
#[default]
Standard,
Expand Down Expand Up @@ -38,9 +38,9 @@ impl TextType {
.push(Text::new(format!(" {desc}")).font(font))
}

fn appearance(&self, style: &StyleType) -> Style {
fn appearance(self, style: &StyleType) -> Style {
Style {
color: if self == &TextType::Standard {
color: if self == TextType::Standard {
None
} else {
Some(highlight(style, self))
Expand All @@ -49,7 +49,7 @@ impl TextType {
}
}

pub fn highlight(style: &StyleType, element: &TextType) -> Color {
pub fn highlight(style: &StyleType, element: TextType) -> Color {
let colors = style.get_palette();
let secondary = colors.secondary;
let is_nightly = style.get_extension().is_nightly;
Expand Down
Loading

0 comments on commit 7b3b235

Please sign in to comment.