Skip to content

Commit 65f8a4a

Browse files
committed
updated layout of BorderedRound buttons
1 parent 96c74ca commit 65f8a4a

File tree

5 files changed

+43
-27
lines changed

5 files changed

+43
-27
lines changed

src/gui/pages/initial_page.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! It contains elements to select network adapter and traffic filters.
44
55
use iced::widget::{
6-
button, horizontal_space, vertical_space, Column, Container, PickList, Radio, Row, Scrollable,
6+
button, horizontal_space, vertical_space, Button, Column, Container, PickList, Row, Scrollable,
77
Text, Tooltip,
88
};
99
use iced::Length::FillPortion;
@@ -138,7 +138,7 @@ fn button_start(style: StyleType, language: Language) -> Tooltip<'static, Messag
138138
fn get_col_adapter(sniffer: &Sniffer, font: Font) -> Column<Message> {
139139
let mut dev_str_list = vec![];
140140
for dev in Device::list().expect("Error retrieving device list\r\n") {
141-
let mut dev_str = "\n".to_string();
141+
let mut dev_str = String::new();
142142
let name = dev.name;
143143
match dev.desc {
144144
None => {
@@ -165,7 +165,6 @@ fn get_col_adapter(sniffer: &Sniffer, font: Font) -> Column<Message> {
165165
let address_string = addr.addr.to_string();
166166
dev_str.push_str(&format!("\n {address_string}"));
167167
}
168-
dev_str.push_str("\n ");
169168
dev_str_list.push((name, dev_str));
170169
}
171170

@@ -183,27 +182,24 @@ fn get_col_adapter(sniffer: &Sniffer, font: Font) -> Column<Message> {
183182
Scrollable::new(dev_str_list.iter().fold(
184183
Column::new().padding(13).spacing(5),
185184
|scroll_adapters, adapter| {
186-
let name = &adapter.0;
185+
let name = adapter.0.clone();
186+
let description = adapter.1.clone();
187187
scroll_adapters.push(
188-
Container::new(
189-
Radio::new(&adapter.1, name, Some(&sniffer.device.name), |name| {
190-
Message::AdapterSelection(name.to_string())
191-
})
192-
.font(font)
193-
.size(15)
188+
Button::new(Text::new(description).font(font))
189+
.padding([20, 30])
194190
.width(Length::Fill)
195-
.style(<StyleTuple as Into<
196-
iced::theme::Radio,
197-
>>::into(
198-
StyleTuple(sniffer.style, ElementType::Standard),
199-
)),
200-
)
201-
.padding(10)
202-
.style(<StyleTuple as Into<
203-
iced::theme::Container,
204-
>>::into(
205-
StyleTuple(sniffer.style, ElementType::BorderedRound),
206-
)),
191+
.style(
192+
StyleTuple(
193+
sniffer.style,
194+
if name == sniffer.device.name {
195+
ElementType::BorderedRoundSelected
196+
} else {
197+
ElementType::BorderedRound
198+
},
199+
)
200+
.into(),
201+
)
202+
.on_press(Message::AdapterSelection(name)),
207203
)
208204
},
209205
))

src/gui/pages/settings_style_page.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ fn get_palette_container(
114114
.height(Length::Fixed(130.0))
115115
.width(Length::Fixed(360.0))
116116
.padding(5)
117-
.style(StyleTuple(style, ElementType::BorderedRound).into())
117+
.style(
118+
StyleTuple(
119+
style,
120+
if on_press.eq(&style) {
121+
ElementType::BorderedRoundSelected
122+
} else {
123+
ElementType::BorderedRound
124+
},
125+
)
126+
.into(),
127+
)
118128
.on_press(Message::Style(on_press))
119129
}

src/gui/styles/button.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ impl button::StyleSheet for StyleTuple {
2727
StyleTuple(_, ElementType::Starred) => STARRED,
2828
StyleTuple(_, ElementType::Badge) => colors.secondary,
2929
StyleTuple(_, ElementType::BorderedRound) => colors.round_containers,
30+
StyleTuple(_, ElementType::BorderedRoundSelected) => {
31+
mix_colors(colors.primary, colors.buttons)
32+
}
3033
_ => colors.buttons,
3134
})),
3235
border_radius: match self {
3336
StyleTuple(_, ElementType::TabActive | ElementType::TabInactive) => 0.0,
34-
StyleTuple(_, ElementType::BorderedRound) => 12.0,
37+
StyleTuple(_, ElementType::BorderedRound | ElementType::BorderedRoundSelected) => {
38+
12.0
39+
}
3540
_ => BORDER_BUTTON_RADIUS,
3641
},
3742
border_width: match self {
@@ -71,7 +76,9 @@ impl button::StyleSheet for StyleTuple {
7176
})),
7277
border_radius: match self {
7378
StyleTuple(_, ElementType::TabActive | ElementType::TabInactive) => 0.0,
74-
StyleTuple(_, ElementType::BorderedRound) => 12.0,
79+
StyleTuple(_, ElementType::BorderedRound | ElementType::BorderedRoundSelected) => {
80+
12.0
81+
}
7582
_ => BORDER_BUTTON_RADIUS,
7683
},
7784
border_width: match self {
@@ -80,12 +87,14 @@ impl button::StyleSheet for StyleTuple {
8087
ElementType::Starred
8188
| ElementType::NotStarred
8289
| ElementType::TabActive
83-
| ElementType::TabInactive,
90+
| ElementType::TabInactive
91+
| ElementType::BorderedRound,
8492
) => 0.0,
8593
_ => BORDER_WIDTH,
8694
},
8795
border_color: match self {
8896
StyleTuple(_, ElementType::Alert) => Color::new(1.0, 0.0, 0.0, 1.0),
97+
StyleTuple(_, ElementType::BorderedRound) => colors.round_borders,
8998
_ => colors.secondary,
9099
},
91100
text_color: match self {

src/gui/styles/types/element_type.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub enum ElementType {
44
Standard,
55
Headers,
66
BorderedRound,
7+
BorderedRoundSelected,
78
TabActive,
89
TabInactive,
910
Starred,

src/gui/styles/types/style_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::{Deserialize, Serialize};
22

33
/// Used to specify the kind of style of the application
4-
#[derive(Clone, Copy, Serialize, Deserialize, Debug, Hash)]
4+
#[derive(Clone, Copy, Serialize, Deserialize, Debug, Hash, PartialEq)]
55
pub enum StyleType {
66
Night,
77
Day,

0 commit comments

Comments
 (0)