Struct TextLayoutKey

Source
pub struct TextLayoutKey { /* private fields */ }
Expand description

Cache key for a text layout (content + style + quantized max width + wrap mode).

Text is represented by a DefaultHasher digest plus byte length. Uniform style keys include font and size but intentionally omit color and decoration. Styled keys add base/span colors after 8-bit quantization and still omit decoration. Widths are rounded to thousandths of a logical pixel. Therefore the key is optimized for cache reuse rather than being a lossless serialization of every request field.

§Examples

use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{TextLayoutKey, TextLayoutParams, WrapMode};
let style = TextStyle::new(FontId::Ui, 14, Color::WHITE);
let a = TextLayoutKey::from_params(&TextLayoutParams {
    text: "same", style, max_width: Some(80.0), wrap_mode: WrapMode::NoWrap,
});
let b = TextLayoutKey::from_params(&TextLayoutParams {
    text: "same", style, max_width: Some(800.0), wrap_mode: WrapMode::NoWrap,
});
assert_eq!(a, b);

Implementations§

Source§

impl TextLayoutKey

Source

pub fn from_params(params: &TextLayoutParams<'_>) -> Self

Builds a cache key from layout parameters.

NoWrap always uses the same sentinel width. Otherwise None uses u32::MAX; finite widths are lower-bounded at zero, multiplied by 1000, rounded, and saturating-cast to u32. NaN behaves as zero, while positive infinity and sufficiently large widths collide with the None sentinel. Uniform color and decoration do not affect this key.

§Examples
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{TextLayoutKey, TextLayoutParams, WrapMode};
let white = TextStyle::new(FontId::Ui, 14, Color::WHITE);
let black = TextStyle::new(FontId::Ui, 14, Color::BLACK).underline();
let a = TextLayoutKey::from_params(&TextLayoutParams { text: "x", style: white, max_width: Some(10.0001), wrap_mode: WrapMode::Word });
let b = TextLayoutKey::from_params(&TextLayoutParams { text: "x", style: black, max_width: Some(10.0002), wrap_mode: WrapMode::Word });
assert_eq!(a, b);
Source

pub fn from_styled_params(params: &StyledTextLayoutParams<'_>) -> Self

Builds a cache key from styled layout parameters.

The key includes ordered span ranges and base/span colors quantized to eight bits per channel. It omits all decorations. Unlike Self::from_params, a base color change normally changes the key; colors that quantize to identical RGBA8 values remain equivalent. Width normalization and sentinels are the same as for uniform text.

§Examples
use ailloli_ui_core::{Color, FontId, TextStyle};
use ailloli_ui_text::{StyledTextLayoutParams, TextLayoutKey, WrapMode};
let white = TextStyle::new(FontId::Mono, 13, Color::WHITE);
let black = TextStyle::new(FontId::Mono, 13, Color::BLACK);
let a = TextLayoutKey::from_styled_params(&StyledTextLayoutParams { text: "x", base_style: white, spans: &[], max_width: None, wrap_mode: WrapMode::NoWrap });
let b = TextLayoutKey::from_styled_params(&StyledTextLayoutParams { text: "x", base_style: black, spans: &[], max_width: None, wrap_mode: WrapMode::NoWrap });
assert_ne!(a, b);

Trait Implementations§

Source§

impl Clone for TextLayoutKey

Source§

fn clone(&self) -> TextLayoutKey

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 TextLayoutKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for TextLayoutKey

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TextLayoutKey

Source§

fn eq(&self, other: &TextLayoutKey) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for TextLayoutKey

Source§

impl Eq for TextLayoutKey

Source§

impl StructuralPartialEq for TextLayoutKey

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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,