pub struct Align { /* private fields */ }Expand description
Align a renderable by adding spaces.
Align wraps a renderable and positions it within the available space by adding padding. Supports both horizontal (left, center, right) and vertical (top, middle, bottom) alignment.
§Example
use rich_rs::{Align, Text, Style};
use rich_rs::align::VerticalAlignMethod;
// Simple center alignment
let text = Text::plain("Centered");
let aligned = Align::center(Box::new(text));
// Right-aligned with background style
let text = Text::plain("Right");
let aligned = Align::right(Box::new(text))
.with_style(Style::new().with_bold(true));
// Full alignment with vertical centering
let text = Text::plain("Middle");
let aligned = Align::center(Box::new(text))
.with_vertical(VerticalAlignMethod::Middle)
.with_height(10);Implementations§
Source§impl Align
impl Align
Sourcepub fn new(
renderable: Box<dyn Renderable + Send + Sync>,
align: AlignMethod,
) -> Self
pub fn new( renderable: Box<dyn Renderable + Send + Sync>, align: AlignMethod, ) -> Self
Sourcepub fn left(renderable: Box<dyn Renderable + Send + Sync>) -> Self
pub fn left(renderable: Box<dyn Renderable + Send + Sync>) -> Self
Create a left-aligned wrapper.
§Example
use rich_rs::{Align, Text};
let text = Text::plain("Left-aligned");
let aligned = Align::left(Box::new(text));Sourcepub fn center(renderable: Box<dyn Renderable + Send + Sync>) -> Self
pub fn center(renderable: Box<dyn Renderable + Send + Sync>) -> Self
Create a center-aligned wrapper.
§Example
use rich_rs::{Align, Text};
let text = Text::plain("Centered");
let aligned = Align::center(Box::new(text));Sourcepub fn right(renderable: Box<dyn Renderable + Send + Sync>) -> Self
pub fn right(renderable: Box<dyn Renderable + Send + Sync>) -> Self
Create a right-aligned wrapper.
§Example
use rich_rs::{Align, Text};
let text = Text::plain("Right-aligned");
let aligned = Align::right(Box::new(text));Sourcepub fn with_style(self, style: Style) -> Self
pub fn with_style(self, style: Style) -> Self
Set the style for padding spaces.
The style is applied to the padding characters (spaces) used for alignment. This is useful for setting a background color on the aligned area.
Sourcepub fn with_vertical(self, vertical: VerticalAlignMethod) -> Self
pub fn with_vertical(self, vertical: VerticalAlignMethod) -> Self
Set the vertical alignment.
Vertical alignment requires a height to be set (either via with_height()
or from ConsoleOptions::height).
Sourcepub fn with_pad(self, pad: bool) -> Self
pub fn with_pad(self, pad: bool) -> Self
Set whether to pad the right side.
When true (default), padding is added to the right to fill the width.
When false, only left padding is added for center/right alignment.
Sourcepub fn with_width(self, width: usize) -> Self
pub fn with_width(self, width: usize) -> Self
Set a fixed width constraint.
The content will be constrained to this width. If not set, uses
ConsoleOptions::max_width.
Sourcepub fn with_height(self, height: usize) -> Self
pub fn with_height(self, height: usize) -> Self
Set a fixed height constraint.
Required for vertical alignment. If not set but vertical alignment is
specified, falls back to ConsoleOptions::height.
Sourcepub fn align(&self) -> AlignMethod
pub fn align(&self) -> AlignMethod
Get the horizontal alignment.
Sourcepub fn vertical(&self) -> Option<VerticalAlignMethod>
pub fn vertical(&self) -> Option<VerticalAlignMethod>
Get the vertical alignment.