Struct LaidOutText

Source
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: TextMetrics

Overall logical-pixel layout extent.

Implementations§

Source§

impl LaidOutText

Source

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);
Source

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);
Source

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()));
Source

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);
Source

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

Source§

fn clone(&self) -> LaidOutText

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LaidOutText

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
§

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