Struct ParleyEngine

Source
pub struct ParleyEngine {
    pub font_cx: FontContext,
    pub layout_cx: LayoutContext<()>,
    pub styled_layout_cx: LayoutContext<[f32; 4]>,
}
Expand description

Thin wrapper around Parley:

  • holds shared FontContext / LayoutContext
  • builds Layout<()> with fractional positioning (quantize = false)

Reusing one engine preserves Parley’s font and layout caches. The type is mutable and not intended for concurrent use without external synchronization. Default creates empty Parley contexts; the deprecated Self::new additionally registers the bundled monospace font and probes assets/fonts. Application code should normally construct crate::TextSystem instead.

§Examples

use ailloli_ui_text::ParleyEngine;
let engine = ParleyEngine::default();
let _font_context = &engine.font_cx;
let _plain_layout_context = &engine.layout_cx;

Fields§

§font_cx: FontContext

Parley font collection and font-selection state.

§layout_cx: LayoutContext<()>

Reusable context for layouts whose glyph runs have no color brush.

§styled_layout_cx: LayoutContext<[f32; 4]>

Reusable context for layouts whose brushes are linear-RGBA arrays.

Implementations§

Source§

impl ParleyEngine

Source

pub fn new() -> Self

👎Deprecated: prefer TextSystem::new() for app and widget code

Creates an engine with the bundled mono font and optional asset fonts.

The method also scans the relative assets/fonts path. Failures there are handled by Fontique and do not make construction fallible. Prefer crate::TextSystem::new in widgets and applications because it owns the font blobs needed by renderers.

§Examples
use ailloli_ui_text::ParleyEngine;
#[allow(deprecated)]
let mut engine = ParleyEngine::new();
assert!(engine.font_cx.collection.family_names().next().is_some());
Source

pub fn layout_text( &mut self, text: &str, style: UiTextStyle, max_width: Option<f32>, ) -> Layout<()>

Lays out text with the given style and optional max width (word wrap).

max_width is in logical pixels; None leaves line breaking unconstrained apart from explicit line separators. Color and decoration are not stored in the returned Layout<()>. Fractional glyph positions are retained.

§Examples
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::ParleyEngine;
#[allow(deprecated)]
let mut engine = ParleyEngine::new();
let layout = engine.layout_text(
    "hello world",
    TextStyle::new(FontId::Ui, 16, Color::WHITE),
    Some(80.0),
);
assert!(layout.height() > 0.0);
Source

pub fn layout_text_with_wrap( &mut self, text: &str, style: UiTextStyle, max_width: Option<f32>, wrap_mode: WrapMode, ) -> Layout<()>

Lays out text with an explicit wrap strategy.

This low-level method always forwards max_width to Parley’s line breaker. In particular, WrapMode::NoWrap does not discard a supplied width here; use crate::layout_text for the higher-level no-wrap contract. crate::WrapMode::WordOrAnywhere additionally enables cluster-level overflow breaking. Positions remain fractional.

§Examples
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{ParleyEngine, WrapMode};
#[allow(deprecated)]
let mut engine = ParleyEngine::new();
let layout = engine.layout_text_with_wrap(
    "an_unbroken_identifier",
    TextStyle::new(FontId::Mono, 14, Color::WHITE),
    Some(40.0),
    WrapMode::WordOrAnywhere,
);
assert!(layout.lines().count() >= 1);
Source

pub fn layout_styled_text_with_wrap( &mut self, text: &str, base_style: UiTextStyle, spans: &[StyledTextSpan], max_width: Option<f32>, wrap_mode: WrapMode, ) -> Layout<[f32; 4]>

Lays out text with ranged text styles and an explicit wrap strategy.

Each span replaces family, logical-pixel size, and linear-RGBA brush in its half-open UTF-8 byte range. Ranges are passed to Parley in slice order and must be valid for text. As in Self::layout_text_with_wrap, this low-level method does not suppress max_width for NoWrap.

§Panics

Parley may panic when a span range is reversed, out of bounds, or not on UTF-8 boundaries; callers must validate externally sourced ranges.

§Examples
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{ParleyEngine, StyledTextSpan, WrapMode};
#[allow(deprecated)]
let mut engine = ParleyEngine::new();
let base = TextStyle::new(FontId::Mono, 14, Color::WHITE);
let spans = [StyledTextSpan { range: 0..2, style: base.underline() }];
let layout = engine.layout_styled_text_with_wrap(
    "fn main", base, &spans, None, WrapMode::NoWrap,
);
assert!(layout.height() > 0.0);

Trait Implementations§

Source§

impl Default for ParleyEngine

Source§

fn default() -> ParleyEngine

Returns the “default value” for a type. 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,