Skip to content

Commit e237f05

Browse files
committed
improve styles setting page
1 parent a01b8d9 commit e237f05

5 files changed

Lines changed: 154 additions & 171 deletions

File tree

src/gui/pages/settings_notifications_page.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use iced::widget::scrollable::Direction;
22
use iced::widget::{Button, Slider, horizontal_space};
33
use iced::widget::{Checkbox, Column, Container, Row, Scrollable, Space, Text, TextInput};
4-
use iced::{Alignment, Font, Length, Padding};
4+
use iced::{Alignment, Font, Length};
55

66
use crate::gui::components::button::button_hide;
77
use crate::gui::components::tab::get_settings_tabs;
@@ -62,13 +62,13 @@ pub fn settings_notifications_page<'a>(sniffer: &Sniffer) -> Container<'a, Messa
6262
.push(Space::with_height(5));
6363

6464
let volume_notification_col = Column::new()
65-
.padding(Padding::ZERO.bottom(5))
6665
.align_x(Alignment::Center)
6766
.width(Length::Fill)
6867
.push(volume_slider(language, font, notifications.volume))
6968
.push(Scrollable::with_direction(
7069
Column::new()
71-
.width(720)
70+
.align_x(Alignment::Center)
71+
.width(Length::Fill)
7272
.push(get_packets_notify(
7373
notifications.packets_notification,
7474
language,
@@ -84,7 +84,7 @@ pub fn settings_notifications_page<'a>(sniffer: &Sniffer) -> Container<'a, Messa
8484
language,
8585
font,
8686
)),
87-
Direction::Vertical(ScrollbarType::properties()),
87+
Direction::Vertical(ScrollbarType::properties().margin(10)),
8888
));
8989

9090
content = content.push(volume_notification_col);

src/gui/pages/settings_style_page.rs

Lines changed: 40 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ use crate::gui::styles::text::TextType;
1717
use crate::gui::styles::types::custom_palette::ExtraStyles;
1818
use crate::gui::styles::types::gradient_type::GradientType;
1919
use crate::gui::styles::types::palette::Palette;
20+
use crate::gui::styles::types::palette_extension::PaletteExtension;
2021
use crate::gui::types::message::Message;
21-
use crate::translations::translations::{
22-
appearance_title_translation, deep_sea_translation, mon_amour_translation,
23-
yeti_day_translation, yeti_night_translation,
24-
};
22+
use crate::translations::translations::appearance_title_translation;
2523
use crate::translations::translations_2::color_gradients_translation;
2624
use crate::translations::translations_3::custom_style_translation;
2725
use crate::utils::formatted_strings::get_path_termination_string;
@@ -37,11 +35,11 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container<Message, StyleType> {
3735
style_path,
3836
..
3937
} = sniffer.configs.lock().unwrap().settings.clone();
40-
let font = style.get_extension().font;
41-
let font_headers = style.get_extension().font_headers;
38+
let PaletteExtension {
39+
font, font_headers, ..
40+
} = style.get_extension();
4241

