BoxPad

Struct BoxPad 

Source
pub struct BoxPad {
    pub top: usize,
    pub down: usize,
    pub left: usize,
    pub right: usize,
}
Expand description

Represents padding values for the text box in all four directions.

BoxPad is used to specify padding between:

  • The box border and the contained text (internal padding)
  • The terminal edges and the box itself (external padding)

§Examples

use boxy_cli::prelude::*;

// Create uniform padding of 2 spaces on all sides
let uniform_padding = BoxPad::uniform(2);

// Create custom padding for each side
let custom_padding = BoxPad::from_tldr(1, 3, 1, 3); // top, left, down, right

// Create horizontal/vertical padding
let h_v_padding = BoxPad::vh(1, 3); // 1 vertical, 3 horizontal

Fields§

§top: usize

Padding at the top

§down: usize

Padding at the bottom

§left: usize

Padding on the left side

§right: usize

Padding on the right side

Implementations§

Source§

impl BoxPad

Source

pub fn new() -> Self

Creates a new BoxPad instance with zero padding on all sides.

§Examples
use boxy_cli::prelude::*;

let padding = BoxPad::new();
// Equivalent to BoxPad { top: 0, down: 0, left: 0, right: 0 }
Source

pub fn from_tldr(top: usize, left: usize, down: usize, right: usize) -> Self

Creates a new BoxPad with specific values for each side.

The parameter order follows the mnemonic “tldr” (top, left, down, right).

§Arguments
  • top - Padding at the top
  • left - Padding on the left side
  • down - Padding at the bottom
  • right - Padding on the right side
§Examples
use boxy_cli::prelude::*;

// Create padding with different values on each side
let padding = BoxPad::from_tldr(2, 4, 2, 4);
// top: 2, left: 4, down: 2, right: 4
Source

pub fn uniform(pad: usize) -> Self

Creates a new BoxPad with the same padding value on all sides.

§Arguments
  • pad - The padding value to use for all sides
§Examples
use boxy_cli::prelude::*;

// Create uniform padding of 3 spaces on all sides
let padding = BoxPad::uniform(3);
// Equivalent to BoxPad { top: 3, down: 3, left: 3, right: 3 }
Source

pub fn vh(vertical: usize, horizontal: usize) -> Self

Creates a new BoxPad with separate values for vertical and horizontal padding.

This is a convenience method that applies the same padding to top/bottom and left/right sides.

§Arguments
  • vertical - Padding for top and bottom
  • horizontal - Padding for left and right
§Examples
use boxy_cli::prelude::*;

// Create padding with 1 space vertically and 3 spaces horizontally
let padding = BoxPad::vh(1, 3);
// Equivalent to BoxPad { top: 1, down: 1, left: 3, right: 3 }
Source

pub fn lr(&self) -> usize

returns the total padidng on either side. used for text wrapping and display time calculations

Trait Implementations§

Source§

impl Debug for BoxPad

Source§

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

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

impl Default for BoxPad

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for BoxPad

§

impl RefUnwindSafe for BoxPad

§

impl Send for BoxPad

§

impl Sync for BoxPad

§

impl Unpin for BoxPad

§

impl UnwindSafe for BoxPad

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> 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, 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.