Struct WrappedText

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

Source

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.);
Source

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

pub fn line_height(&self) -> f32

Vertical distance between line tops in logical UI units.

Source

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.

Source

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>

Source§

fn clone(&self) -> WrappedText<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for WrappedText<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Copy for WrappedText<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for WrappedText<'a>

§

impl<'a> RefUnwindSafe for WrappedText<'a>

§

impl<'a> Send for WrappedText<'a>

§

impl<'a> Sync for WrappedText<'a>

§

impl<'a> Unpin for WrappedText<'a>

§

impl<'a> UnwindSafe for WrappedText<'a>

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.