pub struct LineLayoutCache { /* private fields */ }Expand description
A per-window cache of shaped and wrapped line layouts, retaining the previous frame so reused layouts survive a frame boundary.
Implementations§
Source§impl LineLayoutCache
impl LineLayoutCache
Sourcepub fn new(
platform_text_system: Arc<dyn PlatformTextSystem>,
font_generation: Arc<Atomic<usize>>,
) -> LineLayoutCache
pub fn new( platform_text_system: Arc<dyn PlatformTextSystem>, font_generation: Arc<Atomic<usize>>, ) -> LineLayoutCache
Creates an empty cache backed by platform_text_system.
Sourcepub fn layout_index(&self) -> LineLayoutIndex
pub fn layout_index(&self) -> LineLayoutIndex
Saves the current cache position so it can be reused or truncated later.
Sourcepub fn reuse_layouts(&self, range: Range<LineLayoutIndex>)
pub fn reuse_layouts(&self, range: Range<LineLayoutIndex>)
Re-inserts layouts from the previous frame created before range.
Sourcepub fn truncate_layouts(&self, index: LineLayoutIndex)
pub fn truncate_layouts(&self, index: LineLayoutIndex)
Drops layouts created after index, keeping the cache consistent.
Sourcepub fn finish_frame(&self)
pub fn finish_frame(&self)
Ages the current frame into the previous frame and clears the current one.
Sourcepub fn layout_wrapped_line<Text>(
&self,
text: Text,
font_size: Pixels,
runs: &[FontRun],
wrap_width: Option<Pixels>,
max_lines: Option<usize>,
) -> Arc<WrappedLineLayout> ⓘ
pub fn layout_wrapped_line<Text>( &self, text: Text, font_size: Pixels, runs: &[FontRun], wrap_width: Option<Pixels>, max_lines: Option<usize>, ) -> Arc<WrappedLineLayout> ⓘ
Shapes and wraps text, reusing a cached layout when the inputs match.
Sourcepub fn layout_line<Text>(
&self,
text: Text,
font_size: Pixels,
runs: &[FontRun],
force_width: Option<Pixels>,
) -> Arc<LineLayout> ⓘ
pub fn layout_line<Text>( &self, text: Text, font_size: Pixels, runs: &[FontRun], force_width: Option<Pixels>, ) -> Arc<LineLayout> ⓘ
Shapes a single line of text, reusing a cached layout when the inputs match.
Sourcepub fn try_layout_line_by_hash(
&self,
text_hash: u64,
text_len: usize,
font_size: Pixels,
runs: &[FontRun],
force_width: Option<Pixels>,
) -> Option<Arc<LineLayout>>
pub fn try_layout_line_by_hash( &self, text_hash: u64, text_len: usize, font_size: Pixels, runs: &[FontRun], force_width: Option<Pixels>, ) -> Option<Arc<LineLayout>>
Try to retrieve a previously-shaped line layout using a caller-provided content hash.
This is a non-allocating cache probe: it does not materialize any text. If the layout
is not already cached in either the current frame or previous frame, returns None.
Contract (caller enforced):
- Same
text_hashimplies identical text content (collision risk accepted by caller). text_lenshould be the UTF-8 byte length of the text (helps reduce accidental collisions).
Sourcepub fn layout_line_by_hash(
&self,
text_hash: u64,
text_len: usize,
font_size: Pixels,
runs: &[FontRun],
force_width: Option<Pixels>,
materialize_text: impl FnOnce() -> SharedString,
) -> Arc<LineLayout> ⓘ
pub fn layout_line_by_hash( &self, text_hash: u64, text_len: usize, font_size: Pixels, runs: &[FontRun], force_width: Option<Pixels>, materialize_text: impl FnOnce() -> SharedString, ) -> Arc<LineLayout> ⓘ
Layout a line of text using a caller-provided content hash as the cache key.
This enables cache hits without materializing a contiguous SharedString for text.
If the cache misses, materialize_text is invoked to produce the SharedString for shaping.
Contract (caller enforced):
- Same
text_hashimplies identical text content (collision risk accepted by caller). text_lenshould be the UTF-8 byte length of the text (helps reduce accidental collisions).
Auto Trait Implementations§
impl !Freeze for LineLayoutCache
impl !RefUnwindSafe for LineLayoutCache
impl !UnwindSafe for LineLayoutCache
impl Send for LineLayoutCache
impl Sync for LineLayoutCache
impl Unpin for LineLayoutCache
impl UnsafeUnpin for LineLayoutCache
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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