Fix crash when printing some text

This commit is contained in:
Joscha 2024-03-17 17:35:44 +01:00
parent 4f3d66f6a0
commit d69557daf6
2 changed files with 32 additions and 10 deletions

View file

@ -40,24 +40,34 @@ impl<'a> View<'a> {
}
pub fn get(&self, pos: Vec2) -> Option<Srgba> {
let (x, y) = self.pos_to_buffer_pos(pos).to_u32();
let (x, y) = self.pos_to_buffer_pos(pos).to_u32_checked()?;
let pixel = self.buffer.get_pixel_checked(x, y)?;
Some(color::from_image_color(*pixel))
}
pub fn set(&mut self, pos: Vec2, color: Srgba) {
let (x, y) = self.pos_to_buffer_pos(pos).to_u32();
if let Some(pixel) = self.buffer.get_pixel_mut_checked(x, y) {
let below = color::from_image_color(*pixel);
*pixel = color::to_image_color(color.atop(below));
}
let Some((x, y)) = self.pos_to_buffer_pos(pos).to_u32_checked() else {
return;
};
let Some(pixel) = self.buffer.get_pixel_mut_checked(x, y) else {
return;
};
let below = color::from_image_color(*pixel);
*pixel = color::to_image_color(color.atop(below));
}
pub fn replace(&mut self, pos: Vec2, color: Srgba) {
let (x, y) = self.pos_to_buffer_pos(pos).to_u32();
if let Some(pixel) = self.buffer.get_pixel_mut_checked(x, y) {
*pixel = color::to_image_color(color);
}
let Some((x, y)) = self.pos_to_buffer_pos(pos).to_u32_checked() else {
return;
};
let Some(pixel) = self.buffer.get_pixel_mut_checked(x, y) else {
return;
};
*pixel = color::to_image_color(color);
}
// More complicated drawing primitives