pub struct TextMeasurer { /* private fields */ }Expand description
Measures text with a 2D canvas context, caching the results.
Every label in a chart is measured at least once per layout, and layout runs on every data change. Measuring is a cross-language call into the browser, so the results are cached by text and font: a chart with a thousand axis labels makes a thousand calls the first time and none afterwards.
Implementations§
Source§impl TextMeasurer
Inherent implementation of TextMeasurer.
impl TextMeasurer
Inherent implementation of TextMeasurer.
Sourcepub fn new() -> Option<Self>
pub fn new() -> Option<Self>
Creates a measurer backed by a fresh offscreen canvas.
Returns None when the host has no DOM, which is the case for a
native build.
§Returns
Option<Self>-Some(...)on success,Noneotherwise.
Sourcepub fn approximate() -> Self
pub fn approximate() -> Self
Creates a measurer that estimates the text instead of measuring it.
The estimate is the average advance of a Latin character, which is close enough for a layout that is not going to be drawn — a server-side render, or a native build.
Sourcepub fn measure(&self, text: &str, font: &str) -> TextMetrics
pub fn measure(&self, text: &str, font: &str) -> TextMetrics
Sourcepub fn cache_size(&self) -> usize
pub fn cache_size(&self) -> usize
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Empties the measurement cache.
Trait Implementations§
Source§impl Clone for TextMeasurer
impl Clone for TextMeasurer
Source§impl Debug for TextMeasurer
Implements impl std::fmt::Debug for TextMeasurer.
impl Debug for TextMeasurer
Implements impl std::fmt::Debug for TextMeasurer.