pub struct TextLayout {
pub text: String,
pub content_widths: Option<CachedContentWidths>,
pub layout: Layout<TextBrush>,
}Fields§
§text: String§content_widths: Option<CachedContentWidths>§layout: Layout<TextBrush>Implementations§
Source§impl TextLayout
impl TextLayout
pub fn new() -> Self
Sourcepub fn content_widths(&mut self) -> ContentWidths
pub fn content_widths(&mut self) -> ContentWidths
The layout’s min-content and max-content widths, recomputed only when the inputs to that computation have actually changed.
WHY this is cached: Layout::calculate_content_widths walks every shaped cluster in
the layout, and block layout asks for the content widths two or three times per pass
(once under a min-content constraint, once under max-content, then again for the
definite measure), so the same scan is repeated over the same data.
WHY it is safe: the result is a pure function of exactly two things, the shaped runs and the current width of each inline box.
The shaped runs only change when the inline layout is rebuilt, and every rebuild goes
through build_inline_layout_into, which clears this cache. Damage propagation clears
it too, in the same places it clears the Taffy layout cache, so a text edit or a style
change affecting font, size, weight, letter/word spacing or white-space collapsing
always re-measures.
The inline box widths are the reason this cannot be a plain one-shot cache: they are re-measured on every pass, and an inline box legitimately measures differently under a min-content constraint than under a max-content one, so the same shaped text can yield different content widths from one call to the next. Rather than guess which constraint a cached entry belongs to, we record the box widths the entry was computed from and reuse it only when they are bit-for-bit identical. A layout containing no inline boxes, which is the common case and where the scan cost is concentrated, therefore hits the cache on every pass after the first.
Trait Implementations§
Source§impl Clone for TextLayout
impl Clone for TextLayout
Source§fn clone(&self) -> TextLayout
fn clone(&self) -> TextLayout
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TextLayout
impl Debug for TextLayout
Source§impl Default for TextLayout
impl Default for TextLayout
Source§fn default() -> TextLayout
fn default() -> TextLayout
Auto Trait Implementations§
impl !RefUnwindSafe for TextLayout
impl !UnwindSafe for TextLayout
impl Freeze for TextLayout
impl Send for TextLayout
impl Sync for TextLayout
impl Unpin for TextLayout
impl UnsafeUnpin for TextLayout
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<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more