tuix_core/state/
resource.rs

1#![allow(dead_code)]
2
3pub struct Image {
4    name: String,
5    pub width: u32,
6    pub height: u32,
7    pub data: Vec<u8>,
8}
9
10// pub enum ImageOrId {
11//     Image(image::DynamicImage),
12//     Id(femtovg::ImageId),
13// }
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
16pub struct Resource(u32);
17
18pub struct ResourceManager {
19    //pub images: HashMap<String, Image>,
20    pub stylesheets: Vec<String>, // Stylesheets refer to a fiel path
21    pub themes: Vec<String>,      // Themes are the string content stylesheets
22    pub images: Vec<Image>,
23
24    //pub image_ids: HashMap<Rc<()>, ImageOrId>,
25    count: u32,
26}
27
28impl ResourceManager {
29    pub fn new() -> Self {
30        ResourceManager {
31            //images: HashMap::new(),
32            stylesheets: Vec::new(),
33            themes: Vec::new(),
34            images: Vec::new(),
35            //image_ids: HashMap::new(),
36            count: 0,
37        }
38    }
39
40    // TODO
41    // pub(crate) fn add_image(&mut self, image: image::DynamicImage) -> Rc<()> {
42    //     // self.images.push(Image {
43    //     //     name: name.to_string(),
44    //     //     width,
45    //     //     height,
46    //     //     data,
47    //     // });
48
49    //     let resource = Rc::new(());
50
51    //     self.image_ids
52    //         .insert(resource.clone(), ImageOrId::Image(image));
53
54    //     resource.clone()
55    // }
56
57    pub(crate) fn add_font(&mut self, _name: &str, _path: &str) {}
58    // pub fn add_stylesheet(&mut self, path: String) -> Result<(), std::io::Error> {
59
60    //     let style_string = std::fs::read_to_string(path.clone())?;
61    //     self.stylesheets.push(path);
62
63    //     Ok(())
64    // }
65
66    // pub fn load_image(&mut self, name: &str, path: &str) {
67    //     let img = image::open(path).expect(&format!("failed to load image: {}", path));
68    //     let mut raw_data: Vec<u32> = vec![0; img.to_rgba().into_raw().len() / 4];
69    //     LittleEndian::read_u32_into(img.to_rgba().into_raw().as_ref(), &mut raw_data);
70    //     let image = Image {
71    //         width: img.width() as usize,
72    //         height: img.height() as usize,
73    //         data: raw_data,
74    //     };
75    //     self.images.insert(name.to_string(), image);
76    // }
77}