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::color::Style;
use retroglyph_core::grid::Pos;
use retroglyph_ui::{BoxStyle, Sides};
let grid = BoxStyle::new(Style::new())
.border(true)
.padding(Sides::all(1))
.render("hi");
assert_eq!(grid[Pos::new(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 retroglyph_core::text), so a
wide (2-column) character correctly pushes later characters on the
same line over by 2 columns rather than 1, and gets a proper
WIDE_CHAR_SPACER reservation on the cell to its right, courtesy of
retroglyph_core::grid::Grid::put_tile (wide-char aware on every feature
combination, not just egc; this module still does not depend on it).
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BoxStyle
impl RefUnwindSafe for BoxStyle
impl Send for BoxStyle
impl Sync for BoxStyle
impl Unpin for BoxStyle
impl UnsafeUnpin for BoxStyle
impl UnwindSafe for BoxStyle
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).