Skip to content

Commit

Permalink
make clearing more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl4rry committed Jul 15, 2024
1 parent 637c72b commit 2ac8e7d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 43 deletions.
3 changes: 2 additions & 1 deletion crates/ferrite-tui/src/widgets/background_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ impl<'a> BackgroundWidget<'a> {

impl Widget for BackgroundWidget<'_> {
fn render(self, _: tui::layout::Rect, buf: &mut tui::buffer::Buffer) {
let style = convert_style(&self.theme.background);
for cell in &mut buf.content {
cell.set_style(convert_style(&self.theme.background));
cell.set_style(style);
cell.set_symbol(" ");
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/ferrite-tui/src/widgets/choord_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ferrite_core::{
};
use tui::{
layout,
widgets::{Block, BorderType, Borders, Widget},
widgets::{Block, BorderType, Borders, Clear, Widget},
};
use unicode_width::UnicodeWidthStr;

Expand Down Expand Up @@ -63,6 +63,8 @@ impl Widget for ChoordWidget<'_> {
let top = total_area.height - height;
let area = layout::Rect::new(left, top, width, height);

Clear.render(area, buf);

Block::default()
.title("Choords")
.borders(Borders::ALL)
Expand Down
19 changes: 7 additions & 12 deletions crates/ferrite-tui/src/widgets/completer_widget.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ferrite_core::{palette::completer::Completer, theme::EditorTheme};
use tui::widgets::StatefulWidget;
use tui::widgets::{Clear, StatefulWidget, Widget};
use unicode_width::UnicodeWidthStr;

use crate::glue::convert_style;
Expand Down Expand Up @@ -39,16 +39,11 @@ impl StatefulWidget for CompleterWidget<'_> {
.clamp(1, 10)
.min(area.height.into());

// clear inner area
for i in 0..rows {
buf.set_stringn(
area.left(),
area.bottom() - rows as u16 + i as u16,
" ".repeat(area.width.into()),
area.width.into(),
convert_style(&self.theme.completer),
);
}
let completer_area =
tui::layout::Rect::new(area.x, area.bottom() - rows as u16, area.width, rows as u16);

Clear.render(completer_area, buf);
buf.set_style(completer_area, convert_style(&self.theme.completer));

for row in 0..rows {
for col in 0..columns {
Expand All @@ -61,7 +56,7 @@ impl StatefulWidget for CompleterWidget<'_> {
let style = if Some(index) == completer.current() {
convert_style(&self.theme.completer_selected)
} else {
Default::default()
convert_style(&self.theme.completer)
};
buf.set_stringn(x as u16, y as u16, option.display(), widest, style);
}
Expand Down
9 changes: 2 additions & 7 deletions crates/ferrite-tui/src/widgets/editor_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use ropey::RopeSlice;
use tui::{
layout::Rect,
widgets::{StatefulWidget, Widget},
widgets::{Clear, StatefulWidget, Widget},
};
use unicode_width::UnicodeWidthStr;

Expand Down Expand Up @@ -69,12 +69,7 @@ impl StatefulWidget for EditorWidget<'_> {
return;
}

for x in 0..area.width {
for y in 0..area.height {
let cell = buf.get_mut(x + area.x, y + area.y);
cell.set_symbol(" ");
}
}
Clear.render(area, buf);

let Self {
theme,
Expand Down
7 changes: 6 additions & 1 deletion crates/ferrite-tui/src/widgets/info_line.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use encoding_rs::Encoding;
use ferrite_core::{byte_size::format_byte_size, config::InfoLineConfig, theme::EditorTheme};
use tui::{style::Style, widgets::Widget};
use tui::{
style::Style,
widgets::{Clear, Widget},
};
use unicode_width::UnicodeWidthStr;

use crate::glue::convert_style;
Expand Down Expand Up @@ -50,6 +53,8 @@ impl Widget for InfoLine<'_> {
false => convert_style(&self.theme.info_line_unfocused),
};

Clear.render(area, buf);

let mut left = String::from(" ");
for item in &self.config.left {
if let Some(item) = self.get_info_item(item) {
Expand Down
9 changes: 2 additions & 7 deletions crates/ferrite-tui/src/widgets/logger_widget.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

use ferrite_core::{logger::LoggerState, theme::EditorTheme};
use tui::widgets::StatefulWidget;
use tui::widgets::{Clear, StatefulWidget, Widget};

use crate::glue::convert_style;

Expand Down Expand Up @@ -34,12 +34,7 @@ impl StatefulWidget for LoggerWidget<'_> {
return;
}

for x in 0..area.width {
for y in 0..area.height {
let cell = buf.get_mut(x + area.x, y + area.y);
cell.set_symbol(" ");
}
}
Clear.render(area, buf);

buf.set_style(area, convert_style(&self.theme.background));
for y in 0..area.height.saturating_sub(1) {
Expand Down
17 changes: 3 additions & 14 deletions crates/ferrite-tui/src/widgets/picker_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ropey::RopeSlice;
use tui::{
layout::{Margin, Rect},
text::{Line, Span},
widgets::{Block, BorderType, Borders, StatefulWidget, Widget},
widgets::{Block, BorderType, Borders, Clear, StatefulWidget, Widget},
};
use unicode_width::UnicodeWidthStr;

Expand Down Expand Up @@ -50,6 +50,8 @@ where
buf: &mut tui::buffer::Buffer,
state: &mut Self::State,
) {
Clear.render(area, buf);

let main_block = Block::default()
.title(self.title)
.borders(Borders::all())
Expand All @@ -62,19 +64,6 @@ where
vertical: 1,
});

// TODO use same method as editor_widget to clear background
// TODO clear background color not just foreground color
// clear inner area
for i in 0..inner_area.height {
buf.set_stringn(
inner_area.x,
inner_area.y + i,
" ".repeat(inner_area.width.into()),
inner_area.width.into(),
convert_style(&self.theme.text),
);
}

let search_field_block = Block::default()
.borders(Borders::BOTTOM)
.border_style(convert_style(&self.theme.border))
Expand Down

0 comments on commit 2ac8e7d

Please sign in to comment.