Skip to main content

retroglyph_core/layout/
mod.rs

1//! Text layout: measurement, word wrapping, and bounded alignment.
2//!
3//! [`HAlign`](crate::layout::HAlign) and [`VAlign`](crate::layout::VAlign) are plain data (no allocation, no text handling) and are always
4//! available regardless of the `egc` feature; [`Surface::print_aligned`](crate::surface::Surface::print_aligned)
5//! uses them directly. [`crate::text::Span`] and [`crate::text::Line`] provide styled text
6//! primitives, and [`TextLayout`](crate::layout::TextLayout) is a builder that word-wraps a [`crate::text::Line`] to a
7//! bounded [`Rect`](crate::grid::Rect), then positions it with independent horizontal
8//! ([`HAlign`](crate::layout::HAlign)) and vertical ([`VAlign`](crate::layout::VAlign)) alignment. Measure the result before rendering with
9//! [`TextLayout::measure`](crate::layout::TextLayout::measure). [`wrap`] exposes that same word-wrap pass standalone, for callers
10//! that need the broken-apart [`crate::text::Line`]s rather than a rendered surface.
11//!
12//! [`TextLayout`](crate::layout::TextLayout) and [`wrap`] are only available when the `egc` feature is enabled (requires
13//! `alloc`): both call into `unicode-segmentation`/`unicode-width` directly, with no non-`egc`
14//! fallback path.
15
16mod align;
17#[cfg(feature = "egc")]
18mod text_layout;
19#[cfg(feature = "egc")]
20mod word_wrap;
21
22pub use align::{HAlign, VAlign};
23#[cfg(feature = "egc")]
24pub use text_layout::TextLayout;
25#[cfg(feature = "egc")]
26pub use word_wrap::wrap;