MCPcopy Create free account
hub / github.com/TheRedDeveloper/ply-engine / font_height

Method font_height

src/engine.rs:2032–2054  ·  view source on GitHub ↗

Returns the cached font height for the given (font_asset, font_size) pair. Measures `"Mg"` on the first call for each pair and caches the result.

(&mut self, font_asset: Option<&'static crate::renderer::FontAsset>, font_size: u16)

Source from the content-addressed store, hash-verified

2030 /// Returns the cached font height for the given (font_asset, font_size) pair.
2031 /// Measures `"Mg"` on the first call for each pair and caches the result.
2032 fn font_height(&mut self, font_asset: Option<&'static crate::renderer::FontAsset>, font_size: u16) -> f32 {
2033 let font_key = font_asset.map(|a| a.key()).unwrap_or("");
2034 let key = (font_key, font_size);
2035 if let Some(&h) = self.font_height_cache.get(&key) {
2036 return h;
2037 }
2038 let h = if let Some(ref measure_fn) = self.measure_text_fn {
2039 let config = TextConfig {
2040 font_asset,
2041 font_size,
2042 ..Default::default()
2043 };
2044 measure_fn("Mg", &config).height
2045 } else {
2046 font_size as f32
2047 };
2048 let font_loaded = font_asset
2049 .map_or(true, |a| crate::renderer::FontManager::is_loaded(a));
2050 if font_loaded {
2051 self.font_height_cache.insert(key, h);
2052 }
2053 h
2054 }
2055
2056 fn measure_text_cached(
2057 &mut self,

Callers 4

Calls 2

keyMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected