cotis-utils 0.1.0-alpha

Modular Rust UI framework core
Documentation
//! Text measurement traits shared between layout and renderer crates.
//!
//! This API is stable enough for current integrations, but it is planned for a
//! future refactor together with font management and text config ownership.
use crate::math::Dimensions;

/// Closure type used to measure text during layout.
pub type TextMeasurer<'a, TextConfig> = dyn Fn(&str, &TextConfig) -> Dimensions + 'a;

/// Implemented by renderers that can measure text for layout.
///
/// A renderer provides a closure that maps `(text, config)` into measured
/// [`Dimensions`]. Layout systems call this closure while computing text nodes.
pub trait RendererTextMeasuringProvider<TextConfig> {
    /// Returns a measuring function used by layout code.
    fn provide_measurer(&mut self) -> Box<TextMeasurer<'_, TextConfig>>;
}

/// Layout-side receiver for text measuring functions.
///
/// This trait currently has limited usage in workspace crates and is expected to
/// evolve as text APIs are refactored.
pub trait LayoutTextMeasuring<TextConfig> {
    /// Registers the text measuring function used by the layout implementation.
    fn set_text_measuring_function(&mut self, text: Box<TextMeasurer<'_, TextConfig>>);
}