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: TextMetricsOverall layout extent in logical pixels.
Implementations§
Source§impl PreparedTextLayout
impl PreparedTextLayout
Sourcepub fn text(&self) -> &str
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);Sourcepub fn style(&self) -> TextStyle
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);Sourcepub fn width(&self) -> f32
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);Sourcepub fn height(&self) -> f32
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);Sourcepub fn glyphs(&self) -> &[GlyphInstance]
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()));Sourcepub fn caret_x_at(&self, byte_idx: usize) -> f32
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));Sourcepub fn caret_rect_at(&self, byte_idx: usize, width: f32) -> Rect
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);Sourcepub fn caret_index_at_point(&self, x: f32, y: f32) -> usize
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);