switch to tui clear new in 0.9

This commit is contained in:
Stephan Dilly 2020-04-16 15:12:32 +02:00
parent 7a479b1896
commit 1b90436421
6 changed files with 39 additions and 67 deletions

View File

@ -17,7 +17,7 @@ use tui::{
backend::Backend,
layout::{Alignment, Rect},
style::{Color, Style},
widgets::{Block, Borders, Paragraph, Text},
widgets::{Block, Borders, Clear, Paragraph, Text},
Frame,
};
@ -40,8 +40,9 @@ impl DrawableComponent for CommitComponent {
[Text::Raw(Cow::from(self.msg.clone()))]
};
let area = ui::centered_rect(60, 20, f.size());
f.render_widget(Clear, area);
f.render_widget(
ui::Clear::new(
Paragraph::new(txt.iter())
.block(
Block::default()
@ -49,8 +50,7 @@ impl DrawableComponent for CommitComponent {
.borders(Borders::ALL),
)
.alignment(Alignment::Left),
),
ui::centered_rect(60, 20, f.size()),
area,
);
}
}

View File

@ -12,7 +12,7 @@ use tui::{
backend::Backend,
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Color, Style},
widgets::{Block, Borders, Paragraph, Text},
widgets::{Block, Borders, Clear, Paragraph, Text},
Frame,
};
@ -41,12 +41,11 @@ impl DrawableComponent for HelpComponent {
let area =
ui::centered_rect_absolute(65, height, f.size());
f.render_widget(Clear, area);
f.render_widget(
ui::Clear::new(
Block::default()
.title(strings::HELP_TITLE)
.borders(Borders::ALL),
),
area,
);

View File

@ -9,7 +9,7 @@ use strings::commands;
use tui::{
backend::Backend,
layout::{Alignment, Rect},
widgets::{Block, Borders, Paragraph, Text},
widgets::{Block, Borders, Clear, Paragraph, Text},
Frame,
};
@ -24,8 +24,9 @@ impl DrawableComponent for MsgComponent {
if self.visible {
let txt = vec![Text::Raw(Cow::from(self.msg.as_str()))];
let area = ui::centered_rect_absolute(65, 25, f.size());
f.render_widget(Clear, area);
f.render_widget(
ui::Clear::new(
Paragraph::new(txt.iter())
.block(
Block::default()
@ -34,8 +35,7 @@ impl DrawableComponent for MsgComponent {
)
.wrap(true)
.alignment(Alignment::Left),
),
ui::centered_rect_absolute(65, 25, f.size()),
area,
);
}
}

View File

@ -14,7 +14,7 @@ use tui::{
backend::Backend,
layout::{Alignment, Rect},
style::{Color, Style},
widgets::{Block, Borders, Paragraph, Text},
widgets::{Block, Borders, Clear, Paragraph, Text},
Frame,
};
@ -34,8 +34,9 @@ impl DrawableComponent for ResetComponent {
Style::default().fg(Color::Red),
));
let area = ui::centered_rect(30, 20, f.size());
f.render_widget(Clear, area);
f.render_widget(
ui::Clear::new(
Paragraph::new(txt.iter())
.block(
Block::default()
@ -43,8 +44,7 @@ impl DrawableComponent for ResetComponent {
.borders(Borders::ALL),
)
.alignment(Alignment::Left),
),
ui::centered_rect(30, 20, f.size()),
area,
);
}
}

View File

@ -1,25 +0,0 @@
use tui::{buffer::Buffer, layout::Rect, widgets::Widget};
pub struct Clear<T: Widget>(T);
impl<T: Widget> Clear<T> {
pub fn new(w: T) -> Self {
Self(w)
}
}
impl<T: Widget> Widget for Clear<T> {
fn render(self, area: Rect, buf: &mut Buffer) {
if area.width < 2 || area.height < 2 {
return;
}
for x in area.left()..area.right() {
for y in area.top()..area.bottom() {
buf.get_mut(x, y).reset();
}
}
self.0.render(area, buf);
}
}

View File

@ -1,7 +1,5 @@
mod clear;
mod scrolllist;
pub use clear::Clear;
use scrolllist::ScrollableList;
use tui::{
backend::Backend,