Skip to content

Commit a2d9084

Browse files
committed
Make all widgets use the bg color from Styles
1 parent 2779aa7 commit a2d9084

File tree

12 files changed

+72
-20
lines changed

12 files changed

+72
-20
lines changed

src/canvas/components/data_table/draw.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,13 @@ where
7878
self.styling.border_style
7979
};
8080

81-
let mut block = widget_block(self.props.is_basic, is_selected, self.styling.border_type)
82-
.border_style(border_style);
81+
let mut block = widget_block(
82+
self.props.is_basic,
83+
is_selected,
84+
self.styling.border_type,
85+
self.styling.bg_color_style,
86+
)
87+
.border_style(border_style);
8388

8489
if let Some((left_title, right_title)) = self.generate_title(draw_info, data_len) {
8590
if !self.props.is_basic {

src/canvas/components/data_table/styling.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct DataTableStyling {
1111
pub text_style: Style,
1212
pub highlighted_text_style: Style,
1313
pub title_style: Style,
14+
pub bg_color_style: Style,
1415
}
1516

1617
impl DataTableStyling {
@@ -23,6 +24,7 @@ impl DataTableStyling {
2324
text_style: styles.text_style,
2425
highlighted_text_style: styles.selected_text_style,
2526
title_style: styles.widget_title_style,
27+
bg_color_style: styles.bg_color_style,
2628
}
2729
}
2830
}

src/canvas/components/time_graph/base.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ pub struct TimeGraph<'a> {
6464
/// The graph style.
6565
pub graph_style: Style,
6666

67+
/// The background color
68+
pub bg_color_style: Style,
69+
6770
/// The border style.
6871
pub border_style: Style,
6972

@@ -150,9 +153,14 @@ impl TimeGraph<'_> {
150153
let data = graph_data.into_iter().map(create_dataset).collect();
151154

152155
let block = {
153-
let mut b = widget_block(false, self.is_selected, self.border_type)
154-
.border_style(self.border_style)
155-
.title_top(Line::styled(self.title.as_ref(), self.title_style));
156+
let mut b = widget_block(
157+
false,
158+
self.is_selected,
159+
self.border_type,
160+
self.bg_color_style,
161+
)
162+
.border_style(self.border_style)
163+
.title_top(Line::styled(self.title.as_ref(), self.title_style));
156164

157165
if self.is_expanded {
158166
b = b.title_top(Line::styled(" Esc to go back ", self.title_style).right_aligned())
@@ -167,8 +175,8 @@ impl TimeGraph<'_> {
167175
.x_axis(x_axis)
168176
.y_axis(y_axis)
169177
.marker(self.marker)
178+
.style(self.bg_color_style)
170179
.legend_style(self.graph_style)
171-
.style(Style::default().bg(Color::Blue))
172180
.legend_position(self.legend_position)
173181
.hidden_legend_constraints(
174182
self.legend_constraints
@@ -233,6 +241,7 @@ mod test {
233241
y_bounds: AxisBound::Max(100.5),
234242
y_labels: &Y_LABELS,
235243
graph_style: Style::default().fg(Color::Red),
244+
bg_color_style: Style::default().bg(Color::Black),
236245
border_style: Style::default().fg(Color::Blue),
237246
border_type: BorderType::Plain,
238247
is_selected: false,

src/canvas/components/time_graph/variants/percent.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(crate) struct PercentTimeGraph<'a> {
3535
pub(crate) current_widget: u64,
3636

3737
/// Whether the current widget is expanded.
38-
///
38+
///
3939
/// This is mostly used as a shared mutability workaround due to [`App`]
4040
/// being a giant state struct.
4141
pub(crate) is_expanded: bool,
@@ -70,7 +70,9 @@ impl<'a> PercentTimeGraph<'a> {
7070
Marker::Braille
7171
};
7272

73+
// Why are these declared as variables?
7374
let graph_style = self.styles.graph_style;
75+
let bg_color_style = self.styles.bg_color_style;
7476
let border_style = get_border_style(self.styles, self.widget_id, self.current_widget);
7577
let title_style = self.styles.widget_title_style;
7678
let border_type = self.styles.border_type;
@@ -81,6 +83,7 @@ impl<'a> PercentTimeGraph<'a> {
8183
y_bounds: Y_BOUNDS,
8284
y_labels: &Y_LABELS,
8385
graph_style,
86+
bg_color_style,
8487
border_style,
8588
border_type,
8689
title: self.title,

src/canvas/drawing_utils.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use std::time::Instant;
22

33
use tui::{
4-
layout::Rect, style::{Color, Style}, widgets::{Block, BorderType, Borders}
4+
layout::Rect,
5+
style::{Color, Style},
6+
widgets::{Block, BorderType, Borders},
57
};
68

79
pub const SIDE_BORDERS: Borders = Borders::LEFT.union(Borders::RIGHT);
@@ -28,8 +30,12 @@ pub fn should_hide_x_label(
2830
}
2931

3032
/// Return a widget block.
31-
pub fn widget_block(is_basic: bool, is_selected: bool, border_type: BorderType) -> Block<'static> {
32-
let mut block = Block::default().border_type(border_type).style(Style::default().bg(Color::Blue));
33+
pub fn widget_block(
34+
is_basic: bool, is_selected: bool, border_type: BorderType, bg_color: Style,
35+
) -> Block<'static> {
36+
let mut block = Block::default()
37+
.border_type(border_type)
38+
.style(bg_color);
3339

3440
if is_basic {
3541
if is_selected {

src/canvas/widgets/battery_display.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl Painter {
5151
app_state.app_config_fields.use_basic_mode,
5252
is_selected,
5353
self.styles.border_type,
54+
self.styles.bg_color_style,
5455
)
5556
.border_style(border_style)
5657
.title_top(Line::styled(" Battery ", self.styles.widget_title_style));

src/canvas/widgets/cpu_basic.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ impl Painter {
3535

3636
if app_state.current_widget.widget_id == widget_id {
3737
f.render_widget(
38-
widget_block(true, true, self.styles.border_type)
39-
.border_style(self.styles.highlighted_border_style),
38+
widget_block(
39+
true,
40+
true,
41+
self.styles.border_type,
42+
self.styles.bg_color_style,
43+
)
44+
.border_style(self.styles.highlighted_border_style),
4045
draw_loc,
4146
);
4247
}

src/canvas/widgets/mem_basic.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ impl Painter {
4848

4949
if app_state.current_widget.widget_id == widget_id {
5050
f.render_widget(
51-
widget_block(true, true, self.styles.border_type)
52-
.border_style(self.styles.highlighted_border_style),
51+
widget_block(
52+
true,
53+
true,
54+
self.styles.border_type,
55+
self.styles.bg_color_style,
56+
)
57+
.border_style(self.styles.highlighted_border_style),
5358
draw_loc,
5459
);
5560
}

src/canvas/widgets/network_basic.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ impl Painter {
3434

3535
if app_state.current_widget.widget_id == widget_id {
3636
f.render_widget(
37-
widget_block(true, true, self.styles.border_type)
38-
.border_style(self.styles.highlighted_border_style),
37+
widget_block(
38+
true,
39+
true,
40+
self.styles.border_type,
41+
self.styles.bg_color_style,
42+
)
43+
.border_style(self.styles.highlighted_border_style),
3944
draw_loc,
4045
);
4146
}

src/canvas/widgets/network_graph.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ impl Painter {
237237
y_bounds,
238238
y_labels: &(y_labels.into_iter().map(Into::into).collect::<Vec<_>>()),
239239
graph_style: self.styles.graph_style,
240+
bg_color_style: self.styles.bg_color_style,
240241
border_style,
241242
border_type: self.styles.border_type,
242243
title: " Network ".into(),

0 commit comments

Comments
 (0)