diff options
author | 2023-08-30 05:06:08 +0200 | |
---|---|---|
committer | 2023-08-30 05:06:08 +0200 | |
commit | 89acf0217e0acd92a82bff1fd516cd4266c0878a (patch) | |
tree | 7ed80675520b67c02e1a171a2131100281d7c5d7 /graphics/src/text/cache.rs | |
parent | ed3454301e663a7cb7d73cd56b57b188f4d14a2f (diff) | |
download | iced-89acf0217e0acd92a82bff1fd516cd4266c0878a.tar.gz iced-89acf0217e0acd92a82bff1fd516cd4266c0878a.tar.bz2 iced-89acf0217e0acd92a82bff1fd516cd4266c0878a.zip |
Use `min_bounds` for cached text
Diffstat (limited to '')
-rw-r--r-- | graphics/src/text/cache.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/graphics/src/text/cache.rs b/graphics/src/text/cache.rs index 8aea6715..9e4fbf65 100644 --- a/graphics/src/text/cache.rs +++ b/graphics/src/text/cache.rs @@ -8,7 +8,7 @@ use std::hash::{BuildHasher, Hash, Hasher}; #[allow(missing_debug_implementations)] #[derive(Default)] pub struct Cache { - entries: FxHashMap<KeyHash, cosmic_text::Buffer>, + entries: FxHashMap<KeyHash, Entry>, aliases: FxHashMap<KeyHash, KeyHash>, recently_used: FxHashSet<KeyHash>, hasher: HashBuilder, @@ -25,7 +25,7 @@ impl Cache { Self::default() } - pub fn get(&self, key: &KeyHash) -> Option<&cosmic_text::Buffer> { + pub fn get(&self, key: &KeyHash) -> Option<&Entry> { self.entries.get(key) } @@ -33,7 +33,7 @@ impl Cache { &mut self, font_system: &mut cosmic_text::FontSystem, key: Key<'_>, - ) -> (KeyHash, &mut cosmic_text::Buffer) { + ) -> (KeyHash, &mut Entry) { let hash = key.hash(self.hasher.build_hasher()); if let Some(hash) = self.aliases.get(&hash) { @@ -59,7 +59,10 @@ impl Cache { ); let bounds = text::measure(&buffer); - let _ = entry.insert(buffer); + let _ = entry.insert(Entry { + buffer, + min_bounds: bounds, + }); for bounds in [ bounds, @@ -118,3 +121,9 @@ impl Key<'_> { } pub type KeyHash = u64; + +#[allow(missing_debug_implementations)] +pub struct Entry { + pub buffer: cosmic_text::Buffer, + pub min_bounds: Size, +} |