refactor: update widgets

* all widgets use the consumable builder pattern
* `draw` on terminal expect a closure that take a frame as only arg
This commit is contained in:
Florian Dehau 2018-09-01 14:05:33 +02:00
parent d6016788ef
commit 13e194cd26
26 changed files with 152 additions and 238 deletions

View file

@ -9,6 +9,7 @@ keywords = ["tui", "terminal", "dashboard"]
repository = "https://github.com/fdehau/tui-rs"
license = "MIT"
exclude = ["docs/*", ".travis.yml"]
autoexamples = true
[badges]
travis-ci = { repository = "fdehau/tui-rs" }
@ -31,63 +32,7 @@ rustbox = { version = "0.11.0", optional = true }
stderrlog = "0.3.0"
rand = "0.4.2"
[[example]]
name = "barchart"
path = "examples/barchart.rs"
[[example]]
name = "block"
path = "examples/block.rs"
[[example]]
name = "canvas"
path = "examples/canvas.rs"
[[example]]
name = "chart"
path = "examples/chart.rs"
[[example]]
name = "custom_widget"
path = "examples/custom_widget.rs"
[[example]]
name = "demo"
path = "examples/demo.rs"
[[example]]
name = "gauge"
path = "examples/gauge.rs"
[[example]]
name = "list"
path = "examples/list.rs"
[[example]]
name = "paragraph"
path = "examples/paragraph.rs"
[[example]]
name = "rustbox"
path = "examples/rustbox.rs"
required-features = ["rustbox"]
[[example]]
name = "sparkline"
path = "examples/sparkline.rs"
[[example]]
name = "table"
path = "examples/table.rs"
[[example]]
name = "tabs"
path = "examples/tabs.rs"
[[example]]
name = "user_input"
path = "examples/user_input.rs"
[[example]]
name = "layout"
path = "examples/layout.rs"

View file

@ -99,7 +99,7 @@ fn main() {
terminal.clear().unwrap();
terminal.hide_cursor().unwrap();
app.size = terminal.size().unwrap();
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
loop {
let size = terminal.size().unwrap();
@ -117,15 +117,14 @@ fn main() {
app.advance();
}
}
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
}
terminal.show_cursor().unwrap();
}
fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
{
let mut f = t.get_frame();
fn draw(t: &mut Terminal<MouseBackend>, app: &App) -> Result<(), io::Error> {
t.draw(|mut f| {
let chunks = Layout::default()
.direction(Direction::Vertical)
.margin(2)
@ -161,6 +160,5 @@ fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
.label_style(Style::default().fg(Color::Cyan).modifier(Modifier::Italic))
.render(&mut f, chunks[1]);
}
}
t.draw().unwrap();
})
}

View file

