pub struct WrappedText<'a> { /* private fields */ }Expand description
Immutable borrowed layout. Construction and iteration allocate no storage;
each measurement scans the source to count hidden lines as well as visible
ones. Work is linear in source length, not bounded by the line limit.
Self::lines starts a fresh iterator, so reflow needs no retained cache/reset.
Implementations§
Source§impl<'a> WrappedText<'a>
impl<'a> WrappedText<'a>
Sourcepub fn new(
text: &'a str,
width: f32,
size: f32,
) -> Result<WrappedText<'a>, UiError>
pub fn new( text: &'a str, width: f32, size: f32, ) -> Result<WrappedText<'a>, UiError>
Validate finite nonnegative width and the UI’s 1..=256 size range.
Invalid dimensions return UiError::InvalidLayout. No text-length cap
is imposed on this borrowed view; queuing into Ui has separate budgets.
Widths below one cell (including zero) still wrap one scalar per line,
matching the painter; they require geometric clipping at paint time.
use ferravex_render::ui::{UiError, text_layout::WrappedText};
assert_eq!(WrappedText::new("copy", -1., 18.).unwrap_err(), UiError::InvalidLayout);
let layout = WrappedText::new("AB CD", 24., 16.)?;
assert_eq!(layout.measure().required_height, 32.);
assert_eq!(layout.line_height(), 16.);Sourcepub fn with_limit(self, limit: LineLimit) -> WrappedText<'a>
pub fn with_limit(self, limit: LineLimit) -> WrappedText<'a>
Replace the maximum-line policy without changing the source or wrapping.
use ferravex_render::ui::text_layout::{LineLimit, WrappedText};
let layout = WrappedText::new("A\nB\nC", 60., 8.)?;
let compact = layout.with_limit(LineLimit::Clip(1)).measure();
assert_eq!((compact.visible_lines, compact.hidden_lines), (1, 2));
assert_eq!((compact.height, compact.required_height), (8., 24.));
assert!(compact.is_truncated());
assert_eq!(layout.lines().count(), 3); // Original is reusable.Sourcepub fn line_height(&self) -> f32
pub fn line_height(&self) -> f32
Vertical distance between line tops in logical UI units.
Sourcepub fn lines(&self) -> WrappedLines<'a> ⓘ
pub fn lines(&self) -> WrappedLines<'a> ⓘ
Start an independent, allocation-free iterator of retained line spans.
Each line starts at index as f32 * line_height() below the block top.
Sourcepub fn measure(&self) -> TextBlockMetrics
pub fn measure(&self) -> TextBlockMetrics
Count all wrapped lines and measure the retained block without allocating.
To avoid partial last-line clipping, give Ui::wrapped_text a rectangle
at least height tall. For a fixed card use Clip(n)/Ellipsis(n), with
n = floor(available_height / line_height), and inspect hidden_lines.
Trait Implementations§
Source§impl<'a> Clone for WrappedText<'a>
impl<'a> Clone for WrappedText<'a>
Source§fn clone(&self) -> WrappedText<'a>
fn clone(&self) -> WrappedText<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more