ignore out of bounds renders

This commit is contained in:
Evan Almloff committed 2022-12-05 20:30:05 -06:00
1 parent a823b45af9
commit 57ef56511c
3 files changed
+16 -8

No files matched your search

+2 -2
View File
@@ -158,12 +158,12 @@ fn render_vdom(
let mut style=*taffy.style(root_node).unwrap();
style.size=Size {
width: Dimension::Points(width as f32),
height: Dimension::Points(height as f32),
height: Dimension::Points(height as f32),
};
taffy.set_style(root_node, style).unwrap();
let size =Size {
width: AvailableSpace::Definite(width as f32),
width: AvailableSpace::Definite(width as f32),
height: AvailableSpace::Definite(height as f32),
};
taffy
+11 -4
View File
@@ -36,8 +36,15 @@ pub(crate) fn render_vnode(
location.x += parent_location.x;
location.y += parent_location.y;
let Point { x, y } = location;
let Size { width, height } = size;
let Point { mut x, mut y } = location;
x = x.floor();
y = y.floor();
let Size {
mut width,
mut height,
} = size;
width = width.ceil();
height = height.ceil();
match &node.node_data.node_type {
NodeType::Text { text } => {
@@ -62,7 +69,7 @@ pub(crate) fn render_vnode(
text,
style: node.state.style.core,
};
let area = Rect::new(x as u16, y as u16, *width as u16, *height as u16);
let area = Rect::new(x as u16, y as u16, width as u16, height as u16);
// the renderer will panic if a node is rendered out of range even if the size is zero
if area.width > 0 && area.height > 0 {
@@ -70,7 +77,7 @@ pub(crate) fn render_vnode(
}
}
NodeType::Element { .. } => {
let area = Rect::new(x as u16, y as u16, *width as u16, *height as u16);
let area = Rect::new(x as u16, y as u16, width as u16, height as u16);
// the renderer will panic if a node is rendered out of range even if the size is zero
if area.width > 0 && area.height > 0 {
+3 -2
View File
@@ -22,8 +22,9 @@ impl<'a> RinkBuffer<'a> {
pub fn set(&mut self, x: u16, y: u16, new: RinkCell) {
let area = self.buf.area();
if x < area.x || x > area.width || y < area.y || y > area.height {
panic!("({x}, {y}) is not in {area:?}");
if x < area.x || x >= area.width + area.x || y < area.y || y >= area.height + area.y {
// panic!("({x}, {y}) is not in {area:?}");
return;
}
let mut cell = self.buf.get_mut(x, y);
cell.bg = convert(self.cfg.rendering_mode, new.bg.blend(cell.bg));