Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Iced 0.13 #618

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,551 changes: 803 additions & 748 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,41 @@ pcap = "2.2.0"
etherparse = "0.16.0"
chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
plotters = { version = "0.3.7", default-features = false, features = ["area_series"] }
iced = { version = "0.12.1", features = ["tokio", "svg", "advanced", "lazy"] }
plotters-iced = "0.10.0"
iced = { version = "0.13.1", features = ["tokio", "svg", "advanced", "lazy"] }
plotters-iced = "0.11.0"
maxminddb = "0.24.0"
confy = "0.6.1"
serde = { version = "1.0.210", default-features = false, features = ["derive"] }
rodio = { version = "0.19.0", default-features = false, features = ["mp3"] }
dns-lookup = "2.0.4"
toml = "0.8.19"
once_cell = "1.20.0"
once_cell = "1.20.2"
ctrlc = { version = "3.4.5", features = ["termination"] }
rfd = "0.14.1"
rfd = "0.15.0"
phf = "0.11.2"
phf_shared = "0.11.2"
splines = "4.3.1"

[target.'cfg(not(target_arch = "powerpc64"))'.dependencies]
reqwest = { version = "0.12.7", default-features = false, features = ["json", "blocking", "rustls-tls"] }
reqwest = { version = "0.12.8", default-features = false, features = ["json", "blocking", "rustls-tls"] }

[target.'cfg(target_arch = "powerpc64")'.dependencies]
reqwest = { version = "0.12.7", features = ["json", "blocking"] }
reqwest = { version = "0.12.8", features = ["json", "blocking"] }

#───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

[dev-dependencies]
serde_test = "1.0.177"
rstest = "0.22.0"
rstest = "0.23.0"
serial_test = { version = "3.1.1", default-features = false }

#───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

[build-dependencies]
phf_codegen = "0.11.2"
phf_shared = "0.11.2"
rustrict = { version = "0.7.26", default-features = false, features = ["censor"] }
once_cell = "1.20.0"
rustrict = { version = "0.7.31", default-features = false, features = ["censor"] }
once_cell = "1.19.0"

[target."cfg(windows)".build-dependencies]
winres = "0.1.12"
Expand Down
4 changes: 2 additions & 2 deletions src/chart/types/traffic_chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use plotters::prelude::*;
use plotters_iced::{Chart, ChartBuilder, ChartWidget, DrawingBackend};
use splines::Spline;

use crate::gui::app::FONT_FAMILY_NAME;
use crate::gui::sniffer::FONT_FAMILY_NAME;
use crate::gui::styles::style_constants::CHARTS_LINE_BORDER;
use crate::gui::styles::types::palette::to_rgb_color;
use crate::gui::types::message::Message;
Expand Down Expand Up @@ -118,7 +118,7 @@ impl TrafficChart {
min - gap..max + gap
}

fn font(&self, size: f64) -> TextStyle<'static> {
fn font<'a>(&self, size: f64) -> TextStyle<'a> {
(FONT_FAMILY_NAME, size)
.into_font()
.style(self.style.get_font_weight())
Expand Down
7 changes: 4 additions & 3 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ mod tests {

use serial_test::serial;

use crate::configs::types::config_window::{PositionTuple, SizeTuple};
use crate::gui::styles::types::custom_palette::ExtraStyles;
use crate::gui::styles::types::gradient_type::GradientType;
use crate::notifications::types::notifications::Notifications;
Expand Down Expand Up @@ -88,9 +89,9 @@ mod tests {
device_name: "hey-hey".to_string(),
},
window: ConfigWindow {
position: (440, 99),
size: (452, 870),
thumbnail_position: (20, 20),
position: PositionTuple(440.0, 99.0),
size: SizeTuple(452.0, 870.0),
thumbnail_position: PositionTuple(20.0, 20.0),
},
};
// we want to be sure that modified config is different from defaults
Expand Down
80 changes: 42 additions & 38 deletions src/configs/types/config_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ use serde::{Deserialize, Serialize};
#[cfg(not(test))]
use crate::SNIFFNET_LOWERCASE;

#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Debug)]
pub struct PositionTuple(pub f32, pub f32);
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Debug)]
pub struct SizeTuple(pub f32, pub f32);

#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Debug)]
pub struct ConfigWindow {
pub position: (i32, i32),
pub size: (u32, u32),
pub thumbnail_position: (i32, i32),
pub position: PositionTuple,
pub size: SizeTuple,
pub thumbnail_position: PositionTuple,
}

