Tries to insert RGBA data into the atlas, and returns the position. If the data will not fit into the remaining space, `None` will be returned.
(
&mut self,
data: &[u8],
width: i32,
height: i32,
padding: i32,
)
| 35 | /// |
| 36 | /// If the data will not fit into the remaining space, `None` will be returned. |
| 37 | pub fn insert( |
| 38 | &mut self, |
| 39 | data: &[u8], |
| 40 | width: i32, |
| 41 | height: i32, |
| 42 | padding: i32, |
| 43 | ) -> Option<IRectangle> { |
| 44 | let padded_width = width + padding * 2; |
| 45 | let padded_height = height + padding * 2; |
| 46 | |
| 47 | let space = self.find_space(padded_width, padded_height); |
| 48 | |
| 49 | if let Some(s) = space { |
| 50 | self.texture |
| 51 | .set_region(s.x + padding, s.y + padding, width, height, data); |
| 52 | } |
| 53 | |
| 54 | space |
| 55 | } |
| 56 | |
| 57 | /// Finds a space in the atlas that can fit a sprite of the specified width and height, |
| 58 | /// and returns the position. |