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
impl Padding
Sourcepub fn new(
renderable: Box<dyn Renderable + Send + Sync>,
pad: impl Into<PaddingDimensions>,
) -> Self
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));Sourcepub fn indent(
renderable: Box<dyn Renderable + Send + Sync>,
level: usize,
) -> Self
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);Sourcepub fn unpack(pad: impl Into<PaddingDimensions>) -> (usize, usize, usize, usize)
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));Sourcepub fn with_style(self, style: Style) -> Self
pub fn with_style(self, style: Style) -> Self
Sourcepub fn with_expand(self, expand: bool) -> Self
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.
Trait Implementations§
Source§impl Renderable for Padding
impl Renderable for Padding
Source§fn render(
&self,
console: &Console<Stdout>,
options: &ConsoleOptions,
) -> Segments
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
fn measure( &self, console: &Console<Stdout>, options: &ConsoleOptions, ) -> Measurement
Measure the minimum and maximum width requirements. Read more
Auto Trait Implementations§
impl Freeze for Padding
impl !RefUnwindSafe for Padding
impl Send for Padding
impl Sync for Padding
impl Unpin for Padding
impl !UnwindSafe for Padding
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more