Przeglądaj źródła

ignore out of bounds renders

Evan Almloff 2 lat temu
rodzic
commit
57ef56511c
3 zmienionych plików z 16 dodań i 8 usunięć
  1. 2 2
      packages/tui/src/lib.rs
  2. 11 4
      packages/tui/src/render.rs
  3. 3 2
      packages/tui/src/widget.rs

+ 2 - 2
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

+ 11 - 4
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 {

+ 3 - 2
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));