Struct PreparedTextLayout

Source
pub struct PreparedTextLayout {
    pub lines: Vec<LaidOutLine>,
    pub metrics: TextMetrics,
    /* private fields */
}
Expand description

Laid-out text plus glyph instances ready for GPU atlas rasterization.

The source text, internal Parley layout, and glyph slice are owned through reference-counted allocations. Glyph instances identify font data stored in the face_blobs map supplied to prepare_layout or prepare_styled_layout; they do not copy font bytes individually. Dimensions and glyph positions are logical pixels.

§Examples

use std::collections::HashMap;
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{prepare_layout, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let mut faces = HashMap::new();
let prepared = prepare_layout(
    &mut engine,
    TextLayoutParams::new("hello", TextStyle::new(FontId::Ui, 16, Color::WHITE)),
    &mut faces,
);
assert_eq!(prepared.text(), "hello");
assert!(!prepared.lines.is_empty());

Fields§

§lines: Vec<LaidOutLine>

Per-line summaries in source order.

§metrics: TextMetrics

Overall layout extent in logical pixels.

Implementations§

Source§

impl PreparedTextLayout

Source

pub fn text(&self) -> &str

Returns the source text owned by this prepared layout.

§Examples
use std::collections::HashMap;
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{prepare_layout, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let mut faces = HashMap::new();
let prepared = prepare_layout(&mut engine, TextLayoutParams::new("é", TextStyle::new(FontId::Ui, 14, Color::WHITE)), &mut faces);
assert_eq!(prepared.text().len(), 2);
Source

pub fn style(&self) -> TextStyle

Returns the copyable base style used to build the layout.

For styled layouts this is the style outside overrides; individual glyph colors are available through Self::glyphs.

§Examples
use std::collections::HashMap;
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{prepare_layout, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let style = TextStyle::new(FontId::Mono, 13, Color::WHITE);
let mut faces = HashMap::new();
let prepared = prepare_layout(&mut engine, TextLayoutParams::new("x", style), &mut faces);
assert_eq!(prepared.style(), style);
Source

pub fn width(&self) -> f32

Returns the overall layout width in logical pixels.

§Examples
use std::collections::HashMap;
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{prepare_layout, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let mut faces = HashMap::new();
let prepared = prepare_layout(&mut engine, TextLayoutParams::new("width", TextStyle::new(FontId::Ui, 16, Color::WHITE)), &mut faces);
assert_eq!(prepared.width(), prepared.metrics.width);
Source

pub fn height(&self) -> f32

Returns the overall layout height in logical pixels.

§Examples
use std::collections::HashMap;
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{prepare_layout, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let mut faces = HashMap::new();
let prepared = prepare_layout(&mut engine, TextLayoutParams::new("height", TextStyle::new(FontId::Ui, 16, Color::WHITE)), &mut faces);
assert_eq!(prepared.height(), prepared.metrics.height);
assert!(prepared.height() > 0.0);
Source

pub fn glyphs(&self) -> &[GlyphInstance]

Borrows flattened glyph instances without allocating.

Uniform layouts use color == None; styled layouts attach the effective linear-RGBA run color. An empty input can produce an empty slice.

§Examples
use std::collections::HashMap;
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{prepare_layout, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let mut faces = HashMap::new();
let prepared = prepare_layout(&mut engine, TextLayoutParams::new("Hi", TextStyle::new(FontId::Ui, 16, Color::WHITE)), &mut faces);
assert!(!prepared.glyphs().is_empty());
assert!(prepared.glyphs().iter().all(|glyph| glyph.color.is_none()));
Source

pub fn caret_x_at(&self, byte_idx: usize) -> f32

Maps a UTF-8 byte index to the downstream caret’s logical-pixel X.

Shaped clusters, combining sequences, and ligatures may make multiple byte indices share an X coordinate.

§Examples
use std::collections::HashMap;
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{prepare_layout, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let mut faces = HashMap::new();
let prepared = prepare_layout(&mut engine, TextLayoutParams::new("abc", TextStyle::new(FontId::Ui, 16, Color::WHITE)), &mut faces);
assert!(prepared.caret_x_at(3) >= prepared.caret_x_at(0));
Source

pub fn caret_rect_at(&self, byte_idx: usize, width: f32) -> Rect

Maps a UTF-8 byte index to a logical-pixel caret rectangle.

width is normalized with a zero lower bound; negative and NaN values behave as zero. A downstream affinity resolves ambiguous boundaries. The result height is never negative.

§Examples
use std::collections::HashMap;
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{prepare_layout, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let mut faces = HashMap::new();
let prepared = prepare_layout(&mut engine, TextLayoutParams::new("abc", TextStyle::new(FontId::Ui, 16, Color::WHITE)), &mut faces);
let rect = prepared.caret_rect_at(0, 1.5);
assert!(rect.w >= 1.5 && rect.h >= 0.0);
Source

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

Maps a logical layout-space point to a cluster-aware UTF-8 byte index.

Parley resolves points outside glyph bounds to a valid cursor in the layout. No explicit coordinate clamping is performed here.

§Examples
use std::collections::HashMap;
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{prepare_layout, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let mut faces = HashMap::new();
let prepared = prepare_layout(&mut engine, TextLayoutParams::new("abc", TextStyle::new(FontId::Ui, 16, Color::WHITE)), &mut faces);
assert_eq!(prepared.caret_index_at_point(-100.0, 0.0), 0);

Trait Implementations§

Source§

impl Debug for PreparedTextLayout

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

Source§

type Output = T

Should always be Self
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.
§

impl<T> ErasedDestructor for T
where T: 'static,