Skip to content

Commit 2779aa7

Browse files
committed
Set the background color of each widget
Instead of iterating over every cell and setting the background color of that, just set the color of each widget, which achieves the same effect. This can also be overriden if we add the ability to set the background color of each widget.
1 parent ad0a3d8 commit 2779aa7

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

src/canvas.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use tui::{
1212
Frame, Terminal,
1313
backend::Backend,
1414
layout::{Constraint, Direction, Flex, Layout, Rect},
15-
style::Color,
1615
text::Span,
1716
widgets::Paragraph,
1817
};
@@ -102,17 +101,6 @@ impl Painter {
102101
self.previous_width = terminal_width;
103102
}
104103

105-
// Draw the background color
106-
let area = f.area();
107-
let buf = f.buffer_mut();
108-
for x in area.left()..area.right() {
109-
for y in area.top()..area.bottom() {
110-
if let Some(cell) = buf.cell_mut((x, y)) {
111-
cell.set_bg(Color::Blue);
112-
}
113-
}
114-
}
115-
116104
// TODO: We should probably remove this or make it done elsewhere, not the responsibility of the app.
117105
if app_state.should_get_widget_bounds() {
118106
// If we're force drawing, reset ALL mouse boundaries.

src/canvas/drawing_utils.rs

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

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

87
pub const SIDE_BORDERS: Borders = Borders::LEFT.union(Borders::RIGHT);
@@ -30,7 +29,7 @@ pub fn should_hide_x_label(
3029

3130
/// Return a widget block.
3231
pub fn widget_block(is_basic: bool, is_selected: bool, border_type: BorderType) -> Block<'static> {
33-
let mut block = Block::default().border_type(border_type);
32+
let mut block = Block::default().border_type(border_type).style(Style::default().bg(Color::Blue));
3433

3534
if is_basic {
3635
if is_selected {

0 commit comments

Comments
 (0)