# PretextLayout

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-pretext/struct-pretextlayout/

**struct** · [`ferroui-pretext`](/docs/0.5.0/api/ferroui-pretext/) · v0.5.0

```rust
struct PretextLayout
```

An isolated preparation session. Replacing a backend affects subsequent
preparation; already prepared metrics and shaped objects remain usable.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_backends.rs#L13)

## Members

- [`new`](#function-new)
- [`with_shaper_factory`](#function-with_shaper_factory)
- [`from_factories`](#function-from_factories)
- [`text_measurer_factory`](#function-text_measurer_factory)
- [`text_shaper_factory`](#function-text_shaper_factory)
- [`set_text_measurer_factory`](#function-set_text_measurer_factory)
- [`set_text_shaper_factory`](#function-set_text_shaper_factory)
- [`clear_cache`](#function-clear_cache)
- [`set_locale`](#function-set_locale)
- [`locale`](#function-locale)
- [`layout`](#function-layout)
- [`layout_with_lines`](#function-layout_with_lines)
- [`layout_next_line`](#function-layout_next_line)
- [`layout_next_line_range`](#function-layout_next_line_range)
- [`materialize_line_range`](#function-materialize_line_range)
- [`walk_line_ranges`](#function-walk_line_ranges)
- [`measure_line_stats`](#function-measure_line_stats)
- [`measure_natural_width`](#function-measure_natural_width)
- [`prepare`](#function-prepare)
- [`prepare_with_segments`](#function-prepare_with_segments)
- [`profile_prepare`](#function-profile_prepare)
- [`prepare_rich_inline`](#function-prepare_rich_inline)
- [`layout_next_rich_inline_line_range`](#function-layout_next_rich_inline_line_range)
- [`materialize_rich_inline_line_range`](#function-materialize_rich_inline_line_range)
- [`walk_rich_inline_line_ranges`](#function-walk_rich_inline_line_ranges)
- [`measure_rich_inline_stats`](#function-measure_rich_inline_stats)
- [`shape_text`](#function-shape_text)
- [`try_shape_text`](#function-try_shape_text)
- [`shape_prepared_text`](#function-shape_prepared_text)
- [`layout_next_shaped_line`](#function-layout_next_shaped_line)
- [`materialize_shaped_line_range`](#function-materialize_shaped_line_range)
- [`materialize_shaped_line_range_with_options`](#function-materialize_shaped_line_range_with_options)
- [`materialize_shaped_rich_inline_line_range`](#function-materialize_shaped_rich_inline_line_range)

<a id="function-new"></a>

### new

```rust
fn new(factory: Rc<dyn IPretextTextMeasurerFactory>) -> Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_backends.rs#L25)

<a id="function-with_shaper_factory"></a>

### with_shaper_factory

```rust
fn with_shaper_factory(self: Self, factory: Rc<dyn IPretextTextShaperFactory>) -> Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_backends.rs#L37)

<a id="function-from_factories"></a>

### from_factories

```rust
fn from_factories(factories: impl IntoIterator<Item = Rc<dyn IPretextTextMeasurerFactory>>) -> Result<Self, PretextError>
```

Selects the highest-priority supported registered measurement backend.
Equal priorities retain registration order. Reflection is unnecessary.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_backends.rs#L44)

<a id="function-text_measurer_factory"></a>

### text_measurer_factory

```rust
fn text_measurer_factory(self: &Self) -> Rc<dyn IPretextTextMeasurerFactory>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_backends.rs#L62)

<a id="function-text_shaper_factory"></a>

### text_shaper_factory

```rust
fn text_shaper_factory(self: &Self) -> Result<Rc<dyn IPretextTextShaperFactory>, PretextError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_backends.rs#L66)

<a id="function-set_text_measurer_factory"></a>

### set_text_measurer_factory

```rust
fn set_text_measurer_factory(self: &Self, factory: Rc<dyn IPretextTextMeasurerFactory>)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_backends.rs#L77)

<a id="function-set_text_shaper_factory"></a>

### set_text_shaper_factory

```rust
fn set_text_shaper_factory(self: &Self, factory: Option<Rc<dyn IPretextTextShaperFactory>>)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_backends.rs#L83)

<a id="function-clear_cache"></a>

### clear_cache

```rust
fn clear_cache(self: &Self)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_backends.rs#L89)

<a id="function-set_locale"></a>

### set_locale

```rust
fn set_locale(self: &Self, locale: Option<&str>)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_backends.rs#L100)

<a id="function-locale"></a>

### locale

```rust
fn locale(self: &Self) -> Option<String>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_backends.rs#L105)

<a id="function-layout"></a>

### layout

```rust
fn layout(prepared: &PreparedText, max_width: f64, line_height: f64) -> LayoutResult
```

Counts lines without materializing text or allocating line objects.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_line_break.rs#L160)

<a id="function-layout_with_lines"></a>

### layout_with_lines

```rust
fn layout_with_lines(prepared: &PreparedTextWithSegments, max_width: f64, line_height: f64) -> LayoutLinesResult
```

Materializes the text and geometry of each line.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_line_break.rs#L169)

<a id="function-layout_next_line"></a>

### layout_next_line

```rust
fn layout_next_line(prepared: &PreparedTextWithSegments, start: LayoutCursor, max_width: f64) -> Option<LayoutLine>
```

Resumes at a segment/grapheme cursor. Every returned line advances the
cursor, including when an individual grapheme exceeds the width.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_line_break.rs#L187)

<a id="function-layout_next_line_range"></a>

### layout_next_line_range

```rust
fn layout_next_line_range(prepared: &PreparedTextWithSegments, start: LayoutCursor, max_width: f64) -> Option<LayoutLineRange>
```

Computes the next line without allocating text.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_line_break.rs#L196)

<a id="function-materialize_line_range"></a>

### materialize_line_range

```rust
fn materialize_line_range(prepared: &PreparedTextWithSegments, line: &LayoutLineRange) -> LayoutLine
```

Materializes a previously computed range. The cursor carries enough
information to recover discretionary hyphens without hidden walk state.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_line_break.rs#L210)

<a id="function-walk_line_ranges"></a>

### walk_line_ranges

```rust
fn walk_line_ranges(prepared: &PreparedTextWithSegments, max_width: f64, on_line: impl FnMut(LayoutLineRange) -> ()) -> usize
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_line_break.rs#L226)

<a id="function-measure_line_stats"></a>

### measure_line_stats

```rust
fn measure_line_stats(prepared: &PreparedTextWithSegments, max_width: f64) -> LineStats
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_line_break.rs#L241)

<a id="function-measure_natural_width"></a>

### measure_natural_width

```rust
fn measure_natural_width(prepared: &PreparedTextWithSegments) -> f64
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_line_break.rs#L252)

<a id="function-prepare"></a>

### prepare

```rust
fn prepare(self: &Self, text: &str, font: &str, options: PrepareOptions) -> Result<PreparedText, PretextError>
```

Measures normalized text once for repeated allocation-free layout.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_preparation.rs#L23)

<a id="function-prepare_with_segments"></a>

### prepare_with_segments

```rust
fn prepare_with_segments(self: &Self, text: &str, font: &str, options: PrepareOptions) -> Result<Rc<PreparedTextWithSegments>, PretextError>
```

Retains normalized source segments in addition to reusable metrics.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_preparation.rs#L33)

<a id="function-profile_prepare"></a>

### profile_prepare

```rust
fn profile_prepare(self: &Self, text: &str, font: &str, options: PrepareOptions, now_ms: impl FnMut() -> f64) -> Result<PrepareProfile, PretextError>
```

Profiles analysis and measurement using a caller-supplied monotonic clock
measured in milliseconds. This works with native clocks and browser
`performance.now()` without introducing a platform dependency.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_preparation.rs#L54)

<a id="function-prepare_rich_inline"></a>

### prepare_rich_inline

```rust
fn prepare_rich_inline(self: &Self, items: &[RichInlineItem]) -> Result<Rc<PreparedRichInline>, PretextError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_rich_inline.rs#L154)

<a id="function-layout_next_rich_inline_line_range"></a>

### layout_next_rich_inline_line_range

```rust
fn layout_next_rich_inline_line_range(prepared: &PreparedRichInline, max_width: f64, start: Option<RichInlineCursor>) -> Option<RichInlineLineRange>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_rich_inline.rs#L213)

<a id="function-materialize_rich_inline_line_range"></a>

### materialize_rich_inline_line_range

```rust
fn materialize_rich_inline_line_range(prepared: &PreparedRichInline, line: &RichInlineLineRange) -> RichInlineLine
```

Materialize a range produced from this same prepared flow.

Panics if a caller fabricates a fragment referencing a missing source item,
matching the source's invalid-operation contract for mismatched ranges.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_rich_inline.rs#L245)

<a id="function-walk_rich_inline_line_ranges"></a>

### walk_rich_inline_line_ranges

```rust
fn walk_rich_inline_line_ranges(prepared: &PreparedRichInline, max_width: f64, on_line: impl FnMut(RichInlineLineRange) -> ()) -> usize
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_rich_inline.rs#L281)

<a id="function-measure_rich_inline_stats"></a>

### measure_rich_inline_stats

```rust
fn measure_rich_inline_stats(prepared: &PreparedRichInline, max_width: f64) -> RichInlineStats
```

Compute metrics without allocating fragment vectors or materialized text.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_rich_inline.rs#L299)

<a id="function-shape_text"></a>

### shape_text

```rust
fn shape_text(self: &Self, text: &str, font: &str, options: PretextShapeOptions) -> Result<Rc<PretextShapedRun>, PretextError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_shaping.rs#L128)

<a id="function-try_shape_text"></a>

### try_shape_text

```rust
fn try_shape_text(self: &Self, text: &str, font: &str, options: PretextShapeOptions) -> Option<Rc<PretextShapedRun>>
```

Convenience for hosts that can continue without glyph output.
Use `Self::shape_text` when the precise backend error is needed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_shaping.rs#L139)

<a id="function-shape_prepared_text"></a>

### shape_prepared_text

```rust
fn shape_prepared_text(self: &Self, prepared: Rc<PreparedTextWithSegments>, options: PretextShapeOptions) -> Result<Rc<PreparedShapedText>, PretextError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_shaping.rs#L148)

<a id="function-layout_next_shaped_line"></a>

### layout_next_shaped_line

```rust
fn layout_next_shaped_line(prepared: &PreparedShapedText, start: LayoutCursor, max_width: f64) -> Result<Option<ShapedLayoutLine>, PretextError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_shaping.rs#L217)

<a id="function-materialize_shaped_line_range"></a>

### materialize_shaped_line_range

```rust
fn materialize_shaped_line_range(prepared: &PreparedShapedText, line: &LayoutLineRange) -> Result<ShapedLayoutLine, PretextError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_shaping.rs#L227)

<a id="function-materialize_shaped_line_range_with_options"></a>

### materialize_shaped_line_range_with_options

```rust
fn materialize_shaped_line_range_with_options(self: &Self, prepared: Rc<PreparedTextWithSegments>, line: &LayoutLineRange, options: PretextShapeOptions) -> Result<ShapedLayoutLine, PretextError>
```

Convenience overload for callers retaining only their prepared metrics.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_shaping.rs#L240)

<a id="function-materialize_shaped_rich_inline_line_range"></a>

### materialize_shaped_rich_inline_line_range

```rust
fn materialize_shaped_rich_inline_line_range(self: &Self, prepared: &PreparedRichInline, line: &RichInlineLineRange, options: PretextShapeOptions) -> Result<ShapedRichInlineLine, PretextError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Pretext/FerroUI.Pretext/pretext_layout_shaping.rs#L250)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ErasedDestructor`
- `IntoEither`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
