pub struct BoxStyle { /* private fields */ }Expand description
A box-model wrapper: content, padding, an optional single-line border,
and margin, rendered into a standalone Grid via BoxStyle::render.
Layers from the inside out: content -> padding -> border -> margin.
Margin cells are left empty (transparent, per Grid::new’s default
tiles), matching CSS margin being outside the box’s own background.
§Examples
use retroglyph_core::Style;
use retroglyph_widgets::{BoxStyle, Sides};
let grid = BoxStyle::new(Style::new())
.border(true)
.padding(Sides::all(1))
.render("hi");
assert_eq!(grid.get(2, 2).glyph(), 'h'); // 1 border + 1 padding cell in from the cornerImplementations§
Source§impl BoxStyle
impl BoxStyle
Sourcepub const fn new(style: Style) -> Self
pub const fn new(style: Style) -> Self
A borderless box with no padding/margin, in style, sized to fit its
content.
Sourcepub const fn padding(self, padding: Sides) -> Self
pub const fn padding(self, padding: Sides) -> Self
Sets the padding, between the border (if any) and the content.
Sourcepub const fn margin(self, margin: Sides) -> Self
pub const fn margin(self, margin: Sides) -> Self
Sets the margin, outside the border (if any); left transparent.
Sourcepub const fn border(self, border: bool) -> Self
pub const fn border(self, border: bool) -> Self
Draws a single-line border, in style, around the padding.
Sourcepub const fn width(self, width: u16) -> Self
pub const fn width(self, width: u16) -> Self
Sets an explicit content width (excludes padding/border/margin).
Lines wider than this are clipped; without this, the box sizes to its widest content line.
Sourcepub const fn height(self, height: u16) -> Self
pub const fn height(self, height: u16) -> Self
Sets an explicit content height (excludes padding/border/margin).
Lines past this are dropped; without this, the box sizes to the number of lines in the content.
Sourcepub fn render(&self, text: &str) -> Grid
pub fn render(&self, text: &str) -> Grid
Renders text into a standalone Grid: content, padding, border,
and margin, in that order from the inside out.
text is split only on '\n'; it is not word-wrapped (see the
module docs).
Content is positioned by display column (via unicode-width), so a
wide (2-column) character correctly pushes later characters on the
same line over by 2 columns rather than 1. It is, however, written
without a WIDE_CHAR_SPACER reservation on the cell to its right (see
retroglyph_core::Grid::write_grapheme, which requires the egc
feature this module deliberately does not depend on) – terminal-
rendering backends may misalign output by one column per wide
character as a result. Fully correct wide-character rendering needs
an egc-gated code path; not yet implemented here.
Sourcepub fn render_wrapped(&self, text: &str) -> Grid
pub fn render_wrapped(&self, text: &str) -> Grid
Word-wraps text to this box’s content width, then renders it the
same way as render: content, padding, border, and
margin, from the inside out.
Requires the egc feature: wrapping is delegated to
retroglyph_core::layout::TextLayout, which (unlike render) also
places wide characters correctly, with a proper WIDE_CHAR_SPACER.
If no explicit width was set via BoxStyle::width, text is
measured but not wrapped (there is no width to wrap to), matching
render’s own natural-width fallback.