From 57ef56511cd9a15e3aa865922cafb17001bb3deb Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Mon, 5 Dec 2022 20:30:05 -0600 Subject: [PATCH] ignore out of bounds renders --- packages/tui/src/lib.rs | 4 ++-- packages/tui/src/render.rs | 15 +++++++++++---- packages/tui/src/widget.rs | 5 +++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/tui/src/lib.rs b/packages/tui/src/lib.rs index e3ac36ba6..cb000f00e 100644 --- a/packages/tui/src/lib.rs +++ b/packages/tui/src/lib.rs @@ -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 diff --git a/packages/tui/src/render.rs b/packages/tui/src/render.rs index 7beb543e2..d779418fa 100644 --- a/packages/tui/src/render.rs +++ b/packages/tui/src/render.rs @@ -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 { diff --git a/packages/tui/src/widget.rs b/packages/tui/src/widget.rs index 416538462..7c6645692 100644 --- a/packages/tui/src/widget.rs +++ b/packages/tui/src/widget.rs @@ -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));