pub struct LaidOutText {
pub lines: Vec<LaidOutLine>,
pub metrics: TextMetrics,
/* private fields */
}Expand description
Backend-agnostic layout result (Parley types not exposed).
The value owns a copy of the input text and shares an immutable Parley
layout through an Arc. Dimensions and positions are logical pixels.
Cloning is therefore cheap except for the small metadata vectors.
§Examples
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{layout_text, ParleyEngine, TextLayoutParams};
#[allow(deprecated)]
let mut engine = ParleyEngine::new();
let laid = layout_text(
&mut engine,
TextLayoutParams::new("hello", TextStyle::new(FontId::Ui, 16, Color::WHITE)),
);
assert_eq!(laid.text(), "hello");
assert!(!laid.lines.is_empty());Fields§
§lines: Vec<LaidOutLine>Public per-line summaries in source order.
metrics: TextMetricsOverall logical-pixel layout extent.
Implementations§
Source§impl LaidOutText
impl LaidOutText
Sourcepub fn text(&self) -> &str
pub fn text(&self) -> &str
Returns the owned source text used to build this layout.
§Examples
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{layout_text, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let laid = layout_text(&mut engine, TextLayoutParams::new("é", TextStyle::new(FontId::Ui, 14, Color::WHITE)));
assert_eq!(laid.text().as_bytes().len(), 2);Sourcepub fn style(&self) -> TextStyle
pub fn style(&self) -> TextStyle
Returns the copyable base style supplied to layout_text.
The style color is metadata for the painter; unstyled glyph instances
returned by Self::glyph_instances have color == None.
§Examples
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{layout_text, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let style = TextStyle::new(FontId::Mono, 13, Color::WHITE);
let laid = layout_text(&mut engine, TextLayoutParams::new("x", style));
assert_eq!(laid.style(), style);Sourcepub fn glyph_instances(&self) -> Vec<GlyphInstance>
pub fn glyph_instances(&self) -> Vec<GlyphInstance>
Flattens all positioned glyph runs into renderer-facing instances.
The returned vector is newly allocated on every call. Positions are
logical pixels and keep fractional values. Font sizes are rounded to the
nearest integer and clamped to at least one before conversion to u16;
colors are None because this layout stores () brushes.
§Examples
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{layout_text, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let laid = layout_text(&mut engine, TextLayoutParams::new("Hi", TextStyle::new(FontId::Ui, 16, Color::WHITE)));
let glyphs = laid.glyph_instances();
assert!(!glyphs.is_empty());
assert!(glyphs.iter().all(|glyph| glyph.px_size >= 1 && glyph.color.is_none()));Sourcepub fn width(&self) -> f32
pub fn width(&self) -> f32
Returns the overall Parley layout width in logical pixels.
§Examples
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{layout_text, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let laid = layout_text(&mut engine, TextLayoutParams::new("width", TextStyle::new(FontId::Ui, 16, Color::WHITE)));
assert_eq!(laid.width(), laid.metrics.width);Sourcepub fn height(&self) -> f32
pub fn height(&self) -> f32
Returns the overall Parley layout height in logical pixels.
§Examples
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{layout_text, ParleyEngine, TextLayoutParams};
#[allow(deprecated)] let mut engine = ParleyEngine::new();
let laid = layout_text(&mut engine, TextLayoutParams::new("height", TextStyle::new(FontId::Ui, 16, Color::WHITE)));
assert_eq!(laid.height(), laid.metrics.height);
assert!(laid.height() > 0.0);Trait Implementations§
Source§impl Clone for LaidOutText
impl Clone for LaidOutText
Source§fn clone(&self) -> LaidOutText
fn clone(&self) -> LaidOutText
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more