Merge pull request #10 from Demonthos/master

fixed resize race condition and stop rendering for zero sized nodes
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2022-02-04 23:46:53 -05:00
commit 4fe66dbf64
2 files changed
+21 -14

No files matched your search

+13 -12
View File
@@ -84,10 +84,6 @@ pub fn render_vdom(vdom: &mut VirtualDom, ctx: UnboundedSender<TermEvent>) -> Re
terminal.clear().unwrap();
loop {
let dims = terminal.size().unwrap();
let width = dims.width;
let height = dims.height;
/*
-> collect all the nodes with their layout
-> solve their layout
@@ -110,16 +106,21 @@ pub fn render_vdom(vdom: &mut VirtualDom, ctx: UnboundedSender<TermEvent>) -> Re
*/
let node_id = root_node.try_mounted_id().unwrap();
let root_layout = nodes[&node_id].layout;
layout.compute_layout(
root_layout,
Size {
width: stretch2::prelude::Number::Defined(width as f32),
height: stretch2::prelude::Number::Defined(height as f32),
},
)?;
terminal.draw(|frame| {
//
// size is guaranteed to not change when rendering
let dims = frame.size();
let width = dims.width;
let height = dims.height;
layout
.compute_layout(
root_layout,
Size {
width: stretch2::prelude::Number::Defined(width as f32),
height: stretch2::prelude::Number::Defined(height as f32),
},
)
.unwrap();
render::render_vnode(frame, &layout, &mut nodes, vdom, root_node);
assert!(nodes.is_empty());
})?;
+8 -2
View File
@@ -70,13 +70,19 @@ pub fn render_vnode<'a>(
let label = Label { text: t.text };
let area = Rect::new(*x as u16, *y as u16, *width as u16, *height as u16);
frame.render_widget(label, area);
// 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 {
frame.render_widget(label, area);
}
}
VNode::Element(el) => {
let block = Block::default().style(node.block_style);
let area = Rect::new(*x as u16, *y as u16, *width as u16, *height as u16);
frame.render_widget(block, area);
// 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 {
frame.render_widget(block, area);
}
for el in el.children {
render_vnode(frame, layout, layouts, vdom, el);