Skip to main content

Padding

Struct Padding 

Source
pub struct Padding { /* private fields */ }
Expand description

Draw space around content.

Padding wraps a renderable and adds blank space around it, similar to CSS padding.

§Example

use rich_rs::{Padding, Text, Style, SimpleColor};

let text = Text::plain("Hello, World!");
// Create padding with 2 lines top/bottom, 4 spaces left/right
let padded = Padding::new(Box::new(text), (2, 4))
    .with_style(Style::new().with_bgcolor(SimpleColor::Standard(4)));

Implementations§

Source§

impl Padding

Source

pub fn new( renderable: Box<dyn Renderable + Send + Sync>, pad: impl Into<PaddingDimensions>, ) -> Self

Create a new Padding wrapper.

§Arguments
  • renderable - The content to wrap.
  • pad - Padding dimensions (CSS-style: 1, 2, or 4 values).
§Example
use rich_rs::{Padding, Text};

let text = Text::plain("Hello");
// Single value: all sides same
let p1 = Padding::new(Box::new(text.clone()), 2);
// Two values: (vertical, horizontal)
let p2 = Padding::new(Box::new(text.clone()), (1, 4));
// Four values: (top, right, bottom, left)
let p3 = Padding::new(Box::new(text), (1, 2, 3, 4));
Source

pub fn indent( renderable: Box<dyn Renderable + Send + Sync>, level: usize, ) -> Self

Create a Padding that indents content (left padding only).

This is a convenience method for creating left-only indentation. The expand flag is set to false.

§Arguments
  • renderable - The content to indent.
  • level - Number of spaces to indent.
§Example
use rich_rs::{Padding, Text};

let text = Text::plain("Indented text");
let indented = Padding::indent(Box::new(text), 4);
Source

pub fn unpack(pad: impl Into<PaddingDimensions>) -> (usize, usize, usize, usize)

Unpack padding dimensions to (top, right, bottom, left).

This is the CSS-style unpacking function that can be used independently of creating a Padding struct.

§Example
use rich_rs::Padding;

// Single value
assert_eq!(Padding::unpack(2), (2, 2, 2, 2));
// Two values
assert_eq!(Padding::unpack((1, 4)), (1, 4, 1, 4));
// Four values
assert_eq!(Padding::unpack((1, 2, 3, 4)), (1, 2, 3, 4));
Source

pub fn with_style(self, style: Style) -> Self

Set the style for padding characters.

§Arguments
  • style - Style to apply to padding spaces.
Source

pub fn with_expand(self, expand: bool) -> Self

Set whether to expand to fill available width.

When true (default), the padding expands to fill max_width. When false, the width is based on the inner content’s measurement.

§Arguments
  • expand - Whether to expand to fill width.
Source

pub fn top(&self) -> usize

Get the top padding.

Source

pub fn right(&self) -> usize

Get the right padding.

Source

pub fn bottom(&self) -> usize

Get the bottom padding.

Source

pub fn left(&self) -> usize

Get the left padding.

Source

pub fn style(&self) -> Style

Get the style.

Source

pub fn expand(&self) -> bool

Get whether expand is enabled.

Trait Implementations§

Source§

impl Debug for Padding

Source§

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

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

impl Renderable for Padding

Source§

fn render( &self, console: &Console<Stdout>, options: &ConsoleOptions, ) -> Segments

Render this object to a sequence of segments.
Source§

fn measure( &self, console: &Console<Stdout>, options: &ConsoleOptions, ) -> Measurement

Measure the minimum and maximum width requirements. Read more

Auto Trait Implementations§

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.