pub fn apply(
        &mut self,
        texture_handle: &Handle<Image>,
        textures: &mut Assets<Image>,
    ) -> NinePatch<T> {
        let (texture_size, texture_data) = {
            let t = textures
                .get(texture_handle)
                .expect("could not get texture from handle");
            (t.texture_descriptor.size, &t.data)
        };
        let mut textures_to_add = vec![];
        if self.patch_textures.is_none() || self.original_texture.as_ref() != Some(texture_handle) {
            let mut patch_textures = vec![];
            let mut accu_y = 0;
            for row in &self.patches {
                let mut accu_x = 0;
                for column_item in row {
                    let start_x = accu_x;
                    let end_x = accu_x + to_width(column_item.original_size, texture_size);

                    let start_y = accu_y;
                    let end_y = accu_y + to_height(column_item.original_size, texture_size);

                    let mut patch_texture_data = vec![];
                    for j in start_y as usize..end_y as usize {
                        let start_line = (start_x as usize + j * texture_size.width as usize) * 4;
                        let end_line = (end_x as usize + j * texture_size.width as usize) * 4;
                        patch_texture_data.extend_from_slice(&texture_data[start_line..end_line]);
                    }

                    let patch_texture = Image::new(
                        Extent3d {
                            width: to_width(column_item.original_size, texture_size),
                            height: to_height(column_item.original_size, texture_size),
                            depth_or_array_layers: texture_size.depth_or_array_layers,
                        },
                        TextureDimension::D2,
                        patch_texture_data,
                        TextureFormat::Rgba8UnormSrgb,
                    );
                    textures_to_add.push(patch_texture);
                    accu_x += to_width(column_item.original_size, texture_size);
                }
                accu_y += to_height(row[0].original_size, texture_size);
            }
            textures_to_add.into_iter().for_each(|patch_texture| {
                let patch_texture_handle = textures.add(patch_texture);
                patch_textures.push(patch_texture_handle);
            });
            self.patch_textures = Some(patch_textures);
            self.original_texture = Some(texture_handle.clone());
        }
        NinePatch {
            patches: self.patches.clone(),
            texture_size,
            // background: materials.add(Color::NONE.into()),
            splitted_texture: self.patch_textures.as_ref().cloned().unwrap(),
        }
    }
/// Apply a `NinePatchBuilder` to a texture to get a `NinePatch` ready to be added to entities. This will split
/// the given texture according to the patches.
Apply a `NinePatchBuilder` to a texture to get a `NinePatch` ready to be added to entities. This will split
the given texture according to the patches.
Apply a ` NinePatchBuilder ` to a texture to get a ` NinePatch ` ready to be added to entities . This will split the given texture according to the patches .
pub fn apply(
        &mut self,
        texture_handle: &Handle<Image>,
        textures: &mut Assets<Image>,
    ) -> NinePatch<T> {
        let (texture_size, texture_data) = {
            let t = textures
                .get(texture_handle)
                .expect("could not get texture from handle");
            (t.texture_descriptor.size, &t.data)
        };
        let mut textures_to_add = vec![];
        if self.patch_textures.is_none() || self.original_texture.as_ref() != Some(texture_handle) {
            let mut patch_textures = vec![];
            let mut accu_y = 0;
            for row in &self.patches {
                let mut accu_x = 0;
                for column_item in row {
                    let start_x = accu_x;
                    let end_x = accu_x + to_width(column_item.original_size, texture_size);
                    let start_y = accu_y;
                    let end_y = accu_y + to_height(column_item.original_size, texture_size);
                    let mut patch_texture_data = vec![];
                    for j in start_y as usize..end_y as usize {
                        let start_line = (start_x as usize + j * texture_size.width as usize) * 4;
                        let end_line = (end_x as usize + j * texture_size.width as usize) * 4;
                        patch_texture_data.extend_from_slice(&texture_data[start_line..end_line]);
                    }
                    let patch_texture = Image::new(
                        Extent3d {
                            width: to_width(column_item.original_size, texture_size),
                            height: to_height(column_item.original_size, texture_size),
                            depth_or_array_layers: texture_size.depth_or_array_layers,
                        },
                        TextureDimension::D2,
                        patch_texture_data,
                        TextureFormat::Rgba8UnormSrgb,
                    );
                    textures_to_add.push(patch_texture);
                    accu_x += to_width(column_item.original_size, texture_size);
                }
                accu_y += to_height(row[0].original_size, texture_size);
            }
            textures_to_add.into_iter().for_each(|patch_texture| {
                let patch_texture_handle = textures.add(patch_texture);
                patch_textures.push(patch_texture_handle);
            });
            self.patch_textures = Some(patch_textures);
            self.original_texture = Some(texture_handle.clone());
        }
        NinePatch {
            patches: self.patches.clone(),
            texture_size,
            // background: materials.add(Color::NONE.into()),
            splitted_texture: self.patch_textures.as_ref().cloned().unwrap(),
        }
    }
pub fn apply ( & mut self , texture_handle : & Handle < Image > , textures : & mut Assets < Image > , ) -> NinePatch < T > { let ( texture_size , texture_data ) = { let t = textures . get ( texture_handle ) . expect ( " " ) ; ( t . texture_descriptor . size , & t . data ) } ; let mut textures_to_add = vec ! [ ] ; if self . patch_textures . is_none ( ) || self . original_texture . as_ref ( ) != Some ( texture_handle ) { let mut patch_textures = vec ! [ ] ; let mut accu_y = 0 ; for row in & self . patches { let mut accu_x = 0 ; for column_item in row { let start_x = accu_x ; let end_x = accu_x + to_width ( column_item . original_size , texture_size ) ; let start_y = accu_y ; let end_y = accu_y + to_height ( column_item . original_size , texture_size ) ; let mut patch_texture_data = vec ! [ ] ; for j in start_y as usize .. end_y as usize { let start_line = ( start_x as usize + j * texture_size . width as usize ) * 4 ; let end_line = ( end_x as usize + j * texture_size . width as usize ) * 4 ; patch_texture_data . extend_from_slice ( & texture_data [ start_line .. end_line ] ) ; } let patch_texture = Image :: new ( Extent3d { width : to_width ( column_item . original_size , texture_size ) , height : to_height ( column_item . original_size , texture_size ) , depth_or_array_layers : texture_size . depth_or_array_layers , } , TextureDimension :: D2 , patch_texture_data , TextureFormat :: Rgba8UnormSrgb , ) ; textures_to_add . push ( patch_texture ) ; accu_x += to_width ( column_item . original_size , texture_size ) ; } accu_y += to_height ( row [ 0 ] . original_size , texture_size ) ; } textures_to_add . into_iter ( ) . for_each ( | patch_texture | { let patch_texture_handle = textures . add ( patch_texture ) ; patch_textures . push ( patch_texture_handle ) ; } ) ; self . patch_textures = Some ( patch_textures ) ; self . original_texture = Some ( texture_handle . clone ( ) ) ; } NinePatch { patches : self . patches . clone ( ) , texture_size , // background: materials.add(Color::NONE.into()), splitted_texture : self . patch_textures . as_ref ( ) . cloned ( ) . unwrap ( ) , } }
Apply a `NinePatchBuilder` to a texture to get a `NinePatch` ready to be added to entities.
Apply a ` NinePatchBuilder ` to a texture to get a ` NinePatch ` ready to be added to entities .
&mut self
texture_handle
&Handle<Image>
textures
&mut Assets<Image>