dioxus/examples/layouts.rs

53 lines
1.2 KiB
Rust
Raw Normal View History

2022-01-01 04:53:37 +00:00
use std::collections::HashMap;
2022-02-04 22:57:00 +00:00
use dioxus::prelude::*;
2022-01-01 04:53:37 +00:00
fn main() {
let mut dom = VirtualDom::new(app);
dom.rebuild();
let mut layout = stretch2::Stretch::new();
let mut nodes = HashMap::new();
rink::collect_layout(&mut layout, &mut nodes, &dom, dom.base_scope().root_node());
let node = nodes
.remove(&dom.base_scope().root_node().mounted_id())
.unwrap();
layout
.compute_layout(node.layout, stretch2::geometry::Size::undefined())
.unwrap();
2022-02-04 22:57:00 +00:00
for (_id, node) in nodes.drain() {
2022-01-01 04:53:37 +00:00
println!("{:?}", layout.layout(node.layout));
}
}
fn app(cx: Scope) -> Element {
cx.render(rsx! {
div {
width: "100%",
height: "100%",
flex_direction: "column",
div {
"hi"
}
div {
"bi"
"bi"
}
}
})
}
// fn print_layout(mut nodes: HashMap<ElementId, TuiNode>, node: &VNode) {
// match node {
// VNode::Text(_) => todo!(),
// VNode::Element(_) => todo!(),
// VNode::Fragment(_) => todo!(),
// VNode::Component(_) => todo!(),
// VNode::Placeholder(_) => todo!(),
// }
// }