4342
let mut content = Column::new()
44-
.padding(Padding::ZERO.bottom(5))
4543
.align_x(Alignment::Center)
4644
.width(Length::Fill)
4745
.push(settings_header(
@@ -67,38 +65,26 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container<Message, StyleType> {
6765
.width(Length::Fill)
6866
.push(
6967
Row::new()
70-
.push(get_palette_container(
71-
style,
72-
"Yeti Night".to_string(),
73-
yeti_night_translation(language).to_string(),
74-
Night,
75-
))
76-
.push(Space::with_width(10))
77-
.push(get_palette_container(
78-
style,
79-
"Yeti Day".to_string(),
80-
yeti_day_translation(language).to_string(),
81-
Day,
82-
)),
68+
.push(get_palette_container(style, "Yeti".to_string(), Night))
69+
.push(Space::with_width(15))
70+
.push(get_palette_container(style, "Yeti".to_string(), Day)),
8371
)
84-
.push(Space::with_height(10))
72+
.push(Space::with_height(15))
8573
.push(
8674
Row::new()
8775
.push(get_palette_container(
8876
style,
8977
"Deep Sea".to_string(),
90-
deep_sea_translation(language).to_string(),
9178
DeepSea,
9279
))
93-
.push(Space::with_width(10))
80+
.push(Space::with_width(15))
9481
.push(get_palette_container(
9582
style,
9683
"Mon Amour".to_string(),
97-
mon_amour_translation(language).to_string(),
9884
MonAmour,
9985
)),
10086
)
101-
.push(Space::with_height(10));
87+
.push(Space::with_height(15));
10288
for children in get_extra_palettes(ExtraStyles::all_styles(), style) {
10389
styles_col = styles_col.push(children);
10490
}
@@ -108,8 +94,10 @@ pub fn settings_style_page(sniffer: &Sniffer) -> Container<Message, StyleType> {
10894
}))
10995
.push(Space::with_height(10));
11096

111-
let styles_scroll =
112-
Scrollable::with_direction(styles_col, Direction::Vertical(ScrollbarType::properties()));
97+
let styles_scroll = Scrollable::with_direction(
98+
styles_col,
99+
Direction::Vertical(ScrollbarType::properties().margin(10)),
100+
);
113101

114102
content = content.push(styles_scroll);
115103

@@ -184,32 +172,35 @@ fn gradients_row<'a>(
184172
fn get_palette_container<'a>(
185173
style: StyleType,
186174
name: String,
187-
description: String,
188175
on_press: StyleType,
189176
) -> Button<'a, Message, StyleType> {
190177
let font = style.get_extension().font;
178+
let PaletteExtension {
179+
buttons_color,
180+
is_nightly,
181+
..
182+
} = on_press.get_extension();
191183

192-
let is_custom = matches!(on_press, StyleType::Custom(_));
184+
let caption = Row::new()
185+
.spacing(7)
186+
.push(Text::new(name).font(font))
187+
.push(if is_nightly {
188+
Icon::Moon.to_text().size(15)
189+
} else {
190+
Icon::Sun.to_text()
191+
});
193192

194-
let mut content = Column::new()
193+
let content = Column::new()
195194
.width(Length::Fill)
196195
.align_x(Alignment::Center)
197196
.spacing(5)
198-
.push(Text::new(name).font(font))
199-
.push(get_palette_rule(
200-
on_press.get_palette(),
201-
on_press.get_extension().buttons_color,
202-
is_custom,
203-
));
204-
205-
if !is_custom {
206-
content = content.push(Text::new(description).font(font));
207-
}
197+
.push(caption)
198+
.push(get_palette_rule(on_press.get_palette(), buttons_color));
208199

