Skip to main content

TextMeasurer

Trait TextMeasurer 

Source
pub trait TextMeasurer {
    // Required method
    fn measure(
        &self,
        text: &str,
        style: TextStyle,
        max_width: Option<f32>,
    ) -> TextLayoutResult;

    // Provided method
    fn measure_size(
        &self,
        text: &str,
        style: TextStyle,
        max_width: Option<f32>,
    ) -> Size { ... }
}
Expand description

Pluggable text measurement interface enabling deterministic cross-platform text layout.

Required Methods§

Source

fn measure( &self, text: &str, style: TextStyle, max_width: Option<f32>, ) -> TextLayoutResult

Measures and wraps text under style within an optional max_width constraint.

§Arguments
  • &Self - Text measurer reference.
  • &str - UTF-8 text to lay out.
  • TextStyle - Typography style parameters.
  • Option<f32> - Optional maximum line width in logical pixels.
§Returns
  • TextLayoutResult - Wrapped lines and aggregate bounding box.

Provided Methods§

Source

fn measure_size( &self, text: &str, style: TextStyle, max_width: Option<f32>, ) -> Size

Measures only the aggregate bounding box of text under style within an optional max_width constraint.

§Arguments
  • &Self - Text measurer reference.
  • &str - UTF-8 text to measure.
  • TextStyle - Typography style parameters.
  • Option<f32> - Optional maximum line width in logical pixels.
§Returns
  • Size - Aggregate bounding box without requiring callers to materialize wrapped lines.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl TextMeasurer for DeterministicTextMeasurer

Deterministic cross-platform TextMeasurer implementation.