fn try_load_missing_resources(&mut self, tree: &WidgetUnit) -> Result<(), Error> {
        match tree {
            WidgetUnit::AreaBox(area_box) => {
                self.try_load_missing_resources(&area_box.slot)?;
            }
            WidgetUnit::ContentBox(content_box) => {
                for item in &content_box.items {
                    self.try_load_missing_resources(&item.slot)?;
                }
            }
            WidgetUnit::FlexBox(flex_box) => {
                for item in &flex_box.items {
                    self.try_load_missing_resources(&item.slot)?;
                }
            }
            WidgetUnit::GridBox(grid_box) => {
                for item in &grid_box.items {
                    self.try_load_missing_resources(&item.slot)?;
                }
            }
            WidgetUnit::SizeBox(size_box) => {
                self.try_load_missing_resources(&size_box.slot)?;
            }
            WidgetUnit::ImageBox(image_box) => match &image_box.material {
                ImageBoxMaterial::Image(image) => {
                    if !self.resources.textures.contains_key(&image.id) {
                        self.resources.textures.insert(
                            image.id.clone(),
                            Texture::new(self.context, image.id.clone())
                                .map_err(|e| Error::ImageResourceNotFound(e.to_string()))?,
                        );
                    }
                }
                ImageBoxMaterial::Color(_) | ImageBoxMaterial::Procedural(_) => {}
            },
            WidgetUnit::TextBox(text_box) => {
                let font = &text_box.font;
                if let Entry::Vacant(entry) = self
                    .resources
                    .fonts
                    .entry(format!("{}:{}", font.name, font.size))
                {
                    entry.insert((
                        1.0,
                        Font::vector(self.context, font.name.clone(), font.size as Scalar)
                            .map_err(|e| Error::FontResourceNotFound(e.to_string()))?,
                    ));
                }
            }
            WidgetUnit::PortalBox(_) | WidgetUnit::None => {}
        }

        Ok(())
    }
/// Loads any missing textures or fonts that have not been preloaded
Loads any missing textures or fonts that have not been preloaded
Loads any missing textures or fonts that have not been preloaded
fn try_load_missing_resources(&mut self, tree: &WidgetUnit) -> Result<(), Error> {
        match tree {
            WidgetUnit::AreaBox(area_box) => {
                self.try_load_missing_resources(&area_box.slot)?;
            }
            WidgetUnit::ContentBox(content_box) => {
                for item in &content_box.items {
                    self.try_load_missing_resources(&item.slot)?;
                }
            }
            WidgetUnit::FlexBox(flex_box) => {
                for item in &flex_box.items {
                    self.try_load_missing_resources(&item.slot)?;
                }
            }
            WidgetUnit::GridBox(grid_box) => {
                for item in &grid_box.items {
                    self.try_load_missing_resources(&item.slot)?;
                }
            }
            WidgetUnit::SizeBox(size_box) => {
                self.try_load_missing_resources(&size_box.slot)?;
            }
            WidgetUnit::ImageBox(image_box) => match &image_box.material {
                ImageBoxMaterial::Image(image) => {
                    if !self.resources.textures.contains_key(&image.id) {
                        self.resources.textures.insert(
                            image.id.clone(),
                            Texture::new(self.context, image.id.clone())
                                .map_err(|e| Error::ImageResourceNotFound(e.to_string()))?,
                        );
                    }
                }
                ImageBoxMaterial::Color(_) | ImageBoxMaterial::Procedural(_) => {}
            },
            WidgetUnit::TextBox(text_box) => {
                let font = &text_box.font;
                if let Entry::Vacant(entry) = self
                    .resources
                    .fonts
                    .entry(format!("{}:{}", font.name, font.size))
                {
                    entry.insert((
                        1.0,
                        Font::vector(self.context, font.name.clone(), font.size as Scalar)
                            .map_err(|e| Error::FontResourceNotFound(e.to_string()))?,
                    ));
                }
            }
            WidgetUnit::PortalBox(_) | WidgetUnit::None => {}
        }
        Ok(())
    }
fn try_load_missing_resources ( & mut self , tree : & WidgetUnit ) -> Result < ( ) , Error > { match tree { WidgetUnit :: AreaBox ( area_box ) => { self . try_load_missing_resources ( & area_box . slot ) ? ; } WidgetUnit :: ContentBox ( content_box ) => { for item in & content_box . items { self . try_load_missing_resources ( & item . slot ) ? ; } } WidgetUnit :: FlexBox ( flex_box ) => { for item in & flex_box . items { self . try_load_missing_resources ( & item . slot ) ? ; } } WidgetUnit :: GridBox ( grid_box ) => { for item in & grid_box . items { self . try_load_missing_resources ( & item . slot ) ? ; } } WidgetUnit :: SizeBox ( size_box ) => { self . try_load_missing_resources ( & size_box . slot ) ? ; } WidgetUnit :: ImageBox ( image_box ) => match & image_box . material { ImageBoxMaterial :: Image ( image ) => { if ! self . resources . textures . contains_key ( & image . id ) { self . resources . textures . insert ( image . id . clone ( ) , Texture :: new ( self . context , image . id . clone ( ) ) . map_err ( | e | Error :: ImageResourceNotFound ( e . to_string ( ) ) ) ? , ) ; } } ImageBoxMaterial :: Color ( _ ) | ImageBoxMaterial :: Procedural ( _ ) => { } } , WidgetUnit :: TextBox ( text_box ) => { let font = & text_box . font ; if let Entry :: Vacant ( entry ) = self . resources . fonts . entry ( format ! ( " " font name font size ) ) { entry . insert ( ( 1.0 , Font :: vector ( self . context , font . name . clone ( ) , font . size as Scalar ) . map_err ( | e | Error :: FontResourceNotFound ( e . to_string ( ) ) ) ? , ) ) ; } } WidgetUnit :: PortalBox ( _ ) | WidgetUnit :: None => { } } Ok ( ( ) ) }
Loads any missing textures or fonts that have not been preloaded
Loads any missing textures or fonts that have not been preloaded
&mut self
tree
&WidgetUnit
&mut self
tree
&WidgetUnit