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 horizontalFields§
§top: usizePadding at the top
down: usizePadding at the bottom
left: usizePadding on the left side
right: usizePadding on the right side
Implementations§
Source§impl BoxPad
impl BoxPad
Sourcepub fn new() -> Self
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 }Sourcepub fn from_tldr(top: usize, left: usize, down: usize, right: usize) -> Self
pub fn from_tldr(top: usize, left: usize, down: usize, right: usize) -> Self
Creates a new BoxPad with specific values for each side.
§Argument order
The parameter order follows the mnemonic tldr: top, left, down, right.
Note this is not the CSS order (top/right/bottom/left) — left and right are swapped
relative to what you might expect. When in doubt, use vh for symmetric
padding or name the fields directly.
§Arguments
top- Padding above the contentleft- Padding to the left of the contentdown- Padding below the contentright- Padding to the right of the content
§Examples
use boxy_cli::prelude::*;
let padding = BoxPad::from_tldr(1, 4, 1, 4); // 1 line top/bottom, 4 chars left/right
assert_eq!(padding.top, 1);
assert_eq!(padding.left, 4);
assert_eq!(padding.down, 1);
assert_eq!(padding.right, 4);Sourcepub fn uniform(pad: usize) -> Self
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 }Sourcepub fn vh(vertical: usize, horizontal: usize) -> Self
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 bottomhorizontal- 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 }