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: FontContextParley 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
impl ParleyEngine
Sourcepub fn new() -> Self
👎Deprecated: prefer TextSystem::new() for app and widget code
pub fn new() -> Self
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());Sourcepub fn layout_text(
&mut self,
text: &str,
style: UiTextStyle,
max_width: Option<f32>,
) -> Layout<()>
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);Sourcepub fn layout_text_with_wrap(
&mut self,
text: &str,
style: UiTextStyle,
max_width: Option<f32>,
wrap_mode: WrapMode,
) -> Layout<()>
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);Sourcepub 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]>
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);