Block

Struct Block 

Source
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

Source

pub fn empty() -> Self

Create empty block with width and height zero.

Source

pub fn of_width(width: usize) -> Self

Create block of given width and height 0.

Source

pub fn of_height(height: usize) -> Self

Create block of given height and width 0.

Source

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.

Source

pub fn of_text(text: &str) -> Self

👎Deprecated since 1.2.0: please use Block::of instead

Create block containing given text. Gets width of the text and height 1.

Source

pub fn height(&self) -> usize

Return height of block.

Source

pub fn width(&self) -> usize

Return width of block.

Source

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.

Source

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.

Source

pub fn fill_right(&self, width: usize, filler: char) -> Self

Fill right side of block with given number of the filler character.

Source

pub fn fill_bottom(&self, height: usize, filler: char) -> Self

Fill bottom side of block with given number of the filler character.

Source

pub fn pad_right(&self, width: usize) -> Self

Pad right side of block with given number of spaces.

Source

pub fn pad_left(&self, width: usize) -> Self

Pad left side of block with given number of spaces.

Source

pub fn pad_top(&self, height: usize) -> Self

Source

pub fn pad_bottom(&self, height: usize) -> Self

Pad bottom side of block with given number of empty lines.

Source

pub fn pad_to_width_right(&self, width: usize) -> Self

Pad right so given width is reached. Wider block is untouched.

Source

pub fn pad_to_width_left(&self, width: usize) -> Self

Pad left so given width is reached. Wider block is untouched.

Source

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.

Source

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.

Source

pub fn pad_to_height_top(&self, height: usize) -> Self

Pad top so given height is reached. Higher block is untouched.

Source

pub fn pad_to_height_bottom(&self, height: usize) -> Self

Pad bottom so given height is reached. Higher block is untouched.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn in_front_of(&self, behind: &Block) -> Self

Overlays self in front of given block. Treats spaces as transparent characters.

Source

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.

Source

pub fn render(&self) -> String

Render a string from a block using ‘\n’ as separator between lines. Trims away whitespace on the right side of each line, just to save on final string length.

Trait Implementations§

Source§

impl Clone for Block

Source§

fn clone(&self) -> Block

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Block

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Block

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&str> for Block

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Block

Source§

fn from(text: String) -> Self

Converts to this type from the input type.
Source§

impl From<char> for Block

Source§

fn from(c: char) -> Self

Converts to this type from the input type.
Source§

impl Hash for Block

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Block

Source§

fn eq(&self, other: &Block) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Block

Source§

impl StructuralPartialEq for Block

Auto Trait Implementations§

§

impl Freeze for Block

§

impl RefUnwindSafe for Block

§

impl Send for Block

§

impl Sync for Block

§

impl Unpin for Block

§

impl UnwindSafe for Block

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.