You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tui-rs/examples/custom_widget.rs

43 lines
906 B
Rust

extern crate tui;
7 years ago
use tui::backend::MouseBackend;
use tui::buffer::Buffer;
use tui::layout::Rect;
8 years ago
use tui::style::Style;
6 years ago
use tui::widgets::Widget;
use tui::Terminal;
struct Label<'a> {
text: &'a str,
}
impl<'a> Default for Label<'a> {
fn default() -> Label<'a> {
Label { text: "" }
}
}
impl<'a> Widget for Label<'a> {
fn draw(&mut self, area: Rect, buf: &mut Buffer) {
8 years ago
buf.set_string(area.left(), area.top(), self.text, &Style::default());
}
}
impl<'a> Label<'a> {
fn text(&mut self, text: &'a str) -> &mut Label<'a> {
self.text = text;
self
}
}
fn main() {
7 years ago
let mut terminal = Terminal::new(MouseBackend::new().unwrap()).unwrap();
let size = terminal.size().unwrap();
8 years ago
terminal.clear().unwrap();
terminal
.draw(|mut f| {
Label::default().text("Test").render(&mut f, size);
})
.unwrap();
}