diff --git a/packages/tui/examples/tui_buttons.rs b/packages/tui/examples/tui_buttons.rs index bd9f3da13..852dd1d94 100644 --- a/packages/tui/examples/tui_buttons.rs +++ b/packages/tui/examples/tui_buttons.rs @@ -23,8 +23,8 @@ fn Button(cx: Scope) -> Element { cx.render(rsx! { div{ - width: "20px", - height: "5px", + width: "100%", + height: "100%", background_color: "{color}", tabindex: "{cx.props.layer}", onkeydown: |e| { @@ -70,8 +70,8 @@ fn app(cx: Scope) -> Element { if (x + y) % 2 == 0{ rsx!{ div{ - width: "20px", - height: "5px", + width: "100%", + height: "100%", background_color: "rgb(100, 100, 100)", } } diff --git a/packages/tui/src/layout.rs b/packages/tui/src/layout.rs index 54513268f..1e14f159c 100644 --- a/packages/tui/src/layout.rs +++ b/packages/tui/src/layout.rs @@ -1,6 +1,5 @@ use std::sync::{Arc, Mutex}; -use dioxus_core::*; use dioxus_native_core::layout_attributes::apply_layout_attributes; use dioxus_native_core::node::OwnedAttributeView; use dioxus_native_core::node_ref::{AttributeMask, NodeMask, NodeView}; @@ -98,12 +97,6 @@ impl ChildDepState for TaffyLayout { } } - // the root node fills the entire area - if node.id() == Some(ElementId(0)) { - apply_layout_attributes("width", "100%", &mut style); - apply_layout_attributes("height", "100%", &mut style); - } - // Set all direct nodes as our children let mut child_layout = vec![]; for (l,) in children { diff --git a/packages/tui/src/lib.rs b/packages/tui/src/lib.rs index 8b35ac54c..e3ac36ba6 100644 --- a/packages/tui/src/lib.rs +++ b/packages/tui/src/lib.rs @@ -152,14 +152,24 @@ fn render_vdom( let width = dims.width; let height = dims.height; let root_node = rdom[NodeId(0)].state.layout.node.unwrap(); - - taffy + + // the root node fills the entire area + + let mut style=*taffy.style(root_node).unwrap(); + style.size=Size { + width: Dimension::Points(width as f32), + height: Dimension::Points(height as f32), + }; + taffy.set_style(root_node, style).unwrap(); + + let size =Size { + width: AvailableSpace::Definite(width as f32), + height: AvailableSpace::Definite(height as f32), + }; + taffy .compute_layout( root_node, - Size { - width: AvailableSpace::Definite((width - 1) as f32), - height: AvailableSpace::Definite((height - 1) as f32), - }, + size ) .unwrap(); }