|
1 | 1 | use iced::border::Radius; |
2 | 2 | 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}; |
4 | 4 | use iced_aw::tab_bar; |
5 | 5 |
|
6 | 6 | fn icon(unicode: char) -> Text<'static> { |
@@ -53,9 +53,38 @@ pub fn text_button(_theme: &Theme, status: button::Status) -> button::Style { |
53 | 53 | ButtonStyle::Text.style(&ButtonStyle::Text, status) |
54 | 54 | } |
55 | 55 |
|
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 | + } |
59 | 88 | } |
60 | 89 |
|
61 | 90 | pub fn log_container(log: &str) -> container::StyleFn<Theme> { |
@@ -170,34 +199,3 @@ impl container::Catalog for LogContainer { |
170 | 199 | } |
171 | 200 | } |
172 | 201 | } |
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