1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#![allow(dead_code)]

pub struct Image {
    name: String,
    pub width: u32,
    pub height: u32,
    pub data: Vec<u8>,
}

// pub enum ImageOrId {
//     Image(image::DynamicImage),
//     Id(femtovg::ImageId),
// }

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Resource(u32);

pub struct ResourceManager {
    //pub images: HashMap<String, Image>,
    pub stylesheets: Vec<String>, // Stylesheets refer to a fiel path
    pub themes: Vec<String>,      // Themes are the string content stylesheets
    pub images: Vec<Image>,

    //pub image_ids: HashMap<Rc<()>, ImageOrId>,
    count: u32,
}

impl ResourceManager {
    pub fn new() -> Self {
        ResourceManager {
            //images: HashMap::new(),
            stylesheets: Vec::new(),
            themes: Vec::new(),
            images: Vec::new(),
            //image_ids: HashMap::new(),
            count: 0,
        }
    }

    // TODO
    // pub(crate) fn add_image(&mut self, image: image::DynamicImage) -> Rc<()> {
    //     // self.images.push(Image {
    //     //     name: name.to_string(),
    //     //     width,
    //     //     height,
    //     //     data,
    //     // });

    //     let resource = Rc::new(());

    //     self.image_ids
    //         .insert(resource.clone(), ImageOrId::Image(image));

    //     resource.clone()
    // }

    pub(crate) fn add_font(&mut self, _name: &str, _path: &str) {}
    // pub fn add_stylesheet(&mut self, path: String) -> Result<(), std::io::Error> {

    //     let style_string = std::fs::read_to_string(path.clone())?;
    //     self.stylesheets.push(path);

    //     Ok(())
    // }

    // pub fn load_image(&mut self, name: &str, path: &str) {
    //     let img = image::open(path).expect(&format!("failed to load image: {}", path));
    //     let mut raw_data: Vec<u32> = vec![0; img.to_rgba().into_raw().len() / 4];
    //     LittleEndian::read_u32_into(img.to_rgba().into_raw().as_ref(), &mut raw_data);
    //     let image = Image {
    //         width: img.width() as usize,
    //         height: img.height() as usize,
    //         data: raw_data,
    //     };
    //     self.images.insert(name.to_string(), image);
    // }
}