From 877cb8624bb8a0fcbf9bcfbb2ceeb2b04df5b611 Mon Sep 17 00:00:00 2001 From: GyulyVGC Date: Sun, 21 Dec 2025 00:32:42 +0100 Subject: [PATCH] various iced 0.14 fixes: impl Base for StyleType, update checkboxes, fix spacings --- src/chart/types/donut_chart.rs | 3 - src/gui/components/footer.rs | 2 +- src/gui/pages/initial_page.rs | 6 +- src/gui/pages/settings_notifications_page.rs | 90 +++++++++----------- src/gui/pages/settings_style_page.rs | 22 ++--- src/gui/sniffer.rs | 4 +- src/gui/styles/types/style_type.rs | 55 +++++++++++- 7 files changed, 111 insertions(+), 71 deletions(-) diff --git a/src/chart/types/donut_chart.rs b/src/chart/types/donut_chart.rs index 14566466..1c84aece 100644 --- a/src/chart/types/donut_chart.rs +++ b/src/chart/types/donut_chart.rs @@ -1,7 +1,6 @@ use crate::gui::styles::donut::Catalog; use crate::gui::styles::style_constants::{FONT_SIZE_FOOTER, FONT_SIZE_SUBTITLE}; use crate::networking::types::data_representation::DataRepr; -use iced::alignment::{Horizontal, Vertical}; use iced::widget::canvas::path::Arc; use iced::widget::canvas::{Frame, Text}; use iced::widget::{Canvas, canvas}; @@ -118,8 +117,6 @@ fn draw( frame.fill_text(Text { content: self.title().clone(), position: center, - vertical_alignment: Vertical::Center, - horizontal_alignment: Horizontal::Center, color: style.text_color, size: if self.thumbnail { FONT_SIZE_FOOTER diff --git a/src/gui/components/footer.rs b/src/gui/components/footer.rs index e6db8f9b..c7a6b227 100644 --- a/src/gui/components/footer.rs +++ b/src/gui/components/footer.rs @@ -247,7 +247,7 @@ fn get_release_details<'a>( ) .gap(7.5) .class(ContainerType::Tooltip); - ret_val = ret_val.push(Space::with_width(10)).push(tooltip); + ret_val = ret_val.push(Space::new().width(10)).push(tooltip); } else { // this is the latest release ret_val = ret_val.push(Text::new(" ✔").size(FONT_SIZE_SUBTITLE).font(font_footer)); diff --git a/src/gui/pages/initial_page.rs b/src/gui/pages/initial_page.rs index 53da81ce..7ec63676 100644 --- a/src/gui/pages/initial_page.rs +++ b/src/gui/pages/initial_page.rs @@ -315,7 +315,8 @@ fn get_filters_group<'a>( let bpf = filters.bpf(); let caption = filter_traffic_translation(language); - let checkbox = Checkbox::new(caption, expanded) + let checkbox = Checkbox::new(expanded) + .label(caption) .on_toggle(move |_| Message::ToggleFilters) .size(18) .font(font); @@ -361,7 +362,8 @@ fn get_export_pcap_group_maybe<'a>( let directory = export_pcap.directory(); let caption = export_capture_translation(language); - let checkbox = Checkbox::new(caption, enabled) + let checkbox = Checkbox::new(enabled) + .label(caption) .on_toggle(move |_| Message::ToggleExportPcap) .size(18) .font(font); diff --git a/src/gui/pages/settings_notifications_page.rs b/src/gui/pages/settings_notifications_page.rs index a56ca53c..c2273388 100644 --- a/src/gui/pages/settings_notifications_page.rs +++ b/src/gui/pages/settings_notifications_page.rs @@ -118,31 +118,29 @@ fn get_data_notify<'a>( language: Language, font: Font, ) -> Container<'a, Message, StyleType> { - let checkbox = Checkbox::new( - data_exceeded_translation(language), - data_notification.threshold.is_some(), - ) - .on_toggle(move |toggled| { - if toggled { - Message::UpdateNotificationSettings( - Notification::Data(DataNotification { - threshold: Some(data_notification.previous_threshold), - ..data_notification - }), - false, - ) - } else { - Message::UpdateNotificationSettings( - Notification::Data(DataNotification { - threshold: None, - ..data_notification - }), - false, - ) - } - }) - .size(18) - .font(font); + let checkbox = Checkbox::new(data_notification.threshold.is_some()) + .label(data_exceeded_translation(language)) + .on_toggle(move |toggled| { + if toggled { + Message::UpdateNotificationSettings( + Notification::Data(DataNotification { + threshold: Some(data_notification.previous_threshold), + ..data_notification + }), + false, + ) + } else { + Message::UpdateNotificationSettings( + Notification::Data(DataNotification { + threshold: None, + ..data_notification + }), + false, + ) + } + }) + .size(18) + .font(font); let mut ret_val = Column::new().spacing(15).push(checkbox); @@ -177,22 +175,20 @@ fn get_favorite_notify<'a>( language: Language, font: Font, ) -> Container<'a, Message, StyleType> { - let checkbox = Checkbox::new( - favorite_transmitted_translation(language), - favorite_notification.notify_on_favorite, - ) - .on_toggle(move |toggled| { - Message::UpdateNotificationSettings( - if toggled { - Notification::Favorite(FavoriteNotification::on(favorite_notification.sound)) - } else { - Notification::Favorite(FavoriteNotification::off(favorite_notification.sound)) - }, - false, - ) - }) - .size(18) - .font(font); + let checkbox = Checkbox::new(favorite_notification.notify_on_favorite) + .label(favorite_transmitted_translation(language)) + .on_toggle(move |toggled| { + Message::UpdateNotificationSettings( + if toggled { + Notification::Favorite(FavoriteNotification::on(favorite_notification.sound)) + } else { + Notification::Favorite(FavoriteNotification::off(favorite_notification.sound)) + }, + false, + ) + }) + .size(18) + .font(font); let mut ret_val = Column::new().spacing(15).push(checkbox); @@ -220,13 +216,11 @@ fn get_remote_notifications<'a>( language: Language, font: Font, ) -> Container<'a, Message, StyleType> { - let checkbox = Checkbox::new( - remote_notifications_translation(language), - remote_notifications.is_active(), - ) - .on_toggle(move |_| Message::ToggleRemoteNotifications) - .size(18) - .font(font); + let checkbox = Checkbox::new(remote_notifications.is_active()) + .label(remote_notifications_translation(language)) + .on_toggle(move |_| Message::ToggleRemoteNotifications) + .size(18) + .font(font); let mut ret_val = Column::new().spacing(15).push(checkbox); diff --git a/src/gui/pages/settings_style_page.rs b/src/gui/pages/settings_style_page.rs index efbd68fe..0af32efc 100644 --- a/src/gui/pages/settings_style_page.rs +++ b/src/gui/pages/settings_style_page.rs @@ -50,16 +50,16 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container<'_, Message, StyleTyp language, )) .push(get_settings_tabs(SettingsPage::Appearance, font, language)) - .push(Space::with_height(15)) + .push(Space::new().height(15)) .push( appearance_title_translation(language) .class(TextType::Subtitle) .font(font) .size(FONT_SIZE_SUBTITLE), ) - .push(Space::with_height(15)) + .push(Space::new().height(15)) .push(gradients_row(font, color_gradient, language)) - .push(Space::with_height(15)); + .push(Space::new().height(15)); let mut styles_col = Column::new() .align_x(Alignment::Center) @@ -67,10 +67,10 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container<'_, Message, StyleTyp .push( Row::new() .push(get_palette_container(style, "Yeti".to_string(), Night)) - .push(Space::with_width(15)) + .push(Space::new().width(15)) .push(get_palette_container(style, "Yeti".to_string(), Day)), ) - .push(Space::with_height(15)) + .push(Space::new().height(15)) .push( Row::new() .push(get_palette_container( @@ -78,14 +78,14 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container<'_, Message, StyleTyp "Deep Sea".to_string(), DeepSea, )) - .push(Space::with_width(15)) + .push(Space::new().width(15)) .push(get_palette_container( style, "Mon Amour".to_string(), MonAmour, )), ) - .push(Space::with_height(15)); + .push(Space::new().height(15)); for children in get_extra_palettes(ExtraStyles::all_styles(), style) { styles_col = styles_col.push(children); } @@ -93,7 +93,7 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container<'_, Message, StyleTyp .push(lazy((language, style_path.clone(), style), move |_| { lazy_custom_style_input(language, font, &style_path, style) })) - .push(Space::with_height(10)); + .push(Space::new().height(10)); let styles_scroll = Scrollable::with_direction( styles_col, @@ -262,15 +262,15 @@ fn get_extra_palettes<'a>( children.extend([ Row::new() .push(first) - .push(Space::with_width(15)) + .push(Space::new().width(15)) .push(second) .into(), - >>::into(Space::with_height(15)), + >>::into(Space::new().height(15)), ]); } else { children.extend([ Row::new().push(first).into(), - >>::into(Space::with_height(15)), + >>::into(Space::new().height(15)), ]); } } diff --git a/src/gui/sniffer.rs b/src/gui/sniffer.rs index 393f1130..88c0627a 100644 --- a/src/gui/sniffer.rs +++ b/src/gui/sniffer.rs @@ -514,7 +514,7 @@ pub fn update(&mut self, message: Message) -> Task { window::toggle_decorations(window_id), window::resize(window_id, size), window::move_to(window_id, position.to_point()), - window::change_level(window_id, Level::AlwaysOnTop), + window::set_level(window_id, Level::AlwaysOnTop), ]) } else { if self @@ -525,7 +525,7 @@ pub fn update(&mut self, message: Message) -> Task { } let mut commands = vec![ window::toggle_decorations(window_id), - window::change_level(window_id, Level::Normal), + window::set_level(window_id, Level::Normal), ]; if !triggered_by_resize { let size = self.conf.window.size.to_size(); diff --git a/src/gui/styles/types/style_type.rs b/src/gui/styles/types/style_type.rs index 9bafe396..9e469191 100644 --- a/src/gui/styles/types/style_type.rs +++ b/src/gui/styles/types/style_type.rs @@ -1,4 +1,4 @@ -use iced::application::{Appearance, DefaultStyle}; +use iced::theme::{Base, Mode, Style}; use plotters::prelude::FontStyle; use serde::{Deserialize, Serialize}; @@ -29,14 +29,61 @@ fn default() -> Self { } } -impl DefaultStyle for StyleType { - fn default_style(&self) -> Appearance { +impl Base for StyleType { + fn default(preference: Mode) -> Self { + match preference { + Mode::Light => Self::Custom(ExtraStyles::A11yLight), + _ => Self::Custom(ExtraStyles::A11yDark), + } + } + + fn mode(&self) -> Mode { + match self { + StyleType::Night | StyleType::DeepSea => Mode::Dark, + StyleType::Day | StyleType::MonAmour => Mode::Light, + StyleType::Custom(style) => { + if style.get_extension().is_nightly { + Mode::Dark + } else { + Mode::Light + } + } + } + } + + fn base(&self) -> Style { let colors = self.get_palette(); - Appearance { + Style { background_color: colors.primary, text_color: colors.text_body, } } + + fn palette(&self) -> Option { + None + } + + fn name(&self) -> &str { + match self { + StyleType::Night => "Yeti Night", + StyleType::Day => "Yeti Day", + StyleType::DeepSea => "Deep Sea", + StyleType::MonAmour => "Mon Amour", + StyleType::Custom(style) => match style { + ExtraStyles::DraculaDark => "Dracula Dark", + ExtraStyles::DraculaLight => "Dracula Light", + ExtraStyles::GruvboxDark => "Gruvbox Dark", + ExtraStyles::GruvboxLight => "Gruvbox Light", + ExtraStyles::NordDark => "Nord Dark", + ExtraStyles::NordLight => "Nord Light", + ExtraStyles::SolarizedDark => "Solarized Dark", + ExtraStyles::SolarizedLight => "Solarized Light", + ExtraStyles::A11yDark => "A11y Dark", + ExtraStyles::A11yLight => "A11y Light", + ExtraStyles::CustomToml(_) => "Custom Theme", + }, + } + } } impl StyleType {