Skip to content

Commit fcff94c

Browse files
committed
Adapt TabBar to dynamic themes
1 parent 67abf82 commit fcff94c

2 files changed

Lines changed: 47 additions & 58 deletions

File tree

src/main.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -258,38 +258,29 @@ impl ESLauncher {
258258
.push::<Element<'_, Message>>(
259259
Tab::Instances,
260260
TabLabel::Text("Instances".into()),
261-
iced::widget::column([
262-
iced::widget::horizontal_rule(2).into(),
263-
Row::new()
264-
.push(self.instances_frame.view())
265-
.push(iced::widget::vertical_rule(2))
266-
.push(self.install_frame.view().map(Message::InstallFrameMessage))
267-
.spacing(10)
268-
.padding(iced::Padding {
269-
top: 0.0,
270-
right: 15.0,
271-
bottom: 0.0,
272-
left: 15.0,
273-
})
274-
.into(),
275-
])
261+
iced::widget::column([Row::new()
262+
.push(self.instances_frame.view())
263+
.push(iced::widget::vertical_rule(2))
264+
.push(self.install_frame.view().map(Message::InstallFrameMessage))
265+
.spacing(10)
266+
.padding(iced::Padding {
267+
top: 0.0,
268+
right: 15.0,
269+
bottom: 0.0,
270+
left: 15.0,
271+
})
272+
.into()])
276273
.into(),
277274
)
278275
.push(
279276
Tab::Plugins,
280277
TabLabel::Text("Plugins".into()),
281-
iced::widget::column([
282-
iced::widget::horizontal_rule(2).into(),
283-
self.plugins_frame.view().into(),
284-
]),
278+
iced::widget::column([self.plugins_frame.view().into()]),
285279
)
286280
.push(
287281
Tab::Settings,
288282
TabLabel::Text("Settings".into()),
289-
iced::widget::column([
290-
iced::widget::horizontal_rule(2).into(),
291-
self.settings_frame.view().into(),
292-
]),
283+
iced::widget::column([self.settings_frame.view().into()]),
293284
)
294285
.set_active_tab(&self.active_tab)
295286
.tab_bar_style(tab_bar);

src/style.rs

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use iced::border::Radius;
22
use iced::widget::{button, container, Text};
3-
use iced::{alignment, Background, Border, Color, Font, Length, Shadow, Theme, Vector};
3+
use iced::{alignment, color, Background, Border, Color, Font, Length, Shadow, Theme, Vector};
44
use iced_aw::tab_bar;
55

66
fn icon(unicode: char) -> Text<'static> {
@@ -53,9 +53,38 @@ pub fn text_button(_theme: &Theme, status: button::Status) -> button::Style {
5353
ButtonStyle::Text.style(&ButtonStyle::Text, status)
5454
}
5555

56-
pub fn tab_bar(_theme: &Theme, status: tab_bar::Status) -> tab_bar::Style {
57-
use tab_bar::Catalog;
58-
CustomTabBar::default().style(&CustomTabBar::default(), status)
56+
pub fn tab_bar(theme: &Theme, status: tab_bar::Status) -> tab_bar::Style {
57+
use iced_aw::tab_bar::*;
58+
let background = theme.palette().background;
59+
let primary = theme.extended_palette().primary;
60+
let secondary = theme.extended_palette().secondary;
61+
62+
let default = Style {
63+
tab_label_background: background.into(),
64+
tab_label_border_color: secondary.weak.color,
65+
text_color: theme.palette().text,
66+
..Default::default()
67+
};
68+
69+
match status {
70+
Status::Active => Style {
71+
tab_label_background: primary.base.color.into(),
72+
text_color: primary.base.text,
73+
..default
74+
},
75+
Status::Hovered => Style {
76+
tab_label_background: primary.weak.color.into(),
77+
text_color: primary.weak.text,
78+
..default
79+
},
80+
Status::Disabled => Style { ..default },
81+
_ => Style {
82+
// We don't use these - make it jarring, so if we ever do, it's noticeable
83+
tab_label_background: color!(0xff0000).into(),
84+
text_color: color!(0x00ff00),
85+
..default
86+
},
87+
}
5988
}
6089

6190
pub fn log_container(log: &str) -> container::StyleFn<Theme> {
@@ -170,34 +199,3 @@ impl container::Catalog for LogContainer {
170199
}
171200
}
172201
}
173-
174-
pub struct CustomTabBar;
175-
176-
impl tab_bar::Catalog for CustomTabBar {
177-
type Class<'a> = CustomTabBar;
178-
179-
fn default<'a>() -> Self::Class<'a> {
180-
CustomTabBar {}
181-
}
182-
183-
fn style(&self, class: &Self::Class<'_>, status: tab_bar::Status) -> tab_bar::Style {
184-
match status {
185-
tab_bar::Status::Active => tab_bar::Style {
186-
tab_label_background: Background::Color(Color::from_rgb(1., 1., 1.)),
187-
tab_label_border_width: 0.,
188-
..Default::default()
189-
},
190-
tab_bar::Status::Disabled => tab_bar::Style {
191-
tab_label_background: Background::Color(Color::from_rgb(0.87, 0.87, 0.87)),
192-
tab_label_border_width: 0.,
193-
..Default::default()
194-
},
195-
tab_bar::Status::Hovered => tab_bar::Style {
196-
tab_label_background: Background::Color(Color::from_rgb(0.97, 0.97, 0.97)),
197-
tab_label_border_width: 0.,
198-
..Default::default()
199-
},
200-
_ => Default::default(),
201-
}
202-
}
203-
}

0 commit comments

Comments
 (0)