1use rune::{Image, ImageCache, Waker}; 2use std::cell::RefCell; 3use std::collections::HashMap; 4use std::path::{Path, PathBuf}; 5 6pub struct Images { 7 cache: ImageCache, 8 held: RefCell<HashMap<PathBuf, Image>>, 9} 10 11impl Images { 12 pub fn new(waker: Waker) -> Self { 13 Self { 14 cache: ImageCache::new(waker), 15 held: RefCell::default(), 16 } 17 } 18 19 pub fn file(&self, path: &Path) -> Image { 20 self.held 21 .borrow_mut() 22 .entry(path.to_path_buf()) 23 .or_insert_with(|| self.cache.file(path, 560.0, 2.0)) 24 .clone() 25 } 26}