pub struct Block { /* private fields */ }Expand description
Represents a block, i.e. a rectangle, of some width and height containing text.
The key feature of a Block is that it enables you to easily specify how chunks of text should be positioned in relation to other block, by joining blocks together, either vertically or horizontally, and using paddings and fills.
Implementations§
Source§impl Block
impl Block
Sourcepub fn of<T: ToString>(t: T) -> Self
pub fn of<T: ToString>(t: T) -> Self
Creates block of any argument implementing std::string::ToString
trait, or implicitly by implementing std::fmt::Display. Uses
String representation in block. See Block::of_string.
Sourcepub fn of_text(text: &str) -> Self
👎Deprecated since 1.2.0: please use Block::of instead
pub fn of_text(text: &str) -> Self
Block::of insteadCreate block containing given text. Gets width of the text and height 1.
Sourcepub fn add_text(&self, text: &str) -> Self
pub fn add_text(&self, text: &str) -> Self
Add given text at bottom of block, incementing the height. Width of block will be increased if needed for added line to fit.
Sourcepub fn add_multiple_texts(&self, texts: &[String]) -> Self
pub fn add_multiple_texts(&self, texts: &[String]) -> Self
Add given text lines at bottom of block, incrementing the height accordingly. Width of block will be increades if needed.
Sourcepub fn fill_right(&self, width: usize, filler: char) -> Self
pub fn fill_right(&self, width: usize, filler: char) -> Self
Fill right side of block with given number of the filler character.
Sourcepub fn fill_bottom(&self, height: usize, filler: char) -> Self
pub fn fill_bottom(&self, height: usize, filler: char) -> Self
Fill bottom side of block with given number of the filler character.
Sourcepub fn pad_right(&self, width: usize) -> Self
pub fn pad_right(&self, width: usize) -> Self
Pad right side of block with given number of spaces.
Sourcepub fn pad_left(&self, width: usize) -> Self
pub fn pad_left(&self, width: usize) -> Self
Pad left side of block with given number of spaces.
pub fn pad_top(&self, height: usize) -> Self
Sourcepub fn pad_bottom(&self, height: usize) -> Self
pub fn pad_bottom(&self, height: usize) -> Self
Pad bottom side of block with given number of empty lines.
Sourcepub fn pad_to_width_right(&self, width: usize) -> Self
pub fn pad_to_width_right(&self, width: usize) -> Self
Pad right so given width is reached. Wider block is untouched.
Sourcepub fn pad_to_width_left(&self, width: usize) -> Self
pub fn pad_to_width_left(&self, width: usize) -> Self
Pad left so given width is reached. Wider block is untouched.
Sourcepub fn pad_to_width_center_right(&self, width: usize) -> Self
pub fn pad_to_width_center_right(&self, width: usize) -> Self
Pad both sides so given width is reached. Wider block is untouched. If padding needs to be uneven, there will be more padding on the right side.
Sourcepub fn pad_to_width_center_left(&self, width: usize) -> Self
pub fn pad_to_width_center_left(&self, width: usize) -> Self
Pad both sides so given width is reached. Wider block is untouched. If padding needs to be uneven, there will be more padding on the left side.
Sourcepub fn pad_to_height_top(&self, height: usize) -> Self
pub fn pad_to_height_top(&self, height: usize) -> Self
Pad top so given height is reached. Higher block is untouched.
Sourcepub fn pad_to_height_bottom(&self, height: usize) -> Self
pub fn pad_to_height_bottom(&self, height: usize) -> Self
Pad bottom so given height is reached. Higher block is untouched.
Sourcepub fn pad_to_height_center_top(&self, height: usize) -> Self
pub fn pad_to_height_center_top(&self, height: usize) -> Self
Pad both top and bottom so given height is reached. Higher block is untouched. If padding needs to be uneven, there will be more padding on the top side.
Sourcepub fn pad_to_height_center_bottom(&self, height: usize) -> Self
pub fn pad_to_height_center_bottom(&self, height: usize) -> Self
Pad both top and bottom so given height is reached. Higher block is untouched. If padding needs to be uneven, there will be more padding on the bottom side.
Sourcepub fn beside_top(&self, right: &Block) -> Self
pub fn beside_top(&self, right: &Block) -> Self
Join two blocks horizontally, self to the left and the given block to the right, aligning the top side of the blocks.
Sourcepub fn beside_bottom(&self, right: &Block) -> Self
pub fn beside_bottom(&self, right: &Block) -> Self
Join two blocks horizontally, self to the left and the given block to the right, aligning the bottom side of the blocks.
Sourcepub fn beside_center_bottom(&self, right: &Block) -> Self
pub fn beside_center_bottom(&self, right: &Block) -> Self
Join two blocks horizontally, self to the left and the given block to the right, aligning the center of the blocks. If padding needs to be uneven, there will be more padding on the top side.
Sourcepub fn beside_center_top(&self, right: &Block) -> Self
pub fn beside_center_top(&self, right: &Block) -> Self
Join two blocks horizontally, self to the left and the given block to the right, aligning the center of the blocks. If padding needs to be uneven, there will be more padding on the bottom side.
Sourcepub fn stack_right(&self, bottom: &Block) -> Self
pub fn stack_right(&self, bottom: &Block) -> Self
Join two blocks vertically, self on the top and the given block on the bottom, aligning the right side of the blocks.
Sourcepub fn stack_left(&self, bottom: &Block) -> Self
pub fn stack_left(&self, bottom: &Block) -> Self
Join two blocks vertically, self on the top and the given block on the bottom, aligning the left side of the blocks.
Sourcepub fn stack_center_left(&self, bottom: &Block) -> Self
pub fn stack_center_left(&self, bottom: &Block) -> Self
Join two blocks vertically, self on the top and the given block on the bottom, aligning the center of the blocks. If padding needs to be uneven, there will be more padding on the right side.
Sourcepub fn stack_center_right(&self, bottom: &Block) -> Self
pub fn stack_center_right(&self, bottom: &Block) -> Self
Join two blocks vertically, self on the top and the given block on the bottom, aligning the center of the blocks. If padding needs to be uneven, there will be more padding on the left side.
Sourcepub fn in_front_of(&self, behind: &Block) -> Self
pub fn in_front_of(&self, behind: &Block) -> Self
Overlays self in front of given block. Treats spaces as transparent characters.
Sourcepub fn in_front_of_with_transparency(
&self,
behind: &Block,
transparency: char,
) -> Self
pub fn in_front_of_with_transparency( &self, behind: &Block, transparency: char, ) -> Self
Overlays self in front of given block, showing content of the block behind on the characters defined as transparent.