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: ParagraphMetricsAggregate 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
impl LayoutResult
Sourcepub fn hit_test(&self, x: f32, y: f32) -> Option<(usize, usize, u32)>
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_indexis the index intoLayoutResult::lines,glyph_index_within_lineis the 0-based position within that line’s glyph range (i.e.0is the first glyph of the line),cluster_byte_offsetisPositionedGlyph::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.
Sourcepub fn unique_glyphs_for_atlas(&self) -> Vec<(u16, f32)>
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);
}Sourcepub fn rasterization_inputs(&self) -> Vec<(u16, f32, f32, f32)>
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);
}Sourcepub fn sdf_glyph_set(&self) -> Vec<(u16, f32)>
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
impl Clone for LayoutResult
Source§fn clone(&self) -> LayoutResult
fn clone(&self) -> LayoutResult
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for LayoutResult
impl RefUnwindSafe for LayoutResult
impl Send for LayoutResult
impl Sync for LayoutResult
impl Unpin for LayoutResult
impl UnsafeUnpin for LayoutResult
impl UnwindSafe for LayoutResult
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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