@ -18,14 +18,14 @@ fn main() {
terminal.hide_cursor().unwrap();
let mut term_size = terminal.size().unwrap();
draw(&mut terminal, term_size);
draw(&mut terminal, term_size).unwrap();
for c in stdin.keys() {
let size = terminal.size().unwrap();
if term_size != size {
terminal.resize(size).unwrap();
term_size = size;
}
draw(&mut terminal, term_size);
draw(&mut terminal, term_size).unwrap();
let evt = c.unwrap();
if evt == event::Key::Char('q') {
break;
@ -34,9 +34,8 @@ fn main() {
terminal.show_cursor().unwrap();
}
fn draw(t: &mut Terminal<MouseBackend>, size: Rect) {
{
let mut f = t.get_frame();
fn draw(t: &mut Terminal<MouseBackend>, size: Rect) -> Result<(), io::Error> {
t.draw(|mut f| {
// Wrapping block for a group
// Just draw the block and the group on the same area and build the group
// with at least a margin of 1
@ -81,6 +80,5 @@ fn draw(t: &mut Terminal<MouseBackend>, size: Rect) {
.borders(Borders::LEFT | Borders::RIGHT)
.render(&mut f, chunks[1]);
}
}
t.draw().unwrap();
})
}

View file

@ -107,7 +107,7 @@ fn main() {
terminal.clear().unwrap();
terminal.hide_cursor().unwrap();
app.size = terminal.size().unwrap();
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
loop {
let size = terminal.size().unwrap();
@ -141,15 +141,14 @@ fn main() {
app.advance();
}
}
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
}
terminal.show_cursor().unwrap();
}
fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
{
let mut f = t.get_frame();
fn draw(t: &mut Terminal<MouseBackend>, app: &App) -> Result<(), io::Error> {
t.draw(|mut f| {
let chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
@ -201,7 +200,5 @@ fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
.x_bounds([10.0, 110.0])
.y_bounds([10.0, 110.0])
.render(&mut f, chunks[1]);
}
t.draw().unwrap();
})
}

View file

@ -97,7 +97,7 @@ fn main() {
terminal.clear().unwrap();
terminal.hide_cursor().unwrap();
app.size = terminal.size().unwrap();
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
loop {
let size = terminal.size().unwrap();
@ -115,15 +115,14 @@ fn main() {
app.advance();
}
}
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
}
terminal.show_cursor().unwrap();
}
fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
{
let mut f = t.get_frame();
fn draw(t: &mut Terminal<MouseBackend>, app: &App) -> Result<(), io::Error> {
t.draw(|mut f| {
Chart::default()
.block(
Block::default()
@ -164,6 +163,5 @@ fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
.data(&app.data2),
])
.render(&mut f, app.size);
}
t.draw().unwrap();
})
}

View file

@ -34,8 +34,9 @@ fn main() {
let mut terminal = Terminal::new(MouseBackend::new().unwrap()).unwrap();
let size = terminal.size().unwrap();
terminal.clear().unwrap();
Label::default()
.text("Test")
.render(&mut terminal.get_frame(), size);
terminal.draw().unwrap();
terminal
.draw(|mut f| {
Label::default().text("Test").render(&mut f, size);
})
.unwrap();
}

View file

@ -194,7 +194,7 @@ fn main() {
let tx = tx.clone();
loop {
tx.send(Event::Tick).unwrap();
thread::sleep(time::Duration::from_millis(16));
thread::sleep(time::Duration::from_millis(250));
}
});
@ -268,8 +268,7 @@ fn main() {
}
fn draw(t: &mut Terminal<MouseBackend>, app: &App) -> Result<(), io::Error> {
{
let mut f = t.get_frame();
t.draw(|mut f| {
let chunks = Layout::default()
.constraints([Constraint::Length(3), Constraint::Min(0)].as_ref())
.split(app.size);
@ -289,8 +288,7 @@ fn draw(t: &mut Terminal<MouseBackend>, app: &App) -> Result<(), io::Error> {
}
_ => {}
};
}
t.draw()
})
}
fn draw_first_tab(f: &mut Frame<MouseBackend>, app: &App, area: Rect) {

View file

@ -94,7 +94,7 @@ fn main() {
terminal.clear().unwrap();
terminal.hide_cursor().unwrap();
app.size = terminal.size().unwrap();
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
loop {
let size = terminal.size().unwrap();
@ -112,15 +112,14 @@ fn main() {
app.advance();
}
}
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
}
terminal.show_cursor().unwrap();
}
fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
{
let mut f = t.get_frame();
fn draw(t: &mut Terminal<MouseBackend>, app: &App) -> Result<(), io::Error> {
t.draw(|mut f| {
let chunks = Layout::default()
.direction(Direction::Vertical)
.margin(2)
@ -155,7 +154,5 @@ fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
.percent(app.progress4)
.label(&format!("{}/100", app.progress2))
.render(&mut f, chunks[3]);
}
t.draw().unwrap();
})
}

View file

@ -61,7 +61,7 @@ fn main() {
terminal.clear().unwrap();
terminal.hide_cursor().unwrap();
app.size = terminal.size().unwrap();
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
loop {
let size = terminal.size().unwrap();
@ -76,15 +76,14 @@ fn main() {
break;
},
}
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
}
terminal.show_cursor().unwrap();
}
fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
{
let mut f = t.get_frame();
fn draw(t: &mut Terminal<MouseBackend>, app: &App) -> Result<(), io::Error> {
t.draw(|mut f| {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints(
@ -104,7 +103,5 @@ fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
.title("Block 2")
.borders(Borders::ALL)
.render(&mut f, chunks[2]);
}
t.draw().unwrap();
})
}

View file

@ -117,7 +117,7 @@ fn main() {
terminal.clear().unwrap();
terminal.hide_cursor().unwrap();
app.size = terminal.size().unwrap();
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
loop {
let size = terminal.size().unwrap();
@ -149,15 +149,14 @@ fn main() {
app.advance();
}
}
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
}
terminal.show_cursor().unwrap();
}
fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
{
let mut f = t.get_frame();
fn draw(t: &mut Terminal<MouseBackend>, app: &App) -> Result<(), io::Error> {
t.draw(|mut f| {
let chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
@ -182,13 +181,12 @@ fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
"WARNING" => &app.warning_style,
_ => &app.info_style,
},
)
)
});
List::new(events)
.block(Block::default().borders(Borders::ALL).title("List"))
.start_corner(Corner::BottomLeft)
.render(&mut f, chunks[1]);
}
}
t.draw().unwrap();
})
}

