pub struct Block<W = Element> { /* private fields */ }Expand description
A widget that wrap another widget and adds border and title. A widget that wraps another widget and adds border and title.
Block is typically used to visualize separation and organize sections.
You can customize the border style, type of the border and so on.
§Example
let mut main = Block::horizontal()
.title("Termint".fg(Color::Red))
.border_type(BorderType::Double)
.border_color(Color::LightGray);
let block1 = Block::vertical().title("Sub block");
main.add_child(block1, Constraint::Percent(50));
let block2 = Block::vertical().title("Another");
main.add_child(block2, Constraint::Percent(50));
let mut term = Term::new();
term.render(main)?;Implementations§
Source§impl<W> Block<W>where
W: Widget,
impl<W> Block<W>where
W: Widget,
Sourcepub fn border_type(self, border_type: BorderType) -> Self
pub fn border_type(self, border_type: BorderType) -> Self
Sets the BorderType used to render the Block border.
Sourcepub fn border_style<T>(self, style: T) -> Self
pub fn border_style<T>(self, style: T) -> Self
Sets the style applied to Block borders.
Sourcepub fn border_color(self, color: Color) -> Self
pub fn border_color(self, color: Color) -> Self
Sets the foreground color of the Block borders.
Source§impl Block<Layout>
impl Block<Layout>
Sourcepub fn vertical() -> Self
pub fn vertical() -> Self
Returns a Block containing a vertical Layout as its child.
Very often you want to have a layout inside of a Block widget. This
constructor makes it easier.
§Example
// Creates block with vertical layout as its child
let block1: Block<Layout> = Block::new(Layout::vertical());
// Does the same, but shorter
let block2: Block<Layout> = Block::vertical();Sourcepub fn horizontal() -> Self
pub fn horizontal() -> Self
Returns a Block containing a horizontal Layout as its child.
Very often you want to have a layout inside of a Block widget. This
constructor makes it easier.
§Example
// Creates block with horizontal layout as its child
let block1: Block<Layout> = Block::new(Layout::horizontal());
// Does the same, but shorter
let block2: Block<Layout> = Block::horizontal();Sourcepub fn center(self) -> Self
pub fn center(self) -> Self
Makes Layout center its content in the direction it flexes.
If the layout is flexing its children horizontally, the content will be centered horizontally. Otherwise it will be centered vertically.
Sourcepub fn add_child<T, C>(&mut self, child: T, constraint: C)
👎Deprecated since 0.6.0: Kept for compatibility purposes; use push function instead
pub fn add_child<T, C>(&mut self, child: T, constraint: C)
push function insteadAdds child with its Constraint to Layout
Sourcepub fn push<T, C>(&mut self, child: T, constraint: C)
pub fn push<T, C>(&mut self, child: T, constraint: C)
Adds a child widget with its contraint
§Parameters
child: The widget to add (any type convertible toElement)contraint: Widget’s contraint (any type convertible toConstraint)
Trait Implementations§
Source§impl<W> Widget for Block<W>where
W: Widget,
impl<W> Widget for Block<W>where
W: Widget,
Source§fn height(&self, size: &Vec2) -> usize
fn height(&self, size: &Vec2) -> usize
Widget based on the width of the given
size.