209200
Button::new(content)
210-
.height(if is_custom { 75 } else { 110 })
211-
.width(380)
212-
.padding(5)
201+
.height(80)
202+
.width(350)
203+
.padding(Padding::ZERO.top(10))
213204
.class(if on_press.eq(&style) {
214205
ButtonType::BorderedRoundSelected
215206
} else {
@@ -221,9 +212,8 @@ fn get_palette_container<'a>(
221212
fn get_palette_rule<'a>(
222213
palette: Palette,
223214
buttons_color: Color,
224-
is_custom: bool,
225215
) -> Container<'a, Message, StyleType> {
226-
let height = if is_custom { 25 } else { 40 };
216+
let height = 25;
227217

228218
Container::new(
229219
Row::new()
@@ -255,9 +245,8 @@ fn get_extra_palettes<'a>(
255245
// Map each extra style into a palette container
256246
let mut styles = styles.iter().map(|&style| {
257247
let name = style.to_string();
258-
let description = String::new();
259248
let style = StyleType::Custom(style);
260-
get_palette_container(current_style, name, description, style)
249+
get_palette_container(current_style, name, style)
261250
});
262251

263252
// The best way to do this would be with itertools, but that would introduce another dependency.
@@ -272,15 +261,15 @@ fn get_extra_palettes<'a>(
272261
children.extend([
273262
Row::new()
274263
.push(first)
275-
.push(Space::with_width(10))
264+
.push(Space::with_width(15))
276265
.push(second)
277266
.into(),
278-
<Space as Into<Element<Message, StyleType>>>::into(Space::with_height(10)),
267+
<Space as Into<Element<Message, StyleType>>>::into(Space::with_height(15)),
279268
]);
280269
} else {
281270
children.extend([
282271
Row::new().push(first).into(),
283-
<Space as Into<Element<Message, StyleType>>>::into(Space::with_height(10)),
272+
<Space as Into<Element<Message, StyleType>>>::into(Space::with_height(15)),
284273
]);
285274
}
286275
}
@@ -334,14 +323,9 @@ fn lazy_custom_style_input<'a>(
334323
content = content.push(get_palette_rule(
335324
style.get_palette(),
336325
style.get_extension().buttons_color,
337-
true,
338326
));
339327
} else if let Ok(palette) = custom_palette {
340-
content = content.push(get_palette_rule(
341-
palette,
342-
palette.generate_buttons_color(),
343-
true,
344-
));
328+
content = content.push(get_palette_rule(palette, palette.generate_buttons_color()));
345329
}
346330

347331
Button::new(content)

src/gui/styles/types/custom_palette.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ impl ExtraStyles {
9898
/// Slice of all implemented custom styles
9999
pub const fn all_styles() -> &'static [Self] {
100100
&[
101+
ExtraStyles::A11yDark,
102+
ExtraStyles::A11yLight,
101103
ExtraStyles::DraculaDark,
102104
ExtraStyles::DraculaLight,
103105
ExtraStyles::GruvboxDark,
@@ -106,25 +108,18 @@ impl ExtraStyles {
106108
ExtraStyles::NordLight,
107109
ExtraStyles::SolarizedDark,
108110
ExtraStyles::SolarizedLight,
109-
ExtraStyles::A11yDark,
110-
ExtraStyles::A11yLight,
111111
]
112112
}
113113
}
114114

115115
impl fmt::Display for ExtraStyles {
116116
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
117117
match *self {
118-
ExtraStyles::DraculaLight => write!(f, "Dracula (Day)"),
119-
ExtraStyles::DraculaDark => write!(f, "Dracula (Night)"),
120-
ExtraStyles::GruvboxDark => write!(f, "Gruvbox (Night)"),
121-
ExtraStyles::GruvboxLight => write!(f, "Gruvbox (Day)"),
122-
ExtraStyles::NordLight => write!(f, "Nord (Day)"),
123-
ExtraStyles::NordDark => write!(f, "Nord (Night)"),
124-
ExtraStyles::SolarizedLight => write!(f, "Solarized (Day)"),
125-
ExtraStyles::SolarizedDark => write!(f, "Solarized (Night)"),
126-
ExtraStyles::A11yLight => write!(f, "A11y (Day)"),
127-
ExtraStyles::A11yDark => write!(f, "A11y (Night)"),
118+
ExtraStyles::DraculaLight | ExtraStyles::DraculaDark => write!(f, "Dracula"),
119+
ExtraStyles::GruvboxDark | ExtraStyles::GruvboxLight => write!(f, "Gruvbox"),
120+
ExtraStyles::NordLight | ExtraStyles::NordDark => write!(f, "Nord"),
121+
ExtraStyles::SolarizedLight | ExtraStyles::SolarizedDark => write!(f, "Solarized"),
122+
ExtraStyles::A11yLight | ExtraStyles::A11yDark => write!(f, "A11y"),
128123
// Custom style names aren't used anywhere so this shouldn't be reached
129124
ExtraStyles::CustomToml(_) => unreachable!(),
130125
}

0 commit comments

Comments
 (0)