mirror of
https://github.com/GyulyVGC/sniffnet.git
synced 2026-02-19 15:37:43 -05:00
various iced 0.14 fixes: impl Base for StyleType, update checkboxes, fix spacings
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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(),
|
||||
<Space as Into<Element<Message, StyleType>>>::into(Space::with_height(15)),
|
||||
<Space as Into<Element<Message, StyleType>>>::into(Space::new().height(15)),
|
||||
]);
|
||||
} else {
|
||||
children.extend([
|
||||
Row::new().push(first).into(),
|
||||
<Space as Into<Element<Message, StyleType>>>::into(Space::with_height(15)),
|
||||
<Space as Into<Element<Message, StyleType>>>::into(Space::new().height(15)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,7 +514,7 @@ pub fn update(&mut self, message: Message) -> Task<Message> {
|
||||
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<Message> {
|
||||
}
|
||||
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();
|
||||
|
||||
@@ -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<iced::theme::Palette> {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user