Skip to main content

LayoutResult

Struct LayoutResult 

Source
pub struct LayoutResult {
    pub glyphs: Vec<PositionedGlyph>,
    pub lines: Vec<Line>,
    pub metrics: ParagraphMetrics,
    pub decorations: Vec<DecorationRect>,
    pub inline_objects: Vec<PositionedInlineObject>,
}
Expand description

The structured result of a layout pass.

Fields§

§glyphs: Vec<PositionedGlyph>

All positioned glyphs in logical (reading) order.

§lines: Vec<Line>

Line records indexing into Self::glyphs.

§metrics: ParagraphMetrics

Aggregate metrics.

§decorations: Vec<DecorationRect>

Decoration rectangles computed from the layout (underlines, overlines, strikethroughs). Empty unless decorations are requested via crate::options::LayoutOptions::decoration.

§inline_objects: Vec<PositionedInlineObject>

Positioned inline objects (images, widgets) placed during layout.

Implementations§

Source§

impl LayoutResult

Source

pub fn hit_test(&self, x: f32, y: f32) -> Option<(usize, usize, u32)>

Find the glyph nearest to pixel coordinates (x, y) for hit-testing and cursor placement during text selection.

Returns Some((line_index, glyph_index_within_line, cluster_byte_offset)) where:

  • line_index is the index into LayoutResult::lines,
  • glyph_index_within_line is the 0-based position within that line’s glyph range (i.e. 0 is the first glyph of the line),
  • cluster_byte_offset is PositionedGlyph::cluster — the UTF-8 byte offset of the glyph’s source character.

If (x, y) falls outside all lines the nearest line is chosen. If it falls outside all glyphs on the chosen line the nearest endpoint glyph is returned.

Returns None only when self.lines is empty.

Source

pub fn unique_glyphs_for_atlas(&self) -> Vec<(u16, f32)>

Return the unique (glyph_id, font_size) pairs present in this layout, suitable for pre-warming an SDF atlas or batching rasterisation.

Each (gid, px_size) pair appears exactly once regardless of how many times that glyph occurs in the layout. The order of the returned entries is stable: pairs are emitted in the order their first occurrence is encountered when iterating Self::glyphs from index 0.

The font_size_bits value stored internally as a u32 key is obtained via font_size.to_bits() so that equal IEEE-754 floats are always treated as equal keys even in a HashSet.

§Rasteriser usage
for (glyph_id, px_size) in layout.unique_glyphs_for_atlas() {
    atlas.pre_warm(glyph_id, px_size);
}
Source

pub fn rasterization_inputs(&self) -> Vec<(u16, f32, f32, f32)>

Return per-glyph (glyph_id, x, y, font_size) tuples ready for direct handoff to a rasteriser.

Positions are in pixel coordinates with the origin at the top-left of the text block (matching PositionedGlyph::pos). The returned Vec preserves logical (reading) order and contains exactly one entry per glyph in Self::glyphs.

§Rasteriser usage
for (gid, x, y, px_size) in layout.rasterization_inputs() {
    rasterizer.draw(gid, x, y, px_size);
}
Source

pub fn sdf_glyph_set(&self) -> Vec<(u16, f32)>

Returns the set of glyphs that should be pre-loaded into an SDF atlas before rendering. Each entry is (glyph_id, px_size).

This is an alias for Self::unique_glyphs_for_atlas with an SDF-oriented name for use at the oxitext-sdf integration boundary.

§Usage with oxitext-sdf
let layout = engine.layout(text, runs, &constraints, alignment, None)?;
for (glyph_id, px_size) in layout.sdf_glyph_set() {
    if let Ok(Some(tile)) =
        oxitext_sdf::glyph_to_sdf_tile(font_data, glyph_id, px_size, 64, 4.0)
    {
        atlas.pack_tile(tile);
    }
}

Trait Implementations§

Source§

impl Clone for LayoutResult

Source§

fn clone(&self) -> LayoutResult

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for LayoutResult

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.