impl ConfigWindow {
pub const DEFAULT_SIZE: (u32, u32) = (1190, 670);
const THUMBNAIL_SIZE: (u32, u32) = (360, 222);
pub const DEFAULT_SIZE: SizeTuple = SizeTuple(1190.0, 670.0);
const THUMBNAIL_SIZE: SizeTuple = SizeTuple(360.0, 222.0);

const MIN_POS_X: i32 = -50;
const MIN_POS_Y: i32 = -50;
const MAX_POS_X: i32 = 1100;
const MAX_POS_Y: i32 = 700;
const MIN_POS_X: f32 = -50.0;
const MIN_POS_Y: f32 = -50.0;
const MAX_POS_X: f32 = 1100.0;
const MAX_POS_Y: f32 = 700.0;

const MIN_SIZE_X: u32 = 100;
const MIN_SIZE_Y: u32 = 100;
const MIN_SIZE_X: f32 = 100.0;
const MIN_SIZE_Y: f32 = 100.0;

const FILE_NAME: &'static str = "window";
#[cfg(not(test))]
Expand All @@ -41,17 +46,17 @@ impl ConfigWindow {
confy::store(SNIFFNET_LOWERCASE, Self::FILE_NAME, self).unwrap_or(());
}

pub fn thumbnail_size(factor: f64) -> (u32, u32) {
pub fn thumbnail_size(factor: f64) -> SizeTuple {
Self::THUMBNAIL_SIZE.scale_and_check(factor)
}
}

impl Default for ConfigWindow {
fn default() -> Self {
Self {
position: (0, 0),
position: PositionTuple(0.0, 0.0),
size: ConfigWindow::DEFAULT_SIZE,
thumbnail_position: (0, 0),
thumbnail_position: PositionTuple(0.0, 0.0),
}
}
}
Expand All @@ -60,12 +65,11 @@ pub trait ToPosition {
fn to_position(self) -> Position;
}

impl ToPosition for (i32, i32) {
impl ToPosition for PositionTuple {
fn to_position(self) -> Position {
#[allow(clippy::cast_precision_loss)]
Position::Specific(Point {
x: self.0 as f32,
y: self.1 as f32,
x: self.0,
y: self.1,
})
}
}
Expand All @@ -74,12 +78,11 @@ pub trait ToPoint {
fn to_point(self) -> Point;
}

impl ToPoint for (i32, i32) {
impl ToPoint for PositionTuple {
fn to_point(self) -> Point {
#[allow(clippy::cast_precision_loss)]
Point {
x: self.0 as f32,
y: self.1 as f32,
x: self.0,
y: self.1,
}
}
}
Expand All @@ -88,12 +91,11 @@ pub trait ToSize {
fn to_size(self) -> Size;
}

impl ToSize for (u32, u32) {
impl ToSize for SizeTuple {
fn to_size(self) -> Size {
#[allow(clippy::cast_precision_loss)]
Size {
width: self.0 as f32,
height: self.1 as f32,
width: self.0,
height: self.1,
}
}
}
Expand All @@ -102,26 +104,28 @@ pub trait ScaleAndCheck {
fn scale_and_check(self, factor: f64) -> Self;
}

impl ScaleAndCheck for (u32, u32) {
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
fn scale_and_check(self, factor: f64) -> (u32, u32) {
let mut x = (f64::from(self.0) * factor) as u32;
let mut y = (f64::from(self.1) * factor) as u32;
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;
if x < ConfigWindow::MIN_SIZE_X {
x = ConfigWindow::MIN_SIZE_X;
}
if y < ConfigWindow::MIN_SIZE_Y {
y = ConfigWindow::MIN_SIZE_Y;
}
(x, y)
SizeTuple(x, y)
}
}

impl ScaleAndCheck for (i32, i32) {
#[allow(clippy::cast_possible_truncation)]
fn scale_and_check(self, factor: f64) -> (i32, i32) {
let mut x = (f64::from(self.0) * factor) as i32;
let mut y = (f64::from(self.1) * factor) as i32;
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;
if x < ConfigWindow::MIN_POS_X {
x = ConfigWindow::MIN_POS_X;
}
Expand All @@ -134,7 +138,7 @@ impl ScaleAndCheck for (i32, i32) {
if y > ConfigWindow::MAX_POS_Y {
y = ConfigWindow::MAX_POS_Y;
}
(x, y)
PositionTuple(x, y)
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/countries/country_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ use crate::translations::translations_2::{
};
use crate::{Language, StyleType};

fn get_flag_from_country(
fn get_flag_from_country<'a>(
country: Country,
width: f32,
is_local: bool,
is_loopback: bool,
traffic_type: TrafficType,
language: Language,
) -> (Svg<StyleType>, String) {
) -> (Svg<'a, StyleType>, String) {
#![allow(clippy::too_many_lines)]
let mut tooltip = country.to_string();
let mut svg_style = SvgType::Standard;
Expand Down Expand Up @@ -303,20 +303,20 @@ fn get_flag_from_country(
flag
}
})))
.style(svg_style)
.class(svg_style)
.width(width)
.height(width * 0.75);

(svg, tooltip)
}

pub fn get_flag_tooltip(
pub fn get_flag_tooltip<'a>(
country: Country,
host_info: &DataInfoHost,
language: Language,
font: Font,
thumbnail: bool,
) -> Tooltip<'static, Message, StyleType> {
) -> Tooltip<'a, Message, StyleType> {
let width = if thumbnail {
FLAGS_WIDTH_SMALL
} else {
Expand Down Expand Up @@ -346,7 +346,7 @@ pub fn get_flag_tooltip(
Position::FollowCursor,
)
.snap_within_viewport(true)
.style(tooltip_style);
.class(tooltip_style);

if width == FLAGS_WIDTH_SMALL {
tooltip = tooltip.padding(3);
Expand All @@ -355,13 +355,13 @@ pub fn get_flag_tooltip(
tooltip
}

pub fn get_computer_tooltip(
pub fn get_computer_tooltip<'a>(
is_my_address: bool,
is_local: bool,
traffic_type: TrafficType,
language: Language,
font: Font,
) -> Tooltip<'static, Message, StyleType> {
) -> Tooltip<'a, Message, StyleType> {
let content = Svg::new(Handle::from_memory(Vec::from(
match (is_my_address, is_local, traffic_type) {
(true, _, _) => COMPUTER,
Expand All @@ -371,7 +371,7 @@ pub fn get_computer_tooltip(
(false, false, TrafficType::Unicast) => UNKNOWN,
},
)))
.style(SvgType::AdaptColor)
.class(SvgType::AdaptColor)
.width(FLAGS_WIDTH_BIG)
.height(FLAGS_WIDTH_BIG * 0.75);

Expand All @@ -390,5 +390,5 @@ pub fn get_computer_tooltip(
Position::FollowCursor,
)
.snap_within_viewport(true)
.style(ContainerType::Tooltip)
.class(ContainerType::Tooltip)
}
Loading
Loading