Skip to main content

BoxStyle

Struct BoxStyle 

Source
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 corner

Implementations§

Source§

impl BoxStyle

Source

pub const fn new(style: Style) -> Self

A borderless box with no padding/margin, in style, sized to fit its content.

Source

pub const fn padding(self, padding: Sides) -> Self

Sets the padding, between the border (if any) and the content.

Source

pub const fn margin(self, margin: Sides) -> Self

Sets the margin, outside the border (if any); left transparent.

Source

pub const fn border(self, border: bool) -> Self

Draws a single-line border, in style, around the padding.

Source

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.

Source

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.

Source

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.

Source

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.

Source§

impl BoxStyle

Source

pub const fn text(self, text: &str) -> Boxed<'_>

Pairs this style with text, ready to draw via Widget::render.

Trait Implementations§

Source§

impl Clone for BoxStyle

Source§

fn clone(&self) -> BoxStyle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for BoxStyle

Source§

impl Debug for BoxStyle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<C> WithAlpha for C
where C: Copy,

Source§

fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>

Wraps self with alpha, storing alpha before the color in memory (see AlphaFirst).
Source§

fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>

Wraps self with alpha, storing alpha after the color in memory (see AlphaLast).