Skip to main content

TextLayout

Struct TextLayout 

Source
pub struct TextLayout {
    pub shaped: ShapedText,
    pub align: TextAlign,
    pub bounds: (f32, f32),
}
Expand description

A shaped text block with alignment and bounds information.

Fields§

§shaped: ShapedText

The raw shaped text (glyph positions, line metrics).

§align: TextAlign

Requested alignment.

§bounds: (f32, f32)

(max_width, max_height) — the layout box dimensions.

Implementations§

Source§

impl TextLayout

Source

pub fn new( pipeline: &mut TextPipeline, text: &str, style: &TextStyle, max_width: f32, align: TextAlign, ) -> Result<Self, TextError>

Shape text and apply align within max_width.

§Errors

Propagates shaping errors from the pipeline.

Source

pub fn align_glyphs(&self) -> Vec<Vec<GlyphPosition>>

Apply alignment offsets to glyph positions within bounds.

Returns per-line glyph positions adjusted for the requested alignment.

Source

pub fn hit_test_fast(&self, x: f32) -> usize

Fast O(log n) hit-test over a single horizontal sweep using binary search over sorted glyph x-positions.

Returns the glyph index (into the concatenated flat list of all glyphs across all lines) of the entry whose left edge is closest to x. This is O(log n) in the total number of glyphs, vs. the O(n) linear scan in Self::hit_test.

Unlike Self::hit_test this method ignores the y-coordinate and operates on the full concatenated glyph stream — callers that need per-line hit-testing should pre-filter by line before calling.

Source

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

Return the byte offset of the glyph closest to (x, y).

Useful for click-to-caret positioning.

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> 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, 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.