View file

@ -18,7 +18,7 @@ fn main() {
terminal.hide_cursor().unwrap();
let mut term_size = terminal.size().unwrap();
draw(&mut terminal, term_size);
draw(&mut terminal, term_size).unwrap();
for c in stdin.keys() {
let size = terminal.size().unwrap();
@ -27,7 +27,7 @@ fn main() {
term_size = size;
}
draw(&mut terminal, term_size);
draw(&mut terminal, term_size).unwrap();
let evt = c.unwrap();
if evt == event::Key::Char('q') {
break;
@ -36,9 +36,8 @@ fn main() {
terminal.show_cursor().unwrap();
}
fn draw(t: &mut Terminal<MouseBackend>, size: Rect) {
{
let mut f = t.get_frame();
fn draw(t: &mut Terminal<MouseBackend>, size: Rect) -> Result<(), io::Error> {
t.draw(|mut f| {
Block::default()
.style(Style::default().bg(Color::White))
.render(&mut f, size);
@ -80,6 +79,5 @@ fn draw(t: &mut Terminal<MouseBackend>, size: Rect) {
.alignment(Alignment::Right)
.wrap(true)
.render(&mut f, chunks[2]);
}
t.draw().unwrap();
})
}

View file

@ -94,7 +94,7 @@ fn main() {
terminal.clear().unwrap();
terminal.hide_cursor().unwrap();
app.size = terminal.size().unwrap();
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
loop {
let size = terminal.size().unwrap();
@ -112,15 +112,14 @@ fn main() {
app.advance();
}
}
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
}
terminal.show_cursor().unwrap();
}
fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
{
let mut f = t.get_frame();
fn draw(t: &mut Terminal<MouseBackend>, app: &App) -> Result<(), io::Error> {
t.draw(|mut f| {
let chunks = Layout::default()
.direction(Direction::Vertical)
.margin(2)
@ -161,6 +160,5 @@ fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
.data(&app.data3)
.style(Style::default().fg(Color::Red))
.render(&mut f, chunks[2]);
}
t.draw().unwrap();
})
}

View file

@ -84,8 +84,7 @@ fn main() {
}
fn draw(t: &mut Terminal<MouseBackend>, app: &App) -> Result<(), io::Error> {
{
let mut frame = t.get_frame();
t.draw(|mut f| {
let selected_style = Style::default().fg(Color::Yellow).modifier(Modifier::Bold);
let normal_style = Style::default().fg(Color::White);
let header = ["Header1", "Header2", "Header3"];
@ -104,7 +103,6 @@ fn draw(t: &mut Terminal<MouseBackend>, app: &App) -> Result<(), io::Error> {
Table::new(header.into_iter(), rows)
.block(Block::default().borders(Borders::ALL).title("Table"))
.widths(&[10, 10, 10])
.render(&mut frame, rects[0]);
}
t.draw()
.render(&mut f, rects[0]);
})
}

View file

@ -37,7 +37,7 @@ fn main() {
terminal.clear().unwrap();
terminal.hide_cursor().unwrap();
app.size = terminal.size().unwrap();
draw(&mut terminal, &mut app);
draw(&mut terminal, &mut app).unwrap();
// Main loop
let stdin = io::stdin();
@ -57,15 +57,14 @@ fn main() {
event::Key::Left => app.tabs.previous(),
_ => {}
}
draw(&mut terminal, &mut app);
draw(&mut terminal, &mut app).unwrap();
}
terminal.show_cursor().unwrap();
}
fn draw(t: &mut Terminal<MouseBackend>, app: &mut App) {
{
let mut f = t.get_frame();
fn draw(t: &mut Terminal<MouseBackend>, app: &App) -> Result<(), io::Error> {
t.draw(|mut f| {
let chunks = Layout::default()
.direction(Direction::Vertical)
.margin(5)
@ -109,6 +108,5 @@ fn draw(t: &mut Terminal<MouseBackend>, app: &mut App) {
}
_ => {}
}
}
t.draw().unwrap();
})
}

View file

@ -73,7 +73,7 @@ fn main() {
terminal.clear().unwrap();
terminal.hide_cursor().unwrap();
app.size = terminal.size().unwrap();
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
loop {
let size = terminal.size().unwrap();
@ -100,16 +100,15 @@ fn main() {
_ => {}
},
}
draw(&mut terminal, &app);
draw(&mut terminal, &app).unwrap();
}
terminal.show_cursor().unwrap();
terminal.clear().unwrap();
}
fn draw(t: &mut Terminal<AlternateScreenBackend>, app: &App) {
{
let mut f = t.get_frame();
fn draw(t: &mut Terminal<AlternateScreenBackend>, app: &App) -> Result<(), io::Error> {
t.draw(|mut f| {
let chunks = Layout::default()
.direction(Direction::Vertical)
.margin(2)
@ -126,7 +125,5 @@ fn draw(t: &mut Terminal<AlternateScreenBackend>, app: &App) {
.map(|(i, m)| Item::Data(format!("{}: {}", i, m))),
).block(Block::default().borders(Borders::ALL).title("Messages"))
.render(&mut f, chunks[1]);
}
t.draw().unwrap();
})
}

View file

@ -84,16 +84,12 @@
//! fn draw(t: &mut Terminal<RawBackend>) -> Result<(), io::Error> {
//!
//! let size = t.size()?;
//!
//! {
//! let mut f = t.get_frame();
//! t.draw(|mut f| {
//! Block::default()
//! .title("Block")
//! .borders(Borders::ALL)
//! .render(&mut f, size);
//! }
//!
//! t.draw()
//! })
//! }
//! ```
//!
@ -126,31 +122,27 @@
//! fn draw(t: &mut Terminal<RawBackend>) -> Result<(), io::Error> {
//!
//! let size = t.size()?;
//!
//! {
//! let mut f = t.get_frame();
//! let chunks = Layout::default()
//! .direction(Direction::Vertical)
//! .margin(1)
//! .constraints(
//! [
//! Constraint::Percentage(10),
//! Constraint::Percentage(80),
//! Constraint::Percentage(10)
//! ].as_ref()
//! )
//! .split(size);
//! Block::default()
//! .title("Block")
//! .borders(Borders::ALL)
//! .render(&mut f, chunks[0]);
//! Block::default()
//! .title("Block 2")
//! .borders(Borders::ALL)
//! .render(&mut f, chunks[2]);
//! }
//!
//! t.draw()
//! t.draw(|mut f| {
//! let chunks = Layout::default()
//! .direction(Direction::Vertical)
//! .margin(1)
//! .constraints(
//! [
//! Constraint::Percentage(10),
//! Constraint::Percentage(80),
//! Constraint::Percentage(10)
//! ].as_ref()
//! )
//! .split(size);
//! Block::default()
//! .title("Block")
//! .borders(Borders::ALL)
//! .render(&mut f, chunks[0]);
//! Block::default()
//! .title("Block 2")
//! .borders(Borders::ALL)
//! .render(&mut f, chunks[2]);
//! })
//! }
//! ```
//!

View file

@ -102,7 +102,12 @@ where
}
/// Flushes the current internal state and prepares the interface for the next draw call
pub fn draw(&mut self) -> Result<(), io::Error> {
pub fn draw<F>(&mut self, f: F) -> Result<(), io::Error>
where
F: FnOnce(Frame<B>),
{
f(self.get_frame());
// Draw to stdout
self.flush()?;

View file

@ -67,7 +67,7 @@ impl<'a> Default for BarChart<'a> {
}
impl<'a> BarChart<'a> {
pub fn data(&'a mut self, data: &'a [(&'a str, u64)]) -> &mut BarChart<'a> {
pub fn data(mut self, data: &'a [(&'a str, u64)]) -> BarChart<'a> {
self.data = data;
self.values = Vec::with_capacity(self.data.len());
for &(_, v) in self.data {
@ -76,32 +76,32 @@ impl<'a> BarChart<'a> {
self
}
pub fn block(&'a mut self, block: Block<'a>) -> &mut BarChart<'a> {
pub fn block(mut self, block: Block<'a>) -> BarChart<'a> {
self.block = Some(block);
self
}
pub fn max(&'a mut self, max: u64) -> &mut BarChart<'a> {
pub fn max(mut self, max: u64) -> BarChart<'a> {
self.max = Some(max);
self
}
pub fn bar_width(&'a mut self, width: u16) -> &mut BarChart<'a> {
pub fn bar_width(mut self, width: u16) -> BarChart<'a> {
self.bar_width = width;
self
}
pub fn bar_gap(&'a mut self, gap: u16) -> &mut BarChart<'a> {
pub fn bar_gap(mut self, gap: u16) -> BarChart<'a> {
self.bar_gap = gap;
self
}
pub fn value_style(&'a mut self, style: Style) -> &mut BarChart<'a> {
pub fn value_style(mut self, style: Style) -> BarChart<'a> {
self.value_style = style;
self
}
pub fn label_style(&'a mut self, style: Style) -> &mut BarChart<'a> {
pub fn label_style(mut self, style: Style) -> BarChart<'a> {
self.label_style = style;
self
}
pub fn style(&'a mut self, style: Style) -> &mut BarChart<'a> {
pub fn style(mut self, style: Style) -> BarChart<'a> {
self.style = style;
self
}

View file

@ -194,26 +194,26 @@ impl<'a, F> Canvas<'a, F>
where
F: Fn(&mut Context),
{
pub fn block(&mut self, block: Block<'a>) -> &mut Canvas<'a, F> {
pub fn block(mut self, block: Block<'a>) -> Canvas<'a, F> {
self.block = Some(block);
self
}
pub fn x_bounds(&mut self, bounds: [f64; 2]) -> &mut Canvas<'a, F> {
pub fn x_bounds(mut self, bounds: [f64; 2]) -> Canvas<'a, F> {
self.x_bounds = bounds;
self
}
pub fn y_bounds(&mut self, bounds: [f64; 2]) -> &mut Canvas<'a, F> {
pub fn y_bounds(mut self, bounds: [f64; 2]) -> Canvas<'a, F> {
self.y_bounds = bounds;
self
}
/// Store the closure that will be used to draw to the Canvas
pub fn paint(&mut self, f: F) -> &mut Canvas<'a, F> {
pub fn paint(mut self, f: F) -> Canvas<'a, F> {
self.painter = Some(f);
self
}
pub fn background_color(&'a mut self, color: Color) -> &mut Canvas<'a, F> {
pub fn background_color(mut self, color: Color) -> Canvas<'a, F> {
self.background_color = color;
self
}

View file

@ -195,6 +195,7 @@ impl Default for ChartLayout {
/// .style(Style::default().fg(Color::Magenta))
/// .data(&[(4.0, 5.0), (5.0, 8.0), (7.66, 13.5)])]);
/// # }
/// ```
pub struct Chart<'a, LX, LY>
where
LX: AsRef<str> + 'a,
@ -233,27 +234,27 @@ where
LX: AsRef<str>,
LY: AsRef<str>,
{
pub fn block(&'a mut self, block: Block<'a>) -> &mut Chart<'a, LX, LY> {
pub fn block(mut self, block: Block<'a>) -> Chart<'a, LX, LY> {
self.block = Some(block);
self
}
pub fn style(&mut self, style: Style) -> &mut Chart<'a, LX, LY> {
pub fn style(mut self, style: Style) -> Chart<'a, LX, LY> {
self.style = style;
self
}
pub fn x_axis(&mut self, axis: Axis<'a, LX>) -> &mut Chart<'a, LX, LY> {
pub fn x_axis(mut self, axis: Axis<'a, LX>) -> Chart<'a, LX, LY> {
self.x_axis = axis;
self
}
pub fn y_axis(&mut self, axis: Axis<'a, LY>) -> &mut Chart<'a, LX, LY> {
pub fn y_axis(mut self, axis: Axis<'a, LY>) -> Chart<'a, LX, LY> {
self.y_axis = axis;
self
}
pub fn datasets(&mut self, datasets: &'a [Dataset<'a>]) -> &mut Chart<'a, LX, LY> {
pub fn datasets(mut self, datasets: &'a [Dataset<'a>]) -> Chart<'a, LX, LY> {
self.datasets = datasets;
self
}

View file

@ -39,22 +39,22 @@ impl<'a> Default for Gauge<'a> {
}
impl<'a> Gauge<'a> {
pub fn block(&mut self, block: Block<'a>) -> &mut Gauge<'a> {
pub fn block(mut self, block: Block<'a>) -> Gauge<'a> {
self.block = Some(block);
self
}
pub fn percent(&mut self, percent: u16) -> &mut Gauge<'a> {
pub fn percent(mut self, percent: u16) -> Gauge<'a> {
self.percent = percent;
self
}
pub fn label(&mut self, string: &'a str) -> &mut Gauge<'a> {
pub fn label(mut self, string: &'a str) -> Gauge<'a> {
self.label = Some(string);
self
}
pub fn style(&mut self, style: Style) -> &mut Gauge<'a> {
pub fn style(mut self, style: Style) -> Gauge<'a> {
self.style = style;
self
}

View file

@ -51,12 +51,12 @@ where
}
}
pub fn block(&'b mut self, block: Block<'b>) -> &mut List<'b, 'i, L, D> {
pub fn block(mut self, block: Block<'b>) -> List<'b, 'i, L, D> {
self.block = Some(block);
self
}
pub fn items<I>(&'b mut self, items: I) -> &mut List<'b, 'i, L, D>
pub fn items<I>(mut self, items: I) -> List<'b, 'i, L, D>
where
I: IntoIterator<Item = Item<'i, D>, IntoIter = L>,
{
@ -64,12 +64,12 @@ where
self
}
pub fn style(&'b mut self, style: Style) -> &mut List<'b, 'i, L, D> {
pub fn style(mut self, style: Style) -> List<'b, 'i, L, D> {
self.style = style;
self
}
pub fn start_corner(&'b mut self, corner: Corner) -> &mut List<'b, 'i, L, D> {
pub fn start_corner(mut self, corner: Corner) -> List<'b, 'i, L, D> {
self.start_corner = corner;
self
}
@ -171,12 +171,12 @@ impl<'b> Default for SelectableList<'b> {
}
impl<'b> SelectableList<'b> {
pub fn block(&'b mut self, block: Block<'b>) -> &mut SelectableList<'b> {
pub fn block(mut self, block: Block<'b>) -> SelectableList<'b> {
self.block = Some(block);
self
}
pub fn items<I>(&'b mut self, items: &'b [I]) -> &mut SelectableList<'b>
pub fn items<I>(mut self, items: &'b [I]) -> SelectableList<'b>
where
I: AsRef<str> + 'b,
{
@ -184,22 +184,22 @@ impl<'b> SelectableList<'b> {
self
}
pub fn style(&'b mut self, style: Style) -> &mut SelectableList<'b> {
pub fn style(mut self, style: Style) -> SelectableList<'b> {
self.style = style;
self
}
pub fn highlight_symbol(&'b mut self, highlight_symbol: &'b str) -> &mut SelectableList<'b> {
pub fn highlight_symbol(mut self, highlight_symbol: &'b str) -> SelectableList<'b> {
self.highlight_symbol = Some(highlight_symbol);
self
}
pub fn highlight_style(&'b mut self, highlight_style: Style) -> &mut SelectableList<'b> {
pub fn highlight_style(mut self, highlight_style: Style) -> SelectableList<'b> {
self.highlight_style = highlight_style;
self
}
pub fn select(&'b mut self, index: usize) -> &'b mut SelectableList<'b> {
pub fn select(mut self, index: usize) -> SelectableList<'b> {
self.selected = Some(index);
self
}

View file

@ -70,32 +70,32 @@ where
}
}
pub fn block(&'a mut self, block: Block<'a>) -> &mut Paragraph<'a, 't, T> {
pub fn block(mut self, block: Block<'a>) -> Paragraph<'a, 't, T> {
self.block = Some(block);
self
}
pub fn style(&mut self, style: Style) -> &mut Paragraph<'a, 't, T> {
pub fn style(mut self, style: Style) -> Paragraph<'a, 't, T> {
self.style = style;
self
}
pub fn wrap(&mut self, flag: bool) -> &mut Paragraph<'a, 't, T> {
pub fn wrap(mut self, flag: bool) -> Paragraph<'a, 't, T> {
self.wrapping = flag;
self
}
pub fn raw(&mut self, flag: bool) -> &mut Paragraph<'a, 't, T> {
pub fn raw(mut self, flag: bool) -> Paragraph<'a, 't, T> {
self.raw = flag;
self
}
pub fn scroll(&mut self, offset: u16) -> &mut Paragraph<'a, 't, T> {
pub fn scroll(mut self, offset: u16) -> Paragraph<'a, 't, T> {
self.scroll = offset;
self
}
pub fn alignment(&mut self, alignment: Alignment) -> &mut Paragraph<'a, 't, T> {
pub fn alignment(mut self, alignment: Alignment) -> Paragraph<'a, 't, T> {
self.alignment = alignment;
self
}

View file

@ -46,22 +46,22 @@ impl<'a> Default for Sparkline<'a> {
}
impl<'a> Sparkline<'a> {
pub fn block(&mut self, block: Block<'a>) -> &mut Sparkline<'a> {
pub fn block(mut self, block: Block<'a>) -> Sparkline<'a> {
self.block = Some(block);
self
}
pub fn style(&mut self, style: Style) -> &mut Sparkline<'a> {
pub fn style(mut self, style: Style) -> Sparkline<'a> {
self.style = style;
self
}
pub fn data(&mut self, data: &'a [u64]) -> &mut Sparkline<'a> {
pub fn data(mut self, data: &'a [u64]) -> Sparkline<'a> {
self.data = data;
self
}
pub fn max(&mut self, max: u64) -> &mut Sparkline<'a> {
pub fn max(mut self, max: u64) -> Sparkline<'a> {
self.max = Some(max);
self
}

View file

@ -106,12 +106,12 @@ where
column_spacing: 1,
}
}
pub fn block(&'a mut self, block: Block<'a>) -> &mut Table<'a, 'i, T, H, I, D, R> {
pub fn block(mut self, block: Block<'a>) -> Table<'a, 'i, T, H, I, D, R> {
self.block = Some(block);
self
}
pub fn header<II>(&mut self, header: II) -> &mut Table<'a, 'i, T, H, I, D, R>
pub fn header<II>(mut self, header: II) -> Table<'a, 'i, T, H, I, D, R>
where
II: IntoIterator<Item = T, IntoIter = H>,
{
@ -119,17 +119,17 @@ where
self
}
pub fn header_style(&mut self, style: Style) -> &mut Table<'a, 'i, T, H, I, D, R> {
pub fn header_style(mut self, style: Style) -> Table<'a, 'i, T, H, I, D, R> {
self.header_style = style;
self
}
pub fn widths(&mut self, widths: &'a [u16]) -> &mut Table<'a, 'i, T, H, I, D, R> {
pub fn widths(mut self, widths: &'a [u16]) -> Table<'a, 'i, T, H, I, D, R> {
self.widths = widths;
self
}
pub fn rows<II>(&mut self, rows: II) -> &mut Table<'a, 'i, T, H, I, D, R>
pub fn rows<II>(mut self, rows: II) -> Table<'a, 'i, T, H, I, D, R>
where
II: IntoIterator<Item = Row<'i, D, I>, IntoIter = R>,
{
@ -137,12 +137,12 @@ where
self
}
pub fn style(&mut self, style: Style) -> &mut Table<'a, 'i, T, H, I, D, R> {
pub fn style(mut self, style: Style) -> Table<'a, 'i, T, H, I, D, R> {
self.style = style;
self
}
pub fn column_spacing(&mut self, spacing: u16) -> &mut Table<'a, 'i, T, H, I, D, R> {
pub fn column_spacing(mut self, spacing: u16) -> Table<'a, 'i, T, H, I, D, R> {
self.column_spacing = spacing;
self
}

View file

@ -57,27 +57,27 @@ impl<'a, T> Tabs<'a, T>
where
T: AsRef<str>,
{
pub fn block(&mut self, block: Block<'a>) -> &mut Tabs<'a, T> {
pub fn block(mut self, block: Block<'a>) -> Tabs<'a, T> {
self.block = Some(block);
self
}
pub fn titles(&mut self, titles: &'a [T]) -> &mut Tabs<'a, T> {
pub fn titles(mut self, titles: &'a [T]) -> Tabs<'a, T> {
self.titles = titles;
self
}
pub fn select(&mut self, selected: usize) -> &mut Tabs<'a, T> {
pub fn select(mut self, selected: usize) -> Tabs<'a, T> {
self.selected = selected;
self
}
pub fn style(&mut self, style: Style) -> &mut Tabs<'a, T> {
pub fn style(mut self, style: Style) -> Tabs<'a, T> {
self.style = style;
self
}
pub fn highlight_style(&mut self, style: Style) -> &mut Tabs<'a, T> {
pub fn highlight_style(mut self, style: Style) -> Tabs<'a, T> {
self.highlight_style = style;
self
}