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
impl TextLayoutKey
Sourcepub fn from_params(params: &TextLayoutParams<'_>) -> Self
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);Sourcepub fn from_styled_params(params: &StyledTextLayoutParams<'_>) -> Self
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
impl Clone for TextLayoutKey
Source§fn clone(&self) -> TextLayoutKey
fn clone(&self) -> TextLayoutKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TextLayoutKey
impl Debug for TextLayoutKey
Source§impl Hash for TextLayoutKey
impl Hash for TextLayoutKey
Source§impl PartialEq for TextLayoutKey
impl PartialEq for TextLayoutKey
impl Copy for TextLayoutKey
impl Eq for TextLayoutKey
impl StructuralPartialEq for TextLayoutKey
Auto Trait Implementations§
impl Freeze for TextLayoutKey
impl RefUnwindSafe for TextLayoutKey
impl Send for TextLayoutKey
impl Sync for TextLayoutKey
impl Unpin for TextLayoutKey
impl UnwindSafe for TextLayoutKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.