cotis_utils/text.rs
1//! Text measurement traits shared between layout and renderer crates.
2//!
3//! This API is stable enough for current integrations, but it is planned for a
4//! future refactor together with font management and text config ownership.
5use crate::math::Dimensions;
6
7/// Closure type used to measure text during layout.
8pub type TextMeasurer<'a, TextConfig> = dyn Fn(&str, &TextConfig) -> Dimensions + 'a;
9
10/// Implemented by renderers that can measure text for layout.
11///
12/// A renderer provides a closure that maps `(text, config)` into measured
13/// [`Dimensions`]. Layout systems call this closure while computing text nodes.
14pub trait RendererTextMeasuringProvider<TextConfig> {
15 /// Returns a measuring function used by layout code.
16 fn provide_measurer(&mut self) -> Box<TextMeasurer<'_, TextConfig>>;
17}
18
19/// Layout-side receiver for text measuring functions.
20///
21/// This trait currently has limited usage in workspace crates and is expected to
22/// evolve as text APIs are refactored.
23pub trait LayoutTextMeasuring<TextConfig> {
24 /// Registers the text measuring function used by the layout implementation.
25 fn set_text_measuring_function(&mut self, text: Box<TextMeasurer<'_, TextConfig>>);
26}