label
Styled text label with optional right-padding for column alignment.
struct Component
pub struct ComponentA styled text label, typically used as the key in a key-value display.
Call pad_to to right-pad with spaces for column alignment.
| Field | Type | Description |
|---|---|---|
pad_to |
usize | Minimum width in bytes of text, filled with trailing spaces; 0 means no padding. |
style |
Style | Style painted over the text but not the padding. |
text |
String | Label text, never truncated. |
Implements Display.
Component::new
pub fn new(text: impl Into<String>, style: Style) -> SelfCreate a label with the given text and style, initially unpadded.
| Parameter | Type | Description |
|---|---|---|
text |
impl Into<String> | the label text |
style |
Style | the style to paint it in |
| returns | Self | The unpadded label. |
Component::pad_to
pub fn pad_to(self, width: usize) -> SelfRight-pad with spaces so the label occupies at least width bytes of text.
| Parameter | Type | Description |
|---|---|---|
width |
usize | the minimum width; the padding counts bytes, so it falls short for non-ASCII text |
| returns | Self | The label with the padding set. |