Documentation

pull/3/head
Florian Dehau 8 years ago
parent e00639fab1
commit fcac19d6c5

@ -2,8 +2,13 @@ build:
cargo build
test:
cargo test
doc:
cargo doc
watch:
watchman-make -p 'src/**/*.rs' -t build -p 'test/**/*.rs' -t test
watch-test:
watchman-make -p 'src/**/*.rs' 'tests/**/*.rs' -t test
watch-doc:
watchman-make -p 'src/**/*.rs' -t doc

@ -4,13 +4,36 @@ use style::Color;
use widgets::{Widget, border};
use symbols::line;
/// Base widget to be used with all upper level ones. It may be used to display a box border around
/// the widget and/or add a title.
///
/// # Examples
///
/// ```
/// # extern crate tui;
/// # use tui::widgets::{Block, border};
/// # use tui::style::Color;
/// # fn main() {
/// Block::default()
/// .title("Block")
/// .title_color(Color::Red)
/// .borders(border::LEFT | border::RIGHT)
/// .border_color(Color::White)
/// .background_color(Color::Black);
/// # }
/// ```
#[derive(Clone, Copy)]
pub struct Block<'a> {
pub title: Option<&'a str>,
pub title_color: Color,
pub borders: border::Flags,
pub border_color: Color,
pub background_color: Color,
/// Optional title place on the upper left of the block
title: Option<&'a str>,
/// Title color
title_color: Color,
/// Visible borders
borders: border::Flags,
/// Borders color
border_color: Color,
/// Background color
background_color: Color,
}
impl<'a> Default for Block<'a> {
@ -51,6 +74,7 @@ impl<'a> Block<'a> {
self
}
/// Compute the inner area of a block based on its border visibility rules.
pub fn inner(&self, area: &Rect) -> Rect {
if area.width < 2 || area.height < 2 {
return Rect::default();

@ -3,7 +3,7 @@ use std::cmp::max;
use unicode_width::UnicodeWidthStr;
use widgets::{Widget, Block, border};
use widgets::canvas::{Canvas, Shape, Points};
use widgets::canvas::{Canvas, Points};
use buffer::Buffer;
use layout::Rect;
use style::Color;
@ -388,11 +388,12 @@ impl<'a> Widget for Chart<'a> {
.background_color(self.background_color)
.x_bounds(self.x_axis.bounds)
.y_bounds(self.y_axis.bounds)
.layer([&Points {
coords: dataset.data,
color: dataset.color,
} as &Shape]
.as_ref())
.paint(|ctx| {
ctx.draw(&Points {
coords: dataset.data,
color: dataset.color,
});
})
.draw(&graph_area, buf);
}
}

@ -6,12 +6,35 @@ use layout::Rect;
use style::Color;
use symbols::line;
/// A widget to display available tabs in a multiple panels context.
///
/// # Examples
///
/// ```
/// # extern crate tui;
/// # use tui::widgets::{Block, border, Tabs};
/// # use tui::style::Color;
/// # fn main() {
/// Tabs::default()
/// .block(Block::default().title("Tabs").borders(border::ALL))
/// .titles(&["Tab1", "Tab2", "Tab3", "Tab4"])
/// .color(Color::White)
/// .highlight_color(Color::Yellow)
/// .background_color(Color::Black);
/// # }
/// ```
pub struct Tabs<'a> {
/// A block to wrap this widget in if necessary
block: Option<Block<'a>>,
/// One title for each tab
titles: &'a [&'a str],
/// The index of the selected tabs
selected: usize,
/// The color used to draw the text
color: Color,
/// The background color of this widget
background_color: Color,
/// The color used to display the selected item
highlight_color: Color,
}

@ -1,17 +1,40 @@
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use widgets::{Widget, Block};
use buffer::Buffer;
use layout::Rect;
use style::Color;
/// A widget to display some text. You can specify colors using commands embedded in
/// the text such as "{[color] [text]}".
///
/// # Examples
///
/// ```
/// # extern crate tui;
/// # use tui::widgets::{Block, border, Text};
/// # use tui::style::Color;
/// # fn main() {
/// Text::default()
/// .block(Block::default().title("Text").borders(border::ALL))
/// .color(Color::White)
/// .background_color(Color::Black)
/// .wrap(true)
/// .text("First line\nSecond line\n{red Colored text}.");
/// # }
/// ```
pub struct Text<'a> {
/// A block to wrap the widget in
block: Option<Block<'a>>,
/// The base color used to render the text
color: Color,
/// Background color of the widget
background_color: Color,
/// Wrap the text or not
wrapping: bool,
/// The text to display
text: &'a str,
colors: &'a [(u16, u16, u16, Color, Color)],
}
impl<'a> Default for Text<'a> {
@ -22,7 +45,6 @@ impl<'a> Default for Text<'a> {
background_color: Color::Reset,
wrapping: false,
text: "",
colors: &[],
}
}
}
@ -48,11 +70,6 @@ impl<'a> Text<'a> {
self
}
pub fn colors(&mut self, colors: &'a [(u16, u16, u16, Color, Color)]) -> &mut Text<'a> {
self.colors = colors;
self
}
pub fn wrap(&mut self, flag: bool) -> &mut Text<'a> {
self.wrapping = flag;
self

Loading…
Cancel
Save